Skip to content

Commit

Permalink
resolve: Do not skip extern prelude during speculative resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Oct 17, 2018
1 parent 37ba107 commit 350f9a2
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 4 deletions.
12 changes: 9 additions & 3 deletions src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1980,9 +1980,15 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
}

if !module.no_implicit_prelude {
// `record_used` means that we don't try to load crates during speculative resolution
if record_used && ns == TypeNS && self.extern_prelude.contains(&ident.name) {
let crate_id = self.crate_loader.process_path_extern(ident.name, ident.span);
if ns == TypeNS && self.extern_prelude.contains(&ident.name) {
let crate_id = if record_used {
self.crate_loader.process_path_extern(ident.name, ident.span)
} else if let Some(crate_id) =
self.crate_loader.maybe_process_path_extern(ident.name, ident.span) {
crate_id
} else {
return None;
};
let crate_root = self.get_module(DefId { krate: crate_id, index: CRATE_DEF_INDEX });
self.populate_module_if_necessary(&crate_root);

Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass/extern/extern-prelude-no-speculative.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

// run-pass
#![allow(unused_variables)]
// compile-flags: --extern LooksLikeExternCrate=/path/to/nowhere
// compile-flags: --extern LooksLikeExternCrate

mod m {
pub struct LooksLikeExternCrate;
Expand Down
1 change: 1 addition & 0 deletions src/test/ui/impl-trait/auxiliary/extra-item.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub trait MyTrait {}
10 changes: 10 additions & 0 deletions src/test/ui/impl-trait/extra-item.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// aux-build:extra-item.rs
// compile-flags:--extern extra_item

struct S;

impl extra_item::MyTrait for S {
fn extra() {} //~ ERROR method `extra` is not a member of trait `extra_item::MyTrait`
}

fn main() {}
9 changes: 9 additions & 0 deletions src/test/ui/impl-trait/extra-item.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
error[E0407]: method `extra` is not a member of trait `extra_item::MyTrait`
--> $DIR/extra-item.rs:7:5
|
LL | fn extra() {} //~ ERROR method `extra` is not a member of trait `extra_item::MyTrait`
| ^^^^^^^^^^^^^ not a member of trait `extra_item::MyTrait`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0407`.

0 comments on commit 350f9a2

Please sign in to comment.