Skip to content

Commit b35559a

Browse files
Merge #7959
7959: Prefer names from outer DefMap over extern prelude r=jonas-schievink a=jonas-schievink Fixes #7919 Just one more special case, how bad could it be. bors r+ Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2 parents 83280ea + c2622c9 commit b35559a

File tree

2 files changed

+40
-5
lines changed

2 files changed

+40
-5
lines changed

crates/hir_def/src/nameres/path_resolution.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ impl DefMap {
156156
}
157157
}
158158

159-
pub(super) fn resolve_path_fp_with_macro_single(
159+
fn resolve_path_fp_with_macro_single(
160160
&self,
161161
db: &dyn DefDatabase,
162162
mode: ResolveMode,
@@ -384,10 +384,16 @@ impl DefMap {
384384
}
385385
}
386386
};
387-
let from_extern_prelude = self
388-
.extern_prelude
389-
.get(name)
390-
.map_or(PerNs::none(), |&it| PerNs::types(it, Visibility::Public));
387+
// Give precedence to names in outer `DefMap`s over the extern prelude; only check prelude
388+
// from the crate DefMap.
389+
let from_extern_prelude = match self.block {
390+
Some(_) => PerNs::none(),
391+
None => self
392+
.extern_prelude
393+
.get(name)
394+
.map_or(PerNs::none(), |&it| PerNs::types(it, Visibility::Public)),
395+
};
396+
391397
let from_prelude = self.resolve_in_prelude(db, name);
392398

393399
from_legacy_macro.or(from_scope_or_builtin).or(from_extern_prelude).or(from_prelude)

crates/hir_ty/src/diagnostics.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,35 @@ fn x(a: S) {
705705
)
706706
}
707707

708+
#[test]
709+
fn import_extern_crate_clash_with_inner_item() {
710+
// This is more of a resolver test, but doesn't really work with the hir_def testsuite.
711+
712+
check_diagnostics(
713+
r#"
714+
//- /lib.rs crate:lib deps:jwt
715+
mod permissions;
716+
717+
use permissions::jwt;
718+
719+
fn f() {
720+
fn inner() {}
721+
jwt::Claims {}; // should resolve to the local one with 0 fields, and not get a diagnostic
722+
}
723+
724+
//- /permissions.rs
725+
pub mod jwt {
726+
pub struct Claims {}
727+
}
728+
729+
//- /jwt/lib.rs crate:jwt
730+
pub struct Claims {
731+
field: u8,
732+
}
733+
"#,
734+
);
735+
}
736+
708737
#[test]
709738
fn break_outside_of_loop() {
710739
check_diagnostics(

0 commit comments

Comments
 (0)