mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 22:31:43 +00:00
Merge #6019
6019: Remove make::path_from_text r=matklad a=Veykril This removes the `make::path_from_text` function, which according to a note should've been private. I removed it since it didn't really serve a purpose as it was simply wrapping `make::ast_from_text`. Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
This commit is contained in:
commit
18c62c8a39
6 changed files with 61 additions and 47 deletions
|
@ -13,7 +13,7 @@ use hir_expand::{
|
|||
hygiene::Hygiene,
|
||||
name::{AsName, Name},
|
||||
};
|
||||
use syntax::ast;
|
||||
use syntax::ast::{self, make};
|
||||
|
||||
use crate::{
|
||||
type_ref::{TypeBound, TypeRef},
|
||||
|
@ -100,6 +100,26 @@ impl ModPath {
|
|||
}
|
||||
self.segments.first()
|
||||
}
|
||||
|
||||
pub fn to_ast_path(&self) -> ast::Path {
|
||||
let mut segments = Vec::new();
|
||||
let mut is_abs = false;
|
||||
match self.kind {
|
||||
PathKind::Plain => {}
|
||||
PathKind::Super(0) => segments.push(make::path_segment_self()),
|
||||
PathKind::Super(n) => segments.extend((0..n).map(|_| make::path_segment_super())),
|
||||
PathKind::Crate => segments.push(make::path_segment_crate()),
|
||||
PathKind::Abs => is_abs = true,
|
||||
PathKind::DollarCrate(_) => (),
|
||||
}
|
||||
|
||||
segments.extend(
|
||||
self.segments
|
||||
.iter()
|
||||
.map(|segment| make::path_segment(make::name_ref(&segment.to_string()))),
|
||||
);
|
||||
make::path_from_segments(segments, is_abs)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
|
@ -286,10 +306,8 @@ impl Display for ModPath {
|
|||
};
|
||||
match self.kind {
|
||||
PathKind::Plain => {}
|
||||
PathKind::Super(0) => add_segment("self")?,
|
||||
PathKind::Super(n) => {
|
||||
if n == 0 {
|
||||
add_segment("self")?;
|
||||
}
|
||||
for _ in 0..n {
|
||||
add_segment("super")?;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue