Skip to content

Commit 498968f

Browse files
committed
---
yaml --- r: 185834 b: refs/heads/auto c: 9a69378 h: refs/heads/master v: v3
1 parent 649e6f7 commit 498968f

File tree

7 files changed

+39
-28
lines changed

7 files changed

+39
-28
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1010
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1111
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1212
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
13-
refs/heads/auto: 9739ae4d09a637b914171c873953bb8c13daa0c0
13+
refs/heads/auto: 9a69378e8b61473fbfa55f347286718ca4c5d399
1414
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1515
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1616
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

branches/auto/src/librustc/metadata/decoder.rs

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -172,16 +172,13 @@ fn item_visibility(item: rbml::Doc) -> ast::Visibility {
172172
}
173173
}
174174

175-
fn item_sort(item: rbml::Doc) -> char {
175+
fn item_sort(item: rbml::Doc) -> Option<char> {
176176
let mut ret = None;
177177
reader::tagged_docs(item, tag_item_trait_item_sort, |doc| {
178178
ret = Some(doc.as_str_slice().as_bytes()[0] as char);
179179
false
180180
});
181-
match ret {
182-
Some(r) => r,
183-
None => panic!("No item_sort found")
184-
}
181+
ret
185182
}
186183

187184
fn item_symbol(item: rbml::Doc) -> String {
@@ -344,7 +341,14 @@ fn item_to_def_like(item: rbml::Doc, did: ast::DefId, cnum: ast::CrateNum)
344341
_ => panic!()
345342
}
346343
}
347-
Type => DlDef(def::DefTy(did, false)),
344+
Type => {
345+
if item_sort(item) == Some('t') {
346+
let trait_did = item_reqd_and_translated_parent_item(cnum, item);
347+
DlDef(def::DefAssociatedTy(trait_did, did))
348+
} else {
349+
DlDef(def::DefTy(did, false))
350+
}
351+
}
348352
Mod => DlDef(def::DefMod(did)),
349353
ForeignMod => DlDef(def::DefForeignMod(did)),
350354
StructVariant => {
@@ -829,8 +833,10 @@ pub fn get_impl_items(cdata: Cmd, impl_id: ast::NodeId)
829833
tag_item_impl_item, |doc| {
830834
let def_id = item_def_id(doc, cdata);
831835
match item_sort(doc) {
832-
'r' | 'p' => impl_items.push(ty::MethodTraitItemId(def_id)),
833-
't' => impl_items.push(ty::TypeTraitItemId(def_id)),
836+
Some('r') | Some('p') => {
837+
impl_items.push(ty::MethodTraitItemId(def_id))
838+
}
839+
Some('t') => impl_items.push(ty::TypeTraitItemId(def_id)),
834840
_ => panic!("unknown impl item sort"),
835841
}
836842
true
@@ -854,14 +860,14 @@ pub fn get_trait_item_name_and_kind(intr: Rc<IdentInterner>,
854860
let doc = lookup_item(id, cdata.data());
855861
let name = item_name(&*intr, doc);
856862
match item_sort(doc) {
857-
'r' | 'p' => {
863+
Some('r') | Some('p') => {
858864
let explicit_self = get_explicit_self(doc);
859865
(name, def::TraitItemKind::from_explicit_self_category(explicit_self))
860866
}
861-
't' => (name, def::TypeTraitItemKind),
867+
Some('t') => (name, def::TypeTraitItemKind),
862868
c => {
863869
panic!("get_trait_item_name_and_kind(): unknown trait item kind \
864-
in metadata: `{}`", c)
870+
in metadata: `{:?}`", c)
865871
}
866872
}
867873
}
@@ -887,7 +893,7 @@ pub fn get_impl_or_trait_item<'tcx>(intr: Rc<IdentInterner>,
887893
let vis = item_visibility(method_doc);
888894

889895
match item_sort(method_doc) {
890-
'r' | 'p' => {
896+
Some('r') | Some('p') => {
891897
let generics = doc_generics(method_doc, tcx, cdata, tag_method_ty_generics);
892898
let predicates = doc_predicates(method_doc, tcx, cdata, tag_method_ty_generics);
893899
let fty = doc_method_fty(method_doc, tcx, cdata);
@@ -904,7 +910,7 @@ pub fn get_impl_or_trait_item<'tcx>(intr: Rc<IdentInterner>,
904910
container,
905911
provided_source)))
906912
}
907-
't' => {
913+
Some('t') => {
908914
ty::TypeTraitItem(Rc::new(ty::AssociatedType {
909915
name: name,
910916
vis: vis,
@@ -924,8 +930,10 @@ pub fn get_trait_item_def_ids(cdata: Cmd, id: ast::NodeId)
924930
reader::tagged_docs(item, tag_item_trait_item, |mth| {
925931
let def_id = item_def_id(mth, cdata);
926932
match item_sort(mth) {
927-
'r' | 'p' => result.push(ty::MethodTraitItemId(def_id)),
928-
't' => result.push(ty::TypeTraitItemId(def_id)),
933+
Some('r') | Some('p') => {
934+
result.push(ty::MethodTraitItemId(def_id));
935+
}
936+
Some('t') => result.push(ty::TypeTraitItemId(def_id)),
929937
_ => panic!("unknown trait item sort"),
930938
}
931939
true
@@ -954,7 +962,7 @@ pub fn get_provided_trait_methods<'tcx>(intr: Rc<IdentInterner>,
954962
let did = item_def_id(mth_id, cdata);
955963
let mth = lookup_item(did.node, data);
956964

957-
if item_sort(mth) == 'p' {
965+
if item_sort(mth) == Some('p') {
958966
let trait_item = get_impl_or_trait_item(intr.clone(),
959967
cdata,
960968
did.node,
@@ -1558,7 +1566,7 @@ pub fn is_associated_type(cdata: Cmd, id: ast::NodeId) -> bool {
15581566
let items = reader::get_doc(rbml::Doc::new(cdata.data()), tag_items);
15591567
match maybe_find_item(id, items) {
15601568
None => false,
1561-
Some(item) => item_sort(item) == 't',
1569+
Some(item) => item_sort(item) == Some('t'),
15621570
}
15631571
}
15641572

branches/auto/src/librustc/middle/astencode.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,8 @@ impl tr for def::Def {
442442
},
443443
def::DefTrait(did) => def::DefTrait(did.tr(dcx)),
444444
def::DefTy(did, is_enum) => def::DefTy(did.tr(dcx), is_enum),
445-
def::DefAssociatedTy(did) => def::DefAssociatedTy(did.tr(dcx)),
445+
def::DefAssociatedTy(trait_did, did) =>
446+
def::DefAssociatedTy(trait_did.tr(dcx), did.tr(dcx)),
446447
def::DefAssociatedPath(def::TyParamProvenance::FromSelf(did), ident) =>
447448
def::DefAssociatedPath(def::TyParamProvenance::FromSelf(did.tr(dcx)), ident),
448449
def::DefAssociatedPath(def::TyParamProvenance::FromParam(did), ident) =>

branches/auto/src/librustc/middle/def.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub enum Def {
3232
DefLocal(ast::NodeId),
3333
DefVariant(ast::DefId /* enum */, ast::DefId /* variant */, bool /* is_structure */),
3434
DefTy(ast::DefId, bool /* is_enum */),
35-
DefAssociatedTy(ast::DefId),
35+
DefAssociatedTy(ast::DefId /* trait */, ast::DefId),
3636
// A partially resolved path to an associated type `T::U` where `T` is a concrete
3737
// type (indicated by the DefId) which implements a trait which has an associated
3838
// type `U` (indicated by the Ident).
@@ -134,7 +134,7 @@ impl Def {
134134
match *self {
135135
DefFn(id, _) | DefStaticMethod(id, _) | DefMod(id) |
136136
DefForeignMod(id) | DefStatic(id, _) |
137-
DefVariant(_, id, _) | DefTy(id, _) | DefAssociatedTy(id) |
137+
DefVariant(_, id, _) | DefTy(id, _) | DefAssociatedTy(_, id) |
138138
DefTyParam(_, _, id, _) | DefUse(id) | DefStruct(id) | DefTrait(id) |
139139
DefMethod(id, _, _) | DefConst(id) |
140140
DefAssociatedPath(TyParamProvenance::FromSelf(id), _) |

branches/auto/src/librustc_resolve/build_reduced_graph.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -638,8 +638,8 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
638638
&new_parent,
639639
ForbidDuplicateTypesAndModules,
640640
typedef.span);
641-
let def = DefAssociatedTy(local_def(
642-
typedef.id));
641+
let def = DefAssociatedTy(local_def(item.id),
642+
local_def(typedef.id));
643643
// NB: not IMPORTABLE
644644
let modifiers = if typedef.vis == ast::Public {
645645
PUBLIC
@@ -716,8 +716,8 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
716716
(name, static_flag)
717717
}
718718
ast::TypeTraitItem(ref associated_type) => {
719-
let def = DefAssociatedTy(local_def(
720-
associated_type.ty_param.id));
719+
let def = DefAssociatedTy(local_def(item.id),
720+
local_def(associated_type.ty_param.id));
721721

722722
let name_bindings =
723723
self.add_child(associated_type.ty_param.ident.name,

branches/auto/src/librustc_typeck/astconv.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,9 +1236,8 @@ pub fn ast_ty_to_ty<'tcx>(this: &AstConv<'tcx>,
12361236
def::DefPrimTy(_) => {
12371237
panic!("DefPrimTy arm missed in previous ast_ty_to_prim_ty call");
12381238
}
1239-
def::DefAssociatedTy(trait_type_id) => {
1240-
let path_str = tcx.map.path_to_string(
1241-
tcx.map.get_parent(trait_type_id.node));
1239+
def::DefAssociatedTy(trait_id, _) => {
1240+
let path_str = ty::item_path_str(tcx, trait_id);
12421241
span_err!(tcx.sess, ast_ty.span, E0223,
12431242
"ambiguous associated \
12441243
type; specify the type \

branches/auto/src/test/compile-fail/associated-types-in-ambiguous-context.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,8 @@ trait Grab {
2222
//~^ ERROR ambiguous associated type
2323
}
2424

25+
type X = std::ops::Deref::Target;
26+
//~^ ERROR ambiguous associated type
27+
2528
fn main() {
2629
}

0 commit comments

Comments
 (0)