about summary refs log tree commit diff
diff options
context:
space:
mode:
authorYoung-Flash <871946895@qq.com>2023-11-13 18:14:00 +0800
committerYoung-Flash <871946895@qq.com>2023-11-13 18:14:00 +0800
commit3e5bc9a9c8bfd01e827e7f4062356e484e33387a (patch)
tree5ada9810829934caa172a8c66b150d50df1ea5f8
parent23fde40feddaca9359414dc90cc446d8adabe0dd (diff)
downloadrust-3e5bc9a9c8bfd01e827e7f4062356e484e33387a.tar.gz
rust-3e5bc9a9c8bfd01e827e7f4062356e484e33387a.zip
impl `qualifying_trait` for `PathSegment`
-rw-r--r--crates/syntax/src/ast/node_ext.rs13
1 files changed, 5 insertions, 8 deletions
diff --git a/crates/syntax/src/ast/node_ext.rs b/crates/syntax/src/ast/node_ext.rs
index 457c3c1996f..be5b954ad34 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` '<i32 as core::ops::Add>', 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<ast::PathType> {
-        self.syntax().children().find_map(ast::PathType::cast)
-    }
-
-    pub fn last_path_type(&self) -> Option<ast::PathType> {
-        self.syntax().children().filter_map(ast::PathType::cast).last()
+    pub fn qualifying_trait(&self) -> Option<ast::PathType> {
+        let mut path_types = support::children(self.syntax());
+        let first = path_types.next()?;
+        path_types.next().or(Some(first))
     }
 }