Skip to content
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

fix: add cfg diagnostic for unresolved import error #112854

Merged
merged 1 commit into from
Jun 24, 2023
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
13 changes: 12 additions & 1 deletion compiler/rustc_resolve/src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
return;
}
Expand Down Expand Up @@ -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();
Expand Down
24 changes: 24 additions & 0 deletions tests/ui/cfg/diagnostics-reexport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,30 @@ pub mod inner {
//~^ 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() {
// There is no uwu at this path - no diagnostic.
inner::uwu(); //~ ERROR cannot find function
Expand Down
38 changes: 35 additions & 3 deletions tests/ui/cfg/diagnostics-reexport.stderr
Original file line number Diff line number Diff line change
@@ -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
Noratrieb marked this conversation as resolved.
Show resolved Hide resolved
--> $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`
--> $DIR/diagnostics-reexport.rs:14:12
--> $DIR/diagnostics-reexport.rs:38:12
|
LL | inner::uwu();
| ^^^ not found in `inner`
Expand All @@ -10,6 +41,7 @@ note: found an item that was configured out
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`.