Skip to content

Commit 8a9ef4c

Browse files
committed
Rust: Change canonical paths for trait items
Use `crate::Trait::foo` instead of `<_ as crate::Trait>::foo` for trait items.
1 parent c1b19fb commit 8a9ef4c

2 files changed

Lines changed: 7 additions & 13 deletions

File tree

rust/ql/lib/codeql/rust/internal/PathResolution.qll

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,31 +1095,25 @@ final class TraitItemNode extends ImplOrTraitItemNode, NamedItemNode, TypeItemNo
10951095
bindingset[c]
10961096
private string getCanonicalPathPart(Crate c, int i) {
10971097
i = 0 and
1098-
result = "<_ as "
1099-
or
1100-
i = 1 and
11011098
result = this.getCanonicalPathPrefix(c)
11021099
or
1103-
i = 2 and
1100+
i = 1 and
11041101
result = "::"
11051102
or
1106-
i = 3 and
1103+
i = 2 and
11071104
result = this.getName()
1108-
or
1109-
i = 4 and
1110-
result = ">"
11111105
}
11121106

11131107
language[monotonicAggregates]
11141108
override string getCanonicalPath(Crate c) {
11151109
this.hasCanonicalPath(c) and
1116-
result = strictconcat(int i | i in [1 .. 3] | this.getCanonicalPathPart(c, i) order by i)
1110+
result = strictconcat(int i | i in [0 .. 2] | this.getCanonicalPathPart(c, i) order by i)
11171111
}
11181112

11191113
language[monotonicAggregates]
11201114
override string getCanonicalPathPrefixFor(Crate c, ItemNode child) {
11211115
this.providesCanonicalPathPrefixFor(c, child) and
1122-
result = strictconcat(int i | i in [0 .. 4] | this.getCanonicalPathPart(c, i) order by i)
1116+
result = this.getCanonicalPath(c)
11231117
}
11241118
}
11251119

rust/ql/test/extractor-tests/canonical_path/canonical_paths.expected

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
| regular.rs:1:1:2:18 | impl ...::PartialEq for Struct::<...> { ... } | <test::regular::Struct as core::cmp::PartialEq> |
99
| regular.rs:1:1:2:18 | struct Struct | test::regular::Struct |
1010
| regular.rs:4:1:6:1 | trait Trait | test::regular::Trait |
11-
| regular.rs:5:5:5:16 | fn f | <_ as test::regular::Trait>::f |
11+
| regular.rs:5:5:5:16 | fn f | test::regular::Trait::f |
1212
| regular.rs:8:1:10:1 | impl Trait for Struct { ... } | <test::regular::Struct as test::regular::Trait> |
1313
| regular.rs:9:5:9:18 | fn f | <test::regular::Struct as test::regular::Trait>::f |
1414
| regular.rs:12:1:14:1 | impl Struct { ... } | <test::regular::Struct> |
1515
| regular.rs:13:5:13:18 | fn g | <test::regular::Struct>::g |
1616
| regular.rs:16:1:18:1 | trait TraitWithBlanketImpl | test::regular::TraitWithBlanketImpl |
17-
| regular.rs:17:5:17:16 | fn h | <_ as test::regular::TraitWithBlanketImpl>::h |
17+
| regular.rs:17:5:17:16 | fn h | test::regular::TraitWithBlanketImpl::h |
1818
| regular.rs:24:1:24:12 | fn free | test::regular::free |
1919
| regular.rs:26:1:32:1 | fn usage | test::regular::usage |
2020
| regular.rs:34:1:38:1 | enum MyEnum | test::regular::MyEnum |
@@ -27,6 +27,6 @@
2727
| regular.rs:66:5:66:40 | fn is_alphanum | test::regular::is_alphanum |
2828
| regular.rs:69:1:71:1 | fn is_number_or_letter | test::regular::is_number_or_letter |
2929
| regular.rs:73:1:75:1 | trait Abs | test::regular::Abs |
30-
| regular.rs:74:5:74:25 | fn abs | <_ as test::regular::Abs>::abs |
30+
| regular.rs:74:5:74:25 | fn abs | test::regular::Abs::abs |
3131
| regular.rs:77:1:85:1 | impl Abs for i32 { ... } | <core::i32 as test::regular::Abs> |
3232
| regular.rs:78:5:84:5 | fn abs | <core::i32 as test::regular::Abs>::abs |

0 commit comments

Comments
 (0)