Skip to content

Commit

Permalink
fix: resolve extern prelude for local mods in block modules
Browse files Browse the repository at this point in the history
  • Loading branch information
roife committed May 17, 2024
1 parent 98d768b commit ea2a16c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,8 @@ impl DefCollector<'_> {
.cfg()
.map_or(true, |cfg| self.cfg_options.check(&cfg) != Some(false));
if is_cfg_enabled {
self.inject_prelude();

ModCollector {
def_collector: self,
macro_depth: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ use crate::{
db::DefDatabase,
item_scope::{ImportOrExternCrate, BUILTIN_SCOPE},
item_tree::Fields,
nameres::{sub_namespace_match, BlockInfo, BuiltinShadowMode, DefMap, MacroSubNs},
nameres::{
sub_namespace_match, BlockInfo, BuiltinShadowMode, DefMap, MacroSubNs, ModuleOrigin,
},
path::{ModPath, PathKind},
per_ns::PerNs,
visibility::{RawVisibility, Visibility},
Expand Down Expand Up @@ -221,7 +223,7 @@ impl DefMap {
None => return ResolvePathResult::empty(ReachedFixedPoint::Yes),
};
tracing::debug!("resolving {:?} in crate root (+ extern prelude)", segment);
self.resolve_name_in_crate_root_or_extern_prelude(db, segment)
self.resolve_name_in_crate_root_or_extern_prelude(db, original_module, segment)
}
PathKind::Plain => {
let (_, segment) = match segments.next() {
Expand Down Expand Up @@ -470,9 +472,9 @@ impl DefMap {
};

let extern_prelude = || {
if self.block.is_some() {
// Don't resolve extern prelude in block `DefMap`s, defer it to the crate def map so
// that blocks can properly shadow them
if matches!(self[module].origin, ModuleOrigin::BlockExpr { .. }) {
// Don't resolve extern prelude in pseudo-modules of blocks, because
// they might been shadowed by local names.
return PerNs::none();
}
self.data.extern_prelude.get(name).map_or(PerNs::none(), |&(it, extern_crate)| {
Expand Down Expand Up @@ -505,6 +507,7 @@ impl DefMap {
fn resolve_name_in_crate_root_or_extern_prelude(
&self,
db: &dyn DefDatabase,
module: LocalModuleId,
name: &Name,
) -> PerNs {
let from_crate_root = match self.block {
Expand All @@ -515,8 +518,8 @@ impl DefMap {
None => self[Self::ROOT].scope.get(name),
};
let from_extern_prelude = || {
if self.block.is_some() {
// Don't resolve extern prelude in block `DefMap`s.
if matches!(self[module].origin, ModuleOrigin::BlockExpr { .. }) {
// Don't resolve extern prelude in pseudo-module of a block.
return PerNs::none();
}
self.data.extern_prelude.get(name).copied().map_or(
Expand Down

0 comments on commit ea2a16c

Please sign in to comment.