Skip to content

Commit c27e646

Browse files
committed
consider glob imports in cfg suggestion
1 parent 88b3b52 commit c27e646

File tree

4 files changed

+50
-4
lines changed

4 files changed

+50
-4
lines changed

compiler/rustc_expand/src/expand.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,10 +1319,12 @@ impl InvocationCollectorNode for P<ast::Item> {
13191319

13201320
let mut idents = Vec::new();
13211321
collect_use_tree_leaves(ut, &mut idents);
1322-
return idents;
1322+
idents
1323+
} else if let Some(ident) = self.kind.ident() {
1324+
vec![ident]
1325+
} else {
1326+
vec![]
13231327
}
1324-
1325-
if let Some(ident) = self.kind.ident() { vec![ident] } else { vec![] }
13261328
}
13271329
}
13281330

compiler/rustc_resolve/src/diagnostics.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2623,7 +2623,13 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
26232623
};
26242624

26252625
for &StrippedCfgItem { parent_module, ident, ref cfg } in symbols {
2626-
if parent_module != module || ident.name != *segment {
2626+
let comes_from_same_module = parent_module == module
2627+
|| self.module_map.get(&parent_module).is_some_and(|m| {
2628+
m.glob_importers.borrow().iter().any(|import| {
2629+
import.parent_scope.module.opt_def_id().is_some_and(|m| m == module)
2630+
})
2631+
});
2632+
if !comes_from_same_module || ident.name != *segment {
26272633
continue;
26282634
}
26292635

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// issue#141256
2+
3+
mod original {
4+
#[cfg(false)] //~ NOTE the item is gated here
5+
pub mod gated { //~ NOTE found an item that was configured out
6+
pub fn foo() {}
7+
}
8+
}
9+
10+
mod reexport {
11+
pub use super::original::*;
12+
}
13+
14+
fn main() {
15+
reexport::gated::foo();
16+
//~^ ERROR failed to resolve: could not find `gated` in `reexport`
17+
//~| NOTE could not find `gated` in `reexport`
18+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error[E0433]: failed to resolve: could not find `gated` in `reexport`
2+
--> $DIR/diagnostics-reexport-2.rs:15:15
3+
|
4+
LL | reexport::gated::foo();
5+
| ^^^^^ could not find `gated` in `reexport`
6+
|
7+
note: found an item that was configured out
8+
--> $DIR/diagnostics-reexport-2.rs:5:13
9+
|
10+
LL | pub mod gated {
11+
| ^^^^^
12+
note: the item is gated here
13+
--> $DIR/diagnostics-reexport-2.rs:4:5
14+
|
15+
LL | #[cfg(false)]
16+
| ^^^^^^^^^^^^^
17+
18+
error: aborting due to 1 previous error
19+
20+
For more information about this error, try `rustc --explain E0433`.

0 commit comments

Comments
 (0)