mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 04:19:13 +00:00
Only populate prelude for crate-level DefMaps
This commit is contained in:
parent
f4d56989b6
commit
7ceaba21df
2 changed files with 57 additions and 13 deletions
|
@ -54,20 +54,22 @@ pub(super) fn collect_defs(
|
||||||
) -> DefMap {
|
) -> DefMap {
|
||||||
let crate_graph = db.crate_graph();
|
let crate_graph = db.crate_graph();
|
||||||
|
|
||||||
// populate external prelude
|
if block.is_none() {
|
||||||
for dep in &crate_graph[def_map.krate].dependencies {
|
// populate external prelude
|
||||||
log::debug!("crate dep {:?} -> {:?}", dep.name, dep.crate_id);
|
for dep in &crate_graph[def_map.krate].dependencies {
|
||||||
let dep_def_map = db.crate_def_map(dep.crate_id);
|
log::debug!("crate dep {:?} -> {:?}", dep.name, dep.crate_id);
|
||||||
def_map
|
let dep_def_map = db.crate_def_map(dep.crate_id);
|
||||||
.extern_prelude
|
def_map
|
||||||
.insert(dep.as_name(), dep_def_map.module_id(dep_def_map.root).into());
|
.extern_prelude
|
||||||
|
.insert(dep.as_name(), dep_def_map.module_id(dep_def_map.root).into());
|
||||||
|
|
||||||
// look for the prelude
|
// look for the prelude
|
||||||
// If the dependency defines a prelude, we overwrite an already defined
|
// If the dependency defines a prelude, we overwrite an already defined
|
||||||
// prelude. This is necessary to import the "std" prelude if a crate
|
// prelude. This is necessary to import the "std" prelude if a crate
|
||||||
// depends on both "core" and "std".
|
// depends on both "core" and "std".
|
||||||
if dep_def_map.prelude.is_some() {
|
if dep_def_map.prelude.is_some() {
|
||||||
def_map.prelude = dep_def_map.prelude;
|
def_map.prelude = dep_def_map.prelude;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3897,4 +3897,46 @@ trait A where
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn string_shadowed_with_inner_items() {
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
//- /main.rs crate:main deps:alloc
|
||||||
|
|
||||||
|
/// Custom `String` type.
|
||||||
|
struct String;
|
||||||
|
|
||||||
|
fn f() {
|
||||||
|
let _: String$0;
|
||||||
|
|
||||||
|
fn inner() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
//- /alloc.rs crate:alloc
|
||||||
|
#[prelude_import]
|
||||||
|
pub use string::*;
|
||||||
|
|
||||||
|
mod string {
|
||||||
|
/// This is `alloc::String`.
|
||||||
|
pub struct String;
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
*String*
|
||||||
|
|
||||||
|
```rust
|
||||||
|
main
|
||||||
|
```
|
||||||
|
|
||||||
|
```rust
|
||||||
|
struct String
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
Custom `String` type.
|
||||||
|
"#]],
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue