mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 13:51:31 +00:00
Rename
This commit is contained in:
parent
c0661ce744
commit
263401bf75
3 changed files with 14 additions and 17 deletions
|
@ -35,7 +35,7 @@ fn find_path_inner(
|
|||
let def_map = db.crate_def_map(from.krate);
|
||||
let from_scope: &crate::item_scope::ItemScope = &def_map.modules[from.local_id].scope;
|
||||
if let Some((name, _)) = from_scope.name_of(item) {
|
||||
return Some(ModPath::from_simple_segments(PathKind::Plain, vec![name.clone()]));
|
||||
return Some(ModPath::from_segments(PathKind::Plain, vec![name.clone()]));
|
||||
}
|
||||
|
||||
// - if the item is the crate root, return `crate`
|
||||
|
@ -45,12 +45,12 @@ fn find_path_inner(
|
|||
local_id: def_map.root,
|
||||
}))
|
||||
{
|
||||
return Some(ModPath::from_simple_segments(PathKind::Crate, Vec::new()));
|
||||
return Some(ModPath::from_segments(PathKind::Crate, Vec::new()));
|
||||
}
|
||||
|
||||
// - if the item is the module we're in, use `self`
|
||||
if item == ItemInNs::Types(from.into()) {
|
||||
return Some(ModPath::from_simple_segments(PathKind::Super(0), Vec::new()));
|
||||
return Some(ModPath::from_segments(PathKind::Super(0), Vec::new()));
|
||||
}
|
||||
|
||||
// - if the item is the parent module, use `super` (this is not used recursively, since `super::super` is ugly)
|
||||
|
@ -61,14 +61,14 @@ fn find_path_inner(
|
|||
local_id: parent_id,
|
||||
}))
|
||||
{
|
||||
return Some(ModPath::from_simple_segments(PathKind::Super(1), Vec::new()));
|
||||
return Some(ModPath::from_segments(PathKind::Super(1), Vec::new()));
|
||||
}
|
||||
}
|
||||
|
||||
// - if the item is the crate root of a dependency crate, return the name from the extern prelude
|
||||
for (name, def_id) in &def_map.extern_prelude {
|
||||
if item == ItemInNs::Types(*def_id) {
|
||||
return Some(ModPath::from_simple_segments(PathKind::Plain, vec![name.clone()]));
|
||||
return Some(ModPath::from_segments(PathKind::Plain, vec![name.clone()]));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -79,7 +79,7 @@ fn find_path_inner(
|
|||
&prelude_def_map.modules[prelude_module.local_id].scope;
|
||||
if let Some((name, vis)) = prelude_scope.name_of(item) {
|
||||
if vis.is_visible_from(db, from) {
|
||||
return Some(ModPath::from_simple_segments(PathKind::Plain, vec![name.clone()]));
|
||||
return Some(ModPath::from_segments(PathKind::Plain, vec![name.clone()]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,10 +39,7 @@ impl ModPath {
|
|||
lower::lower_path(path, hygiene).map(|it| it.mod_path)
|
||||
}
|
||||
|
||||
pub fn from_simple_segments(
|
||||
kind: PathKind,
|
||||
segments: impl IntoIterator<Item = Name>,
|
||||
) -> ModPath {
|
||||
pub fn from_segments(kind: PathKind, segments: impl IntoIterator<Item = Name>) -> ModPath {
|
||||
let segments = segments.into_iter().collect::<Vec<_>>();
|
||||
ModPath { kind, segments }
|
||||
}
|
||||
|
@ -240,7 +237,7 @@ impl From<Name> for Path {
|
|||
fn from(name: Name) -> Path {
|
||||
Path {
|
||||
type_anchor: None,
|
||||
mod_path: ModPath::from_simple_segments(PathKind::Plain, iter::once(name)),
|
||||
mod_path: ModPath::from_segments(PathKind::Plain, iter::once(name)),
|
||||
generic_args: vec![None],
|
||||
}
|
||||
}
|
||||
|
@ -248,7 +245,7 @@ impl From<Name> for Path {
|
|||
|
||||
impl From<Name> for ModPath {
|
||||
fn from(name: Name) -> ModPath {
|
||||
ModPath::from_simple_segments(PathKind::Plain, iter::once(name))
|
||||
ModPath::from_segments(PathKind::Plain, iter::once(name))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -311,7 +308,7 @@ macro_rules! __known_path {
|
|||
macro_rules! __path {
|
||||
($start:ident $(:: $seg:ident)*) => ({
|
||||
$crate::__known_path!($start $(:: $seg)*);
|
||||
$crate::path::ModPath::from_simple_segments($crate::path::PathKind::Abs, vec![
|
||||
$crate::path::ModPath::from_segments($crate::path::PathKind::Abs, vec![
|
||||
$crate::path::__name![$start], $($crate::path::__name![$seg],)*
|
||||
])
|
||||
});
|
||||
|
|
|
@ -84,7 +84,7 @@ fn convert_path(prefix: Option<ModPath>, path: ast::Path, hygiene: &Hygiene) ->
|
|||
res
|
||||
}
|
||||
Either::Right(crate_id) => {
|
||||
return Some(ModPath::from_simple_segments(
|
||||
return Some(ModPath::from_segments(
|
||||
PathKind::DollarCrate(crate_id),
|
||||
iter::empty(),
|
||||
))
|
||||
|
@ -95,19 +95,19 @@ fn convert_path(prefix: Option<ModPath>, path: ast::Path, hygiene: &Hygiene) ->
|
|||
if prefix.is_some() {
|
||||
return None;
|
||||
}
|
||||
ModPath::from_simple_segments(PathKind::Crate, iter::empty())
|
||||
ModPath::from_segments(PathKind::Crate, iter::empty())
|
||||
}
|
||||
ast::PathSegmentKind::SelfKw => {
|
||||
if prefix.is_some() {
|
||||
return None;
|
||||
}
|
||||
ModPath::from_simple_segments(PathKind::Super(0), iter::empty())
|
||||
ModPath::from_segments(PathKind::Super(0), iter::empty())
|
||||
}
|
||||
ast::PathSegmentKind::SuperKw => {
|
||||
if prefix.is_some() {
|
||||
return None;
|
||||
}
|
||||
ModPath::from_simple_segments(PathKind::Super(1), iter::empty())
|
||||
ModPath::from_segments(PathKind::Super(1), iter::empty())
|
||||
}
|
||||
ast::PathSegmentKind::Type { .. } => {
|
||||
// not allowed in imports
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue