From 7ceaba21dff56ea46f2327895f34a00dc558464d Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Fri, 2 Apr 2021 19:00:26 +0200 Subject: Only populate prelude for crate-level DefMaps --- crates/hir_def/src/nameres/collector.rs | 30 ++++++++++++----------- crates/ide/src/hover.rs | 42 +++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 14 deletions(-) (limited to 'crates') diff --git a/crates/hir_def/src/nameres/collector.rs b/crates/hir_def/src/nameres/collector.rs index 5badefabf..6f946a6dd 100644 --- a/crates/hir_def/src/nameres/collector.rs +++ b/crates/hir_def/src/nameres/collector.rs @@ -54,20 +54,22 @@ pub(super) fn collect_defs( ) -> DefMap { let crate_graph = db.crate_graph(); - // populate external prelude - for dep in &crate_graph[def_map.krate].dependencies { - log::debug!("crate dep {:?} -> {:?}", dep.name, dep.crate_id); - let dep_def_map = db.crate_def_map(dep.crate_id); - def_map - .extern_prelude - .insert(dep.as_name(), dep_def_map.module_id(dep_def_map.root).into()); - - // look for the prelude - // If the dependency defines a prelude, we overwrite an already defined - // prelude. This is necessary to import the "std" prelude if a crate - // depends on both "core" and "std". - if dep_def_map.prelude.is_some() { - def_map.prelude = dep_def_map.prelude; + if block.is_none() { + // populate external prelude + for dep in &crate_graph[def_map.krate].dependencies { + log::debug!("crate dep {:?} -> {:?}", dep.name, dep.crate_id); + let dep_def_map = db.crate_def_map(dep.crate_id); + def_map + .extern_prelude + .insert(dep.as_name(), dep_def_map.module_id(dep_def_map.root).into()); + + // look for the prelude + // If the dependency defines a prelude, we overwrite an already defined + // prelude. This is necessary to import the "std" prelude if a crate + // depends on both "core" and "std". + if dep_def_map.prelude.is_some() { + def_map.prelude = dep_def_map.prelude; + } } } diff --git a/crates/ide/src/hover.rs b/crates/ide/src/hover.rs index 28e2e17dc..614433417 100644 --- a/crates/ide/src/hover.rs +++ b/crates/ide/src/hover.rs @@ -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. + "#]], + ) + } } -- cgit v1.2.3