diff options
Diffstat (limited to 'crates/ra_hir_def/src/nameres')
-rw-r--r-- | crates/ra_hir_def/src/nameres/collector.rs | 5 | ||||
-rw-r--r-- | crates/ra_hir_def/src/nameres/raw.rs | 15 |
2 files changed, 17 insertions, 3 deletions
diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs index 7499dff31..193067f73 100644 --- a/crates/ra_hir_def/src/nameres/collector.rs +++ b/crates/ra_hir_def/src/nameres/collector.rs | |||
@@ -438,7 +438,10 @@ where | |||
438 | } else { | 438 | } else { |
439 | match import.path.segments.last() { | 439 | match import.path.segments.last() { |
440 | Some(last_segment) => { | 440 | Some(last_segment) => { |
441 | let name = import.alias.clone().unwrap_or_else(|| last_segment.clone()); | 441 | let name = match &import.alias { |
442 | raw::ImportAlias::Alias(name) => name.clone(), | ||
443 | _ => last_segment.clone(), // "use as ;" and "use as _;" are treated the same way | ||
444 | }; | ||
442 | log::debug!("resolved import {:?} ({:?}) to {:?}", name, import, def); | 445 | log::debug!("resolved import {:?} ({:?}) to {:?}", name, import, def); |
443 | 446 | ||
444 | // extern crates in the crate root are special-cased to insert entries into the extern prelude: rust-lang/rust#54658 | 447 | // extern crates in the crate root are special-cased to insert entries into the extern prelude: rust-lang/rust#54658 |
diff --git a/crates/ra_hir_def/src/nameres/raw.rs b/crates/ra_hir_def/src/nameres/raw.rs index fac1169ef..f068b4d4e 100644 --- a/crates/ra_hir_def/src/nameres/raw.rs +++ b/crates/ra_hir_def/src/nameres/raw.rs | |||
@@ -145,7 +145,7 @@ impl_arena_id!(Import); | |||
145 | #[derive(Debug, Clone, PartialEq, Eq)] | 145 | #[derive(Debug, Clone, PartialEq, Eq)] |
146 | pub struct ImportData { | 146 | pub struct ImportData { |
147 | pub(super) path: ModPath, | 147 | pub(super) path: ModPath, |
148 | pub(super) alias: Option<Name>, | 148 | pub(super) alias: ImportAlias, |
149 | pub(super) is_glob: bool, | 149 | pub(super) is_glob: bool, |
150 | pub(super) is_prelude: bool, | 150 | pub(super) is_prelude: bool, |
151 | pub(super) is_extern_crate: bool, | 151 | pub(super) is_extern_crate: bool, |
@@ -153,6 +153,13 @@ pub struct ImportData { | |||
153 | pub(super) visibility: RawVisibility, | 153 | pub(super) visibility: RawVisibility, |
154 | } | 154 | } |
155 | 155 | ||
156 | #[derive(Debug, Clone, PartialEq, Eq)] | ||
157 | pub enum ImportAlias { | ||
158 | NoAlias, | ||
159 | Unnamed, // use Foo as _; | ||
160 | Alias(Name), | ||
161 | } | ||
162 | |||
156 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 163 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
157 | pub(super) struct Def(RawId); | 164 | pub(super) struct Def(RawId); |
158 | impl_arena_id!(Def); | 165 | impl_arena_id!(Def); |
@@ -353,7 +360,11 @@ impl RawItemsCollector { | |||
353 | let path = ModPath::from_name_ref(&name_ref); | 360 | let path = ModPath::from_name_ref(&name_ref); |
354 | let visibility = | 361 | let visibility = |
355 | RawVisibility::from_ast_with_hygiene(extern_crate.visibility(), &self.hygiene); | 362 | RawVisibility::from_ast_with_hygiene(extern_crate.visibility(), &self.hygiene); |
356 | let alias = extern_crate.alias().and_then(|a| a.name()).map(|it| it.as_name()); | 363 | let alias = extern_crate.alias().map_or(ImportAlias::NoAlias, |a| { |
364 | a.name() | ||
365 | .map(|it| it.as_name()) | ||
366 | .map_or(ImportAlias::Unnamed, |a| ImportAlias::Alias(a)) | ||
367 | }); | ||
357 | let attrs = self.parse_attrs(&extern_crate); | 368 | let attrs = self.parse_attrs(&extern_crate); |
358 | // FIXME: cfg_attr | 369 | // FIXME: cfg_attr |
359 | let is_macro_use = extern_crate.has_atom_attr("macro_use"); | 370 | let is_macro_use = extern_crate.has_atom_attr("macro_use"); |