diff --git a/crates/syntax/src/ast/node_ext.rs b/crates/syntax/src/ast/node_ext.rs index 457c3c1996fe..be5b954ad345 100644 --- a/crates/syntax/src/ast/node_ext.rs +++ b/crates/syntax/src/ast/node_ext.rs @@ -361,15 +361,12 @@ impl ast::Impl { } } -// for `PathSegment` '', call `first_path_type` will get `i32` and `last_path_type` will get `core::ops::Add` -// 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)` +// [#15778](https://github.com/rust-lang/rust-analyzer/issues/15778) impl ast::PathSegment { - pub fn first_path_type(&self) -> Option { - self.syntax().children().find_map(ast::PathType::cast) - } - - pub fn last_path_type(&self) -> Option { - self.syntax().children().filter_map(ast::PathType::cast).last() + pub fn qualifying_trait(&self) -> Option { + let mut path_types = support::children(self.syntax()); + let first = path_types.next()?; + path_types.next().or(Some(first)) } }