Skip to content

Commit

Permalink
Auto merge of #59258 - euclio:suggestions-filter-crate, r=oli-obk
Browse files Browse the repository at this point in the history
filter suggestions from extern prelude

Fixes #59027.

Modifies the candidate gathering code to call `filter_fn` on extern crates, which causes them to be filtered out when looking for a type.
  • Loading branch information
bors committed Mar 25, 2019
2 parents d91b32b + a9108eb commit 4c27fb1
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 7 deletions.
26 changes: 20 additions & 6 deletions src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4047,13 +4047,27 @@ impl<'a> Resolver<'a> {
} else {
// Items from the prelude
if !module.no_implicit_prelude {
names.extend(self.extern_prelude.iter().map(|(ident, _)| {
TypoSuggestion {
candidate: ident.name,
article: "a",
kind: "crate",
}
names.extend(self.extern_prelude.clone().iter().flat_map(|(ident, _)| {
self.crate_loader
.maybe_process_path_extern(ident.name, ident.span)
.and_then(|crate_id| {
let crate_mod = Def::Mod(DefId {
krate: crate_id,
index: CRATE_DEF_INDEX,
});

if filter_fn(crate_mod) {
Some(TypoSuggestion {
candidate: ident.name,
article: "a",
kind: "crate",
})
} else {
None
}
})
}));

if let Some(prelude) = self.prelude {
add_module_candidates(prelude, &mut names);
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/proc-macro/resolve-error.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ error: cannot find derive macro `attr_proc_macra` in this scope
--> $DIR/resolve-error.rs:44:10
|
LL | #[derive(attr_proc_macra)]
| ^^^^^^^^^^^^^^^ help: try: `attr_proc_macro`
| ^^^^^^^^^^^^^^^

error: cannot find macro `FooWithLongNama!` in this scope
--> $DIR/resolve-error.rs:49:5
Expand Down
3 changes: 3 additions & 0 deletions src/test/ui/suggestions/auxiliary/foo.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
//! Contains a struct with almost the same name as itself, to trigger Levenshtein suggestions.

pub struct Foo;
7 changes: 7 additions & 0 deletions src/test/ui/suggestions/no-extern-crate-in-type.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// aux-build:foo.rs

extern crate foo;

type Output = Option<Foo>; //~ ERROR cannot find type `Foo`

fn main() {}
13 changes: 13 additions & 0 deletions src/test/ui/suggestions/no-extern-crate-in-type.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
error[E0412]: cannot find type `Foo` in this scope
--> $DIR/no-extern-crate-in-type.rs:5:22
|
LL | type Output = Option<Foo>;
| ^^^ not found in this scope
help: possible candidate is found in another module, you can import it into scope
|
LL | use foo::Foo;
|

error: aborting due to previous error

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

0 comments on commit 4c27fb1

Please sign in to comment.