Skip to content

Commit 5eac68c

Browse files
committed
Auto merge of #29210 - arielb1:suggest-overflow, r=eddyb
This prevents a stack-overflow when the module graph was cyclic. Fixes #29181 r? @eddyb
2 parents 7bb0ac5 + ad4cdf7 commit 5eac68c

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

src/librustc_typeck/check/method/suggest.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use middle::lang_items::FnOnceTraitLangItem;
2323
use middle::subst::Substs;
2424
use middle::traits::{Obligation, SelectionContext};
2525
use metadata::{csearch, cstore, decoder};
26+
use util::nodemap::{FnvHashSet};
2627

2728
use syntax::ast;
2829
use syntax::codemap::Span;
@@ -406,7 +407,9 @@ pub fn all_traits<'a>(ccx: &'a CrateCtxt) -> AllTraits<'a> {
406407
}, ccx.tcx.map.krate());
407408

408409
// Cross-crate:
410+
let mut external_mods = FnvHashSet();
409411
fn handle_external_def(traits: &mut AllTraitsVec,
412+
external_mods: &mut FnvHashSet<DefId>,
410413
ccx: &CrateCtxt,
411414
cstore: &cstore::CStore,
412415
dl: decoder::DefLike) {
@@ -415,8 +418,12 @@ pub fn all_traits<'a>(ccx: &'a CrateCtxt) -> AllTraits<'a> {
415418
traits.push(TraitInfo::new(did));
416419
}
417420
decoder::DlDef(def::DefMod(did)) => {
421+
if !external_mods.insert(did) {
422+
return;
423+
}
418424
csearch::each_child_of_item(cstore, did, |dl, _, _| {
419-
handle_external_def(traits, ccx, cstore, dl)
425+
handle_external_def(traits, external_mods,
426+
ccx, cstore, dl)
420427
})
421428
}
422429
_ => {}
@@ -425,7 +432,9 @@ pub fn all_traits<'a>(ccx: &'a CrateCtxt) -> AllTraits<'a> {
425432
let cstore = &ccx.tcx.sess.cstore;
426433
cstore.iter_crate_data(|cnum, _| {
427434
csearch::each_top_level_item_of_crate(cstore, cnum, |dl, _, _| {
428-
handle_external_def(&mut traits, ccx, cstore, dl)
435+
handle_external_def(&mut traits,
436+
&mut external_mods,
437+
ccx, cstore, dl)
429438
})
430439
});
431440

src/test/auxiliary/issue-29181.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![crate_type="lib"]
12+
13+
pub mod foo {
14+
pub use super::*;
15+
}

src/test/compile-fail/issue-29181.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// aux-build:issue-29181.rs
12+
13+
extern crate issue_29181 as foo;
14+
15+
fn main() {
16+
0.homura(); //~ ERROR no method named `homura` found
17+
}

0 commit comments

Comments
 (0)