Skip to content

Commit e9ac149

Browse files
authored
Unrolled build for #141548
Rollup merge of #141548 - bvanjoi:issue-141256, r=petrochenkov consider glob imports in cfg suggestion Fixes #141256 r? ```@petrochenkov```
2 parents 40311c4 + e908094 commit e9ac149

File tree

4 files changed

+200
-5
lines changed

4 files changed

+200
-5
lines changed

compiler/rustc_expand/src/expand.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,10 +1319,10 @@ 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 {
1324+
self.kind.ident().into_iter().collect()
13231325
}
1324-
1325-
if let Some(ident) = self.kind.ident() { vec![ident] } else { vec![] }
13261326
}
13271327
}
13281328

compiler/rustc_resolve/src/diagnostics.rs

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_ast::{
66
};
77
use rustc_ast_pretty::pprust;
88
use rustc_attr_data_structures::{self as attr, Stability};
9-
use rustc_data_structures::fx::FxHashSet;
9+
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1010
use rustc_data_structures::unord::UnordSet;
1111
use rustc_errors::codes::*;
1212
use rustc_errors::{
@@ -2623,7 +2623,53 @@ 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+
if ident.name != *segment {
2627+
continue;
2628+
}
2629+
2630+
fn comes_from_same_module_for_glob(
2631+
r: &Resolver<'_, '_>,
2632+
parent_module: DefId,
2633+
module: DefId,
2634+
visited: &mut FxHashMap<DefId, bool>,
2635+
) -> bool {
2636+
if let Some(&cached) = visited.get(&parent_module) {
2637+
// this branch is prevent from being called recursively infinity,
2638+
// because there has some cycles in globs imports,
2639+
// see more spec case at `tests/ui/cfg/diagnostics-reexport-2.rs#reexport32`
2640+
return cached;
2641+
}
2642+
visited.insert(parent_module, false);
2643+
let res = r.module_map.get(&parent_module).is_some_and(|m| {
2644+
for importer in m.glob_importers.borrow().iter() {
2645+
if let Some(next_parent_module) = importer.parent_scope.module.opt_def_id()
2646+
{
2647+
if next_parent_module == module
2648+
|| comes_from_same_module_for_glob(
2649+
r,
2650+
next_parent_module,
2651+
module,
2652+
visited,
2653+
)
2654+
{
2655+
return true;
2656+
}
2657+
}
2658+
}
2659+
false
2660+
});
2661+
visited.insert(parent_module, res);
2662+
res
2663+
}
2664+
2665+
let comes_from_same_module = parent_module == module
2666+
|| comes_from_same_module_for_glob(
2667+
self,
2668+
parent_module,
2669+
module,
2670+
&mut Default::default(),
2671+
);
2672+
if !comes_from_same_module {
26272673
continue;
26282674
}
26292675

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// issue#141256
2+
3+
mod original {
4+
#[cfg(false)]
5+
//~^ NOTE the item is gated here
6+
//~| NOTE the item is gated here
7+
//~| NOTE the item is gated here
8+
//~| NOTE the item is gated here
9+
//~| NOTE the item is gated here
10+
pub mod gated {
11+
//~^ NOTE found an item that was configured out
12+
//~| NOTE found an item that was configured out
13+
//~| NOTE found an item that was configured out
14+
//~| NOTE found an item that was configured out
15+
//~| NOTE found an item that was configured out
16+
pub fn foo() {}
17+
}
18+
}
19+
20+
mod reexport {
21+
pub use super::original::*;
22+
}
23+
24+
mod reexport2 {
25+
pub use super::reexport::*;
26+
}
27+
28+
mod reexport30 {
29+
pub use super::original::*;
30+
pub use super::reexport31::*;
31+
}
32+
33+
mod reexport31 {
34+
pub use super::reexport30::*;
35+
}
36+
37+
mod reexport32 {
38+
pub use super::reexport30::*;
39+
}
40+
41+
fn main() {
42+
reexport::gated::foo();
43+
//~^ ERROR failed to resolve: could not find `gated` in `reexport`
44+
//~| NOTE could not find `gated` in `reexport`
45+
46+
reexport2::gated::foo();
47+
//~^ ERROR failed to resolve: could not find `gated` in `reexport2`
48+
//~| NOTE could not find `gated` in `reexport2`
49+
50+
reexport30::gated::foo();
51+
//~^ ERROR failed to resolve: could not find `gated` in `reexport30`
52+
//~| NOTE could not find `gated` in `reexport30`
53+
54+
reexport31::gated::foo();
55+
//~^ ERROR failed to resolve: could not find `gated` in `reexport31`
56+
//~| NOTE could not find `gated` in `reexport31`
57+
58+
reexport32::gated::foo();
59+
//~^ ERROR failed to resolve: could not find `gated` in `reexport32`
60+
//~| NOTE could not find `gated` in `reexport32`
61+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
error[E0433]: failed to resolve: could not find `gated` in `reexport`
2+
--> $DIR/diagnostics-reexport-2.rs:42: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:10: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[E0433]: failed to resolve: could not find `gated` in `reexport2`
19+
--> $DIR/diagnostics-reexport-2.rs:46:16
20+
|
21+
LL | reexport2::gated::foo();
22+
| ^^^^^ could not find `gated` in `reexport2`
23+
|
24+
note: found an item that was configured out
25+
--> $DIR/diagnostics-reexport-2.rs:10:13
26+
|
27+
LL | pub mod gated {
28+
| ^^^^^
29+
note: the item is gated here
30+
--> $DIR/diagnostics-reexport-2.rs:4:5
31+
|
32+
LL | #[cfg(false)]
33+
| ^^^^^^^^^^^^^
34+
35+
error[E0433]: failed to resolve: could not find `gated` in `reexport30`
36+
--> $DIR/diagnostics-reexport-2.rs:50:17
37+
|
38+
LL | reexport30::gated::foo();
39+
| ^^^^^ could not find `gated` in `reexport30`
40+
|
41+
note: found an item that was configured out
42+
--> $DIR/diagnostics-reexport-2.rs:10:13
43+
|
44+
LL | pub mod gated {
45+
| ^^^^^
46+
note: the item is gated here
47+
--> $DIR/diagnostics-reexport-2.rs:4:5
48+
|
49+
LL | #[cfg(false)]
50+
| ^^^^^^^^^^^^^
51+
52+
error[E0433]: failed to resolve: could not find `gated` in `reexport31`
53+
--> $DIR/diagnostics-reexport-2.rs:54:17
54+
|
55+
LL | reexport31::gated::foo();
56+
| ^^^^^ could not find `gated` in `reexport31`
57+
|
58+
note: found an item that was configured out
59+
--> $DIR/diagnostics-reexport-2.rs:10:13
60+
|
61+
LL | pub mod gated {
62+
| ^^^^^
63+
note: the item is gated here
64+
--> $DIR/diagnostics-reexport-2.rs:4:5
65+
|
66+
LL | #[cfg(false)]
67+
| ^^^^^^^^^^^^^
68+
69+
error[E0433]: failed to resolve: could not find `gated` in `reexport32`
70+
--> $DIR/diagnostics-reexport-2.rs:58:17
71+
|
72+
LL | reexport32::gated::foo();
73+
| ^^^^^ could not find `gated` in `reexport32`
74+
|
75+
note: found an item that was configured out
76+
--> $DIR/diagnostics-reexport-2.rs:10:13
77+
|
78+
LL | pub mod gated {
79+
| ^^^^^
80+
note: the item is gated here
81+
--> $DIR/diagnostics-reexport-2.rs:4:5
82+
|
83+
LL | #[cfg(false)]
84+
| ^^^^^^^^^^^^^
85+
86+
error: aborting due to 5 previous errors
87+
88+
For more information about this error, try `rustc --explain E0433`.

0 commit comments

Comments
 (0)