aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def
diff options
context:
space:
mode:
authorzombiefungus <[email protected]>2020-02-02 13:04:06 +0000
committerzombiefungus <[email protected]>2020-02-02 13:04:24 +0000
commitf4f71e361ee632a7a09b633934a9c0a11f4a9be7 (patch)
treeddc461410065761d4f4397e96ea915ea9264609a /crates/ra_hir_def
parent7d527159457420d55f1ee2f70615098a10176b91 (diff)
include requested changes
Diffstat (limited to 'crates/ra_hir_def')
-rw-r--r--crates/ra_hir_def/src/nameres/collector.rs7
-rw-r--r--crates/ra_hir_def/src/nameres/raw.rs20
-rw-r--r--crates/ra_hir_def/src/path.rs15
-rw-r--r--crates/ra_hir_def/src/path/lower/lower_use.rs13
4 files changed, 28 insertions, 27 deletions
diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs
index 193067f73..6352c71ef 100644
--- a/crates/ra_hir_def/src/nameres/collector.rs
+++ b/crates/ra_hir_def/src/nameres/collector.rs
@@ -22,7 +22,7 @@ use crate::{
22 diagnostics::DefDiagnostic, mod_resolution::ModDir, path_resolution::ReachedFixedPoint, 22 diagnostics::DefDiagnostic, mod_resolution::ModDir, path_resolution::ReachedFixedPoint,
23 raw, BuiltinShadowMode, CrateDefMap, ModuleData, ModuleOrigin, ResolveMode, 23 raw, BuiltinShadowMode, CrateDefMap, ModuleData, ModuleOrigin, ResolveMode,
24 }, 24 },
25 path::{ModPath, PathKind}, 25 path::{ImportAlias, ModPath, PathKind},
26 per_ns::PerNs, 26 per_ns::PerNs,
27 visibility::Visibility, 27 visibility::Visibility,
28 AdtId, AstId, ConstLoc, ContainerId, EnumLoc, EnumVariantId, FunctionLoc, ImplLoc, Intern, 28 AdtId, AstId, ConstLoc, ContainerId, EnumLoc, EnumVariantId, FunctionLoc, ImplLoc, Intern,
@@ -439,8 +439,9 @@ where
439 match import.path.segments.last() { 439 match import.path.segments.last() {
440 Some(last_segment) => { 440 Some(last_segment) => {
441 let name = match &import.alias { 441 let name = match &import.alias {
442 raw::ImportAlias::Alias(name) => name.clone(), 442 Some(ImportAlias::Alias(name)) => name.clone(),
443 _ => last_segment.clone(), // "use as ;" and "use as _;" are treated the same way 443 Some(ImportAlias::Underscore) => last_segment.clone(), // FIXME rust-analyzer#2736
444 None => last_segment.clone(),
444 }; 445 };
445 log::debug!("resolved import {:?} ({:?}) to {:?}", name, import, def); 446 log::debug!("resolved import {:?} ({:?}) to {:?}", name, import, def);
446 447
diff --git a/crates/ra_hir_def/src/nameres/raw.rs b/crates/ra_hir_def/src/nameres/raw.rs
index f068b4d4e..650cf1f98 100644
--- a/crates/ra_hir_def/src/nameres/raw.rs
+++ b/crates/ra_hir_def/src/nameres/raw.rs
@@ -22,8 +22,11 @@ use ra_syntax::{
22use test_utils::tested_by; 22use test_utils::tested_by;
23 23
24use crate::{ 24use crate::{
25 attr::Attrs, db::DefDatabase, path::ModPath, visibility::RawVisibility, FileAstId, HirFileId, 25 attr::Attrs,
26 InFile, 26 db::DefDatabase,
27 path::{ImportAlias, ModPath},
28 visibility::RawVisibility,
29 FileAstId, HirFileId, InFile,
27}; 30};
28 31
29/// `RawItems` is a set of top-level items in a file (except for impls). 32/// `RawItems` is a set of top-level items in a file (except for impls).
@@ -145,7 +148,7 @@ impl_arena_id!(Import);
145#[derive(Debug, Clone, PartialEq, Eq)] 148#[derive(Debug, Clone, PartialEq, Eq)]
146pub struct ImportData { 149pub struct ImportData {
147 pub(super) path: ModPath, 150 pub(super) path: ModPath,
148 pub(super) alias: ImportAlias, 151 pub(super) alias: Option<ImportAlias>,
149 pub(super) is_glob: bool, 152 pub(super) is_glob: bool,
150 pub(super) is_prelude: bool, 153 pub(super) is_prelude: bool,
151 pub(super) is_extern_crate: bool, 154 pub(super) is_extern_crate: bool,
@@ -153,13 +156,6 @@ pub struct ImportData {
153 pub(super) visibility: RawVisibility, 156 pub(super) visibility: RawVisibility,
154} 157}
155 158
156#[derive(Debug, Clone, PartialEq, Eq)]
157pub enum ImportAlias {
158 NoAlias,
159 Unnamed, // use Foo as _;
160 Alias(Name),
161}
162
163#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 159#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
164pub(super) struct Def(RawId); 160pub(super) struct Def(RawId);
165impl_arena_id!(Def); 161impl_arena_id!(Def);
@@ -360,10 +356,10 @@ impl RawItemsCollector {
360 let path = ModPath::from_name_ref(&name_ref); 356 let path = ModPath::from_name_ref(&name_ref);
361 let visibility = 357 let visibility =
362 RawVisibility::from_ast_with_hygiene(extern_crate.visibility(), &self.hygiene); 358 RawVisibility::from_ast_with_hygiene(extern_crate.visibility(), &self.hygiene);
363 let alias = extern_crate.alias().map_or(ImportAlias::NoAlias, |a| { 359 let alias = extern_crate.alias().map(|a| {
364 a.name() 360 a.name()
365 .map(|it| it.as_name()) 361 .map(|it| it.as_name())
366 .map_or(ImportAlias::Unnamed, |a| ImportAlias::Alias(a)) 362 .map_or(ImportAlias::Underscore, |a| ImportAlias::Alias(a))
367 }); 363 });
368 let attrs = self.parse_attrs(&extern_crate); 364 let attrs = self.parse_attrs(&extern_crate);
369 // FIXME: cfg_attr 365 // FIXME: cfg_attr
diff --git a/crates/ra_hir_def/src/path.rs b/crates/ra_hir_def/src/path.rs
index 27ccf6643..fb7692191 100644
--- a/crates/ra_hir_def/src/path.rs
+++ b/crates/ra_hir_def/src/path.rs
@@ -34,6 +34,14 @@ pub enum PathKind {
34 DollarCrate(CrateId), 34 DollarCrate(CrateId),
35} 35}
36 36
37#[derive(Debug, Clone, PartialEq, Eq)]
38pub enum ImportAlias {
39 /// Unnamed alias, as in `use Foo as _;`
40 Underscore,
41 /// Named alias
42 Alias(Name),
43}
44
37impl ModPath { 45impl ModPath {
38 pub fn from_src(path: ast::Path, hygiene: &Hygiene) -> Option<ModPath> { 46 pub fn from_src(path: ast::Path, hygiene: &Hygiene) -> Option<ModPath> {
39 lower::lower_path(path, hygiene).map(|it| it.mod_path) 47 lower::lower_path(path, hygiene).map(|it| it.mod_path)
@@ -57,12 +65,7 @@ impl ModPath {
57 pub(crate) fn expand_use_item( 65 pub(crate) fn expand_use_item(
58 item_src: InFile<ast::UseItem>, 66 item_src: InFile<ast::UseItem>,
59 hygiene: &Hygiene, 67 hygiene: &Hygiene,
60 mut cb: impl FnMut( 68 mut cb: impl FnMut(ModPath, &ast::UseTree, /* is_glob */ bool, Option<ImportAlias>),
61 ModPath,
62 &ast::UseTree,
63 /* is_glob */ bool,
64 crate::nameres::raw::ImportAlias,
65 ),
66 ) { 69 ) {
67 if let Some(tree) = item_src.value.use_tree() { 70 if let Some(tree) = item_src.value.use_tree() {
68 lower::lower_use_tree(None, tree, hygiene, &mut cb); 71 lower::lower_use_tree(None, tree, hygiene, &mut cb);
diff --git a/crates/ra_hir_def/src/path/lower/lower_use.rs b/crates/ra_hir_def/src/path/lower/lower_use.rs
index f693cefbc..d2bc9d193 100644
--- a/crates/ra_hir_def/src/path/lower/lower_use.rs
+++ b/crates/ra_hir_def/src/path/lower/lower_use.rs
@@ -8,14 +8,13 @@ use hir_expand::{hygiene::Hygiene, name::AsName};
8use ra_syntax::ast::{self, NameOwner}; 8use ra_syntax::ast::{self, NameOwner};
9use test_utils::tested_by; 9use test_utils::tested_by;
10 10
11use crate::nameres::raw::ImportAlias; 11use crate::path::{ImportAlias, ModPath, PathKind};
12use crate::path::{ModPath, PathKind};
13 12
14pub(crate) fn lower_use_tree( 13pub(crate) fn lower_use_tree(
15 prefix: Option<ModPath>, 14 prefix: Option<ModPath>,
16 tree: ast::UseTree, 15 tree: ast::UseTree,
17 hygiene: &Hygiene, 16 hygiene: &Hygiene,
18 cb: &mut dyn FnMut(ModPath, &ast::UseTree, bool, ImportAlias), 17 cb: &mut dyn FnMut(ModPath, &ast::UseTree, bool, Option<ImportAlias>),
19) { 18) {
20 if let Some(use_tree_list) = tree.use_tree_list() { 19 if let Some(use_tree_list) = tree.use_tree_list() {
21 let prefix = match tree.path() { 20 let prefix = match tree.path() {
@@ -32,8 +31,10 @@ pub(crate) fn lower_use_tree(
32 lower_use_tree(prefix.clone(), child_tree, hygiene, cb); 31 lower_use_tree(prefix.clone(), child_tree, hygiene, cb);
33 } 32 }
34 } else { 33 } else {
35 let alias = tree.alias().map_or(ImportAlias::NoAlias, |a| { 34 let alias = tree.alias().map(|a| {
36 a.name().map(|it| it.as_name()).map_or(ImportAlias::Unnamed, |a| ImportAlias::Alias(a)) 35 a.name()
36 .map(|it| it.as_name())
37 .map_or(ImportAlias::Underscore, |a| ImportAlias::Alias(a))
37 }); 38 });
38 let is_glob = tree.has_star(); 39 let is_glob = tree.has_star();
39 if let Some(ast_path) = tree.path() { 40 if let Some(ast_path) = tree.path() {
@@ -57,7 +58,7 @@ pub(crate) fn lower_use_tree(
57 } else if is_glob { 58 } else if is_glob {
58 tested_by!(glob_enum_group); 59 tested_by!(glob_enum_group);
59 if let Some(prefix) = prefix { 60 if let Some(prefix) = prefix {
60 cb(prefix, &tree, is_glob, ImportAlias::NoAlias) 61 cb(prefix, &tree, is_glob, None)
61 } 62 }
62 } 63 }
63 } 64 }