Skip to content

Commit f4f71e3

Browse files
author
zombiefungus
committed
include requested changes
1 parent 7d52715 commit f4f71e3

File tree

4 files changed

+28
-27
lines changed

4 files changed

+28
-27
lines changed

crates/ra_hir_def/src/nameres/collector.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use crate::{
2222
diagnostics::DefDiagnostic, mod_resolution::ModDir, path_resolution::ReachedFixedPoint,
2323
raw, BuiltinShadowMode, CrateDefMap, ModuleData, ModuleOrigin, ResolveMode,
2424
},
25-
path::{ModPath, PathKind},
25+
path::{ImportAlias, ModPath, PathKind},
2626
per_ns::PerNs,
2727
visibility::Visibility,
2828
AdtId, AstId, ConstLoc, ContainerId, EnumLoc, EnumVariantId, FunctionLoc, ImplLoc, Intern,
@@ -439,8 +439,9 @@ where
439439
match import.path.segments.last() {
440440
Some(last_segment) => {
441441
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
442+
Some(ImportAlias::Alias(name)) => name.clone(),
443+
Some(ImportAlias::Underscore) => last_segment.clone(), // FIXME rust-analyzer#2736
444+
None => last_segment.clone(),
444445
};
445446
log::debug!("resolved import {:?} ({:?}) to {:?}", name, import, def);
446447

crates/ra_hir_def/src/nameres/raw.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@ use ra_syntax::{
2222
use test_utils::tested_by;
2323

2424
use crate::{
25-
attr::Attrs, db::DefDatabase, path::ModPath, visibility::RawVisibility, FileAstId, HirFileId,
26-
InFile,
25+
attr::Attrs,
26+
db::DefDatabase,
27+
path::{ImportAlias, ModPath},
28+
visibility::RawVisibility,
29+
FileAstId, HirFileId, InFile,
2730
};
2831

2932
/// `RawItems` is a set of top-level items in a file (except for impls).
@@ -145,21 +148,14 @@ impl_arena_id!(Import);
145148
#[derive(Debug, Clone, PartialEq, Eq)]
146149
pub struct ImportData {
147150
pub(super) path: ModPath,
148-
pub(super) alias: ImportAlias,
151+
pub(super) alias: Option<ImportAlias>,
149152
pub(super) is_glob: bool,
150153
pub(super) is_prelude: bool,
151154
pub(super) is_extern_crate: bool,
152155
pub(super) is_macro_use: bool,
153156
pub(super) visibility: RawVisibility,
154157
}
155158

156-
#[derive(Debug, Clone, PartialEq, Eq)]
157-
pub enum ImportAlias {
158-
NoAlias,
159-
Unnamed, // use Foo as _;
160-
Alias(Name),
161-
}
162-
163159
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
164160
pub(super) struct Def(RawId);
165161
impl_arena_id!(Def);
@@ -360,10 +356,10 @@ impl RawItemsCollector {
360356
let path = ModPath::from_name_ref(&name_ref);
361357
let visibility =
362358
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| {
364360
a.name()
365361
.map(|it| it.as_name())
366-
.map_or(ImportAlias::Unnamed, |a| ImportAlias::Alias(a))
362+
.map_or(ImportAlias::Underscore, |a| ImportAlias::Alias(a))
367363
});
368364
let attrs = self.parse_attrs(&extern_crate);
369365
// FIXME: cfg_attr

crates/ra_hir_def/src/path.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ pub enum PathKind {
3434
DollarCrate(CrateId),
3535
}
3636

37+
#[derive(Debug, Clone, PartialEq, Eq)]
38+
pub enum ImportAlias {
39+
/// Unnamed alias, as in `use Foo as _;`
40+
Underscore,
41+
/// Named alias
42+
Alias(Name),
43+
}
44+
3745
impl ModPath {
3846
pub fn from_src(path: ast::Path, hygiene: &Hygiene) -> Option<ModPath> {
3947
lower::lower_path(path, hygiene).map(|it| it.mod_path)
@@ -57,12 +65,7 @@ impl ModPath {
5765
pub(crate) fn expand_use_item(
5866
item_src: InFile<ast::UseItem>,
5967
hygiene: &Hygiene,
60-
mut cb: impl FnMut(
61-
ModPath,
62-
&ast::UseTree,
63-
/* is_glob */ bool,
64-
crate::nameres::raw::ImportAlias,
65-
),
68+
mut cb: impl FnMut(ModPath, &ast::UseTree, /* is_glob */ bool, Option<ImportAlias>),
6669
) {
6770
if let Some(tree) = item_src.value.use_tree() {
6871
lower::lower_use_tree(None, tree, hygiene, &mut cb);

crates/ra_hir_def/src/path/lower/lower_use.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@ use hir_expand::{hygiene::Hygiene, name::AsName};
88
use ra_syntax::ast::{self, NameOwner};
99
use test_utils::tested_by;
1010

11-
use crate::nameres::raw::ImportAlias;
12-
use crate::path::{ModPath, PathKind};
11+
use crate::path::{ImportAlias, ModPath, PathKind};
1312

1413
pub(crate) fn lower_use_tree(
1514
prefix: Option<ModPath>,
1615
tree: ast::UseTree,
1716
hygiene: &Hygiene,
18-
cb: &mut dyn FnMut(ModPath, &ast::UseTree, bool, ImportAlias),
17+
cb: &mut dyn FnMut(ModPath, &ast::UseTree, bool, Option<ImportAlias>),
1918
) {
2019
if let Some(use_tree_list) = tree.use_tree_list() {
2120
let prefix = match tree.path() {
@@ -32,8 +31,10 @@ pub(crate) fn lower_use_tree(
3231
lower_use_tree(prefix.clone(), child_tree, hygiene, cb);
3332
}
3433
} else {
35-
let alias = tree.alias().map_or(ImportAlias::NoAlias, |a| {
36-
a.name().map(|it| it.as_name()).map_or(ImportAlias::Unnamed, |a| ImportAlias::Alias(a))
34+
let alias = tree.alias().map(|a| {
35+
a.name()
36+
.map(|it| it.as_name())
37+
.map_or(ImportAlias::Underscore, |a| ImportAlias::Alias(a))
3738
});
3839
let is_glob = tree.has_star();
3940
if let Some(ast_path) = tree.path() {
@@ -57,7 +58,7 @@ pub(crate) fn lower_use_tree(
5758
} else if is_glob {
5859
tested_by!(glob_enum_group);
5960
if let Some(prefix) = prefix {
60-
cb(prefix, &tree, is_glob, ImportAlias::NoAlias)
61+
cb(prefix, &tree, is_glob, None)
6162
}
6263
}
6364
}

0 commit comments

Comments
 (0)