File tree Expand file tree Collapse file tree 2 files changed +378
-5
lines changed
rust/ql/test/library-tests/type-inference Expand file tree Collapse file tree 2 files changed +378
-5
lines changed Original file line number Diff line number Diff line change @@ -2696,6 +2696,44 @@ pub mod path_buf {
2696
2696
}
2697
2697
}
2698
2698
2699
+ mod if_expr {
2700
+ pub trait MyTrait < T : Sized > {
2701
+ fn m ( & self ) -> T ;
2702
+ }
2703
+
2704
+ struct S < T > ( T ) ;
2705
+
2706
+ impl MyTrait < i32 > for S < i32 > {
2707
+ fn m ( & self ) -> i32 {
2708
+ self . 0 // $ fieldof=S
2709
+ }
2710
+ }
2711
+
2712
+ impl MyTrait < i32 > for S < S < i32 > > {
2713
+ fn m ( & self ) -> i32 {
2714
+ self . 0 . 0 // $ fieldof=S
2715
+ }
2716
+ }
2717
+
2718
+ impl < T : Copy > S < T > {
2719
+ fn m2 ( & self ) -> S < S < T > > {
2720
+ S ( S ( self . 0 ) ) // $ fieldof=S
2721
+ }
2722
+ }
2723
+
2724
+ pub fn f ( b : bool ) -> Box < dyn MyTrait < i32 > > {
2725
+ // This code exhibits an explosion in type inference when type information is propagated
2726
+ // from an `if` expression to its branches.
2727
+ let x = S ( 1 ) ;
2728
+ if b {
2729
+ let x = x. m2 ( ) ; // $ target=m2
2730
+ Box :: new ( x) // $ target=new
2731
+ } else {
2732
+ Box :: new ( x) // $ target=new
2733
+ }
2734
+ }
2735
+ }
2736
+
2699
2737
mod blanket_impl;
2700
2738
mod closure;
2701
2739
mod dereference;
@@ -2733,4 +2771,5 @@ fn main() {
2733
2771
pattern_matching:: test_all_patterns ( ) ; // $ target=test_all_patterns
2734
2772
pattern_matching_experimental:: box_patterns ( ) ; // $ target=box_patterns
2735
2773
dyn_type:: test ( ) ; // $ target=test
2774
+ if_expr:: f ( true ) ; // $ target=f
2736
2775
}
You can’t perform that action at this time.
0 commit comments