include requested changes

This commit is contained in:
zombiefungus
2020-02-02 08:04:06 -05:00
parent 7d52715945
commit f4f71e361e
4 changed files with 28 additions and 27 deletions
+4 -3
View File
@@ -22,7 +22,7 @@
diagnostics::DefDiagnostic, mod_resolution::ModDir, path_resolution::ReachedFixedPoint,
raw, BuiltinShadowMode, CrateDefMap, ModuleData, ModuleOrigin, ResolveMode,
},
path::{ModPath, PathKind},
path::{ImportAlias, ModPath, PathKind},
per_ns::PerNs,
visibility::Visibility,
AdtId, AstId, ConstLoc, ContainerId, EnumLoc, EnumVariantId, FunctionLoc, ImplLoc, Intern,
@@ -439,8 +439,9 @@ fn record_resolved_import(&mut self, directive: &ImportDirective) {
match import.path.segments.last() {
Some(last_segment) => {
let name = match &import.alias {
raw::ImportAlias::Alias(name) => name.clone(),
_ => last_segment.clone(), // "use as ;" and "use as _;" are treated the same way
Some(ImportAlias::Alias(name)) => name.clone(),
Some(ImportAlias::Underscore) => last_segment.clone(), // FIXME rust-analyzer#2736
None => last_segment.clone(),
};
log::debug!("resolved import {:?} ({:?}) to {:?}", name, import, def);
+8 -12
View File
@@ -22,8 +22,11 @@
use test_utils::tested_by;
use crate::{
attr::Attrs, db::DefDatabase, path::ModPath, visibility::RawVisibility, FileAstId, HirFileId,
InFile,
attr::Attrs,
db::DefDatabase,
path::{ImportAlias, ModPath},
visibility::RawVisibility,
FileAstId, HirFileId, InFile,
};
/// `RawItems` is a set of top-level items in a file (except for impls).
@@ -145,7 +148,7 @@ pub(super) enum ModuleData {
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ImportData {
pub(super) path: ModPath,
pub(super) alias: ImportAlias,
pub(super) alias: Option<ImportAlias>,
pub(super) is_glob: bool,
pub(super) is_prelude: bool,
pub(super) is_extern_crate: bool,
@@ -153,13 +156,6 @@ 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);
@@ -360,10 +356,10 @@ fn add_extern_crate_item(
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().map_or(ImportAlias::NoAlias, |a| {
let alias = extern_crate.alias().map(|a| {
a.name()
.map(|it| it.as_name())
.map_or(ImportAlias::Unnamed, |a| ImportAlias::Alias(a))
.map_or(ImportAlias::Underscore, |a| ImportAlias::Alias(a))
});
let attrs = self.parse_attrs(&extern_crate);
// FIXME: cfg_attr
+9 -6
View File
@@ -34,6 +34,14 @@ pub enum PathKind {
DollarCrate(CrateId),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ImportAlias {
/// Unnamed alias, as in `use Foo as _;`
Underscore,
/// Named alias
Alias(Name),
}
impl ModPath {
pub fn from_src(path: ast::Path, hygiene: &Hygiene) -> Option<ModPath> {
lower::lower_path(path, hygiene).map(|it| it.mod_path)
@@ -57,12 +65,7 @@ pub(crate) fn from_tt_ident(ident: &tt::Ident) -> ModPath {
pub(crate) fn expand_use_item(
item_src: InFile<ast::UseItem>,
hygiene: &Hygiene,
mut cb: impl FnMut(
ModPath,
&ast::UseTree,
/* is_glob */ bool,
crate::nameres::raw::ImportAlias,
),
mut cb: impl FnMut(ModPath, &ast::UseTree, /* is_glob */ bool, Option<ImportAlias>),
) {
if let Some(tree) = item_src.value.use_tree() {
lower::lower_use_tree(None, tree, hygiene, &mut cb);
@@ -8,14 +8,13 @@
use ra_syntax::ast::{self, NameOwner};
use test_utils::tested_by;
use crate::nameres::raw::ImportAlias;
use crate::path::{ModPath, PathKind};
use crate::path::{ImportAlias, ModPath, PathKind};
pub(crate) fn lower_use_tree(
prefix: Option<ModPath>,
tree: ast::UseTree,
hygiene: &Hygiene,
cb: &mut dyn FnMut(ModPath, &ast::UseTree, bool, ImportAlias),
cb: &mut dyn FnMut(ModPath, &ast::UseTree, bool, Option<ImportAlias>),
) {
if let Some(use_tree_list) = tree.use_tree_list() {
let prefix = match tree.path() {
@@ -32,8 +31,10 @@ pub(crate) fn lower_use_tree(
lower_use_tree(prefix.clone(), child_tree, hygiene, cb);
}
} else {
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 alias = tree.alias().map(|a| {
a.name()
.map(|it| it.as_name())
.map_or(ImportAlias::Underscore, |a| ImportAlias::Alias(a))
});
let is_glob = tree.has_star();
if let Some(ast_path) = tree.path() {
@@ -57,7 +58,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, ImportAlias::NoAlias)
cb(prefix, &tree, is_glob, None)
}
}
}