add new ImportAlias enum to differentiate no alias from an _ alias
This commit is contained in:
parent
dce7dc44be
commit
7d52715945
@ -438,7 +438,10 @@ where
|
||||
} else {
|
||||
match import.path.segments.last() {
|
||||
Some(last_segment) => {
|
||||
let name = import.alias.clone().unwrap_or_else(|| last_segment.clone());
|
||||
let name = match &import.alias {
|
||||
raw::ImportAlias::Alias(name) => name.clone(),
|
||||
_ => last_segment.clone(), // "use as ;" and "use as _;" are treated the same way
|
||||
};
|
||||
log::debug!("resolved import {:?} ({:?}) to {:?}", name, import, def);
|
||||
|
||||
// extern crates in the crate root are special-cased to insert entries into the extern prelude: rust-lang/rust#54658
|
||||
|
@ -145,7 +145,7 @@ impl_arena_id!(Import);
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct ImportData {
|
||||
pub(super) path: ModPath,
|
||||
pub(super) alias: Option<Name>,
|
||||
pub(super) alias: ImportAlias,
|
||||
pub(super) is_glob: bool,
|
||||
pub(super) is_prelude: bool,
|
||||
pub(super) is_extern_crate: bool,
|
||||
@ -153,6 +153,13 @@ pub struct ImportData {
|
||||
pub(super) visibility: RawVisibility,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum ImportAlias {
|
||||
NoAlias,
|
||||
Unnamed, // use Foo as _;
|
||||
Alias(Name),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub(super) struct Def(RawId);
|
||||
impl_arena_id!(Def);
|
||||
@ -353,7 +360,11 @@ impl RawItemsCollector {
|
||||
let path = ModPath::from_name_ref(&name_ref);
|
||||
let visibility =
|
||||
RawVisibility::from_ast_with_hygiene(extern_crate.visibility(), &self.hygiene);
|
||||
let alias = extern_crate.alias().and_then(|a| a.name()).map(|it| it.as_name());
|
||||
let alias = extern_crate.alias().map_or(ImportAlias::NoAlias, |a| {
|
||||
a.name()
|
||||
.map(|it| it.as_name())
|
||||
.map_or(ImportAlias::Unnamed, |a| ImportAlias::Alias(a))
|
||||
});
|
||||
let attrs = self.parse_attrs(&extern_crate);
|
||||
// FIXME: cfg_attr
|
||||
let is_macro_use = extern_crate.has_atom_attr("macro_use");
|
||||
|
@ -57,7 +57,12 @@ impl ModPath {
|
||||
pub(crate) fn expand_use_item(
|
||||
item_src: InFile<ast::UseItem>,
|
||||
hygiene: &Hygiene,
|
||||
mut cb: impl FnMut(ModPath, &ast::UseTree, /* is_glob */ bool, Option<Name>),
|
||||
mut cb: impl FnMut(
|
||||
ModPath,
|
||||
&ast::UseTree,
|
||||
/* is_glob */ bool,
|
||||
crate::nameres::raw::ImportAlias,
|
||||
),
|
||||
) {
|
||||
if let Some(tree) = item_src.value.use_tree() {
|
||||
lower::lower_use_tree(None, tree, hygiene, &mut cb);
|
||||
|
@ -4,20 +4,18 @@
|
||||
use std::iter;
|
||||
|
||||
use either::Either;
|
||||
use hir_expand::{
|
||||
hygiene::Hygiene,
|
||||
name::{AsName, Name},
|
||||
};
|
||||
use hir_expand::{hygiene::Hygiene, name::AsName};
|
||||
use ra_syntax::ast::{self, NameOwner};
|
||||
use test_utils::tested_by;
|
||||
|
||||
use crate::nameres::raw::ImportAlias;
|
||||
use crate::path::{ModPath, PathKind};
|
||||
|
||||
pub(crate) fn lower_use_tree(
|
||||
prefix: Option<ModPath>,
|
||||
tree: ast::UseTree,
|
||||
hygiene: &Hygiene,
|
||||
cb: &mut dyn FnMut(ModPath, &ast::UseTree, bool, Option<Name>),
|
||||
cb: &mut dyn FnMut(ModPath, &ast::UseTree, bool, ImportAlias),
|
||||
) {
|
||||
if let Some(use_tree_list) = tree.use_tree_list() {
|
||||
let prefix = match tree.path() {
|
||||
@ -34,7 +32,9 @@ pub(crate) fn lower_use_tree(
|
||||
lower_use_tree(prefix.clone(), child_tree, hygiene, cb);
|
||||
}
|
||||
} else {
|
||||
let alias = tree.alias().and_then(|a| a.name()).map(|a| a.as_name());
|
||||
let alias = tree.alias().map_or(ImportAlias::NoAlias, |a| {
|
||||
a.name().map(|it| it.as_name()).map_or(ImportAlias::Unnamed, |a| ImportAlias::Alias(a))
|
||||
});
|
||||
let is_glob = tree.has_star();
|
||||
if let Some(ast_path) = tree.path() {
|
||||
// Handle self in a path.
|
||||
@ -57,7 +57,7 @@ pub(crate) fn lower_use_tree(
|
||||
} else if is_glob {
|
||||
tested_by!(glob_enum_group);
|
||||
if let Some(prefix) = prefix {
|
||||
cb(prefix, &tree, is_glob, None)
|
||||
cb(prefix, &tree, is_glob, ImportAlias::NoAlias)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user