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) {
None => {
if qualifier.first_qualifier().map_or(true, |it| sema.resolve_path(&it).is_none()) {
let mut qualifier = qualifier
.segments_of_this_path_only_rev()
let qualifier = qualifier
.segments()
.map(|seg| seg.name_ref().map(|name| SmolStr::new(name.text())))
.collect::<Option<Vec<_>>>()?;
qualifier.reverse();
ImportCandidate::Path(PathImportCandidate { qualifier: Some(qualifier), name })
} else {
return None;

View File

@ -283,11 +283,6 @@ pub fn first_segment(&self) -> Option<ast::PathSegment> {
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 {
let path_range = self.syntax().text_range();
successors(self.first_segment(), move |p| {
@ -305,10 +300,6 @@ pub fn qualifiers(&self) -> impl Iterator<Item = ast::Path> + Clone {
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 {
let mut this = self.clone();
while let Some(path) = this.parent_path() {