mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-14 06:03:58 +00:00
Prefer names from outer DefMap over extern prelude
This commit is contained in:
parent
83280ea574
commit
c2622c9228
2 changed files with 40 additions and 5 deletions
|
@ -156,7 +156,7 @@ impl DefMap {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn resolve_path_fp_with_macro_single(
|
fn resolve_path_fp_with_macro_single(
|
||||||
&self,
|
&self,
|
||||||
db: &dyn DefDatabase,
|
db: &dyn DefDatabase,
|
||||||
mode: ResolveMode,
|
mode: ResolveMode,
|
||||||
|
@ -384,10 +384,16 @@ impl DefMap {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let from_extern_prelude = self
|
// Give precedence to names in outer `DefMap`s over the extern prelude; only check prelude
|
||||||
.extern_prelude
|
// from the crate DefMap.
|
||||||
.get(name)
|
let from_extern_prelude = match self.block {
|
||||||
.map_or(PerNs::none(), |&it| PerNs::types(it, Visibility::Public));
|
Some(_) => PerNs::none(),
|
||||||
|
None => self
|
||||||
|
.extern_prelude
|
||||||
|
.get(name)
|
||||||
|
.map_or(PerNs::none(), |&it| PerNs::types(it, Visibility::Public)),
|
||||||
|
};
|
||||||
|
|
||||||
let from_prelude = self.resolve_in_prelude(db, name);
|
let from_prelude = self.resolve_in_prelude(db, name);
|
||||||
|
|
||||||
from_legacy_macro.or(from_scope_or_builtin).or(from_extern_prelude).or(from_prelude)
|
from_legacy_macro.or(from_scope_or_builtin).or(from_extern_prelude).or(from_prelude)
|
||||||
|
|
|
@ -705,6 +705,35 @@ fn x(a: S) {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn import_extern_crate_clash_with_inner_item() {
|
||||||
|
// This is more of a resolver test, but doesn't really work with the hir_def testsuite.
|
||||||
|
|
||||||
|
check_diagnostics(
|
||||||
|
r#"
|
||||||
|
//- /lib.rs crate:lib deps:jwt
|
||||||
|
mod permissions;
|
||||||
|
|
||||||
|
use permissions::jwt;
|
||||||
|
|
||||||
|
fn f() {
|
||||||
|
fn inner() {}
|
||||||
|
jwt::Claims {}; // should resolve to the local one with 0 fields, and not get a diagnostic
|
||||||
|
}
|
||||||
|
|
||||||
|
//- /permissions.rs
|
||||||
|
pub mod jwt {
|
||||||
|
pub struct Claims {}
|
||||||
|
}
|
||||||
|
|
||||||
|
//- /jwt/lib.rs crate:jwt
|
||||||
|
pub struct Claims {
|
||||||
|
field: u8,
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn break_outside_of_loop() {
|
fn break_outside_of_loop() {
|
||||||
check_diagnostics(
|
check_diagnostics(
|
||||||
|
|
Loading…
Reference in a new issue