Skip to content
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
10 changes: 5 additions & 5 deletions compiler/rustc_hir/src/attrs/data_structures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,15 +277,15 @@ impl Default for MacroUseArgs {
}

#[derive(Debug, Clone, Encodable, Decodable, HashStable_Generic)]
pub struct StrippedCfgItem<ModId = DefId> {
pub parent_module: ModId,
pub struct StrippedCfgItem<ScopeId = DefId> {
pub parent_scope: ScopeId,
pub ident: Ident,
pub cfg: (CfgEntry, Span),
}

impl<ModId> StrippedCfgItem<ModId> {
pub fn map_mod_id<New>(self, f: impl FnOnce(ModId) -> New) -> StrippedCfgItem<New> {
StrippedCfgItem { parent_module: f(self.parent_module), ident: self.ident, cfg: self.cfg }
impl<ScopeId> StrippedCfgItem<ScopeId> {
pub fn map_scope_id<New>(self, f: impl FnOnce(ScopeId) -> New) -> StrippedCfgItem<New> {
StrippedCfgItem { parent_scope: f(self.parent_scope), ident: self.ident, cfg: self.cfg }
}
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_metadata/src/rmeta/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1223,7 +1223,7 @@ impl<'a> CrateMetadataRef<'a> {
.root
.stripped_cfg_items
.decode((self, tcx))
.map(|item| item.map_mod_id(|index| DefId { krate: cnum, index }));
.map(|item| item.map_scope_id(|index| DefId { krate: cnum, index }));
tcx.arena.alloc_from_iter(item_names)
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_metadata/src/rmeta/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2145,7 +2145,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
self.tcx
.stripped_cfg_items(LOCAL_CRATE)
.into_iter()
.map(|item| item.clone().map_mod_id(|def_id| def_id.index)),
.map(|item| item.clone().map_scope_id(|def_id| def_id.index)),
)
}

Expand Down
12 changes: 5 additions & 7 deletions compiler/rustc_resolve/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3083,24 +3083,22 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
.stripped_cfg_items
.iter()
.filter_map(|item| {
let parent_module = self.opt_local_def_id(item.parent_module)?.to_def_id();
Some(StrippedCfgItem {
parent_module,
ident: item.ident,
cfg: item.cfg.clone(),
})
let parent_scope = self.opt_local_def_id(item.parent_scope)?.to_def_id();
Some(StrippedCfgItem { parent_scope, ident: item.ident, cfg: item.cfg.clone() })
})
.collect::<Vec<_>>();
local_items.as_slice()
} else {
self.tcx.stripped_cfg_items(module.krate)
};

for &StrippedCfgItem { parent_module, ident, ref cfg } in symbols {
for &StrippedCfgItem { parent_scope, ident, ref cfg } in symbols {
if ident.name != *segment {
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,
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_resolve/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1817,9 +1817,9 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
.stripped_cfg_items
.into_iter()
.filter_map(|item| {
let parent_module =
self.node_id_to_def_id.get(&item.parent_module)?.key().to_def_id();
Some(StrippedCfgItem { parent_module, ident: item.ident, cfg: item.cfg })
let parent_scope =
self.node_id_to_def_id.get(&item.parent_scope)?.key().to_def_id();
Some(StrippedCfgItem { parent_scope, ident: item.ident, cfg: item.cfg })
})
.collect();

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_resolve/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ impl<'ra, 'tcx> ResolverExpand for Resolver<'ra, 'tcx> {
cfg_span: Span,
) {
self.stripped_cfg_items.push(StrippedCfgItem {
parent_module: parent_node,
parent_scope: parent_node,
ident,
cfg: (cfg, cfg_span),
});
Expand Down
9 changes: 9 additions & 0 deletions tests/ui/resolve/pub-in-path-153848.rs
Original file line number Diff line number Diff line change
@@ -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() {}
21 changes: 21 additions & 0 deletions tests/ui/resolve/pub-in-path-153848.stderr
Original file line number Diff line number Diff line change
@@ -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`.
Loading