Skip to content

filter suggestions from extern prelude #59258

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4046,13 +4046,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`.