diff options
Diffstat (limited to 'crates/ra_hir')
-rw-r--r-- | crates/ra_hir/src/marks.rs | 1 | ||||
-rw-r--r-- | crates/ra_hir/src/nameres/collector.rs | 24 | ||||
-rw-r--r-- | crates/ra_hir/src/nameres/tests.rs | 26 |
3 files changed, 41 insertions, 10 deletions
diff --git a/crates/ra_hir/src/marks.rs b/crates/ra_hir/src/marks.rs index e8f3005f1..bbf57004d 100644 --- a/crates/ra_hir/src/marks.rs +++ b/crates/ra_hir/src/marks.rs | |||
@@ -1,4 +1,5 @@ | |||
1 | test_utils::marks!( | 1 | test_utils::marks!( |
2 | bogus_paths | ||
2 | name_res_works_for_broken_modules | 3 | name_res_works_for_broken_modules |
3 | can_import_enum_variant | 4 | can_import_enum_variant |
4 | type_var_cycles_resolve_completely | 5 | type_var_cycles_resolve_completely |
diff --git a/crates/ra_hir/src/nameres/collector.rs b/crates/ra_hir/src/nameres/collector.rs index cbe850ba4..e7afc34c9 100644 --- a/crates/ra_hir/src/nameres/collector.rs +++ b/crates/ra_hir/src/nameres/collector.rs | |||
@@ -213,18 +213,22 @@ where | |||
213 | } | 213 | } |
214 | } | 214 | } |
215 | } else { | 215 | } else { |
216 | let last_segment = import.path.segments.last().unwrap(); | 216 | match import.path.segments.last() { |
217 | let name = import.alias.clone().unwrap_or_else(|| last_segment.name.clone()); | 217 | Some(last_segment) => { |
218 | log::debug!("resolved import {:?} ({:?}) to {:?}", name, import, def); | 218 | let name = import.alias.clone().unwrap_or_else(|| last_segment.name.clone()); |
219 | 219 | log::debug!("resolved import {:?} ({:?}) to {:?}", name, import, def); | |
220 | // extern crates in the crate root are special-cased to insert entries into the extern prelude: rust-lang/rust#54658 | 220 | |
221 | if import.is_extern_crate && module_id == self.def_map.root { | 221 | // extern crates in the crate root are special-cased to insert entries into the extern prelude: rust-lang/rust#54658 |
222 | if let Some(def) = def.take_types() { | 222 | if import.is_extern_crate && module_id == self.def_map.root { |
223 | self.def_map.extern_prelude.insert(name.clone(), def); | 223 | if let Some(def) = def.take_types() { |
224 | self.def_map.extern_prelude.insert(name.clone(), def); | ||
225 | } | ||
226 | } | ||
227 | let resolution = Resolution { def, import: Some(import_id) }; | ||
228 | self.update(module_id, Some(import_id), &[(name, resolution)]); | ||
224 | } | 229 | } |
230 | None => tested_by!(bogus_paths), | ||
225 | } | 231 | } |
226 | let resolution = Resolution { def, import: Some(import_id) }; | ||
227 | self.update(module_id, Some(import_id), &[(name, resolution)]); | ||
228 | } | 232 | } |
229 | } | 233 | } |
230 | 234 | ||
diff --git a/crates/ra_hir/src/nameres/tests.rs b/crates/ra_hir/src/nameres/tests.rs index 36c1d74ce..f73f9d8a6 100644 --- a/crates/ra_hir/src/nameres/tests.rs +++ b/crates/ra_hir/src/nameres/tests.rs | |||
@@ -97,6 +97,32 @@ E: t | |||
97 | } | 97 | } |
98 | 98 | ||
99 | #[test] | 99 | #[test] |
100 | fn bogus_paths() { | ||
101 | covers!(bogus_paths); | ||
102 | let map = def_map( | ||
103 | " | ||
104 | //- /lib.rs | ||
105 | mod foo; | ||
106 | struct S; | ||
107 | use self; | ||
108 | |||
109 | //- /foo/mod.rs | ||
110 | use super; | ||
111 | use crate; | ||
112 | |||
113 | ", | ||
114 | ); | ||
115 | assert_snapshot_matches!(map, @r###" | ||
116 | crate | ||
117 | foo: t | ||
118 | S: t v | ||
119 | |||
120 | crate::foo | ||
121 | "### | ||
122 | ) | ||
123 | } | ||
124 | |||
125 | #[test] | ||
100 | fn use_as() { | 126 | fn use_as() { |
101 | let map = def_map( | 127 | let map = def_map( |
102 | " | 128 | " |