Skip to content

Commit 5697a7e

Browse files
committed
Rust: More type inference tests
1 parent bc53fee commit 5697a7e

File tree

2 files changed

+88
-42
lines changed

2 files changed

+88
-42
lines changed

rust/ql/test/library-tests/type-inference/main.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2837,6 +2837,33 @@ mod local_function {
28372837
}
28382838
}
28392839

2840+
mod block_types {
2841+
#[rustfmt::skip]
2842+
fn f1(cond: bool) -> i32 {
2843+
// Block that evaluates to unit
2844+
let a = { // $ MISSING: type=a:()
2845+
if cond {
2846+
return 12;
2847+
}
2848+
};
2849+
0
2850+
}
2851+
2852+
#[rustfmt::skip]
2853+
fn f2() -> i32 {
2854+
// Block that does not evaluate to unit
2855+
let b = 'label: { // $ MISSING: b:i32 SPURIOUS: certainType=b:()
2856+
break 'label 12;
2857+
};
2858+
println!("b: {:?}", b);
2859+
0
2860+
}
2861+
2862+
fn f3() -> i32 {
2863+
return 0;
2864+
} // should only have type `i32`, not `()`
2865+
}
2866+
28402867
mod blanket_impl;
28412868
mod closure;
28422869
mod dereference;

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

