remove unnecessary ast::Path::segments alternatives

This commit is contained in:
davidsemakula 2024-01-06 12:53:56 +03:00
parent 6403dbf011
commit 89d6b011c4
2 changed files with 2 additions and 12 deletions

View file

@ -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;

View file

@ -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() {