@@ -6,20 +6,19 @@ use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKi
66use rustc_middle:: ty:: Ty ;
77use rustc_span:: { sym, Span } ;
88use rustc_trait_selection:: traits;
9- use std:: mem;
109
1110pub ( super ) struct GatherLocalsVisitor < ' a , ' tcx > {
1211 fcx : & ' a FnCtxt < ' a , ' tcx > ,
1312 parent_id : hir:: HirId ,
1413 // parameters are special cases of patterns, but we want to handle them as
1514 // *distinct* cases. so track when we are hitting a pattern *within* an fn
1615 // parameter.
17- outermost_fn_param_pat : bool ,
16+ outermost_fn_param_pat : Option < Span > ,
1817}
1918
2019impl < ' a , ' tcx > GatherLocalsVisitor < ' a , ' tcx > {
2120 pub ( super ) fn new ( fcx : & ' a FnCtxt < ' a , ' tcx > , parent_id : hir:: HirId ) -> Self {
22- Self { fcx, parent_id, outermost_fn_param_pat : false }
21+ Self { fcx, parent_id, outermost_fn_param_pat : None }
2322 }
2423
2524 fn assign ( & mut self , span : Span , nid : hir:: HirId , ty_opt : Option < LocalTy < ' tcx > > ) -> Ty < ' tcx > {
@@ -92,7 +91,7 @@ impl<'a, 'tcx> Visitor<'tcx> for GatherLocalsVisitor<'a, 'tcx> {
9291 }
9392
9493 fn visit_param ( & mut self , param : & ' tcx hir:: Param < ' tcx > ) {
95- let old_outermost_fn_param_pat = mem :: replace ( & mut self . outermost_fn_param_pat , true ) ;
94+ let old_outermost_fn_param_pat = self . outermost_fn_param_pat . replace ( param . ty_span ) ;
9695 intravisit:: walk_param ( self , param) ;
9796 self . outermost_fn_param_pat = old_outermost_fn_param_pat;
9897 }
@@ -102,12 +101,12 @@ impl<'a, 'tcx> Visitor<'tcx> for GatherLocalsVisitor<'a, 'tcx> {
102101 if let PatKind :: Binding ( _, _, ident, _) = p. kind {
103102 let var_ty = self . assign ( p. span , p. hir_id , None ) ;
104103
105- if self . outermost_fn_param_pat {
104+ if let Some ( ty_span ) = self . outermost_fn_param_pat {
106105 if !self . fcx . tcx . features ( ) . unsized_fn_params {
107106 self . fcx . require_type_is_sized (
108107 var_ty,
109108 p. span ,
110- traits:: SizedArgumentType ( Some ( p . span ) ) ,
109+ traits:: SizedArgumentType ( Some ( ty_span ) ) ,
111110 ) ;
112111 }
113112 } else {
@@ -123,7 +122,7 @@ impl<'a, 'tcx> Visitor<'tcx> for GatherLocalsVisitor<'a, 'tcx> {
123122 var_ty
124123 ) ;
125124 }
126- let old_outermost_fn_param_pat = mem :: replace ( & mut self . outermost_fn_param_pat , false ) ;
125+ let old_outermost_fn_param_pat = self . outermost_fn_param_pat . take ( ) ;
127126 intravisit:: walk_pat ( self , p) ;
128127 self . outermost_fn_param_pat = old_outermost_fn_param_pat;
129128 }
0 commit comments