Skip to content

Commit 1a5496a

Browse files
committed
---
yaml --- r: 22975 b: refs/heads/master c: b65dd9d h: refs/heads/master i: 22973: 17b08d5 22971: 388fbc8 22967: 5059796 22959: 6c78ca5 22943: 481ca0e 22911: e663af9 v: v3
1 parent 190de43 commit 1a5496a

File tree

14 files changed

+70
-22
lines changed

14 files changed

+70
-22
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: a805a1fb37443601819604954510cb312a724fe9
2+
refs/heads/master: b65dd9d0908ba75ee4cf128058858aea87e4508a
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: cd6f24f9d14ac90d167386a56e7a6ac1f0318195
55
refs/heads/try: ffbe0e0e00374358b789b0037bcb3a577cd218be

trunk/src/libsyntax/ast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ enum item_ {
724724
/* dtor is optional */
725725
option<class_dtor>
726726
),
727-
item_trait(~[ty_param], ~[trait_method]),
727+
item_trait(~[ty_param], ~[@trait_ref], ~[trait_method]),
728728
item_impl(~[ty_param],
729729
~[@trait_ref], /* traits this impl implements */
730730
@ty, /* self */

trunk/src/libsyntax/ast_map.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,15 @@ fn map_item(i: @item, cx: ctx, v: vt) {
231231
// only need to handle methods
232232
do vec::iter(ms) |m| { map_method(d_id, p, m, cx); }
233233
}
234-
item_trait(tps, methods) {
234+
item_trait(tps, traits, methods) {
235+
// Map trait refs to their parent classes. This is
236+
// so we can find the self_ty
237+
for traits.each |p| {
238+
cx.map.insert(p.ref_id, node_item(i, item_path));
239+
// This is so we can look up the right things when
240+
// encoding/decoding
241+
cx.map.insert(p.impl_id, node_item(i, item_path));
242+
}
235243
for methods.each |tm| {
236244
let id = ast_util::trait_method_to_ty_method(tm).id;
237245
let d_id = ast_util::local_def(i.id);

trunk/src/libsyntax/fold.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,9 @@ fn noop_fold_item_underscore(i: item_, fld: ast_fold) -> item_ {
279279
fld.fold_ty(ty),
280280
vec::map(methods, |x| fld.fold_method(x)))
281281
}
282-
item_trait(tps, methods) {
282+
item_trait(tps, traits, methods) {
283283
item_trait(fold_ty_params(tps, fld),
284+
vec::map(traits, |p| fold_trait_ref(p, fld)),
284285
/* FIXME (#2543) */ copy methods)
285286
}
286287
item_mac(m) {

trunk/src/libsyntax/parse/parser.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2278,8 +2278,18 @@ class parser {
22782278
let ident = self.parse_ident();
22792279
self.parse_region_param();
22802280
let tps = self.parse_ty_params();
2281+
2282+
// Parse traits, if necessary.
2283+
let traits;
2284+
if self.token == token::COLON {
2285+
self.bump();
2286+
traits = self.parse_trait_ref_list(token::LBRACE);
2287+
} else {
2288+
traits = ~[];
2289+
}
2290+
22812291
let meths = self.parse_trait_methods();
2282-
(ident, item_trait(tps, meths), none)
2292+
(ident, item_trait(tps, traits, meths), none)
22832293
}
22842294
22852295
// Parses four variants (with the region/type params always optional):

trunk/src/libsyntax/print/pprust.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,10 +590,15 @@ fn print_item(s: ps, &&item: @ast::item) {
590590
}
591591
bclose(s, item.span);
592592
}
593-
ast::item_trait(tps, methods) {
593+
ast::item_trait(tps, traits, methods) {
594594
head(s, ~"trait");
595595
word(s.s, *item.ident);
596596
print_type_params(s, tps);
597+
if vec::len(traits) != 0u {
598+
word_space(s, ~":");
599+
commasep(s, inconsistent, traits, |s, p|
600+
print_path(s, p.path, false));
601+
}
597602
word(s.s, ~" ");
598603
bopen(s);
599604
for methods.each |meth| { print_trait_method(s, meth); }

trunk/src/libsyntax/visit.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,9 @@ fn visit_item<E>(i: @item, e: E, v: vt<E>) {
162162
ast_util::local_def(i.id), e, v)
163163
};
164164
}
165-
item_trait(tps, methods) {
165+
item_trait(tps, traits, methods) {
166166
v.visit_ty_params(tps, e, v);
167+
for traits.each |p| { visit_path(p.path, e, v); }
167168
for methods.each |m| {
168169
v.visit_trait_method(m, e, v);
169170
}

trunk/src/rustc/metadata/encoder.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
813813
vec::append(tps, m.tps));
814814
}
815815
}
816-
item_trait(tps, ms) {
816+
item_trait(tps, traits, ms) {
817817
add_to_index();
818818
ebml_w.start_tag(tag_items_data_item);
819819
encode_def_id(ebml_w, local_def(item.id));
@@ -844,6 +844,9 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
844844
i += 1u;
845845
}
846846
encode_path(ebml_w, path, ast_map::path_name(item.ident));
847+
for traits.each |associated_trait| {
848+
encode_trait_ref(ebml_w, ecx, associated_trait)
849+
}
847850
ebml_w.end_tag();
848851
}
849852
item_mac(*) { fail ~"item macros unimplemented" }

trunk/src/rustc/middle/resolve3.rs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -988,7 +988,7 @@ class Resolver {
988988
visit_item(item, new_parent, visitor);
989989
}
990990

991-
item_trait(_, methods) {
991+
item_trait(_, _, methods) {
992992
// Add the names of all the methods to the trait info.
993993
let method_names = @atom_hashmap();
994994
for methods.each |method| {
@@ -3063,7 +3063,7 @@ class Resolver {
30633063
self_type, methods, visitor);
30643064
}
30653065

3066-
item_trait(type_parameters, methods) {
3066+
item_trait(type_parameters, traits, methods) {
30673067
// Create a new rib for the self type.
30683068
let self_type_rib = @Rib(NormalRibKind);
30693069
(*self.type_ribs).push(self_type_rib);
@@ -3077,6 +3077,27 @@ class Resolver {
30773077

30783078
self.resolve_type_parameters(type_parameters, visitor);
30793079

3080+
// Resolve derived traits.
3081+
for traits.each |trt| {
3082+
match self.resolve_path(trt.path, TypeNS, true,
3083+
visitor) {
3084+
none =>
3085+
self.session.span_err(trt.path.span,
3086+
~"attempt to derive a \
3087+
nonexistent trait"),
3088+
some(def) => {
3089+
// Write a mapping from the trait ID to the
3090+
// definition of the trait into the definition
3091+
// map.
3092+
3093+
debug!{"(resolving trait) found trait def: \
3094+
%?", def};
3095+
3096+
self.record_def(trt.ref_id, def);
3097+
}
3098+
}
3099+
}
3100+
30803101
for methods.each |method| {
30813102
// Create a new rib for the method-specific type
30823103
// parameters.

trunk/src/rustc/middle/typeck/check.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ fn check_item(ccx: @crate_ctxt, it: @ast::item) {
419419
node_id: it.id };
420420
for ms.each |m| { check_method(ccx, m, self_info);}
421421
}
422-
ast::item_trait(_, trait_methods) {
422+
ast::item_trait(_, _, trait_methods) {
423423
for trait_methods.each |trait_method| {
424424
alt trait_method {
425425
required(ty_m) {
@@ -434,7 +434,7 @@ fn check_item(ccx: @crate_ctxt, it: @ast::item) {
434434
}
435435
}
436436
}
437-
ast::item_class(tps, traits, members, m_ctor, m_dtor) {
437+
ast::item_class(tps, _, members, m_ctor, m_dtor) {
438438
let tcx = ccx.tcx;
439439
let class_t = {self_ty: ty::node_id_to_type(tcx, it.id),
440440
node_id: it.id};

trunk/src/rustc/middle/typeck/collect.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,19 @@ fn collect_item_types(ccx: @crate_ctxt, crate: @ast::crate) {
3838
let substs = {self_r: none, self_ty: none, tps: ~[]};
3939

4040
alt intrinsic_item.node {
41-
42-
ast::item_trait(_, _) {
41+
ast::item_trait(*) => {
4342
let ty = ty::mk_trait(ccx.tcx, def_id, substs);
4443
ccx.tcx.intrinsic_defs.insert
4544
(intrinsic_item.ident, (def_id, ty));
4645
}
4746

48-
ast::item_enum(_, _) {
47+
ast::item_enum(*) => {
4948
let ty = ty::mk_enum(ccx.tcx, def_id, substs);
5049
ccx.tcx.intrinsic_defs.insert
5150
(intrinsic_item.ident, (def_id, ty));
5251
}
5352

54-
_ { }
53+
_ => {}
5554
}
5655
}
5756
}
@@ -147,7 +146,7 @@ fn ensure_trait_methods(ccx: @crate_ctxt, id: ast::node_id) {
147146
let tcx = ccx.tcx;
148147
let rp = tcx.region_paramd_items.contains_key(id);
149148
alt check tcx.items.get(id) {
150-
ast_map::node_item(@{node: ast::item_trait(_, ms), _}, _) {
149+
ast_map::node_item(@{node: ast::item_trait(_, _, ms), _}, _) {
151150
store_methods::<ast::trait_method>(ccx, id, ms, |m| {
152151
alt m {
153152
required(ty_m) {
@@ -339,7 +338,7 @@ fn convert(ccx: @crate_ctxt, it: @ast::item) {
339338
check_methods_against_trait(ccx, tps, rp, selfty, t, cms);
340339
}
341340
}
342-
ast::item_trait(tps, trait_methods) {
341+
ast::item_trait(tps, _, trait_methods) {
343342
let tpt = ty_of_item(ccx, it);
344343
debug!{"item_trait(it.id=%d, tpt.ty=%s)",
345344
it.id, ty_to_str(tcx, tpt.ty)};
@@ -550,7 +549,7 @@ fn ty_of_item(ccx: @crate_ctxt, it: @ast::item)
550549
tcx.tcache.insert(local_def(it.id), tpt);
551550
return tpt;
552551
}
553-
ast::item_trait(tps, ms) {
552+
ast::item_trait(tps, _, ms) {
554553
let {bounds, substs} = mk_substs(ccx, tps, rp);
555554
let t = ty::mk_trait(tcx, local_def(it.id), substs);
556555
let tpt = {bounds: bounds, rp: rp, ty: t};

trunk/src/rustdoc/attr_pass.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ fn merge_method_attrs(
205205
let attrs: ~[(~str, option<~str>)] = do astsrv::exec(srv) |ctxt| {
206206
alt ctxt.ast_map.get(item_id) {
207207
ast_map::node_item(@{
208-
node: ast::item_trait(_, methods), _
208+
node: ast::item_trait(_, _, methods), _
209209
}, _) {
210210
vec::map(methods, |method| {
211211
alt method {

trunk/src/rustdoc/extract.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ fn moddoc_from_mod(
8484
enumdoc_from_enum(itemdoc, variants)
8585
))
8686
}
87-
ast::item_trait(_, methods) {
87+
ast::item_trait(_, _, methods) {
8888
some(doc::traittag(
8989
traitdoc_from_trait(itemdoc, methods)
9090
))

trunk/src/rustdoc/tystr_pass.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ fn get_method_sig(
169169
do astsrv::exec(srv) |ctxt| {
170170
alt check ctxt.ast_map.get(item_id) {
171171
ast_map::node_item(@{
172-
node: ast::item_trait(_, methods), _
172+
node: ast::item_trait(_, _, methods), _
173173
}, _) {
174174
alt check vec::find(methods, |method| {
175175
alt method {

0 commit comments

Comments
 (0)