Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitea2a16c

Browse files
committed
fix: resolve extern prelude for local mods in block modules
1 parent98d768b commitea2a16c

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

‎src/tools/rust-analyzer/crates/hir-def/src/nameres/collector.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,8 @@ impl DefCollector<'_> {
395395
.cfg()
396396
.map_or(true, |cfg|self.cfg_options.check(&cfg) !=Some(false));
397397
if is_cfg_enabled{
398+
self.inject_prelude();
399+
398400
ModCollector{
399401
def_collector:self,
400402
macro_depth:0,

‎src/tools/rust-analyzer/crates/hir-def/src/nameres/path_resolution.rs‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ use crate::{
1818
db::DefDatabase,
1919
item_scope::{ImportOrExternCrate,BUILTIN_SCOPE},
2020
item_tree::Fields,
21-
nameres::{sub_namespace_match,BlockInfo,BuiltinShadowMode,DefMap,MacroSubNs},
21+
nameres::{
22+
sub_namespace_match,BlockInfo,BuiltinShadowMode,DefMap,MacroSubNs,ModuleOrigin,
23+
},
2224
path::{ModPath,PathKind},
2325
per_ns::PerNs,
2426
visibility::{RawVisibility,Visibility},
@@ -221,7 +223,7 @@ impl DefMap {
221223
None =>returnResolvePathResult::empty(ReachedFixedPoint::Yes),
222224
};
223225
tracing::debug!("resolving {:?} in crate root (+ extern prelude)", segment);
224-
self.resolve_name_in_crate_root_or_extern_prelude(db, segment)
226+
self.resolve_name_in_crate_root_or_extern_prelude(db,original_module,segment)
225227
}
226228
PathKind::Plain =>{
227229
let(_, segment) =match segments.next(){
@@ -470,9 +472,9 @@ impl DefMap {
470472
};
471473

472474
let extern_prelude = ||{
473-
ifself.block.is_some(){
474-
// Don't resolve extern prelude inblock `DefMap`s, defer it to the crate def map so
475-
//that blocks can properly shadow them
475+
ifmatches!(self[module].origin,ModuleOrigin::BlockExpr{ ..}){
476+
// Don't resolve extern prelude inpseudo-modules of blocks, because
477+
//they might been shadowed by local names.
476478
returnPerNs::none();
477479
}
478480
self.data.extern_prelude.get(name).map_or(PerNs::none(), |&(it, extern_crate)|{
@@ -505,6 +507,7 @@ impl DefMap {
505507
fnresolve_name_in_crate_root_or_extern_prelude(
506508
&self,
507509
db:&dynDefDatabase,
510+
module:LocalModuleId,
508511
name:&Name,
509512
) ->PerNs{
510513
let from_crate_root =matchself.block{
@@ -515,8 +518,8 @@ impl DefMap {
515518
None =>self[Self::ROOT].scope.get(name),
516519
};
517520
let from_extern_prelude = ||{
518-
ifself.block.is_some(){
519-
// Don't resolve extern prelude inblock `DefMap`s.
521+
ifmatches!(self[module].origin,ModuleOrigin::BlockExpr{ ..}){
522+
// Don't resolve extern prelude inpseudo-module of a block.
520523
returnPerNs::none();
521524
}
522525
self.data.extern_prelude.get(name).copied().map_or(

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp