File tree Expand file tree Collapse file tree 2 files changed +21
-9
lines changed Expand file tree Collapse file tree 2 files changed +21
-9
lines changed Original file line number Diff line number Diff line change @@ -735,10 +735,11 @@ impl<'a> InferenceContext<'a> {
735
735
_ => self . table . new_type_var ( ) ,
736
736
} ;
737
737
738
+ let expected = Expectation :: has_type ( elem_ty. clone ( ) ) ;
738
739
let len = match array {
739
740
Array :: ElementList ( items) => {
740
741
for expr in items. iter ( ) {
741
- let cur_elem_ty = self . infer_expr_inner ( * expr, expected) ;
742
+ let cur_elem_ty = self . infer_expr_inner ( * expr, & expected) ;
742
743
elem_ty = self . coerce_merge_branch ( Some ( * expr) , & elem_ty, & cur_elem_ty) ;
743
744
}
744
745
Some ( items. len ( ) as u64 )
Original file line number Diff line number Diff line change @@ -117,23 +117,34 @@ fn recursive_vars_2() {
117
117
"# ,
118
118
expect ! [ [ r#"
119
119
10..79 '{ ...x)]; }': ()
120
- 20..21 'x': {unknown}
121
- 24..31 'unknown': {unknown}
120
+ 20..21 'x': & {unknown}
121
+ 24..31 'unknown': & {unknown}
122
122
41..42 'y': {unknown}
123
123
45..52 'unknown': {unknown}
124
- 58..76 '[(x, y..., &x)]': [({unknown}, {unknown}); 2]
125
- 59..65 '(x, y)': ({unknown}, {unknown})
126
- 60..61 'x': {unknown}
124
+ 58..76 '[(x, y..., &x)]': [(& {unknown}, {unknown}); 2]
125
+ 59..65 '(x, y)': (& {unknown}, {unknown})
126
+ 60..61 'x': & {unknown}
127
127
63..64 'y': {unknown}
128
- 67..75 '(&y, &x)': (&{unknown}, & {unknown})
128
+ 67..75 '(&y, &x)': (&{unknown}, {unknown})
129
129
68..70 '&y': &{unknown}
130
130
69..70 'y': {unknown}
131
- 72..74 '&x': &{unknown}
132
- 73..74 'x': {unknown}
131
+ 72..74 '&x': && {unknown}
132
+ 73..74 'x': & {unknown}
133
133
"# ] ] ,
134
134
) ;
135
135
}
136
136
137
+ #[ test]
138
+ fn array_elements_expected_type ( ) {
139
+ check_no_mismatches (
140
+ r#"
141
+ fn test() {
142
+ let x: [[u32; 2]; 2] = [[1, 2], [3, 4]];
143
+ }
144
+ "# ,
145
+ ) ;
146
+ }
147
+
137
148
#[ test]
138
149
fn infer_std_crash_1 ( ) {
139
150
// caused stack overflow, taken from std
You can’t perform that action at this time.
0 commit comments