@@ -163,7 +163,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
163163 /// Conversely, inside this module, `check_pat_top` should never be used.
164164 #[ instrument( level = "debug" , skip( self , pat_info) ) ]
165165 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;
167167 let path_res = match & pat. kind {
168168 PatKind :: Path ( qpath) => {
169169 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> {
172172 } ;
173173 let adjust_mode = self . calc_adjust_mode ( pat, path_res. map ( |( res, ..) | res) ) ;
174174 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 } ;
175177
176178 let ty = match pat. kind {
177179 PatKind :: Wild => expected,
178180 PatKind :: Lit ( lt) => self . check_pat_lit ( pat. span , lt, expected, ti) ,
179181 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+ }
196188 PatKind :: Path ( ref qpath) => {
197189 self . check_pat_path ( pat, qpath, path_res. unwrap ( ) , expected, ti)
198190 }
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+ }
207194 PatKind :: Or ( pats) => {
208195 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) ;
214197 }
215198 expected
216199 }
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+ }
245208 } ;
246209
247210 self . write_ty ( pat. hir_id , ty) ;
@@ -624,7 +587,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
624587 expected : Ty < ' tcx > ,
625588 pat_info : PatInfo < ' tcx , ' _ > ,
626589 ) -> 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;
628591
629592 // Determine the binding mode...
630593 let bm = match ba {
@@ -663,11 +626,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
663626 }
664627
665628 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) ;
671630 }
672631
673632 local_ty
@@ -892,37 +851,23 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
892851 expected : Ty < ' tcx > ,
893852 pat_info : PatInfo < ' tcx , ' _ > ,
894853 ) -> Ty < ' tcx > {
895- let PatInfo { binding_mode : def_bm, top_info : ti, decl_origin } = pat_info;
896-
897854 // Resolve the path and check the definition for errors.
898855 let ( variant, pat_ty) = match self . check_struct_path ( qpath, pat. hir_id ) {
899856 Ok ( data) => data,
900857 Err ( guar) => {
901858 let err = Ty :: new_error ( self . tcx , guar) ;
902859 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) ;
909861 }
910862 return err;
911863 }
912864 } ;
913865
914866 // 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 ) ;
916868
917869 // 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) {
926871 pat_ty
927872 } else {
928873 Ty :: new_misc_error ( self . tcx )
@@ -2144,11 +2089,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
21442089 /// If we're in an irrefutable pattern we prefer the array impl candidate given that
21452090 /// the slice impl candidate would be be rejected anyway (if no ambiguity existed).
21462091 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 ,
21522095 }
21532096 }
21542097
@@ -2183,6 +2126,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
21832126 }
21842127
21852128 let expected = self . structurally_resolve_type ( span, expected) ;
2129+ debug ! ( ?expected) ;
2130+
21862131 let ( element_ty, opt_slice_ty, inferred) = match * expected. kind ( ) {
21872132 // An array, so we might have something like `let [a, b, c] = [0, 1, 2];`.
21882133 ty:: Array ( element_ty, len) => {
0 commit comments