Rust: fix <X as Y> path extraction

This works around a quirk in rust-analyzer's AST generation machinery,
where for an `<X as Y>` path there might be no way to directly get `Y`
from the path segment.
This commit is contained in:
Paolo Tranquilli
2025-02-24 10:34:33 +01:00
parent 1b2d842b44
commit 689e7b8440
24 changed files with 290 additions and 289 deletions

View File

@@ -9,11 +9,10 @@
| gen_path_expr.rs:7:13:7:15 | <...> | hasQualifier: | no | hasPart: | yes |
| gen_path_expr.rs:7:13:7:20 | ...::foo | hasQualifier: | yes | hasPart: | yes |
| gen_path_expr.rs:7:14:7:14 | T | hasQualifier: | no | hasPart: | yes |
| gen_path_expr.rs:7:14:7:14 | T | hasQualifier: | no | hasPart: | yes |
| gen_path_expr.rs:8:13:8:31 | <...> | hasQualifier: | no | hasPart: | yes |
| gen_path_expr.rs:8:13:8:36 | ...::foo | hasQualifier: | yes | hasPart: | yes |
| gen_path_expr.rs:8:14:8:21 | TypeRepr | hasQualifier: | no | hasPart: | yes |
| gen_path_expr.rs:8:14:8:21 | TypeRepr | hasQualifier: | no | hasPart: | yes |
| gen_path_expr.rs:8:26:8:30 | Trait | hasQualifier: | no | hasPart: | yes |
| gen_path_pat.rs:5:11:5:11 | x | hasQualifier: | no | hasPart: | yes |
| gen_path_pat.rs:6:9:6:11 | Foo | hasQualifier: | no | hasPart: | yes |
| gen_path_pat.rs:6:9:6:16 | ...::Bar | hasQualifier: | yes | hasPart: | yes |

View File

@@ -1,26 +1,25 @@
| gen_path.rs:5:9:5:18 | some_crate | hasGenericArgList: | no | hasNameRef: | yes | hasParenthesizedArgList: | no | hasPathType: | no | hasRetType: | no | hasReturnTypeSyntax: | no | hasTypeRepr: | no |
| gen_path.rs:5:21:5:31 | some_module | hasGenericArgList: | no | hasNameRef: | yes | hasParenthesizedArgList: | no | hasPathType: | no | hasRetType: | no | hasReturnTypeSyntax: | no | hasTypeRepr: | no |
| gen_path.rs:5:34:5:42 | some_item | hasGenericArgList: | no | hasNameRef: | yes | hasParenthesizedArgList: | no | hasPathType: | no | hasRetType: | no | hasReturnTypeSyntax: | no | hasTypeRepr: | no |
| gen_path.rs:6:5:6:7 | foo | hasGenericArgList: | no | hasNameRef: | yes | hasParenthesizedArgList: | no | hasPathType: | no | hasRetType: | no | hasReturnTypeSyntax: | no | hasTypeRepr: | no |
| gen_path.rs:6:10:6:12 | bar | hasGenericArgList: | no | hasNameRef: | yes | hasParenthesizedArgList: | no | hasPathType: | no | hasRetType: | no | hasReturnTypeSyntax: | no | hasTypeRepr: | no |
| gen_path_expr.rs:5:13:5:20 | variable | hasGenericArgList: | no | hasNameRef: | yes | hasParenthesizedArgList: | no | hasPathType: | no | hasRetType: | no | hasReturnTypeSyntax: | no | hasTypeRepr: | no |
| gen_path_expr.rs:6:13:6:15 | foo | hasGenericArgList: | no | hasNameRef: | yes | hasParenthesizedArgList: | no | hasPathType: | no | hasRetType: | no | hasReturnTypeSyntax: | no | hasTypeRepr: | no |
| gen_path_expr.rs:6:18:6:20 | bar | hasGenericArgList: | no | hasNameRef: | yes | hasParenthesizedArgList: | no | hasPathType: | no | hasRetType: | no | hasReturnTypeSyntax: | no | hasTypeRepr: | no |
| gen_path_expr.rs:7:13:7:15 | <...> | hasGenericArgList: | no | hasNameRef: | no | hasParenthesizedArgList: | no | hasPathType: | yes | hasRetType: | no | hasReturnTypeSyntax: | no | hasTypeRepr: | yes |
| gen_path_expr.rs:7:14:7:14 | T | hasGenericArgList: | no | hasNameRef: | yes | hasParenthesizedArgList: | no | hasPathType: | no | hasRetType: | no | hasReturnTypeSyntax: | no | hasTypeRepr: | no |
| gen_path_expr.rs:7:14:7:14 | T | hasGenericArgList: | no | hasNameRef: | yes | hasParenthesizedArgList: | no | hasPathType: | no | hasRetType: | no | hasReturnTypeSyntax: | no | hasTypeRepr: | no |
| gen_path_expr.rs:7:18:7:20 | foo | hasGenericArgList: | no | hasNameRef: | yes | hasParenthesizedArgList: | no | hasPathType: | no | hasRetType: | no | hasReturnTypeSyntax: | no | hasTypeRepr: | no |
| gen_path_expr.rs:8:13:8:31 | <...> | hasGenericArgList: | no | hasNameRef: | no | hasParenthesizedArgList: | no | hasPathType: | yes | hasRetType: | no | hasReturnTypeSyntax: | no | hasTypeRepr: | yes |
| gen_path_expr.rs:8:14:8:21 | TypeRepr | hasGenericArgList: | no | hasNameRef: | yes | hasParenthesizedArgList: | no | hasPathType: | no | hasRetType: | no | hasReturnTypeSyntax: | no | hasTypeRepr: | no |
| gen_path_expr.rs:8:14:8:21 | TypeRepr | hasGenericArgList: | no | hasNameRef: | yes | hasParenthesizedArgList: | no | hasPathType: | no | hasRetType: | no | hasReturnTypeSyntax: | no | hasTypeRepr: | no |
| gen_path_expr.rs:8:34:8:36 | foo | hasGenericArgList: | no | hasNameRef: | yes | hasParenthesizedArgList: | no | hasPathType: | no | hasRetType: | no | hasReturnTypeSyntax: | no | hasTypeRepr: | no |
| gen_path_pat.rs:5:11:5:11 | x | hasGenericArgList: | no | hasNameRef: | yes | hasParenthesizedArgList: | no | hasPathType: | no | hasRetType: | no | hasReturnTypeSyntax: | no | hasTypeRepr: | no |
| gen_path_pat.rs:6:9:6:11 | Foo | hasGenericArgList: | no | hasNameRef: | yes | hasParenthesizedArgList: | no | hasPathType: | no | hasRetType: | no | hasReturnTypeSyntax: | no | hasTypeRepr: | no |
| gen_path_pat.rs:6:14:6:16 | Bar | hasGenericArgList: | no | hasNameRef: | yes | hasParenthesizedArgList: | no | hasPathType: | no | hasRetType: | no | hasReturnTypeSyntax: | no | hasTypeRepr: | no |
| gen_path_type_repr.rs:5:14:5:16 | std | hasGenericArgList: | no | hasNameRef: | yes | hasParenthesizedArgList: | no | hasPathType: | no | hasRetType: | no | hasReturnTypeSyntax: | no | hasTypeRepr: | no |
| gen_path_type_repr.rs:5:19:5:29 | collections | hasGenericArgList: | no | hasNameRef: | yes | hasParenthesizedArgList: | no | hasPathType: | no | hasRetType: | no | hasReturnTypeSyntax: | no | hasTypeRepr: | no |
| gen_path_type_repr.rs:5:32:5:48 | HashMap::<...> | hasGenericArgList: | yes | hasNameRef: | yes | hasParenthesizedArgList: | no | hasPathType: | no | hasRetType: | no | hasReturnTypeSyntax: | no | hasTypeRepr: | no |
| gen_path_type_repr.rs:5:40:5:42 | i32 | hasGenericArgList: | no | hasNameRef: | yes | hasParenthesizedArgList: | no | hasPathType: | no | hasRetType: | no | hasReturnTypeSyntax: | no | hasTypeRepr: | no |
| gen_path_type_repr.rs:5:45:5:47 | i32 | hasGenericArgList: | no | hasNameRef: | yes | hasParenthesizedArgList: | no | hasPathType: | no | hasRetType: | no | hasReturnTypeSyntax: | no | hasTypeRepr: | no |
| gen_path_type_repr.rs:6:14:6:14 | X | hasGenericArgList: | no | hasNameRef: | yes | hasParenthesizedArgList: | no | hasPathType: | no | hasRetType: | no | hasReturnTypeSyntax: | no | hasTypeRepr: | no |
| gen_path_type_repr.rs:6:17:6:20 | Item | hasGenericArgList: | no | hasNameRef: | yes | hasParenthesizedArgList: | no | hasPathType: | no | hasRetType: | no | hasReturnTypeSyntax: | no | hasTypeRepr: | no |
| gen_path.rs:5:9:5:18 | some_crate | hasGenericArgList: | no | hasNameRef: | yes | hasParenthesizedArgList: | no | hasRetType: | no | hasReturnTypeSyntax: | no | hasTypeRepr: | no | hasTraitTypeRepr: | no |
| gen_path.rs:5:21:5:31 | some_module | hasGenericArgList: | no | hasNameRef: | yes | hasParenthesizedArgList: | no | hasRetType: | no | hasReturnTypeSyntax: | no | hasTypeRepr: | no | hasTraitTypeRepr: | no |
| gen_path.rs:5:34:5:42 | some_item | hasGenericArgList: | no | hasNameRef: | yes | hasParenthesizedArgList: | no | hasRetType: | no | hasReturnTypeSyntax: | no | hasTypeRepr: | no | hasTraitTypeRepr: | no |
| gen_path.rs:6:5:6:7 | foo | hasGenericArgList: | no | hasNameRef: | yes | hasParenthesizedArgList: | no | hasRetType: | no | hasReturnTypeSyntax: | no | hasTypeRepr: | no | hasTraitTypeRepr: | no |
| gen_path.rs:6:10:6:12 | bar | hasGenericArgList: | no | hasNameRef: | yes | hasParenthesizedArgList: | no | hasRetType: | no | hasReturnTypeSyntax: | no | hasTypeRepr: | no | hasTraitTypeRepr: | no |
| gen_path_expr.rs:5:13:5:20 | variable | hasGenericArgList: | no | hasNameRef: | yes | hasParenthesizedArgList: | no | hasRetType: | no | hasReturnTypeSyntax: | no | hasTypeRepr: | no | hasTraitTypeRepr: | no |
| gen_path_expr.rs:6:13:6:15 | foo | hasGenericArgList: | no | hasNameRef: | yes | hasParenthesizedArgList: | no | hasRetType: | no | hasReturnTypeSyntax: | no | hasTypeRepr: | no | hasTraitTypeRepr: | no |
| gen_path_expr.rs:6:18:6:20 | bar | hasGenericArgList: | no | hasNameRef: | yes | hasParenthesizedArgList: | no | hasRetType: | no | hasReturnTypeSyntax: | no | hasTypeRepr: | no | hasTraitTypeRepr: | no |
| gen_path_expr.rs:7:13:7:15 | <...> | hasGenericArgList: | no | hasNameRef: | no | hasParenthesizedArgList: | no | hasRetType: | no | hasReturnTypeSyntax: | no | hasTypeRepr: | yes | hasTraitTypeRepr: | no |
| gen_path_expr.rs:7:14:7:14 | T | hasGenericArgList: | no | hasNameRef: | yes | hasParenthesizedArgList: | no | hasRetType: | no | hasReturnTypeSyntax: | no | hasTypeRepr: | no | hasTraitTypeRepr: | no |
| gen_path_expr.rs:7:18:7:20 | foo | hasGenericArgList: | no | hasNameRef: | yes | hasParenthesizedArgList: | no | hasRetType: | no | hasReturnTypeSyntax: | no | hasTypeRepr: | no | hasTraitTypeRepr: | no |
| gen_path_expr.rs:8:13:8:31 | <...> | hasGenericArgList: | no | hasNameRef: | no | hasParenthesizedArgList: | no | hasRetType: | no | hasReturnTypeSyntax: | no | hasTypeRepr: | yes | hasTraitTypeRepr: | yes |
| gen_path_expr.rs:8:14:8:21 | TypeRepr | hasGenericArgList: | no | hasNameRef: | yes | hasParenthesizedArgList: | no | hasRetType: | no | hasReturnTypeSyntax: | no | hasTypeRepr: | no | hasTraitTypeRepr: | no |
| gen_path_expr.rs:8:26:8:30 | Trait | hasGenericArgList: | no | hasNameRef: | yes | hasParenthesizedArgList: | no | hasRetType: | no | hasReturnTypeSyntax: | no | hasTypeRepr: | no | hasTraitTypeRepr: | no |
| gen_path_expr.rs:8:34:8:36 | foo | hasGenericArgList: | no | hasNameRef: | yes | hasParenthesizedArgList: | no | hasRetType: | no | hasReturnTypeSyntax: | no | hasTypeRepr: | no | hasTraitTypeRepr: | no |
| gen_path_pat.rs:5:11:5:11 | x | hasGenericArgList: | no | hasNameRef: | yes | hasParenthesizedArgList: | no | hasRetType: | no | hasReturnTypeSyntax: | no | hasTypeRepr: | no | hasTraitTypeRepr: | no |
| gen_path_pat.rs:6:9:6:11 | Foo | hasGenericArgList: | no | hasNameRef: | yes | hasParenthesizedArgList: | no | hasRetType: | no | hasReturnTypeSyntax: | no | hasTypeRepr: | no | hasTraitTypeRepr: | no |
| gen_path_pat.rs:6:14:6:16 | Bar | hasGenericArgList: | no | hasNameRef: | yes | hasParenthesizedArgList: | no | hasRetType: | no | hasReturnTypeSyntax: | no | hasTypeRepr: | no | hasTraitTypeRepr: | no |
| gen_path_type_repr.rs:5:14:5:16 | std | hasGenericArgList: | no | hasNameRef: | yes | hasParenthesizedArgList: | no | hasRetType: | no | hasReturnTypeSyntax: | no | hasTypeRepr: | no | hasTraitTypeRepr: | no |
| gen_path_type_repr.rs:5:19:5:29 | collections | hasGenericArgList: | no | hasNameRef: | yes | hasParenthesizedArgList: | no | hasRetType: | no | hasReturnTypeSyntax: | no | hasTypeRepr: | no | hasTraitTypeRepr: | no |
| gen_path_type_repr.rs:5:32:5:48 | HashMap::<...> | hasGenericArgList: | yes | hasNameRef: | yes | hasParenthesizedArgList: | no | hasRetType: | no | hasReturnTypeSyntax: | no | hasTypeRepr: | no | hasTraitTypeRepr: | no |
| gen_path_type_repr.rs:5:40:5:42 | i32 | hasGenericArgList: | no | hasNameRef: | yes | hasParenthesizedArgList: | no | hasRetType: | no | hasReturnTypeSyntax: | no | hasTypeRepr: | no | hasTraitTypeRepr: | no |
| gen_path_type_repr.rs:5:45:5:47 | i32 | hasGenericArgList: | no | hasNameRef: | yes | hasParenthesizedArgList: | no | hasRetType: | no | hasReturnTypeSyntax: | no | hasTypeRepr: | no | hasTraitTypeRepr: | no |
| gen_path_type_repr.rs:6:14:6:14 | X | hasGenericArgList: | no | hasNameRef: | yes | hasParenthesizedArgList: | no | hasRetType: | no | hasReturnTypeSyntax: | no | hasTypeRepr: | no | hasTraitTypeRepr: | no |
| gen_path_type_repr.rs:6:17:6:20 | Item | hasGenericArgList: | no | hasNameRef: | yes | hasParenthesizedArgList: | no | hasRetType: | no | hasReturnTypeSyntax: | no | hasTypeRepr: | no | hasTraitTypeRepr: | no |

View File

@@ -4,7 +4,7 @@ import TestUtils
from
PathSegment x, string hasGenericArgList, string hasNameRef, string hasParenthesizedArgList,
string hasPathType, string hasRetType, string hasReturnTypeSyntax, string hasTypeRepr
string hasRetType, string hasReturnTypeSyntax, string hasTypeRepr, string hasTraitTypeRepr
where
toBeTested(x) and
not x.isUnknown() and
@@ -15,10 +15,11 @@ where
then hasParenthesizedArgList = "yes"
else hasParenthesizedArgList = "no"
) and
(if x.hasPathType() then hasPathType = "yes" else hasPathType = "no") and
(if x.hasRetType() then hasRetType = "yes" else hasRetType = "no") and
(if x.hasReturnTypeSyntax() then hasReturnTypeSyntax = "yes" else hasReturnTypeSyntax = "no") and
if x.hasTypeRepr() then hasTypeRepr = "yes" else hasTypeRepr = "no"
(if x.hasTypeRepr() then hasTypeRepr = "yes" else hasTypeRepr = "no") and
if x.hasTraitTypeRepr() then hasTraitTypeRepr = "yes" else hasTraitTypeRepr = "no"
select x, "hasGenericArgList:", hasGenericArgList, "hasNameRef:", hasNameRef,
"hasParenthesizedArgList:", hasParenthesizedArgList, "hasPathType:", hasPathType, "hasRetType:",
hasRetType, "hasReturnTypeSyntax:", hasReturnTypeSyntax, "hasTypeRepr:", hasTypeRepr
"hasParenthesizedArgList:", hasParenthesizedArgList, "hasRetType:", hasRetType,
"hasReturnTypeSyntax:", hasReturnTypeSyntax, "hasTypeRepr:", hasTypeRepr, "hasTraitTypeRepr:",
hasTraitTypeRepr

