mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-03 07:04:49 +00:00
remove unnecessary ast::Path::segments alternatives
This commit is contained in:
parent
6403dbf011
commit
89d6b011c4
2 changed files with 2 additions and 12 deletions
|
@ -681,11 +681,10 @@ fn path_import_candidate(
|
||||||
Some(qualifier) => match sema.resolve_path(&qualifier) {
|
Some(qualifier) => match sema.resolve_path(&qualifier) {
|
||||||
None => {
|
None => {
|
||||||
if qualifier.first_qualifier().map_or(true, |it| sema.resolve_path(&it).is_none()) {
|
if qualifier.first_qualifier().map_or(true, |it| sema.resolve_path(&it).is_none()) {
|
||||||
let mut qualifier = qualifier
|
let qualifier = qualifier
|
||||||
.segments_of_this_path_only_rev()
|
.segments()
|
||||||
.map(|seg| seg.name_ref().map(|name| SmolStr::new(name.text())))
|
.map(|seg| seg.name_ref().map(|name| SmolStr::new(name.text())))
|
||||||
.collect::<Option<Vec<_>>>()?;
|
.collect::<Option<Vec<_>>>()?;
|
||||||
qualifier.reverse();
|
|
||||||
ImportCandidate::Path(PathImportCandidate { qualifier: Some(qualifier), name })
|
ImportCandidate::Path(PathImportCandidate { qualifier: Some(qualifier), name })
|
||||||
} else {
|
} else {
|
||||||
return None;
|
return None;
|
||||||
|
|
|
@ -283,11 +283,6 @@ impl ast::Path {
|
||||||
self.first_qualifier_or_self().segment()
|
self.first_qualifier_or_self().segment()
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: Check usages of Self::segments, they might be wrong because of the logic of the bloew function
|
|
||||||
pub fn segments_of_this_path_only_rev(&self) -> impl Iterator<Item = ast::PathSegment> + Clone {
|
|
||||||
self.qualifiers_and_self().filter_map(|it| it.segment())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn segments(&self) -> impl Iterator<Item = ast::PathSegment> + Clone {
|
pub fn segments(&self) -> impl Iterator<Item = ast::PathSegment> + Clone {
|
||||||
let path_range = self.syntax().text_range();
|
let path_range = self.syntax().text_range();
|
||||||
successors(self.first_segment(), move |p| {
|
successors(self.first_segment(), move |p| {
|
||||||
|
@ -305,10 +300,6 @@ impl ast::Path {
|
||||||
successors(self.qualifier(), |p| p.qualifier())
|
successors(self.qualifier(), |p| p.qualifier())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn qualifiers_and_self(&self) -> impl Iterator<Item = ast::Path> + Clone {
|
|
||||||
successors(Some(self.clone()), |p| p.qualifier())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn top_path(&self) -> ast::Path {
|
pub fn top_path(&self) -> ast::Path {
|
||||||
let mut this = self.clone();
|
let mut this = self.clone();
|
||||||
while let Some(path) = this.parent_path() {
|
while let Some(path) = this.parent_path() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue