From 757f224bce0cea63228034e68ca593f9ad11c5da Mon Sep 17 00:00:00 2001 From: mu001999 Date: Mon, 16 Mar 2026 22:22:25 +0800 Subject: [PATCH] Use nearest non block module as the correct parent module --- compiler/rustc_resolve/src/diagnostics.rs | 2 ++ tests/ui/resolve/pub-in-path-153848.rs | 9 +++++++++ tests/ui/resolve/pub-in-path-153848.stderr | 21 +++++++++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 tests/ui/resolve/pub-in-path-153848.rs create mode 100644 tests/ui/resolve/pub-in-path-153848.stderr diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs index 927269d74996..f11468239630 100644 --- a/compiler/rustc_resolve/src/diagnostics.rs +++ b/compiler/rustc_resolve/src/diagnostics.rs @@ -3097,6 +3097,8 @@ pub(crate) fn find_cfg_stripped(&self, err: &mut Diag<'_>, segment: &Symbol, mod continue; } + let parent_module = self.get_nearest_non_block_module(parent_scope).def_id(); + fn comes_from_same_module_for_glob( r: &Resolver<'_, '_>, parent_module: DefId, diff --git a/tests/ui/resolve/pub-in-path-153848.rs b/tests/ui/resolve/pub-in-path-153848.rs new file mode 100644 index 000000000000..40045e96987f --- /dev/null +++ b/tests/ui/resolve/pub-in-path-153848.rs @@ -0,0 +1,9 @@ +//@ edition: 2015 + +pub(in a) mod aa { //~ ERROR cannot find module or crate `a` in the crate root +} +mod test { + #[cfg(test)] + use super::a; +} +fn main() {} diff --git a/tests/ui/resolve/pub-in-path-153848.stderr b/tests/ui/resolve/pub-in-path-153848.stderr new file mode 100644 index 000000000000..06973a4c0bf3 --- /dev/null +++ b/tests/ui/resolve/pub-in-path-153848.stderr @@ -0,0 +1,21 @@ +error[E0433]: cannot find module or crate `a` in the crate root + --> $DIR/pub-in-path-153848.rs:3:8 + | +LL | pub(in a) mod aa { + | ^ use of unresolved module or unlinked crate `a` + | +note: found an item that was configured out + --> $DIR/pub-in-path-153848.rs:7:16 + | +LL | #[cfg(test)] + | ---- the item is gated here +LL | use super::a; + | ^ +help: you might be missing a crate named `a`, add it to your project and import it in your code + | +LL + extern crate a; + | + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0433`.