Skip to content

Commit 97c5a44

Browse files
author
James Miller
committed
De-share trait_ref
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.
1 parent 62c83bb commit 97c5a44

File tree

19 files changed

+128
-127
lines changed

19 files changed

+128
-127
lines changed

src/librustc/front/config.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,10 @@ fn fold_foreign_mod(
9898
fn fold_item_underscore(cx: @Context, item: &ast::item_,
9999
fld: @fold::ast_fold) -> ast::item_ {
100100
let item = match *item {
101-
ast::item_impl(ref a, b, c, ref methods) => {
101+
ast::item_impl(ref a, ref b, c, ref methods) => {
102102
let methods = methods.iter().filter(|m| method_in_cfg(cx, **m))
103103
.transform(|x| *x).collect();
104-
ast::item_impl(/*bad*/ copy *a, b, c, methods)
104+
ast::item_impl(/*bad*/ copy *a, /*bad*/ copy *b, c, methods)
105105
}
106106
ast::item_trait(ref a, ref b, ref methods) => {
107107
let methods = methods.iter().filter(|m| trait_method_in_cfg(cx, *m) )

src/librustc/metadata/decoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1141,7 +1141,7 @@ fn list_crate_attributes(intr: @ident_interner, md: ebml::Doc, hash: &str,
11411141

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

11471147
out.write_str("\n\n");

src/librustc/metadata/encoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1003,7 +1003,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
10031003
index);
10041004
}
10051005
}
1006-
item_impl(ref generics, opt_trait, ty, ref methods) => {
1006+
item_impl(ref generics, ref opt_trait, ty, ref methods) => {
10071007
add_to_index();
10081008
ebml_w.start_tag(tag_items_data_item);
10091009
encode_def_id(ebml_w, local_def(item.id));

src/librustc/middle/kind.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ fn check_item(item: @item, (cx, visitor): (Context, visit::vt<Context>)) {
117117
// If this is a destructor, check kinds.
118118
if !attrs_contains_name(item.attrs, "unsafe_destructor") {
119119
match item.node {
120-
item_impl(_, Some(trait_ref), self_type, _) => {
120+
item_impl(_, Some(ref trait_ref), self_type, _) => {
121121
match cx.tcx.def_map.find(&trait_ref.ref_id) {
122122
None => cx.tcx.sess.bug("trait ref not in def map!"),
123123
Some(&trait_def) => {

src/librustc/middle/reachable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ impl ReachableContext {
141141
}
142142
}
143143
}
144-
item_impl(ref generics, trait_ref, _, ref methods) => {
144+
item_impl(ref generics, ref trait_ref, _, ref methods) => {
145145
// XXX(pcwalton): We conservatively assume any methods
146146
// on a trait implementation are reachable, when this
147147
// is not the case. We could be more precise by only

src/librustc/middle/resolve.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3533,7 +3533,7 @@ impl Resolver {
35333533
}
35343534

35353535
item_impl(ref generics,
3536-
implemented_traits,
3536+
ref implemented_traits,
35373537
self_type,
35383538
ref methods) => {
35393539
self.resolve_implementation(item.id,
@@ -3811,7 +3811,7 @@ impl Resolver {
38113811
type_parameter_bound: &TyParamBound,
38123812
visitor: ResolveVisitor) {
38133813
match *type_parameter_bound {
3814-
TraitTyParamBound(tref) => {
3814+
TraitTyParamBound(ref tref) => {
38153815
self.resolve_trait_reference(tref, visitor, TraitBoundingTypeParameter)
38163816
}
38173817
RegionTyParamBound => {}
@@ -3913,7 +3913,7 @@ impl Resolver {
39133913
pub fn resolve_implementation(@mut self,
39143914
id: node_id,
39153915
generics: &Generics,
3916-
opt_trait_reference: Option<@trait_ref>,
3916+
opt_trait_reference: &Option<trait_ref>,
39173917
self_type: @Ty,
39183918
methods: &[@method],
39193919
visitor: ResolveVisitor) {
@@ -3929,7 +3929,7 @@ impl Resolver {
39293929
// Resolve the trait reference, if necessary.
39303930
let original_trait_refs;
39313931
match opt_trait_reference {
3932-
Some(trait_reference) => {
3932+
&Some(ref trait_reference) => {
39333933
self.resolve_trait_reference(trait_reference, visitor, TraitImplementation);
39343934

39353935
// Record the current set of trait references.
@@ -3944,7 +3944,7 @@ impl Resolver {
39443944
&mut self.current_trait_refs,
39453945
Some(new_trait_refs)));
39463946
}
3947-
None => {
3947+
&None => {
39483948
original_trait_refs = None;
39493949
}
39503950
}

src/librustc/middle/ty.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3624,12 +3624,12 @@ pub fn impl_trait_ref(cx: ctxt, id: ast::def_id) -> Option<@TraitRef> {
36243624
debug!("(impl_trait_ref) searching for trait impl %?", id);
36253625
match cx.items.find(&id.node) {
36263626
Some(&ast_map::node_item(@ast::item {
3627-
node: ast::item_impl(_, opt_trait, _, _),
3627+
node: ast::item_impl(_, ref opt_trait, _, _),
36283628
_},
36293629
_)) => {
36303630
match opt_trait {
3631-
Some(t) => Some(ty::node_id_to_trait_ref(cx, t.ref_id)),
3632-
None => None
3631+
&Some(ref t) => Some(ty::node_id_to_trait_ref(cx, t.ref_id)),
3632+
&None => None
36333633
}
36343634
}
36353635
_ => None

src/librustc/middle/typeck/astconv.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,7 @@ fn conv_builtin_bounds(tcx: ty::ctxt, ast_bounds: &Option<OptVec<ast::TyParamBou
764764
let mut builtin_bounds = ty::EmptyBuiltinBounds();
765765
for bound_vec.iter().advance |ast_bound| {
766766
match *ast_bound {
767-
ast::TraitTyParamBound(b) => {
767+
ast::TraitTyParamBound(ref b) => {
768768
match lookup_def_tcx(tcx, b.path.span, b.ref_id) {
769769
ast::def_trait(trait_did) => {
770770
if try_add_builtin_trait(tcx,

src/librustc/middle/typeck/coherence.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,11 @@ impl CoherenceChecker {
207207
// self.crate_context.tcx.sess.str_of(item.ident));
208208

209209
match item.node {
210-
item_impl(_, opt_trait, _, _) => {
211-
self.check_implementation(item,
212-
opt_trait.iter().transform(|&x| x).collect());
210+
item_impl(_, ref opt_trait, _, _) => {
211+
let opt_trait : ~[trait_ref] = opt_trait.iter()
212+
.transform(|&x| x)
213+
.collect();
214+
self.check_implementation(item, opt_trait);
213215
}
214216
_ => {
215217
// Nothing to do.
@@ -238,7 +240,7 @@ impl CoherenceChecker {
238240

239241
pub fn check_implementation(&self,
240242
item: @item,
241-
associated_traits: ~[@trait_ref]) {
243+
associated_traits: &[trait_ref]) {
242244
let tcx = self.crate_context.tcx;
243245
let self_type = ty::lookup_item_type(tcx, local_def(item.id));
244246

@@ -646,7 +648,7 @@ impl CoherenceChecker {
646648
a trait or new type instead");
647649
}
648650
}
649-
item_impl(_, Some(trait_ref), _, _) => {
651+
item_impl(_, Some(ref trait_ref), _, _) => {
650652
// `for_ty` is `Type` in `impl Trait for Type`
651653
let for_ty =
652654
ty::node_id_to_type(self.crate_context.tcx,
@@ -678,7 +680,7 @@ impl CoherenceChecker {
678680
})));
679681
}
680682

681-
pub fn trait_ref_to_trait_def_id(&self, trait_ref: @trait_ref) -> def_id {
683+
pub fn trait_ref_to_trait_def_id(&self, trait_ref: &trait_ref) -> def_id {
682684
let def_map = self.crate_context.tcx.def_map;
683685
let trait_def = def_map.get_copy(&trait_ref.ref_id);
684686
let trait_id = def_id_of_def(trait_def);
@@ -805,7 +807,7 @@ impl CoherenceChecker {
805807
// Check that we have implementations of every trait method
806808
for trait_refs.iter().advance |trait_ref| {
807809
let trait_did =
808-
self.trait_ref_to_trait_def_id(*trait_ref);
810+
self.trait_ref_to_trait_def_id(trait_ref);
809811
self.please_check_that_trait_methods_are_implemented(
810812
&mut methods,
811813
trait_did,
@@ -817,7 +819,7 @@ impl CoherenceChecker {
817819
// if a method of that name is not inherent to the
818820
// impl, use the provided definition in the trait.
819821
for trait_refs.iter().advance |trait_ref| {
820-
let trait_did = self.trait_ref_to_trait_def_id(*trait_ref);
822+
let trait_did = self.trait_ref_to_trait_def_id(trait_ref);
821823
self.add_provided_methods_to_impl(
822824
&mut methods,
823825
&trait_did,

src/librustc/middle/typeck/collect.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -378,15 +378,15 @@ pub fn ensure_supertraits(ccx: &CrateCtxt,
378378
id: ast::node_id,
379379
sp: codemap::span,
380380
rp: Option<ty::region_variance>,
381-
ast_trait_refs: &[@ast::trait_ref],
381+
ast_trait_refs: &[ast::trait_ref],
382382
generics: &ast::Generics)
383383
{
384384
let tcx = ccx.tcx;
385385
if tcx.supertraits.contains_key(&local_def(id)) { return; }
386386

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

@@ -441,7 +441,7 @@ pub fn compare_impl_method(tcx: ty::ctxt,
441441
fmt!("method `%s` has a `%s` declaration in the impl, \
442442
but not in the trait",
443443
tcx.sess.str_of(trait_m.ident),
444-
explicit_self_to_str(impl_m.explicit_self, tcx.sess.intr())));
444+
explicit_self_to_str(&impl_m.explicit_self, tcx.sess.intr())));
445445
return;
446446
}
447447
(_, &ast::sty_static) => {
@@ -450,7 +450,7 @@ pub fn compare_impl_method(tcx: ty::ctxt,
450450
fmt!("method `%s` has a `%s` declaration in the trait, \
451451
but not in the impl",
452452
tcx.sess.str_of(trait_m.ident),
453-
explicit_self_to_str(trait_m.explicit_self, tcx.sess.intr())));
453+
explicit_self_to_str(&trait_m.explicit_self, tcx.sess.intr())));
454454
return;
455455
}
456456
_ => {
@@ -813,7 +813,7 @@ pub fn convert(ccx: &CrateCtxt, it: &ast::item) {
813813
generics,
814814
rp);
815815
}
816-
ast::item_impl(ref generics, opt_trait_ref, selfty, ref ms) => {
816+
ast::item_impl(ref generics, ref opt_trait_ref, selfty, ref ms) => {
817817
let i_ty_generics = ty_generics(ccx, rp, generics, 0);
818818
let region_parameterization =
819819
RegionParameterization::from_variance_and_generics(rp, generics);
@@ -839,7 +839,7 @@ pub fn convert(ccx: &CrateCtxt, it: &ast::item) {
839839
&i_ty_generics, generics,
840840
parent_visibility);
841841
for opt_trait_ref.iter().advance |t| {
842-
check_methods_against_trait(ccx, generics, rp, selfty, *t, cms);
842+
check_methods_against_trait(ccx, generics, rp, selfty, t, cms);
843843
}
844844
}
845845
ast::item_trait(ref generics, ref supertraits, ref trait_methods) => {
@@ -1184,7 +1184,7 @@ pub fn ty_generics(ccx: &CrateCtxt,
11841184
};
11851185
for ast_bounds.iter().advance |ast_bound| {
11861186
match *ast_bound {
1187-
TraitTyParamBound(b) => {
1187+
TraitTyParamBound(ref b) => {
11881188
let ty = ty::mk_param(ccx.tcx, param_ty.idx, param_ty.def_id);
11891189
let trait_ref = instantiate_trait_ref(ccx, b, rp, generics, ty);
11901190
if !astconv::try_add_builtin_trait(

src/libsyntax/ast.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ pub static crate_node_id: node_id = 0;
132132
// the "special" built-in traits (see middle::lang_items) and
133133
// detects Copy, Send, Send, and Freeze.
134134
pub enum TyParamBound {
135-
TraitTyParamBound(@trait_ref),
135+
TraitTyParamBound(trait_ref),
136136
RegionTyParamBound
137137
}
138138

@@ -1002,9 +1002,9 @@ pub enum item_ {
10021002
item_ty(@Ty, Generics),
10031003
item_enum(enum_def, Generics),
10041004
item_struct(@struct_def, Generics),
1005-
item_trait(Generics, ~[@trait_ref], ~[trait_method]),
1005+
item_trait(Generics, ~[trait_ref], ~[trait_method]),
10061006
item_impl(Generics,
1007-
Option<@trait_ref>, // (optional) trait this impl implements
1007+
Option<trait_ref>, // (optional) trait this impl implements
10081008
@Ty, // self
10091009
~[@method]),
10101010
// a macro invocation (which includes macro definition)

src/libsyntax/ast_util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ pub fn view_path_id(p: &view_path) -> node_id {
580580

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

src/libsyntax/ext/build.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ pub trait AstBuilder {
6868

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

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

@@ -358,8 +358,8 @@ impl AstBuilder for @ExtCtxt {
358358
}
359359
}
360360

361-
fn trait_ref(&self, path: ast::Path) -> @ast::trait_ref {
362-
@ast::trait_ref {
361+
fn trait_ref(&self, path: ast::Path) -> ast::trait_ref {
362+
ast::trait_ref {
363363
path: path,
364364
ref_id: self.next_id()
365365
}

src/libsyntax/ext/log_syntax.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub fn expand_syntax_ext(cx: @ExtCtxt,
2626
cx.print_backtrace();
2727
io::stdout().write_line(
2828
print::pprust::tt_to_str(
29-
ast::tt_delim(vec::to_owned(tt)),
29+
&ast::tt_delim(vec::to_owned(tt)),
3030
get_ident_interner()));
3131

3232
//trivial expression

src/libsyntax/ext/tt/macro_rules.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ pub fn add_new_extension(cx: @ExtCtxt,
8282
io::println(fmt!("%s! { %s }",
8383
cx.str_of(name),
8484
print::pprust::tt_to_str(
85-
ast::tt_delim(vec::to_owned(arg)),
85+
&ast::tt_delim(vec::to_owned(arg)),
8686
get_ident_interner())));
8787
}
8888

src/libsyntax/fold.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ pub fn fold_fn_decl(decl: &ast::fn_decl, fld: @ast_fold) -> ast::fn_decl {
162162

163163
fn fold_ty_param_bound(tpb: &TyParamBound, fld: @ast_fold) -> TyParamBound {
164164
match *tpb {
165-
TraitTyParamBound(ty) => TraitTyParamBound(fold_trait_ref(ty, fld)),
165+
TraitTyParamBound(ref ty) => TraitTyParamBound(fold_trait_ref(ty, fld)),
166166
RegionTyParamBound => RegionTyParamBound
167167
}
168168
}
@@ -296,10 +296,10 @@ pub fn noop_fold_item_underscore(i: &item_, fld: @ast_fold) -> item_ {
296296
let struct_def = fold_struct_def(*struct_def, fld);
297297
item_struct(struct_def, /* FIXME (#2543) */ copy *generics)
298298
}
299-
item_impl(ref generics, ifce, ty, ref methods) => {
299+
item_impl(ref generics, ref ifce, ty, ref methods) => {
300300
item_impl(
301301
fold_generics(generics, fld),
302-
ifce.map(|p| fold_trait_ref(*p, fld)),
302+
ifce.map(|p| fold_trait_ref(p, fld)),
303303
fld.fold_ty(ty),
304304
methods.map(|x| fld.fold_method(*x))
305305
)
@@ -313,7 +313,7 @@ pub fn noop_fold_item_underscore(i: &item_, fld: @ast_fold) -> item_ {
313313
};
314314
item_trait(
315315
fold_generics(generics, fld),
316-
traits.map(|p| fold_trait_ref(*p, fld)),
316+
traits.map(|p| fold_trait_ref(p, fld)),
317317
methods
318318
)
319319
}
@@ -335,8 +335,8 @@ fn fold_struct_def(struct_def: @ast::struct_def, fld: @ast_fold)
335335
}
336336
}
337337

338-
fn fold_trait_ref(p: @trait_ref, fld: @ast_fold) -> @trait_ref {
339-
@ast::trait_ref {
338+
fn fold_trait_ref(p: &trait_ref, fld: @ast_fold) -> trait_ref {
339+
ast::trait_ref {
340340
path: fld.fold_path(&p.path),
341341
ref_id: fld.new_id(p.ref_id),
342342
}

src/libsyntax/parse/parser.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3566,7 +3566,7 @@ impl Parser {
35663566
// New-style trait. Reinterpret the type as a trait.
35673567
let opt_trait_ref = match ty.node {
35683568
ty_path(ref path, @None, node_id) => {
3569-
Some(@trait_ref {
3569+
Some(trait_ref {
35703570
path: /* bad */ copy *path,
35713571
ref_id: node_id
35723572
})
@@ -3608,15 +3608,15 @@ impl Parser {
36083608
}
36093609

36103610
// parse a::B<~str,int>
3611-
fn parse_trait_ref(&self) -> @trait_ref {
3612-
@ast::trait_ref {
3611+
fn parse_trait_ref(&self) -> trait_ref {
3612+
ast::trait_ref {
36133613
path: self.parse_path_with_tps(false),
36143614
ref_id: self.get_id(),
36153615
}
36163616
}
36173617

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

0 commit comments

Comments
 (0)