Skip to content

Commit a1f2f23

Browse files
Rollup merge of #112854 - bvanjoi:fix-112674, r=Nilstrieb
fix: add cfg diagnostic for unresolved import error Fixes #112674 An easy fix, r? `@Nilstrieb`
2 parents 696d722 + 8c8c7ef commit a1f2f23

File tree

3 files changed

+71
-4
lines changed

3 files changed

+71
-4
lines changed

compiler/rustc_resolve/src/imports.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
609609
}
610610
}
611611

612-
fn throw_unresolved_import_error(&self, errors: Vec<(&Import<'_>, UnresolvedImportError)>) {
612+
fn throw_unresolved_import_error(&mut self, errors: Vec<(&Import<'_>, UnresolvedImportError)>) {
613613
if errors.is_empty() {
614614
return;
615615
}
@@ -679,6 +679,17 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
679679
_ => {}
680680
}
681681
}
682+
683+
match &import.kind {
684+
ImportKind::Single { source, .. } => {
685+
if let Some(ModuleOrUniformRoot::Module(module)) = import.imported_module.get()
686+
&& let Some(module) = module.opt_def_id()
687+
{
688+
self.find_cfg_stripped(&mut diag, &source.name, module)
689+
}
690+
},
691+
_ => {}
692+
}
682693
}
683694

684695
diag.emit();

tests/ui/cfg/diagnostics-reexport.rs

+24
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,30 @@ pub mod inner {
99
//~^ NOTE found an item that was configured out
1010
}
1111

12+
pub use a::x;
13+
//~^ ERROR unresolved import `a::x`
14+
//~| NOTE no `x` in `a`
15+
16+
mod a {
17+
#[cfg(no)]
18+
pub fn x() {}
19+
//~^ NOTE found an item that was configured out
20+
}
21+
22+
pub use b::{x, y};
23+
//~^ ERROR unresolved imports `b::x`, `b::y`
24+
//~| NOTE no `x` in `b`
25+
//~| NOTE no `y` in `b`
26+
27+
mod b {
28+
#[cfg(no)]
29+
pub fn x() {}
30+
//~^ NOTE found an item that was configured out
31+
#[cfg(no)]
32+
pub fn y() {}
33+
//~^ NOTE found an item that was configured out
34+
}
35+
1236
fn main() {
1337
// There is no uwu at this path - no diagnostic.
1438
inner::uwu(); //~ ERROR cannot find function
+35-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,36 @@
1+
error[E0432]: unresolved import `a::x`
2+
--> $DIR/diagnostics-reexport.rs:12:9
3+
|
4+
LL | pub use a::x;
5+
| ^^^^ no `x` in `a`
6+
|
7+
note: found an item that was configured out
8+
--> $DIR/diagnostics-reexport.rs:18:12
9+
|
10+
LL | pub fn x() {}
11+
| ^
12+
13+
error[E0432]: unresolved imports `b::x`, `b::y`
14+
--> $DIR/diagnostics-reexport.rs:22:13
15+
|
16+
LL | pub use b::{x, y};
17+
| ^ ^ no `y` in `b`
18+
| |
19+
| no `x` in `b`
20+
|
21+
note: found an item that was configured out
22+
--> $DIR/diagnostics-reexport.rs:29:12
23+
|
24+
LL | pub fn x() {}
25+
| ^
26+
note: found an item that was configured out
27+
--> $DIR/diagnostics-reexport.rs:32:12
28+
|
29+
LL | pub fn y() {}
30+
| ^
31+
132
error[E0425]: cannot find function `uwu` in module `inner`
2-
--> $DIR/diagnostics-reexport.rs:14:12
33+
--> $DIR/diagnostics-reexport.rs:38:12
334
|
435
LL | inner::uwu();
536
| ^^^ not found in `inner`
@@ -10,6 +41,7 @@ note: found an item that was configured out
1041
LL | pub use super::uwu;
1142
| ^^^
1243

13-
error: aborting due to previous error
44+
error: aborting due to 3 previous errors
1445

15-
For more information about this error, try `rustc --explain E0425`.
46+
Some errors have detailed explanations: E0425, E0432.
47+
For more information about an error, try `rustc --explain E0425`.

0 commit comments

Comments
 (0)