diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/hir_def/src/nameres/collector.rs | 30 | ||||
-rw-r--r-- | crates/ide/src/hover.rs | 42 |
2 files changed, 58 insertions, 14 deletions
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( | |||
54 | ) -> DefMap { | 54 | ) -> DefMap { |
55 | let crate_graph = db.crate_graph(); | 55 | let crate_graph = db.crate_graph(); |
56 | 56 | ||
57 | // populate external prelude | 57 | if block.is_none() { |
58 | for dep in &crate_graph[def_map.krate].dependencies { | 58 | // populate external prelude |
59 | log::debug!("crate dep {:?} -> {:?}", dep.name, dep.crate_id); | 59 | for dep in &crate_graph[def_map.krate].dependencies { |
60 | let dep_def_map = db.crate_def_map(dep.crate_id); | 60 | log::debug!("crate dep {:?} -> {:?}", dep.name, dep.crate_id); |
61 | def_map | 61 | let dep_def_map = db.crate_def_map(dep.crate_id); |
62 | .extern_prelude | 62 | def_map |
63 | .insert(dep.as_name(), dep_def_map.module_id(dep_def_map.root).into()); | 63 | .extern_prelude |
64 | 64 | .insert(dep.as_name(), dep_def_map.module_id(dep_def_map.root).into()); | |
65 | // look for the prelude | 65 | |
66 | // If the dependency defines a prelude, we overwrite an already defined | 66 | // look for the prelude |
67 | // prelude. This is necessary to import the "std" prelude if a crate | 67 | // If the dependency defines a prelude, we overwrite an already defined |
68 | // depends on both "core" and "std". | 68 | // prelude. This is necessary to import the "std" prelude if a crate |
69 | if dep_def_map.prelude.is_some() { | 69 | // depends on both "core" and "std". |
70 | def_map.prelude = dep_def_map.prelude; | 70 | if dep_def_map.prelude.is_some() { |
71 | def_map.prelude = dep_def_map.prelude; | ||
72 | } | ||
71 | } | 73 | } |
72 | } | 74 | } |
73 | 75 | ||
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 | |||
3897 | "#]], | 3897 | "#]], |
3898 | ); | 3898 | ); |
3899 | } | 3899 | } |
3900 | |||
3901 | #[test] | ||
3902 | fn string_shadowed_with_inner_items() { | ||
3903 | check( | ||
3904 | r#" | ||
3905 | //- /main.rs crate:main deps:alloc | ||
3906 | |||
3907 | /// Custom `String` type. | ||
3908 | struct String; | ||
3909 | |||
3910 | fn f() { | ||
3911 | let _: String$0; | ||
3912 | |||
3913 | fn inner() {} | ||
3914 | } | ||
3915 | |||
3916 | //- /alloc.rs crate:alloc | ||
3917 | #[prelude_import] | ||
3918 | pub use string::*; | ||
3919 | |||
3920 | mod string { | ||
3921 | /// This is `alloc::String`. | ||
3922 | pub struct String; | ||
3923 | } | ||
3924 | "#, | ||
3925 | expect![[r#" | ||
3926 | *String* | ||
3927 | |||
3928 | ```rust | ||
3929 | main | ||
3930 | ``` | ||
3931 | |||
3932 | ```rust | ||
3933 | struct String | ||
3934 | ``` | ||
3935 | |||
3936 | --- | ||
3937 | |||
3938 | Custom `String` type. | ||
3939 | "#]], | ||
3940 | ) | ||
3941 | } | ||
3900 | } | 3942 | } |