From 7d527159457420d55f1ee2f70615098a10176b91 Mon Sep 17 00:00:00 2001 From: zombiefungus Date: Thu, 30 Jan 2020 23:14:20 -0500 Subject: add new ImportAlias enum to differentiate no alias from an _ alias --- crates/ra_hir_def/src/path/lower/lower_use.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'crates/ra_hir_def/src/path') 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 531878174..f693cefbc 100644 --- a/crates/ra_hir_def/src/path/lower/lower_use.rs +++ b/crates/ra_hir_def/src/path/lower/lower_use.rs @@ -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, tree: ast::UseTree, hygiene: &Hygiene, - cb: &mut dyn FnMut(ModPath, &ast::UseTree, bool, Option), + 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) } } } -- cgit v1.2.3 From f4f71e361ee632a7a09b633934a9c0a11f4a9be7 Mon Sep 17 00:00:00 2001 From: zombiefungus Date: Sun, 2 Feb 2020 08:04:06 -0500 Subject: include requested changes --- crates/ra_hir_def/src/path/lower/lower_use.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'crates/ra_hir_def/src/path') 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}; 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, tree: ast::UseTree, hygiene: &Hygiene, - cb: &mut dyn FnMut(ModPath, &ast::UseTree, bool, ImportAlias), + cb: &mut dyn FnMut(ModPath, &ast::UseTree, bool, Option), ) { 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) } } } -- cgit v1.2.3