View File

@@ -7,10 +7,9 @@
| gen_path_expr.rs:6:13:6:15 | foo | gen_path_expr.rs:6:13:6:15 | foo |
| gen_path_expr.rs:6:18:6:20 | bar | gen_path_expr.rs:6:18:6:20 | bar |
| gen_path_expr.rs:7:14:7:14 | T | gen_path_expr.rs:7:14:7:14 | T |
| gen_path_expr.rs:7:14:7:14 | T | gen_path_expr.rs:7:14:7:14 | T |
| gen_path_expr.rs:7:18:7:20 | foo | gen_path_expr.rs:7:18:7:20 | foo |
| gen_path_expr.rs:8:14:8:21 | TypeRepr | gen_path_expr.rs:8:14:8:21 | TypeRepr |
| gen_path_expr.rs:8:14:8:21 | TypeRepr | gen_path_expr.rs:8:14:8:21 | TypeRepr |
| gen_path_expr.rs:8:26:8:30 | Trait | gen_path_expr.rs:8:26:8:30 | Trait |
| gen_path_expr.rs:8:34:8:36 | foo | gen_path_expr.rs:8:34:8:36 | foo |
| gen_path_pat.rs:5:11:5:11 | x | gen_path_pat.rs:5:11:5:11 | x |
| gen_path_pat.rs:6:9:6:11 | Foo | gen_path_pat.rs:6:9:6:11 | Foo |

