Skip to content

Commit a9108eb

Browse files
committed
filter suggestions from extern prelude
1 parent 16e7e05 commit a9108eb

File tree

5 files changed

+44
-7
lines changed

5 files changed

+44
-7
lines changed

src/librustc_resolve/lib.rs

+20-6
Original file line numberDiff line numberDiff line change
@@ -4046,13 +4046,27 @@ impl<'a> Resolver<'a> {
40464046
} else {
40474047
// Items from the prelude
40484048
if !module.no_implicit_prelude {
4049-
names.extend(self.extern_prelude.iter().map(|(ident, _)| {
4050-
TypoSuggestion {
4051-
candidate: ident.name,
4052-
article: "a",
4053-
kind: "crate",
4054-
}
4049+
names.extend(self.extern_prelude.clone().iter().flat_map(|(ident, _)| {
4050+
self.crate_loader
4051+
.maybe_process_path_extern(ident.name, ident.span)
4052+
.and_then(|crate_id| {
4053+
let crate_mod = Def::Mod(DefId {
4054+
krate: crate_id,
4055+
index: CRATE_DEF_INDEX,
4056+
});
4057+
4058+
if filter_fn(crate_mod) {
4059+
Some(TypoSuggestion {
4060+
candidate: ident.name,
4061+
article: "a",
4062+
kind: "crate",
4063+
})
4064+
} else {
4065+
None
4066+
}
4067+
})
40554068
}));
4069+
40564070
if let Some(prelude) = self.prelude {
40574071
add_module_candidates(prelude, &mut names);
40584072
}

src/test/ui/proc-macro/resolve-error.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ error: cannot find derive macro `attr_proc_macra` in this scope
2020
--> $DIR/resolve-error.rs:44:10
2121
|
2222
LL | #[derive(attr_proc_macra)]
23-
| ^^^^^^^^^^^^^^^ help: try: `attr_proc_macro`
23+
| ^^^^^^^^^^^^^^^
2424

2525
error: cannot find macro `FooWithLongNama!` in this scope
2626
--> $DIR/resolve-error.rs:49:5
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
//! Contains a struct with almost the same name as itself, to trigger Levenshtein suggestions.
2+
3+
pub struct Foo;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// aux-build:foo.rs
2+
3+
extern crate foo;
4+
5+
type Output = Option<Foo>; //~ ERROR cannot find type `Foo`
6+
7+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error[E0412]: cannot find type `Foo` in this scope
2+
--> $DIR/no-extern-crate-in-type.rs:5:22
3+
|
4+
LL | type Output = Option<Foo>;
5+
| ^^^ not found in this scope
6+
help: possible candidate is found in another module, you can import it into scope
7+
|
8+
LL | use foo::Foo;
9+
|
10+
11+
error: aborting due to previous error
12+
13+
For more information about this error, try `rustc --explain E0412`.

0 commit comments

Comments
 (0)