Skip to content

Commit 4c27fb1

Browse files
committed
Auto merge of #59258 - euclio:suggestions-filter-crate, r=oli-obk
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.
2 parents d91b32b + a9108eb commit 4c27fb1

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
@@ -4047,13 +4047,27 @@ impl<'a> Resolver<'a> {
40474047
} else {
40484048
// Items from the prelude
40494049
if !module.no_implicit_prelude {
4050-
names.extend(self.extern_prelude.iter().map(|(ident, _)| {
4051-
TypoSuggestion {
4052-
candidate: ident.name,
4053-
article: "a",
4054-
kind: "crate",
4055-
}
4050+
names.extend(self.extern_prelude.clone().iter().flat_map(|(ident, _)| {
4051+
self.crate_loader
4052+
.maybe_process_path_extern(ident.name, ident.span)
4053+
.and_then(|crate_id| {
4054+
let crate_mod = Def::Mod(DefId {
4055+
krate: crate_id,
4056+
index: CRATE_DEF_INDEX,
4057+
});
4058+
4059+
if filter_fn(crate_mod) {
4060+
Some(TypoSuggestion {
4061+
candidate: ident.name,
4062+
article: "a",
4063+
kind: "crate",
4064+
})
4065+
} else {
4066+
None
4067+
}
4068+
})
40564069
}));
4070+
40574071
if let Some(prelude) = self.prelude {
40584072
add_module_candidates(prelude, &mut names);
40594073
}

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)