View File

@@ -0,0 +1 @@
| gen_path_expr.rs:8:13:8:31 | <...> | gen_path_expr.rs:8:26:8:30 | Trait |

View File

@@ -4,4 +4,4 @@ import TestUtils
from PathSegment x
where toBeTested(x) and not x.isUnknown()
select x, x.getPathType()
select x, x.getTraitTypeRepr()

View File

@@ -1,7 +1,6 @@
| gen_path_expr.rs:7:14:7:14 | T | hasPath: | yes |
| gen_path_expr.rs:7:14:7:14 | T | hasPath: | yes |
| gen_path_expr.rs:8:14:8:21 | TypeRepr | hasPath: | yes |
| gen_path_expr.rs:8:14:8:21 | TypeRepr | hasPath: | yes |
| gen_path_expr.rs:8:26:8:30 | Trait | hasPath: | yes |
| gen_path_type_repr.rs:5:14:5:48 | ...::HashMap::<...> | hasPath: | yes |
| gen_path_type_repr.rs:5:40:5:42 | i32 | hasPath: | yes |
| gen_path_type_repr.rs:5:45:5:47 | i32 | hasPath: | yes |

View File

@@ -1,7 +1,6 @@
| gen_path_expr.rs:7:14:7:14 | T | gen_path_expr.rs:7:14:7:14 | T |
| gen_path_expr.rs:7:14:7:14 | T | gen_path_expr.rs:7:14:7:14 | T |
| gen_path_expr.rs:8:14:8:21 | TypeRepr | gen_path_expr.rs:8:14:8:21 | TypeRepr |
| gen_path_expr.rs:8:14:8:21 | TypeRepr | gen_path_expr.rs:8:14:8:21 | TypeRepr |
| gen_path_expr.rs:8:26:8:30 | Trait | gen_path_expr.rs:8:26:8:30 | Trait |
| gen_path_type_repr.rs:5:14:5:48 | ...::HashMap::<...> | gen_path_type_repr.rs:5:14:5:48 | ...::HashMap::<...> |
| gen_path_type_repr.rs:5:40:5:42 | i32 | gen_path_type_repr.rs:5:40:5:42 | i32 |
| gen_path_type_repr.rs:5:45:5:47 | i32 | gen_path_type_repr.rs:5:45:5:47 | i32 |