Lines changed: 61 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -6424,48 +6424,67 @@ inferType
64246424
| main.rs:2835:13:2835:13 | x | | {EXTERNAL LOCATION} | i32 |
64256425
| main.rs:2835:13:2835:17 | ... + ... | | {EXTERNAL LOCATION} | i32 |
64266426
| main.rs:2835:17:2835:17 | 1 | | {EXTERNAL LOCATION} | i32 |
6427-
| main.rs:2845:11:2880:1 | { ... } | | file://:0:0:0:0 | () |
6428-
| main.rs:2846:5:2846:21 | ...::f(...) | | file://:0:0:0:0 | () |
6429-
| main.rs:2847:5:2847:20 | ...::f(...) | | main.rs:72:5:72:21 | Foo |
6430-
| main.rs:2848:5:2848:60 | ...::g(...) | | main.rs:72:5:72:21 | Foo |
6431-
| main.rs:2848:20:2848:38 | ...::Foo {...} | | main.rs:72:5:72:21 | Foo |
6432-
| main.rs:2848:41:2848:59 | ...::Foo {...} | | main.rs:72:5:72:21 | Foo |
6433-
| main.rs:2849:5:2849:35 | ...::f(...) | | file://:0:0:0:0 | () |
6434-
| main.rs:2850:5:2850:41 | ...::f(...) | | file://:0:0:0:0 | () |
6435-
| main.rs:2851:5:2851:45 | ...::test(...) | | file://:0:0:0:0 | () |
6436-
| main.rs:2852:5:2852:30 | ...::f(...) | | file://:0:0:0:0 | () |
6437-
| main.rs:2853:5:2853:33 | ...::f(...) | | file://:0:0:0:0 | () |
6438-
| main.rs:2854:5:2854:21 | ...::f(...) | | file://:0:0:0:0 | () |
6439-
| main.rs:2855:5:2855:27 | ...::f(...) | | file://:0:0:0:0 | () |
6440-
| main.rs:2856:5:2856:32 | ...::f(...) | | file://:0:0:0:0 | () |
6441-
| main.rs:2857:5:2857:23 | ...::f(...) | | file://:0:0:0:0 | () |
6442-
| main.rs:2858:5:2858:36 | ...::f(...) | | file://:0:0:0:0 | () |
6443-
| main.rs:2859:5:2859:35 | ...::f(...) | | file://:0:0:0:0 | () |
6444-
| main.rs:2860:5:2860:29 | ...::f(...) | | file://:0:0:0:0 | () |
6445-
| main.rs:2861:5:2861:23 | ...::f(...) | | file://:0:0:0:0 | () |
6446-
| main.rs:2862:5:2862:24 | ...::f(...) | | file://:0:0:0:0 | () |
6447-
| main.rs:2863:5:2863:17 | ...::f(...) | | file://:0:0:0:0 | () |
6448-
| main.rs:2864:5:2864:18 | ...::f(...) | | file://:0:0:0:0 | () |
6449-
| main.rs:2865:5:2865:15 | ...::f(...) | | {EXTERNAL LOCATION} | trait Future |
6450-
| main.rs:2865:5:2865:15 | ...::f(...) | Output | file://:0:0:0:0 | () |
6451-
| main.rs:2866:5:2866:19 | ...::f(...) | | file://:0:0:0:0 | () |
6452-
| main.rs:2867:5:2867:17 | ...::f(...) | | file://:0:0:0:0 | () |
6453-
| main.rs:2868:5:2868:14 | ...::f(...) | | file://:0:0:0:0 | () |
6454-
| main.rs:2869:5:2869:27 | ...::f(...) | | file://:0:0:0:0 | () |
6455-
| main.rs:2870:5:2870:15 | ...::f(...) | | file://:0:0:0:0 | () |
6456-
| main.rs:2871:5:2871:43 | ...::f(...) | | file://:0:0:0:0 | () |
6457-
| main.rs:2872:5:2872:15 | ...::f(...) | | file://:0:0:0:0 | () |
6458-
| main.rs:2873:5:2873:17 | ...::f(...) | | file://:0:0:0:0 | () |
6459-
| main.rs:2874:5:2874:23 | ...::test(...) | | file://:0:0:0:0 | () |
6460-
| main.rs:2875:5:2875:41 | ...::test_all_patterns(...) | | file://:0:0:0:0 | () |
6461-
| main.rs:2876:5:2876:49 | ...::box_patterns(...) | | file://:0:0:0:0 | () |
6462-
| main.rs:2877:5:2877:20 | ...::test(...) | | file://:0:0:0:0 | () |
6463-
| main.rs:2878:5:2878:20 | ...::f(...) | | {EXTERNAL LOCATION} | Box |
6464-
| main.rs:2878:5:2878:20 | ...::f(...) | A | {EXTERNAL LOCATION} | Global |
6465-
| main.rs:2878:5:2878:20 | ...::f(...) | T | main.rs:2787:5:2789:5 | dyn MyTrait |
6466-
| main.rs:2878:5:2878:20 | ...::f(...) | T.dyn(T) | {EXTERNAL LOCATION} | i32 |
6467-
| main.rs:2878:16:2878:19 | true | | {EXTERNAL LOCATION} | bool |
6468-
| main.rs:2879:5:2879:23 | ...::f(...) | | file://:0:0:0:0 | () |
6427+
| main.rs:2842:11:2842:14 | cond | | {EXTERNAL LOCATION} | bool |
6428+
| main.rs:2842:30:2850:5 | { ... } | | {EXTERNAL LOCATION} | i32 |
6429+
| main.rs:2845:16:2845:19 | cond | | {EXTERNAL LOCATION} | bool |
6430+
| main.rs:2846:24:2846:25 | 12 | | {EXTERNAL LOCATION} | i32 |
6431+
| main.rs:2849:9:2849:9 | 0 | | {EXTERNAL LOCATION} | i32 |
6432+
| main.rs:2853:20:2860:5 | { ... } | | {EXTERNAL LOCATION} | i32 |
6433+
| main.rs:2855:13:2855:13 | b | | file://:0:0:0:0 | () |
6434+
| main.rs:2855:17:2857:9 | 'label: { ... } | | file://:0:0:0:0 | () |
6435+
| main.rs:2856:26:2856:27 | 12 | | {EXTERNAL LOCATION} | i32 |
6436+
| main.rs:2858:18:2858:26 | "b: {:?}\\n" | | file://:0:0:0:0 | & |
6437+
| main.rs:2858:18:2858:26 | "b: {:?}\\n" | &T | {EXTERNAL LOCATION} | str |
6438+
| main.rs:2858:18:2858:29 | ...::_print(...) | | file://:0:0:0:0 | () |
6439+
| main.rs:2858:18:2858:29 | FormatArgsExpr | | {EXTERNAL LOCATION} | Arguments |
6440+
| main.rs:2858:18:2858:29 | MacroExpr | | {EXTERNAL LOCATION} | Arguments |
6441+
| main.rs:2858:18:2858:29 | { ... } | | file://:0:0:0:0 | () |
6442+
| main.rs:2858:29:2858:29 | b | | file://:0:0:0:0 | () |
6443+
| main.rs:2859:9:2859:9 | 0 | | {EXTERNAL LOCATION} | i32 |
6444+
| main.rs:2862:20:2864:5 | { ... } | | {EXTERNAL LOCATION} | i32 |
6445+
| main.rs:2863:16:2863:16 | 0 | | {EXTERNAL LOCATION} | i32 |
6446+
| main.rs:2872:11:2907:1 | { ... } | | file://:0:0:0:0 | () |
6447+
| main.rs:2873:5:2873:21 | ...::f(...) | | file://:0:0:0:0 | () |
6448+
| main.rs:2874:5:2874:20 | ...::f(...) | | main.rs:72:5:72:21 | Foo |
6449+
| main.rs:2875:5:2875:60 | ...::g(...) | | main.rs:72:5:72:21 | Foo |
6450+
| main.rs:2875:20:2875:38 | ...::Foo {...} | | main.rs:72:5:72:21 | Foo |
6451+
| main.rs:2875:41:2875:59 | ...::Foo {...} | | main.rs:72:5:72:21 | Foo |
6452+
| main.rs:2876:5:2876:35 | ...::f(...) | | file://:0:0:0:0 | () |
6453+
| main.rs:2877:5:2877:41 | ...::f(...) | | file://:0:0:0:0 | () |
6454+
| main.rs:2878:5:2878:45 | ...::test(...) | | file://:0:0:0:0 | () |
6455+
| main.rs:2879:5:2879:30 | ...::f(...) | | file://:0:0:0:0 | () |
6456+
| main.rs:2880:5:2880:33 | ...::f(...) | | file://:0:0:0:0 | () |
6457+
| main.rs:2881:5:2881:21 | ...::f(...) | | file://:0:0:0:0 | () |
6458+
| main.rs:2882:5:2882:27 | ...::f(...) | | file://:0:0:0:0 | () |
6459+
| main.rs:2883:5:2883:32 | ...::f(...) | | file://:0:0:0:0 | () |
6460+
| main.rs:2884:5:2884:23 | ...::f(...) | | file://:0:0:0:0 | () |
6461+
| main.rs:2885:5:2885:36 | ...::f(...) | | file://:0:0:0:0 | () |
6462+
| main.rs:2886:5:2886:35 | ...::f(...) | | file://:0:0:0:0 | () |
6463+
| main.rs:2887:5:2887:29 | ...::f(...) | | file://:0:0:0:0 | () |
6464+
| main.rs:2888:5:2888:23 | ...::f(...) | | file://:0:0:0:0 | () |
6465+
| main.rs:2889:5:2889:24 | ...::f(...) | | file://:0:0:0:0 | () |
6466+
| main.rs:2890:5:2890:17 | ...::f(...) | | file://:0:0:0:0 | () |
6467+
| main.rs:2891:5:2891:18 | ...::f(...) | | file://:0:0:0:0 | () |
6468+
| main.rs:2892:5:2892:15 | ...::f(...) | | {EXTERNAL LOCATION} | trait Future |
6469+
| main.rs:2892:5:2892:15 | ...::f(...) | Output | file://:0:0:0:0 | () |
6470+
| main.rs:2893:5:2893:19 | ...::f(...) | | file://:0:0:0:0 | () |
6471+
| main.rs:2894:5:2894:17 | ...::f(...) | | file://:0:0:0:0 | () |
6472+
| main.rs:2895:5:2895:14 | ...::f(...) | | file://:0:0:0:0 | () |
6473+
| main.rs:2896:5:2896:27 | ...::f(...) | | file://:0:0:0:0 | () |
6474+
| main.rs:2897:5:2897:15 | ...::f(...) | | file://:0:0:0:0 | () |
6475+
| main.rs:2898:5:2898:43 | ...::f(...) | | file://:0:0:0:0 | () |
6476+
| main.rs:2899:5:2899:15 | ...::f(...) | | file://:0:0:0:0 | () |
6477+
| main.rs:2900:5:2900:17 | ...::f(...) | | file://:0:0:0:0 | () |
6478+
| main.rs:2901:5:2901:23 | ...::test(...) | | file://:0:0:0:0 | () |
6479+
| main.rs:2902:5:2902:41 | ...::test_all_patterns(...) | | file://:0:0:0:0 | () |
6480+
| main.rs:2903:5:2903:49 | ...::box_patterns(...) | | file://:0:0:0:0 | () |
6481+
| main.rs:2904:5:2904:20 | ...::test(...) | | file://:0:0:0:0 | () |
6482+
| main.rs:2905:5:2905:20 | ...::f(...) | | {EXTERNAL LOCATION} | Box |
6483+
| main.rs:2905:5:2905:20 | ...::f(...) | A | {EXTERNAL LOCATION} | Global |
6484+
| main.rs:2905:5:2905:20 | ...::f(...) | T | main.rs:2787:5:2789:5 | dyn MyTrait |
6485+
| main.rs:2905:5:2905:20 | ...::f(...) | T.dyn(T) | {EXTERNAL LOCATION} | i32 |
6486+
| main.rs:2905:16:2905:19 | true | | {EXTERNAL LOCATION} | bool |
6487+
| main.rs:2906:5:2906:23 | ...::f(...) | | file://:0:0:0:0 | () |
64696488
| pattern_matching.rs:13:26:133:1 | { ... } | | {EXTERNAL LOCATION} | Option |
64706489
| pattern_matching.rs:13:26:133:1 | { ... } | T | file://:0:0:0:0 | () |
64716490
| pattern_matching.rs:14:9:14:13 | value | | {EXTERNAL LOCATION} | Option |

0 commit comments

Comments
 (0)