Skip to content

Commit 82a2e8e

Browse files
committed
Fix an infinite loop in the stability check that was the result of
various bugs in `trait_id_of_impl`. The end result was that looking up the "trait_id_of_impl" with a trait's def-id yielded the same trait again, even though it ought to have yielded None.
1 parent 6ed3f24 commit 82a2e8e

File tree

3 files changed

+22
-26
lines changed

3 files changed

+22
-26
lines changed

src/librustc/metadata/decoder.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -441,9 +441,15 @@ pub fn get_impl_trait<'tcx>(cdata: Cmd,
441441
-> Option<Rc<ty::TraitRef<'tcx>>>
442442
{
443443
let item_doc = lookup_item(id, cdata.data());
444-
reader::maybe_get_doc(item_doc, tag_item_trait_ref).map(|tp| {
445-
doc_trait_ref(tp, tcx, cdata)
446-
})
444+
let fam = item_family(item_doc);
445+
match fam {
446+
Family::Impl => {
447+
reader::maybe_get_doc(item_doc, tag_item_trait_ref).map(|tp| {
448+
doc_trait_ref(tp, tcx, cdata)
449+
})
450+
}
451+
_ => None
452+
}
447453
}
448454

449455
pub fn get_impl_vtables<'tcx>(cdata: Cmd,

src/librustc/middle/stability.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
//! A pass that annotates every item and method with its stability level,
1212
//! propagating default levels lexically from parent to children ast nodes.
1313
14-
use util::nodemap::{NodeMap, DefIdMap};
14+
use middle::ty;
15+
use metadata::csearch;
1516
use syntax::codemap::Span;
1617
use syntax::{attr, visit};
1718
use syntax::ast;
@@ -21,8 +22,8 @@ use syntax::ast::{TypeMethod, Method, Generics, StructField, TypeTraitItem};
2122
use syntax::ast_util::is_local;
2223
use syntax::attr::Stability;
2324
use syntax::visit::{FnKind, FkMethod, Visitor};
24-
use middle::ty;
25-
use metadata::csearch;
25+
use util::nodemap::{NodeMap, DefIdMap};
26+
use util::ppaux::Repr;
2627

2728
use std::mem::replace;
2829

@@ -154,10 +155,13 @@ impl Index {
154155
/// Lookup the stability for a node, loading external crate
155156
/// metadata as necessary.
156157
pub fn lookup(tcx: &ty::ctxt, id: DefId) -> Option<Stability> {
158+
debug!("lookup(id={})",
159+
id.repr(tcx));
160+
157161
// is this definition the implementation of a trait method?
158162
match ty::trait_item_of_item(tcx, id) {
159-
Some(ty::MethodTraitItemId(trait_method_id))
160-
if trait_method_id != id => {
163+
Some(ty::MethodTraitItemId(trait_method_id)) if trait_method_id != id => {
164+
debug!("lookup: trait_method_id={}", trait_method_id);
161165
return lookup(tcx, trait_method_id)
162166
}
163167
_ => {}
@@ -178,6 +182,7 @@ pub fn lookup(tcx: &ty::ctxt, id: DefId) -> Option<Stability> {
178182
// stability of the trait to determine the stability of any
179183
// unmarked impls for it. See FIXME above for more details.
180184

185+
debug!("lookup: trait_id={}", trait_id);
181186
lookup(tcx, trait_id)
182187
} else {
183188
None

src/librustc/middle/ty.rs

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2862,8 +2862,6 @@ pub fn maybe_walk_ty<'tcx,F>(ty_root: Ty<'tcx>, mut f: F)
28622862
walker.skip_current_subtree();
28632863
}
28642864
}
2865-
2866-
maybe_walk_ty_(ty, &mut f);
28672865
}
28682866

28692867
// Folds types from the bottom up.
@@ -6071,22 +6069,9 @@ pub fn populate_implementations_for_trait_if_necessary(
60716069
/// Given the def_id of an impl, return the def_id of the trait it implements.
60726070
/// If it implements no trait, return `None`.
60736071
pub fn trait_id_of_impl(tcx: &ctxt,
6074-
def_id: ast::DefId) -> Option<ast::DefId> {
6075-
let node = match tcx.map.find(def_id.node) {
6076-
Some(node) => node,
6077-
None => return None
6078-
};
6079-
match node {
6080-
ast_map::NodeItem(item) => {
6081-
match item.node {
6082-
ast::ItemImpl(_, _, Some(ref trait_ref), _, _) => {
6083-
Some(node_id_to_trait_ref(tcx, trait_ref.ref_id).def_id)
6084-
}
6085-
_ => None
6086-
}
6087-
}
6088-
_ => None
6089-
}
6072+
def_id: ast::DefId)
6073+
-> Option<ast::DefId> {
6074+
ty::impl_trait_ref(tcx, def_id).map(|tr| tr.def_id)
60906075
}
60916076

60926077
/// If the given def ID describes a method belonging to an impl, return the

0 commit comments

Comments
 (0)