View File

@@ -9,11 +9,10 @@
| gen_path_expr.rs:7:13:7:15 | <...> | gen_path_expr.rs:7:13:7:15 | <...> |
| gen_path_expr.rs:7:13:7:20 | ...::foo | gen_path_expr.rs:7:18:7:20 | foo |
| gen_path_expr.rs:7:14:7:14 | T | gen_path_expr.rs:7:14:7:14 | T |
| gen_path_expr.rs:7:14:7:14 | T | gen_path_expr.rs:7:14:7:14 | T |
| gen_path_expr.rs:8:13:8:31 | <...> | gen_path_expr.rs:8:13:8:31 | <...> |
| gen_path_expr.rs:8:13:8:36 | ...::foo | gen_path_expr.rs:8:34:8:36 | foo |
| gen_path_expr.rs:8:14:8:21 | TypeRepr | gen_path_expr.rs:8:14:8:21 | TypeRepr |
| gen_path_expr.rs:8:14:8:21 | TypeRepr | gen_path_expr.rs:8:14:8:21 | TypeRepr |
| gen_path_expr.rs:8:26:8:30 | Trait | gen_path_expr.rs:8:26:8:30 | Trait |
| gen_path_pat.rs:5:11:5:11 | x | gen_path_pat.rs:5:11:5:11 | x |
| gen_path_pat.rs:6:9:6:11 | Foo | gen_path_pat.rs:6:9:6:11 | Foo |
| gen_path_pat.rs:6:9:6:16 | ...::Bar | gen_path_pat.rs:6:14:6:16 | Bar |