Skip to content

Commit a09b37e

Browse files
committed
Rust: Expand on toString of IdentPat
1 parent 0aa08a3 commit a09b37e

File tree

11 files changed

+194
-182
lines changed

11 files changed

+194
-182
lines changed

rust/ql/lib/codeql/rust/elements/internal/IdentPatImpl.qll

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,18 @@ module Impl {
2828
* ```
2929
*/
3030
class IdentPat extends Generated::IdentPat {
31-
override string toString() { result = this.getName().getText() }
31+
override string toString() {
32+
result = strictconcat(int i | | this.toStringPart(i), " " order by i)
33+
}
34+
35+
private string toStringPart(int index) {
36+
index = 0 and this.isRef() and result = "ref"
37+
or
38+
index = 1 and this.isMut() and result = "mut"
39+
or
40+
index = 2 and result = this.getName().getText()
41+
or
42+
index = 3 and this.hasPat() and result = "@ ..."
43+
}
3244
}
3345
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
| gen_ident_pat.rs:6:22:6:22 | y | getNumberOfAttrs: | 0 | isMut: | no | isRef: | no | hasName: | yes | hasPat: | no |
2-
| gen_ident_pat.rs:10:9:10:25 | y | getNumberOfAttrs: | 0 | isMut: | no | isRef: | no | hasName: | yes | hasPat: | yes |
2+
| gen_ident_pat.rs:10:9:10:25 | y @ ... | getNumberOfAttrs: | 0 | isMut: | no | isRef: | no | hasName: | yes | hasPat: | yes |
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
| gen_ident_pat.rs:6:22:6:22 | y | gen_ident_pat.rs:6:22:6:22 | y |
2-
| gen_ident_pat.rs:10:9:10:25 | y | gen_ident_pat.rs:10:9:10:9 | y |
2+
| gen_ident_pat.rs:10:9:10:25 | y @ ... | gen_ident_pat.rs:10:9:10:9 | y |
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
| gen_ident_pat.rs:10:9:10:25 | y | gen_ident_pat.rs:10:11:10:25 | ...::Some(...) |
1+
| gen_ident_pat.rs:10:9:10:25 | y @ ... | gen_ident_pat.rs:10:11:10:25 | ...::Some(...) |

rust/ql/test/library-tests/controlflow/BasicBlocks.expected

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -612,32 +612,32 @@ dominates
612612
| test.rs:396:13:396:13 | _ | test.rs:396:13:396:13 | _ |
613613
| test.rs:400:5:405:5 | enter fn identifier_pattern_with_subpattern | test.rs:400:5:405:5 | enter fn identifier_pattern_with_subpattern |
614614
| test.rs:400:5:405:5 | enter fn identifier_pattern_with_subpattern | test.rs:401:9:404:9 | match 43 { ... } |
615-
| test.rs:400:5:405:5 | enter fn identifier_pattern_with_subpattern | test.rs:402:13:402:21 | [match(true)] n |
615+
| test.rs:400:5:405:5 | enter fn identifier_pattern_with_subpattern | test.rs:402:13:402:21 | [match(true)] n @ ... |
616616
| test.rs:400:5:405:5 | enter fn identifier_pattern_with_subpattern | test.rs:402:17:402:17 | 1 |
617617
| test.rs:400:5:405:5 | enter fn identifier_pattern_with_subpattern | test.rs:402:20:402:21 | 10 |
618618
| test.rs:400:5:405:5 | enter fn identifier_pattern_with_subpattern | test.rs:403:13:403:13 | _ |
619619
| test.rs:401:9:404:9 | match 43 { ... } | test.rs:401:9:404:9 | match 43 { ... } |
620-
| test.rs:402:13:402:21 | [match(true)] n | test.rs:402:13:402:21 | [match(true)] n |
621-
| test.rs:402:17:402:17 | 1 | test.rs:402:13:402:21 | [match(true)] n |
620+
| test.rs:402:13:402:21 | [match(true)] n @ ... | test.rs:402:13:402:21 | [match(true)] n @ ... |
621+
| test.rs:402:17:402:17 | 1 | test.rs:402:13:402:21 | [match(true)] n @ ... |
622622
| test.rs:402:17:402:17 | 1 | test.rs:402:17:402:17 | 1 |
623623
| test.rs:402:17:402:17 | 1 | test.rs:402:20:402:21 | 10 |
624-
| test.rs:402:20:402:21 | 10 | test.rs:402:13:402:21 | [match(true)] n |
624+
| test.rs:402:20:402:21 | 10 | test.rs:402:13:402:21 | [match(true)] n @ ... |
625625
| test.rs:402:20:402:21 | 10 | test.rs:402:20:402:21 | 10 |
626626
| test.rs:403:13:403:13 | _ | test.rs:403:13:403:13 | _ |
627627
| test.rs:407:5:414:5 | enter fn identifier_pattern_with_ref | test.rs:407:5:414:5 | enter fn identifier_pattern_with_ref |
628628
| test.rs:407:5:414:5 | enter fn identifier_pattern_with_ref | test.rs:409:9:412:9 | match a { ... } |
629-
| test.rs:407:5:414:5 | enter fn identifier_pattern_with_ref | test.rs:410:13:410:29 | [match(true)] n |
629+
| test.rs:407:5:414:5 | enter fn identifier_pattern_with_ref | test.rs:410:13:410:29 | [match(true)] ref mut n @ ... |
630630
| test.rs:407:5:414:5 | enter fn identifier_pattern_with_ref | test.rs:410:25:410:25 | 1 |
631631
| test.rs:407:5:414:5 | enter fn identifier_pattern_with_ref | test.rs:410:28:410:29 | 10 |
632-
| test.rs:407:5:414:5 | enter fn identifier_pattern_with_ref | test.rs:411:13:411:21 | n |
632+
| test.rs:407:5:414:5 | enter fn identifier_pattern_with_ref | test.rs:411:13:411:21 | ref mut n |
633633
| test.rs:409:9:412:9 | match a { ... } | test.rs:409:9:412:9 | match a { ... } |
634-
| test.rs:410:13:410:29 | [match(true)] n | test.rs:410:13:410:29 | [match(true)] n |
635-
| test.rs:410:25:410:25 | 1 | test.rs:410:13:410:29 | [match(true)] n |
634+
| test.rs:410:13:410:29 | [match(true)] ref mut n @ ... | test.rs:410:13:410:29 | [match(true)] ref mut n @ ... |
635+
| test.rs:410:25:410:25 | 1 | test.rs:410:13:410:29 | [match(true)] ref mut n @ ... |
636636
| test.rs:410:25:410:25 | 1 | test.rs:410:25:410:25 | 1 |
637637
| test.rs:410:25:410:25 | 1 | test.rs:410:28:410:29 | 10 |
638-
| test.rs:410:28:410:29 | 10 | test.rs:410:13:410:29 | [match(true)] n |
638+
| test.rs:410:28:410:29 | 10 | test.rs:410:13:410:29 | [match(true)] ref mut n @ ... |
639639
| test.rs:410:28:410:29 | 10 | test.rs:410:28:410:29 | 10 |
640-
| test.rs:411:13:411:21 | n | test.rs:411:13:411:21 | n |
640+
| test.rs:411:13:411:21 | ref mut n | test.rs:411:13:411:21 | ref mut n |
641641
| test.rs:418:5:423:5 | enter fn test_infinite_loop | test.rs:418:5:423:5 | enter fn test_infinite_loop |
642642
| test.rs:418:5:423:5 | enter fn test_infinite_loop | test.rs:420:13:420:14 | TupleExpr |
643643
| test.rs:420:13:420:14 | TupleExpr | test.rs:420:13:420:14 | TupleExpr |
@@ -1223,25 +1223,25 @@ postDominance
12231223
| test.rs:400:5:405:5 | enter fn identifier_pattern_with_subpattern | test.rs:400:5:405:5 | enter fn identifier_pattern_with_subpattern |
12241224
| test.rs:401:9:404:9 | match 43 { ... } | test.rs:400:5:405:5 | enter fn identifier_pattern_with_subpattern |
12251225
| test.rs:401:9:404:9 | match 43 { ... } | test.rs:401:9:404:9 | match 43 { ... } |
1226-
| test.rs:401:9:404:9 | match 43 { ... } | test.rs:402:13:402:21 | [match(true)] n |
1226+
| test.rs:401:9:404:9 | match 43 { ... } | test.rs:402:13:402:21 | [match(true)] n @ ... |
12271227
| test.rs:401:9:404:9 | match 43 { ... } | test.rs:402:17:402:17 | 1 |
12281228
| test.rs:401:9:404:9 | match 43 { ... } | test.rs:402:20:402:21 | 10 |
12291229
| test.rs:401:9:404:9 | match 43 { ... } | test.rs:403:13:403:13 | _ |
1230-
| test.rs:402:13:402:21 | [match(true)] n | test.rs:402:13:402:21 | [match(true)] n |
1230+
| test.rs:402:13:402:21 | [match(true)] n @ ... | test.rs:402:13:402:21 | [match(true)] n @ ... |
12311231
| test.rs:402:17:402:17 | 1 | test.rs:402:17:402:17 | 1 |
12321232
| test.rs:402:20:402:21 | 10 | test.rs:402:20:402:21 | 10 |
12331233
| test.rs:403:13:403:13 | _ | test.rs:403:13:403:13 | _ |
12341234
| test.rs:407:5:414:5 | enter fn identifier_pattern_with_ref | test.rs:407:5:414:5 | enter fn identifier_pattern_with_ref |
12351235
| test.rs:409:9:412:9 | match a { ... } | test.rs:407:5:414:5 | enter fn identifier_pattern_with_ref |
12361236
| test.rs:409:9:412:9 | match a { ... } | test.rs:409:9:412:9 | match a { ... } |
1237-
| test.rs:409:9:412:9 | match a { ... } | test.rs:410:13:410:29 | [match(true)] n |
1237+
| test.rs:409:9:412:9 | match a { ... } | test.rs:410:13:410:29 | [match(true)] ref mut n @ ... |
12381238
| test.rs:409:9:412:9 | match a { ... } | test.rs:410:25:410:25 | 1 |
12391239
| test.rs:409:9:412:9 | match a { ... } | test.rs:410:28:410:29 | 10 |
1240-
| test.rs:409:9:412:9 | match a { ... } | test.rs:411:13:411:21 | n |
1241-
| test.rs:410:13:410:29 | [match(true)] n | test.rs:410:13:410:29 | [match(true)] n |
1240+
| test.rs:409:9:412:9 | match a { ... } | test.rs:411:13:411:21 | ref mut n |
1241+
| test.rs:410:13:410:29 | [match(true)] ref mut n @ ... | test.rs:410:13:410:29 | [match(true)] ref mut n @ ... |
12421242
| test.rs:410:25:410:25 | 1 | test.rs:410:25:410:25 | 1 |
12431243
| test.rs:410:28:410:29 | 10 | test.rs:410:28:410:29 | 10 |
1244-
| test.rs:411:13:411:21 | n | test.rs:411:13:411:21 | n |
1244+
| test.rs:411:13:411:21 | ref mut n | test.rs:411:13:411:21 | ref mut n |
12451245
| test.rs:418:5:423:5 | enter fn test_infinite_loop | test.rs:418:5:423:5 | enter fn test_infinite_loop |
12461246
| test.rs:420:13:420:14 | TupleExpr | test.rs:420:13:420:14 | TupleExpr |
12471247
| test.rs:427:5:429:5 | enter fn say_hello | test.rs:427:5:429:5 | enter fn say_hello |
@@ -1503,15 +1503,15 @@ immediateDominator
15031503
| test.rs:395:20:395:20 | 3 | test.rs:395:13:395:13 | 5 |
15041504
| test.rs:396:13:396:13 | _ | test.rs:395:13:395:15 | RangePat |
15051505
| test.rs:401:9:404:9 | match 43 { ... } | test.rs:400:5:405:5 | enter fn identifier_pattern_with_subpattern |
1506-
| test.rs:402:13:402:21 | [match(true)] n | test.rs:402:20:402:21 | 10 |
1506+
| test.rs:402:13:402:21 | [match(true)] n @ ... | test.rs:402:20:402:21 | 10 |
15071507
| test.rs:402:17:402:17 | 1 | test.rs:400:5:405:5 | enter fn identifier_pattern_with_subpattern |
15081508
| test.rs:402:20:402:21 | 10 | test.rs:402:17:402:17 | 1 |
15091509
| test.rs:403:13:403:13 | _ | test.rs:400:5:405:5 | enter fn identifier_pattern_with_subpattern |
15101510
| test.rs:409:9:412:9 | match a { ... } | test.rs:407:5:414:5 | enter fn identifier_pattern_with_ref |
1511-
| test.rs:410:13:410:29 | [match(true)] n | test.rs:410:28:410:29 | 10 |
1511+
| test.rs:410:13:410:29 | [match(true)] ref mut n @ ... | test.rs:410:28:410:29 | 10 |
15121512
| test.rs:410:25:410:25 | 1 | test.rs:407:5:414:5 | enter fn identifier_pattern_with_ref |
15131513
| test.rs:410:28:410:29 | 10 | test.rs:410:25:410:25 | 1 |
1514-
| test.rs:411:13:411:21 | n | test.rs:407:5:414:5 | enter fn identifier_pattern_with_ref |
1514+
| test.rs:411:13:411:21 | ref mut n | test.rs:407:5:414:5 | enter fn identifier_pattern_with_ref |
15151515
| test.rs:420:13:420:14 | TupleExpr | test.rs:418:5:423:5 | enter fn test_infinite_loop |
15161516
| test.rs:444:28:449:9 | exit { ... } (normal) | test.rs:444:28:449:9 | enter { ... } |
15171517
| test.rs:445:13:447:13 | if b {...} | test.rs:444:28:449:9 | enter { ... } |
@@ -2011,16 +2011,16 @@ joinBlockPredecessor
20112011
| test.rs:395:13:395:15 | RangePat | test.rs:394:16:394:16 | 2 | 0 |
20122012
| test.rs:396:13:396:13 | _ | test.rs:395:13:395:13 | 5 | 0 |
20132013
| test.rs:396:13:396:13 | _ | test.rs:395:13:395:15 | RangePat | 1 |
2014-
| test.rs:401:9:404:9 | match 43 { ... } | test.rs:402:13:402:21 | [match(true)] n | 0 |
2014+
| test.rs:401:9:404:9 | match 43 { ... } | test.rs:402:13:402:21 | [match(true)] n @ ... | 0 |
20152015
| test.rs:401:9:404:9 | match 43 { ... } | test.rs:403:13:403:13 | _ | 1 |
20162016
| test.rs:403:13:403:13 | _ | test.rs:400:5:405:5 | enter fn identifier_pattern_with_subpattern | 2 |
20172017
| test.rs:403:13:403:13 | _ | test.rs:402:17:402:17 | 1 | 1 |
20182018
| test.rs:403:13:403:13 | _ | test.rs:402:20:402:21 | 10 | 0 |
2019-
| test.rs:409:9:412:9 | match a { ... } | test.rs:410:13:410:29 | [match(true)] n | 0 |
2020-
| test.rs:409:9:412:9 | match a { ... } | test.rs:411:13:411:21 | n | 1 |
2021-
| test.rs:411:13:411:21 | n | test.rs:407:5:414:5 | enter fn identifier_pattern_with_ref | 2 |
2022-
| test.rs:411:13:411:21 | n | test.rs:410:25:410:25 | 1 | 1 |
2023-
| test.rs:411:13:411:21 | n | test.rs:410:28:410:29 | 10 | 0 |
2019+
| test.rs:409:9:412:9 | match a { ... } | test.rs:410:13:410:29 | [match(true)] ref mut n @ ... | 0 |
2020+
| test.rs:409:9:412:9 | match a { ... } | test.rs:411:13:411:21 | ref mut n | 1 |
2021+
| test.rs:411:13:411:21 | ref mut n | test.rs:407:5:414:5 | enter fn identifier_pattern_with_ref | 2 |
2022+
| test.rs:411:13:411:21 | ref mut n | test.rs:410:25:410:25 | 1 | 1 |
2023+
| test.rs:411:13:411:21 | ref mut n | test.rs:410:28:410:29 | 10 | 0 |
20242024
| test.rs:420:13:420:14 | TupleExpr | test.rs:418:5:423:5 | enter fn test_infinite_loop | 1 |
20252025
| test.rs:420:13:420:14 | TupleExpr | test.rs:420:13:420:14 | TupleExpr | 0 |
20262026
| test.rs:444:28:449:9 | exit { ... } (normal) | test.rs:445:13:447:13 | if b {...} | 1 |

0 commit comments

Comments
 (0)