1
Fork 0

Rollup merge of #112854 - bvanjoi:fix-112674, r=Nilstrieb

fix: add cfg diagnostic for unresolved import error

Fixes #112674

An easy fix, r? `@Nilstrieb`
This commit is contained in:
Guillaume Gomez 2023-06-24 20:26:44 +02:00 committed by GitHub
commit a1f2f23f0f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 71 additions and 4 deletions

View file

@ -609,7 +609,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
} }
} }
fn throw_unresolved_import_error(&self, errors: Vec<(&Import<'_>, UnresolvedImportError)>) { fn throw_unresolved_import_error(&mut self, errors: Vec<(&Import<'_>, UnresolvedImportError)>) {
if errors.is_empty() { if errors.is_empty() {
return; return;
} }
@ -679,6 +679,17 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
_ => {} _ => {}
} }
} }
match &import.kind {
ImportKind::Single { source, .. } => {
if let Some(ModuleOrUniformRoot::Module(module)) = import.imported_module.get()
&& let Some(module) = module.opt_def_id()
{
self.find_cfg_stripped(&mut diag, &source.name, module)
}
},
_ => {}
}
} }
diag.emit(); diag.emit();

View file

@ -9,6 +9,30 @@ pub mod inner {
//~^ NOTE found an item that was configured out //~^ NOTE found an item that was configured out
} }
pub use a::x;
//~^ ERROR unresolved import `a::x`
//~| NOTE no `x` in `a`
mod a {
#[cfg(no)]
pub fn x() {}
//~^ NOTE found an item that was configured out
}
pub use b::{x, y};
//~^ ERROR unresolved imports `b::x`, `b::y`
//~| NOTE no `x` in `b`
//~| NOTE no `y` in `b`
mod b {
#[cfg(no)]
pub fn x() {}
//~^ NOTE found an item that was configured out
#[cfg(no)]
pub fn y() {}
//~^ NOTE found an item that was configured out
}
fn main() { fn main() {
// There is no uwu at this path - no diagnostic. // There is no uwu at this path - no diagnostic.
inner::uwu(); //~ ERROR cannot find function inner::uwu(); //~ ERROR cannot find function

View file

@ -1,5 +1,36 @@
error[E0432]: unresolved import `a::x`
--> $DIR/diagnostics-reexport.rs:12:9
|
LL | pub use a::x;
| ^^^^ no `x` in `a`
|
note: found an item that was configured out
--> $DIR/diagnostics-reexport.rs:18:12
|
LL | pub fn x() {}
| ^
error[E0432]: unresolved imports `b::x`, `b::y`
--> $DIR/diagnostics-reexport.rs:22:13
|
LL | pub use b::{x, y};
| ^ ^ no `y` in `b`
| |
| no `x` in `b`
|
note: found an item that was configured out
--> $DIR/diagnostics-reexport.rs:29:12
|
LL | pub fn x() {}
| ^
note: found an item that was configured out
--> $DIR/diagnostics-reexport.rs:32:12
|
LL | pub fn y() {}
| ^
error[E0425]: cannot find function `uwu` in module `inner` error[E0425]: cannot find function `uwu` in module `inner`
--> $DIR/diagnostics-reexport.rs:14:12 --> $DIR/diagnostics-reexport.rs:38:12
| |
LL | inner::uwu(); LL | inner::uwu();
| ^^^ not found in `inner` | ^^^ not found in `inner`
@ -10,6 +41,7 @@ note: found an item that was configured out
LL | pub use super::uwu; LL | pub use super::uwu;
| ^^^ | ^^^
error: aborting due to previous error error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0425`. Some errors have detailed explanations: E0425, E0432.
For more information about an error, try `rustc --explain E0425`.