Skip to content

Commit f232335

Browse files
authored
Merge pull request #20291 from hvitved/rust/type-inference-more-certain-types
Rust: Add more cases to `inferCertainType`
2 parents b7c1e1e + 6453b71 commit f232335

File tree

2 files changed

+14
-24
lines changed

2 files changed

+14
-24
lines changed

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,20 @@ private module CertainTypeInference {
374374
or
375375
result = inferLiteralType(n, path, true)
376376
or
377+
result = inferRefNodeType(n) and
378+
path.isEmpty()
379+
or
380+
result = inferTupleRootType(n) and
381+
path.isEmpty()
382+
or
383+
result = inferAsyncBlockExprRootType(n) and
384+
path.isEmpty()
385+
or
386+
result = inferArrayExprType(n) and
387+
path.isEmpty()
388+
or
389+
result = inferCastExprType(n, path)
390+
or
377391
infersCertainTypeAt(n, path, result.getATypeParameter())
378392
}
379393

@@ -2366,30 +2380,18 @@ private module Cached {
23662380
or
23672381
result = inferStructExprType(n, path)
23682382
or
2369-
result = inferTupleRootType(n) and
2370-
path.isEmpty()
2371-
or
23722383
result = inferPathExprType(n, path)
23732384
or
23742385
result = inferCallExprBaseType(n, path)
23752386
or
23762387
result = inferFieldExprType(n, path)
23772388
or
2378-
result = inferRefNodeType(n) and
2379-
path.isEmpty()
2380-
or
23812389
result = inferTryExprType(n, path)
23822390
or
23832391
result = inferLiteralType(n, path, false)
23842392
or
2385-
result = inferAsyncBlockExprRootType(n) and
2386-
path.isEmpty()
2387-
or
23882393
result = inferAwaitExprType(n, path)
23892394
or
2390-
result = inferArrayExprType(n) and
2391-
path.isEmpty()
2392-
or
23932395
result = inferRangeExprType(n) and
23942396
path.isEmpty()
23952397
or
@@ -2401,8 +2403,6 @@ private module Cached {
24012403
or
24022404
result = inferClosureExprType(n, path)
24032405
or
2404-
result = inferCastExprType(n, path)
2405-
or
24062406
result = inferStructPatType(n, path)
24072407
or
24082408
result = inferTupleStructPatType(n, path)

rust/ql/test/library-tests/type-inference/type-inference.expected

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2720,7 +2720,6 @@ inferType
27202720
| main.rs:1407:13:1407:19 | &... | &T.&T.&T | file://:0:0:0:0 | & |
27212721
| main.rs:1407:13:1407:19 | &... | &T.&T.&T.&T | main.rs:1403:5:1403:13 | S |
27222722
| main.rs:1407:14:1407:19 | &... | | file://:0:0:0:0 | & |
2723-
| main.rs:1407:14:1407:19 | &... | | main.rs:1403:5:1403:13 | S |
27242723
| main.rs:1407:14:1407:19 | &... | &T | file://:0:0:0:0 | & |
27252724
| main.rs:1407:14:1407:19 | &... | &T.&T | file://:0:0:0:0 | & |
27262725
| main.rs:1407:14:1407:19 | &... | &T.&T.&T | main.rs:1403:5:1403:13 | S |
@@ -2740,7 +2739,6 @@ inferType
27402739
| main.rs:1411:13:1411:19 | &... | &T.&T.&T | file://:0:0:0:0 | & |
27412740
| main.rs:1411:13:1411:19 | &... | &T.&T.&T.&T | main.rs:1403:5:1403:13 | S |
27422741
| main.rs:1411:14:1411:19 | &... | | file://:0:0:0:0 | & |
2743-
| main.rs:1411:14:1411:19 | &... | | main.rs:1403:5:1403:13 | S |
27442742
| main.rs:1411:14:1411:19 | &... | &T | file://:0:0:0:0 | & |
27452743
| main.rs:1411:14:1411:19 | &... | &T.&T | file://:0:0:0:0 | & |
27462744
| main.rs:1411:14:1411:19 | &... | &T.&T.&T | main.rs:1403:5:1403:13 | S |
@@ -2766,7 +2764,6 @@ inferType
27662764
| main.rs:1419:13:1419:16 | &... | &T.&T.&T | file://:0:0:0:0 | & |
27672765
| main.rs:1419:13:1419:16 | &... | &T.&T.&T.&T | main.rs:1403:5:1403:13 | S |
27682766
| main.rs:1419:14:1419:16 | &... | | file://:0:0:0:0 | & |
2769-
| main.rs:1419:14:1419:16 | &... | | main.rs:1403:5:1403:13 | S |
27702767
| main.rs:1419:14:1419:16 | &... | &T | file://:0:0:0:0 | & |
27712768
| main.rs:1419:14:1419:16 | &... | &T.&T | file://:0:0:0:0 | & |
27722769
| main.rs:1419:14:1419:16 | &... | &T.&T.&T | main.rs:1403:5:1403:13 | S |
@@ -2797,7 +2794,6 @@ inferType
27972794
| main.rs:1429:19:1429:24 | &... | &T | {EXTERNAL LOCATION} | bool |
27982795
| main.rs:1429:19:1429:24 | &... | &T | file://:0:0:0:0 | & |
27992796
| main.rs:1429:19:1429:24 | &... | &T.&T | {EXTERNAL LOCATION} | bool |
2800-
| main.rs:1429:20:1429:24 | &true | | {EXTERNAL LOCATION} | bool |
28012797
| main.rs:1429:20:1429:24 | &true | | file://:0:0:0:0 | & |
28022798
| main.rs:1429:20:1429:24 | &true | &T | {EXTERNAL LOCATION} | bool |
28032799
| main.rs:1429:21:1429:24 | true | | {EXTERNAL LOCATION} | bool |
@@ -3729,7 +3725,6 @@ inferType
37293725
| main.rs:1916:9:1916:10 | S1 | | main.rs:1909:5:1909:14 | S1 |
37303726
| main.rs:1919:41:1921:5 | { ... } | | main.rs:1919:16:1919:39 | ImplTraitTypeRepr |
37313727
| main.rs:1920:9:1920:20 | { ... } | | {EXTERNAL LOCATION} | trait Future |
3732-
| main.rs:1920:9:1920:20 | { ... } | | main.rs:1919:16:1919:39 | ImplTraitTypeRepr |
37333728
| main.rs:1920:9:1920:20 | { ... } | Output | main.rs:1909:5:1909:14 | S1 |
37343729
| main.rs:1920:17:1920:18 | S1 | | main.rs:1909:5:1909:14 | S1 |
37353730
| main.rs:1929:13:1929:42 | SelfParam | | {EXTERNAL LOCATION} | Pin |
@@ -4563,7 +4558,6 @@ inferType
45634558
| main.rs:2375:22:2375:34 | map1.values() | V.A | {EXTERNAL LOCATION} | Global |
45644559
| main.rs:2375:22:2375:34 | map1.values() | V.T | file://:0:0:0:0 | & |
45654560
| main.rs:2375:22:2375:34 | map1.values() | V.T.&T | {EXTERNAL LOCATION} | str |
4566-
| main.rs:2376:13:2376:24 | TuplePat | | {EXTERNAL LOCATION} | Item |
45674561
| main.rs:2376:13:2376:24 | TuplePat | | file://:0:0:0:0 | (T_2) |
45684562
| main.rs:2376:13:2376:24 | TuplePat | 0(2) | file://:0:0:0:0 | & |
45694563
| main.rs:2376:13:2376:24 | TuplePat | 0(2).&T | {EXTERNAL LOCATION} | i32 |
@@ -4592,7 +4586,6 @@ inferType
45924586
| main.rs:2376:29:2376:39 | map1.iter() | V.A | {EXTERNAL LOCATION} | Global |
45934587
| main.rs:2376:29:2376:39 | map1.iter() | V.T | file://:0:0:0:0 | & |
45944588
| main.rs:2376:29:2376:39 | map1.iter() | V.T.&T | {EXTERNAL LOCATION} | str |
4595-
| main.rs:2377:13:2377:24 | TuplePat | | {EXTERNAL LOCATION} | Item |
45964589
| main.rs:2377:13:2377:24 | TuplePat | | file://:0:0:0:0 | (T_2) |
45974590
| main.rs:2377:13:2377:24 | TuplePat | 0(2) | file://:0:0:0:0 | & |
45984591
| main.rs:2377:13:2377:24 | TuplePat | 0(2).&T | {EXTERNAL LOCATION} | i32 |
@@ -5454,7 +5447,6 @@ inferType
54545447
| pattern_matching.rs:264:22:264:33 | MacroExpr | | {EXTERNAL LOCATION} | Arguments |
54555448
| pattern_matching.rs:269:13:269:23 | ref_mut_val | | {EXTERNAL LOCATION} | i32 |
54565449
| pattern_matching.rs:269:27:269:30 | 5i32 | | {EXTERNAL LOCATION} | i32 |
5457-
| pattern_matching.rs:270:11:270:26 | &mut ref_mut_val | | {EXTERNAL LOCATION} | i32 |
54585450
| pattern_matching.rs:270:11:270:26 | &mut ref_mut_val | | file://:0:0:0:0 | & |
54595451
| pattern_matching.rs:270:11:270:26 | &mut ref_mut_val | &T | {EXTERNAL LOCATION} | i32 |
54605452
| pattern_matching.rs:270:16:270:26 | ref_mut_val | | {EXTERNAL LOCATION} | i32 |
@@ -5939,9 +5931,7 @@ inferType
59395931
| pattern_matching.rs:510:25:510:40 | &... | &T.[T;...] | {EXTERNAL LOCATION} | i32 |
59405932
| pattern_matching.rs:510:25:510:40 | &... | &T.[T] | {EXTERNAL LOCATION} | i32 |
59415933
| pattern_matching.rs:510:26:510:40 | [...] | | file://:0:0:0:0 | [] |
5942-
| pattern_matching.rs:510:26:510:40 | [...] | | file://:0:0:0:0 | [] |
59435934
| pattern_matching.rs:510:26:510:40 | [...] | [T;...] | {EXTERNAL LOCATION} | i32 |
5944-
| pattern_matching.rs:510:26:510:40 | [...] | [T] | {EXTERNAL LOCATION} | i32 |
59455935
| pattern_matching.rs:510:27:510:27 | 1 | | {EXTERNAL LOCATION} | i32 |
59465936
| pattern_matching.rs:510:30:510:30 | 2 | | {EXTERNAL LOCATION} | i32 |
59475937
| pattern_matching.rs:510:33:510:33 | 3 | | {EXTERNAL LOCATION} | i32 |

0 commit comments

Comments
 (0)