Skip to content

Commit

Permalink
De-share trait_ref
Browse files Browse the repository at this point in the history
Also, makes the pretty-printer use & instead of @ as much as possible,
which will help with later changes, though in the interim has produced
some... interesting constructs.
  • Loading branch information
James Miller committed Jul 7, 2013
1 parent 62c83bb commit 97c5a44
Show file tree
Hide file tree
Showing 19 changed files with 128 additions and 127 deletions.
4 changes: 2 additions & 2 deletions src/librustc/front/config.rs
Expand Up @@ -98,10 +98,10 @@ fn fold_foreign_mod(
fn fold_item_underscore(cx: @Context, item: &ast::item_,
fld: @fold::ast_fold) -> ast::item_ {
let item = match *item {
ast::item_impl(ref a, b, c, ref methods) => {
ast::item_impl(ref a, ref b, c, ref methods) => {
let methods = methods.iter().filter(|m| method_in_cfg(cx, **m))
.transform(|x| *x).collect();
ast::item_impl(/*bad*/ copy *a, b, c, methods)
ast::item_impl(/*bad*/ copy *a, /*bad*/ copy *b, c, methods)
}
ast::item_trait(ref a, ref b, ref methods) => {
let methods = methods.iter().filter(|m| trait_method_in_cfg(cx, *m) )
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/metadata/decoder.rs
Expand Up @@ -1141,7 +1141,7 @@ fn list_crate_attributes(intr: @ident_interner, md: ebml::Doc, hash: &str,

let r = get_attributes(md);
for r.iter().advance |attr| {
out.write_str(fmt!("%s\n", pprust::attribute_to_str(*attr, intr)));
out.write_str(fmt!("%s\n", pprust::attribute_to_str(attr, intr)));
}

out.write_str("\n\n");
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/metadata/encoder.rs
Expand Up @@ -1003,7 +1003,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
index);
}
}
item_impl(ref generics, opt_trait, ty, ref methods) => {
item_impl(ref generics, ref opt_trait, ty, ref methods) => {
add_to_index();
ebml_w.start_tag(tag_items_data_item);
encode_def_id(ebml_w, local_def(item.id));
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/kind.rs
Expand Up @@ -117,7 +117,7 @@ fn check_item(item: @item, (cx, visitor): (Context, visit::vt<Context>)) {
// If this is a destructor, check kinds.
if !attrs_contains_name(item.attrs, "unsafe_destructor") {
match item.node {
item_impl(_, Some(trait_ref), self_type, _) => {
item_impl(_, Some(ref trait_ref), self_type, _) => {
match cx.tcx.def_map.find(&trait_ref.ref_id) {
None => cx.tcx.sess.bug("trait ref not in def map!"),
Some(&trait_def) => {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/reachable.rs
Expand Up @@ -141,7 +141,7 @@ impl ReachableContext {
}
}
}
item_impl(ref generics, trait_ref, _, ref methods) => {
item_impl(ref generics, ref trait_ref, _, ref methods) => {
// XXX(pcwalton): We conservatively assume any methods
// on a trait implementation are reachable, when this
// is not the case. We could be more precise by only
Expand Down
10 changes: 5 additions & 5 deletions src/librustc/middle/resolve.rs
Expand Up @@ -3533,7 +3533,7 @@ impl Resolver {
}

item_impl(ref generics,
implemented_traits,
ref implemented_traits,
self_type,
ref methods) => {
self.resolve_implementation(item.id,
Expand Down Expand Up @@ -3811,7 +3811,7 @@ impl Resolver {
type_parameter_bound: &TyParamBound,
visitor: ResolveVisitor) {
match *type_parameter_bound {
TraitTyParamBound(tref) => {
TraitTyParamBound(ref tref) => {
self.resolve_trait_reference(tref, visitor, TraitBoundingTypeParameter)
}
RegionTyParamBound => {}
Expand Down Expand Up @@ -3913,7 +3913,7 @@ impl Resolver {
pub fn resolve_implementation(@mut self,
id: node_id,
generics: &Generics,
opt_trait_reference: Option<@trait_ref>,
opt_trait_reference: &Option<trait_ref>,
self_type: @Ty,
methods: &[@method],
visitor: ResolveVisitor) {
Expand All @@ -3929,7 +3929,7 @@ impl Resolver {
// Resolve the trait reference, if necessary.
let original_trait_refs;
match opt_trait_reference {
Some(trait_reference) => {
&Some(ref trait_reference) => {
self.resolve_trait_reference(trait_reference, visitor, TraitImplementation);

// Record the current set of trait references.
Expand All @@ -3944,7 +3944,7 @@ impl Resolver {
&mut self.current_trait_refs,
Some(new_trait_refs)));
}
None => {
&None => {
original_trait_refs = None;
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/middle/ty.rs
Expand Up @@ -3624,12 +3624,12 @@ pub fn impl_trait_ref(cx: ctxt, id: ast::def_id) -> Option<@TraitRef> {
debug!("(impl_trait_ref) searching for trait impl %?", id);
match cx.items.find(&id.node) {
Some(&ast_map::node_item(@ast::item {
node: ast::item_impl(_, opt_trait, _, _),
node: ast::item_impl(_, ref opt_trait, _, _),
_},
_)) => {
match opt_trait {
Some(t) => Some(ty::node_id_to_trait_ref(cx, t.ref_id)),
None => None
&Some(ref t) => Some(ty::node_id_to_trait_ref(cx, t.ref_id)),
&None => None
}
}
_ => None
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/typeck/astconv.rs
Expand Up @@ -764,7 +764,7 @@ fn conv_builtin_bounds(tcx: ty::ctxt, ast_bounds: &Option<OptVec<ast::TyParamBou
let mut builtin_bounds = ty::EmptyBuiltinBounds();
for bound_vec.iter().advance |ast_bound| {
match *ast_bound {
ast::TraitTyParamBound(b) => {
ast::TraitTyParamBound(ref b) => {
match lookup_def_tcx(tcx, b.path.span, b.ref_id) {
ast::def_trait(trait_did) => {
if try_add_builtin_trait(tcx,
Expand Down
18 changes: 10 additions & 8 deletions src/librustc/middle/typeck/coherence.rs
Expand Up @@ -207,9 +207,11 @@ impl CoherenceChecker {
// self.crate_context.tcx.sess.str_of(item.ident));

match item.node {
item_impl(_, opt_trait, _, _) => {
self.check_implementation(item,
opt_trait.iter().transform(|&x| x).collect());
item_impl(_, ref opt_trait, _, _) => {
let opt_trait : ~[trait_ref] = opt_trait.iter()
.transform(|&x| x)
.collect();
self.check_implementation(item, opt_trait);
}
_ => {
// Nothing to do.
Expand Down Expand Up @@ -238,7 +240,7 @@ impl CoherenceChecker {

pub fn check_implementation(&self,
item: @item,
associated_traits: ~[@trait_ref]) {
associated_traits: &[trait_ref]) {
let tcx = self.crate_context.tcx;
let self_type = ty::lookup_item_type(tcx, local_def(item.id));

Expand Down Expand Up @@ -646,7 +648,7 @@ impl CoherenceChecker {
a trait or new type instead");
}
}
item_impl(_, Some(trait_ref), _, _) => {
item_impl(_, Some(ref trait_ref), _, _) => {
// `for_ty` is `Type` in `impl Trait for Type`
let for_ty =
ty::node_id_to_type(self.crate_context.tcx,
Expand Down Expand Up @@ -678,7 +680,7 @@ impl CoherenceChecker {
})));
}

pub fn trait_ref_to_trait_def_id(&self, trait_ref: @trait_ref) -> def_id {
pub fn trait_ref_to_trait_def_id(&self, trait_ref: &trait_ref) -> def_id {
let def_map = self.crate_context.tcx.def_map;
let trait_def = def_map.get_copy(&trait_ref.ref_id);
let trait_id = def_id_of_def(trait_def);
Expand Down Expand Up @@ -805,7 +807,7 @@ impl CoherenceChecker {
// Check that we have implementations of every trait method
for trait_refs.iter().advance |trait_ref| {
let trait_did =
self.trait_ref_to_trait_def_id(*trait_ref);
self.trait_ref_to_trait_def_id(trait_ref);
self.please_check_that_trait_methods_are_implemented(
&mut methods,
trait_did,
Expand All @@ -817,7 +819,7 @@ impl CoherenceChecker {
// if a method of that name is not inherent to the
// impl, use the provided definition in the trait.
for trait_refs.iter().advance |trait_ref| {
let trait_did = self.trait_ref_to_trait_def_id(*trait_ref);
let trait_did = self.trait_ref_to_trait_def_id(trait_ref);
self.add_provided_methods_to_impl(
&mut methods,
&trait_did,
Expand Down
14 changes: 7 additions & 7 deletions src/librustc/middle/typeck/collect.rs
Expand Up @@ -378,15 +378,15 @@ pub fn ensure_supertraits(ccx: &CrateCtxt,
id: ast::node_id,
sp: codemap::span,
rp: Option<ty::region_variance>,
ast_trait_refs: &[@ast::trait_ref],
ast_trait_refs: &[ast::trait_ref],
generics: &ast::Generics)
{
let tcx = ccx.tcx;
if tcx.supertraits.contains_key(&local_def(id)) { return; }

let self_ty = ty::mk_self(ccx.tcx, local_def(id));
let mut ty_trait_refs: ~[@ty::TraitRef] = ~[];
for ast_trait_refs.iter().advance |&ast_trait_ref| {
for ast_trait_refs.iter().advance |ast_trait_ref| {
let trait_ref = instantiate_trait_ref(ccx, ast_trait_ref, rp,
generics, self_ty);

Expand Down Expand Up @@ -441,7 +441,7 @@ pub fn compare_impl_method(tcx: ty::ctxt,
fmt!("method `%s` has a `%s` declaration in the impl, \
but not in the trait",
tcx.sess.str_of(trait_m.ident),
explicit_self_to_str(impl_m.explicit_self, tcx.sess.intr())));
explicit_self_to_str(&impl_m.explicit_self, tcx.sess.intr())));
return;
}
(_, &ast::sty_static) => {
Expand All @@ -450,7 +450,7 @@ pub fn compare_impl_method(tcx: ty::ctxt,
fmt!("method `%s` has a `%s` declaration in the trait, \
but not in the impl",
tcx.sess.str_of(trait_m.ident),
explicit_self_to_str(trait_m.explicit_self, tcx.sess.intr())));
explicit_self_to_str(&trait_m.explicit_self, tcx.sess.intr())));
return;
}
_ => {
Expand Down Expand Up @@ -813,7 +813,7 @@ pub fn convert(ccx: &CrateCtxt, it: &ast::item) {
generics,
rp);
}
ast::item_impl(ref generics, opt_trait_ref, selfty, ref ms) => {
ast::item_impl(ref generics, ref opt_trait_ref, selfty, ref ms) => {
let i_ty_generics = ty_generics(ccx, rp, generics, 0);
let region_parameterization =
RegionParameterization::from_variance_and_generics(rp, generics);
Expand All @@ -839,7 +839,7 @@ pub fn convert(ccx: &CrateCtxt, it: &ast::item) {
&i_ty_generics, generics,
parent_visibility);
for opt_trait_ref.iter().advance |t| {
check_methods_against_trait(ccx, generics, rp, selfty, *t, cms);
check_methods_against_trait(ccx, generics, rp, selfty, t, cms);
}
}
ast::item_trait(ref generics, ref supertraits, ref trait_methods) => {
Expand Down Expand Up @@ -1184,7 +1184,7 @@ pub fn ty_generics(ccx: &CrateCtxt,
};
for ast_bounds.iter().advance |ast_bound| {
match *ast_bound {
TraitTyParamBound(b) => {
TraitTyParamBound(ref b) => {
let ty = ty::mk_param(ccx.tcx, param_ty.idx, param_ty.def_id);
let trait_ref = instantiate_trait_ref(ccx, b, rp, generics, ty);
if !astconv::try_add_builtin_trait(
Expand Down
6 changes: 3 additions & 3 deletions src/libsyntax/ast.rs
Expand Up @@ -132,7 +132,7 @@ pub static crate_node_id: node_id = 0;
// the "special" built-in traits (see middle::lang_items) and
// detects Copy, Send, Send, and Freeze.
pub enum TyParamBound {
TraitTyParamBound(@trait_ref),
TraitTyParamBound(trait_ref),
RegionTyParamBound
}

Expand Down Expand Up @@ -1002,9 +1002,9 @@ pub enum item_ {
item_ty(@Ty, Generics),
item_enum(enum_def, Generics),
item_struct(@struct_def, Generics),
item_trait(Generics, ~[@trait_ref], ~[trait_method]),
item_trait(Generics, ~[trait_ref], ~[trait_method]),
item_impl(Generics,
Option<@trait_ref>, // (optional) trait this impl implements
Option<trait_ref>, // (optional) trait this impl implements
@Ty, // self
~[@method]),
// a macro invocation (which includes macro definition)
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ast_util.rs
Expand Up @@ -580,7 +580,7 @@ pub fn view_path_id(p: &view_path) -> node_id {

/// Returns true if the given struct def is tuple-like; i.e. that its fields
/// are unnamed.
pub fn struct_def_is_tuple_like(struct_def: @ast::struct_def) -> bool {
pub fn struct_def_is_tuple_like(struct_def: &ast::struct_def) -> bool {
struct_def.ctor_id.is_some()
}

Expand Down
6 changes: 3 additions & 3 deletions src/libsyntax/ext/build.rs
Expand Up @@ -68,7 +68,7 @@ pub trait AstBuilder {

fn typaram(&self, id: ast::ident, bounds: @OptVec<ast::TyParamBound>) -> ast::TyParam;

fn trait_ref(&self, path: ast::Path) -> @ast::trait_ref;
fn trait_ref(&self, path: ast::Path) -> ast::trait_ref;
fn typarambound(&self, path: ast::Path) -> ast::TyParamBound;
fn lifetime(&self, span: span, ident: ast::ident) -> ast::Lifetime;

Expand Down Expand Up @@ -358,8 +358,8 @@ impl AstBuilder for @ExtCtxt {
}
}

fn trait_ref(&self, path: ast::Path) -> @ast::trait_ref {
@ast::trait_ref {
fn trait_ref(&self, path: ast::Path) -> ast::trait_ref {
ast::trait_ref {
path: path,
ref_id: self.next_id()
}
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ext/log_syntax.rs
Expand Up @@ -26,7 +26,7 @@ pub fn expand_syntax_ext(cx: @ExtCtxt,
cx.print_backtrace();
io::stdout().write_line(
print::pprust::tt_to_str(
ast::tt_delim(vec::to_owned(tt)),
&ast::tt_delim(vec::to_owned(tt)),
get_ident_interner()));

//trivial expression
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ext/tt/macro_rules.rs
Expand Up @@ -82,7 +82,7 @@ pub fn add_new_extension(cx: @ExtCtxt,
io::println(fmt!("%s! { %s }",
cx.str_of(name),
print::pprust::tt_to_str(
ast::tt_delim(vec::to_owned(arg)),
&ast::tt_delim(vec::to_owned(arg)),
get_ident_interner())));
}

Expand Down
12 changes: 6 additions & 6 deletions src/libsyntax/fold.rs
Expand Up @@ -162,7 +162,7 @@ pub fn fold_fn_decl(decl: &ast::fn_decl, fld: @ast_fold) -> ast::fn_decl {

fn fold_ty_param_bound(tpb: &TyParamBound, fld: @ast_fold) -> TyParamBound {
match *tpb {
TraitTyParamBound(ty) => TraitTyParamBound(fold_trait_ref(ty, fld)),
TraitTyParamBound(ref ty) => TraitTyParamBound(fold_trait_ref(ty, fld)),
RegionTyParamBound => RegionTyParamBound
}
}
Expand Down Expand Up @@ -296,10 +296,10 @@ pub fn noop_fold_item_underscore(i: &item_, fld: @ast_fold) -> item_ {
let struct_def = fold_struct_def(*struct_def, fld);
item_struct(struct_def, /* FIXME (#2543) */ copy *generics)
}
item_impl(ref generics, ifce, ty, ref methods) => {
item_impl(ref generics, ref ifce, ty, ref methods) => {
item_impl(
fold_generics(generics, fld),
ifce.map(|p| fold_trait_ref(*p, fld)),
ifce.map(|p| fold_trait_ref(p, fld)),
fld.fold_ty(ty),
methods.map(|x| fld.fold_method(*x))
)
Expand All @@ -313,7 +313,7 @@ pub fn noop_fold_item_underscore(i: &item_, fld: @ast_fold) -> item_ {
};
item_trait(
fold_generics(generics, fld),
traits.map(|p| fold_trait_ref(*p, fld)),
traits.map(|p| fold_trait_ref(p, fld)),
methods
)
}
Expand All @@ -335,8 +335,8 @@ fn fold_struct_def(struct_def: @ast::struct_def, fld: @ast_fold)
}
}

fn fold_trait_ref(p: @trait_ref, fld: @ast_fold) -> @trait_ref {
@ast::trait_ref {
fn fold_trait_ref(p: &trait_ref, fld: @ast_fold) -> trait_ref {
ast::trait_ref {
path: fld.fold_path(&p.path),
ref_id: fld.new_id(p.ref_id),
}
Expand Down
8 changes: 4 additions & 4 deletions src/libsyntax/parse/parser.rs
Expand Up @@ -3566,7 +3566,7 @@ impl Parser {
// New-style trait. Reinterpret the type as a trait.
let opt_trait_ref = match ty.node {
ty_path(ref path, @None, node_id) => {
Some(@trait_ref {
Some(trait_ref {
path: /* bad */ copy *path,
ref_id: node_id
})
Expand Down Expand Up @@ -3608,15 +3608,15 @@ impl Parser {
}

// parse a::B<~str,int>
fn parse_trait_ref(&self) -> @trait_ref {
@ast::trait_ref {
fn parse_trait_ref(&self) -> trait_ref {
ast::trait_ref {
path: self.parse_path_with_tps(false),
ref_id: self.get_id(),
}
}

// parse B + C<~str,int> + D
fn parse_trait_ref_list(&self, ket: &token::Token) -> ~[@trait_ref] {
fn parse_trait_ref_list(&self, ket: &token::Token) -> ~[trait_ref] {
self.parse_seq_to_before_end(
ket,
seq_sep_trailing_disallowed(token::BINOP(token::PLUS)),
Expand Down

0 comments on commit 97c5a44

Please sign in to comment.