impl qualifying_trait for PathSegment

This commit is contained in:
Young-Flash 2023-11-13 18:14:00 +08:00
parent 23fde40fed
commit 3e5bc9a9c8

View File

@ -361,15 +361,12 @@ pub fn for_trait_name_ref(name_ref: &ast::NameRef) -> Option<ast::Impl> {
} }
} }
// for `PathSegment` '<i32 as core::ops::Add>', call `first_path_type` will get `i32` and `last_path_type` will get `core::ops::Add` // [#15778](https://github.com/rust-lang/rust-analyzer/issues/15778)
// for '<&i32 as core::ops::Add>', call `first_path_type` and `last_path_type` will both get `core::ops::Add` cause `&i32` is `Type(RefType)`
impl ast::PathSegment { impl ast::PathSegment {
pub fn first_path_type(&self) -> Option<ast::PathType> { pub fn qualifying_trait(&self) -> Option<ast::PathType> {
self.syntax().children().find_map(ast::PathType::cast) let mut path_types = support::children(self.syntax());
} let first = path_types.next()?;
path_types.next().or(Some(first))
pub fn last_path_type(&self) -> Option<ast::PathType> {
self.syntax().children().filter_map(ast::PathType::cast).last()
} }
} }