@@ -163,7 +163,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
163
163
/// Conversely, inside this module, `check_pat_top` should never be used.
164
164
#[ instrument( level = "debug" , skip( self , pat_info) ) ]
165
165
fn check_pat ( & self , pat : & ' tcx Pat < ' tcx > , expected : Ty < ' tcx > , pat_info : PatInfo < ' tcx , ' _ > ) {
166
- let PatInfo { binding_mode : def_bm, top_info : ti, decl_origin } = pat_info;
166
+ let PatInfo { binding_mode : def_bm, top_info : ti, .. } = pat_info;
167
167
let path_res = match & pat. kind {
168
168
PatKind :: Path ( qpath) => {
169
169
Some ( self . resolve_ty_and_res_fully_qualified_call ( qpath, pat. hir_id , pat. span ) )
@@ -172,76 +172,39 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
172
172
} ;
173
173
let adjust_mode = self . calc_adjust_mode ( pat, path_res. map ( |( res, ..) | res) ) ;
174
174
let ( expected, def_bm) = self . calc_default_binding_mode ( pat, expected, def_bm, adjust_mode) ;
175
+ let pat_info =
176
+ PatInfo { binding_mode : def_bm, top_info : ti, decl_origin : pat_info. decl_origin } ;
175
177
176
178
let ty = match pat. kind {
177
179
PatKind :: Wild => expected,
178
180
PatKind :: Lit ( lt) => self . check_pat_lit ( pat. span , lt, expected, ti) ,
179
181
PatKind :: Range ( lhs, rhs, _) => self . check_pat_range ( pat. span , lhs, rhs, expected, ti) ,
180
- PatKind :: Binding ( ba, var_id, _, sub) => self . check_pat_ident (
181
- pat,
182
- ba,
183
- var_id,
184
- sub,
185
- expected,
186
- PatInfo { binding_mode : def_bm, top_info : ti, decl_origin } ,
187
- ) ,
188
- PatKind :: TupleStruct ( ref qpath, subpats, ddpos) => self . check_pat_tuple_struct (
189
- pat,
190
- qpath,
191
- subpats,
192
- ddpos,
193
- expected,
194
- PatInfo { binding_mode : def_bm, top_info : ti, decl_origin } ,
195
- ) ,
182
+ PatKind :: Binding ( ba, var_id, _, sub) => {
183
+ self . check_pat_ident ( pat, ba, var_id, sub, expected, pat_info)
184
+ }
185
+ PatKind :: TupleStruct ( ref qpath, subpats, ddpos) => {
186
+ self . check_pat_tuple_struct ( pat, qpath, subpats, ddpos, expected, pat_info)
187
+ }
196
188
PatKind :: Path ( ref qpath) => {
197
189
self . check_pat_path ( pat, qpath, path_res. unwrap ( ) , expected, ti)
198
190
}
199
- PatKind :: Struct ( ref qpath, fields, has_rest_pat) => self . check_pat_struct (
200
- pat,
201
- qpath,
202
- fields,
203
- has_rest_pat,
204
- expected,
205
- PatInfo { binding_mode : def_bm, top_info : ti, decl_origin } ,
206
- ) ,
191
+ PatKind :: Struct ( ref qpath, fields, has_rest_pat) => {
192
+ self . check_pat_struct ( pat, qpath, fields, has_rest_pat, expected, pat_info)
193
+ }
207
194
PatKind :: Or ( pats) => {
208
195
for pat in pats {
209
- self . check_pat (
210
- pat,
211
- expected,
212
- PatInfo { binding_mode : def_bm, top_info : ti, decl_origin } ,
213
- ) ;
196
+ self . check_pat ( pat, expected, pat_info) ;
214
197
}
215
198
expected
216
199
}
217
- PatKind :: Tuple ( elements, ddpos) => self . check_pat_tuple (
218
- pat. span ,
219
- elements,
220
- ddpos,
221
- expected,
222
- PatInfo { binding_mode : def_bm, top_info : ti, decl_origin } ,
223
- ) ,
224
- PatKind :: Box ( inner) => self . check_pat_box (
225
- pat. span ,
226
- inner,
227
- expected,
228
- PatInfo { binding_mode : def_bm, top_info : ti, decl_origin } ,
229
- ) ,
230
- PatKind :: Ref ( inner, mutbl) => self . check_pat_ref (
231
- pat,
232
- inner,
233
- mutbl,
234
- expected,
235
- PatInfo { binding_mode : def_bm, top_info : ti, decl_origin } ,
236
- ) ,
237
- PatKind :: Slice ( before, slice, after) => self . check_pat_slice (
238
- pat. span ,
239
- before,
240
- slice,
241
- after,
242
- expected,
243
- PatInfo { binding_mode : def_bm, top_info : ti, decl_origin } ,
244
- ) ,
200
+ PatKind :: Tuple ( elements, ddpos) => {
201
+ self . check_pat_tuple ( pat. span , elements, ddpos, expected, pat_info)
202
+ }
203
+ PatKind :: Box ( inner) => self . check_pat_box ( pat. span , inner, expected, pat_info) ,
204
+ PatKind :: Ref ( inner, mutbl) => self . check_pat_ref ( pat, inner, mutbl, expected, pat_info) ,
205
+ PatKind :: Slice ( before, slice, after) => {
206
+ self . check_pat_slice ( pat. span , before, slice, after, expected, pat_info)
207
+ }
245
208
} ;
246
209
247
210
self . write_ty ( pat. hir_id , ty) ;
@@ -624,7 +587,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
624
587
expected : Ty < ' tcx > ,
625
588
pat_info : PatInfo < ' tcx , ' _ > ,
626
589
) -> Ty < ' tcx > {
627
- let PatInfo { binding_mode : def_bm, top_info : ti, decl_origin } = pat_info;
590
+ let PatInfo { binding_mode : def_bm, top_info : ti, .. } = pat_info;
628
591
629
592
// Determine the binding mode...
630
593
let bm = match ba {
@@ -663,11 +626,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
663
626
}
664
627
665
628
if let Some ( p) = sub {
666
- self . check_pat (
667
- p,
668
- expected,
669
- PatInfo { binding_mode : def_bm, top_info : ti, decl_origin } ,
670
- ) ;
629
+ self . check_pat ( p, expected, pat_info) ;
671
630
}
672
631
673
632
local_ty
@@ -892,37 +851,23 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
892
851
expected : Ty < ' tcx > ,
893
852
pat_info : PatInfo < ' tcx , ' _ > ,
894
853
) -> Ty < ' tcx > {
895
- let PatInfo { binding_mode : def_bm, top_info : ti, decl_origin } = pat_info;
896
-
897
854
// Resolve the path and check the definition for errors.
898
855
let ( variant, pat_ty) = match self . check_struct_path ( qpath, pat. hir_id ) {
899
856
Ok ( data) => data,
900
857
Err ( guar) => {
901
858
let err = Ty :: new_error ( self . tcx , guar) ;
902
859
for field in fields {
903
- let ti = ti;
904
- self . check_pat (
905
- field. pat ,
906
- err,
907
- PatInfo { binding_mode : def_bm, top_info : ti, decl_origin } ,
908
- ) ;
860
+ self . check_pat ( field. pat , err, pat_info) ;
909
861
}
910
862
return err;
911
863
}
912
864
} ;
913
865
914
866
// Type-check the path.
915
- self . demand_eqtype_pat ( pat. span , expected, pat_ty, ti ) ;
867
+ self . demand_eqtype_pat ( pat. span , expected, pat_ty, pat_info . top_info ) ;
916
868
917
869
// Type-check subpatterns.
918
- if self . check_struct_pat_fields (
919
- pat_ty,
920
- & pat,
921
- variant,
922
- fields,
923
- has_rest_pat,
924
- PatInfo { binding_mode : def_bm, top_info : ti, decl_origin } ,
925
- ) {
870
+ if self . check_struct_pat_fields ( pat_ty, & pat, variant, fields, has_rest_pat, pat_info) {
926
871
pat_ty
927
872
} else {
928
873
Ty :: new_misc_error ( self . tcx )
@@ -2144,11 +2089,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2144
2089
/// If we're in an irrefutable pattern we prefer the array impl candidate given that
2145
2090
/// the slice impl candidate would be be rejected anyway (if no ambiguity existed).
2146
2091
fn pat_is_irrefutable ( & self , decl_origin : Option < DeclOrigin < ' _ > > ) -> bool {
2147
- if let Some ( decl_origin) = decl_origin {
2148
- decl_origin. try_get_els ( ) . is_none ( )
2149
- && matches ! ( decl_origin, DeclOrigin :: LocalDecl { .. } )
2150
- } else {
2151
- false
2092
+ match decl_origin {
2093
+ Some ( DeclOrigin :: LocalDecl { els : None } ) => true ,
2094
+ Some ( DeclOrigin :: LocalDecl { els : Some ( _) } | DeclOrigin :: LetExpr ) | None => false ,
2152
2095
}
2153
2096
}
2154
2097
@@ -2183,6 +2126,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2183
2126
}
2184
2127
2185
2128
let expected = self . structurally_resolve_type ( span, expected) ;
2129
+ debug ! ( ?expected) ;
2130
+
2186
2131
let ( element_ty, opt_slice_ty, inferred) = match * expected. kind ( ) {
2187
2132
// An array, so we might have something like `let [a, b, c] = [0, 1, 2];`.
2188
2133
ty:: Array ( element_ty, len) => {
0 commit comments