File tree 2 files changed +36
-1
lines changed
2 files changed +36
-1
lines changed Original file line number Diff line number Diff line change @@ -911,7 +911,15 @@ impl<'a> InferenceContext<'a> {
911
911
let lhs_ty = self . insert_type_vars_shallow ( lhs_ty) ;
912
912
let ty = match self . coerce ( None , & rhs_ty, & lhs_ty) {
913
913
Ok ( ty) => ty,
914
- Err ( _) => self . err_ty ( ) ,
914
+ Err ( _) => {
915
+ self . result . type_mismatches . insert (
916
+ lhs. into ( ) ,
917
+ TypeMismatch { expected : rhs_ty. clone ( ) , actual : lhs_ty. clone ( ) } ,
918
+ ) ;
919
+ // `rhs_ty` is returned so no further type mismatches are
920
+ // reported because of this mismatch.
921
+ rhs_ty
922
+ }
915
923
} ;
916
924
self . write_expr_ty ( lhs, ty. clone ( ) ) ;
917
925
return ty;
Original file line number Diff line number Diff line change @@ -3043,3 +3043,30 @@ fn main() {
3043
3043
"# ,
3044
3044
) ;
3045
3045
}
3046
+
3047
+ #[ test]
3048
+ fn destructuring_assignment_type_mismatch_on_identifier ( ) {
3049
+ check (
3050
+ r#"
3051
+ struct S { v: i64 }
3052
+ struct TS(i64);
3053
+ fn main() {
3054
+ let mut a: usize = 0;
3055
+ (a,) = (0i64,);
3056
+ //^expected i64, got usize
3057
+
3058
+ let mut a: usize = 0;
3059
+ [a,] = [0i64,];
3060
+ //^expected i64, got usize
3061
+
3062
+ let mut a: usize = 0;
3063
+ S { v: a } = S { v: 0 };
3064
+ //^expected i64, got usize
3065
+
3066
+ let mut a: usize = 0;
3067
+ TS(a) = TS(0);
3068
+ //^expected i64, got usize
3069
+ }
3070
+ "# ,
3071
+ ) ;
3072
+ }
You can’t perform that action at this time.
0 commit comments