@@ -6,20 +6,19 @@ use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKi
6
6
use rustc_middle:: ty:: Ty ;
7
7
use rustc_span:: { sym, Span } ;
8
8
use rustc_trait_selection:: traits;
9
- use std:: mem;
10
9
11
10
pub ( super ) struct GatherLocalsVisitor < ' a , ' tcx > {
12
11
fcx : & ' a FnCtxt < ' a , ' tcx > ,
13
12
parent_id : hir:: HirId ,
14
13
// parameters are special cases of patterns, but we want to handle them as
15
14
// *distinct* cases. so track when we are hitting a pattern *within* an fn
16
15
// parameter.
17
- outermost_fn_param_pat : bool ,
16
+ outermost_fn_param_pat : Option < Span > ,
18
17
}
19
18
20
19
impl < ' a , ' tcx > GatherLocalsVisitor < ' a , ' tcx > {
21
20
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 }
23
22
}
24
23
25
24
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> {
92
91
}
93
92
94
93
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 ) ;
96
95
intravisit:: walk_param ( self , param) ;
97
96
self . outermost_fn_param_pat = old_outermost_fn_param_pat;
98
97
}
@@ -102,12 +101,12 @@ impl<'a, 'tcx> Visitor<'tcx> for GatherLocalsVisitor<'a, 'tcx> {
102
101
if let PatKind :: Binding ( _, _, ident, _) = p. kind {
103
102
let var_ty = self . assign ( p. span , p. hir_id , None ) ;
104
103
105
- if self . outermost_fn_param_pat {
104
+ if let Some ( ty_span ) = self . outermost_fn_param_pat {
106
105
if !self . fcx . tcx . features ( ) . unsized_fn_params {
107
106
self . fcx . require_type_is_sized (
108
107
var_ty,
109
108
p. span ,
110
- traits:: SizedArgumentType ( Some ( p . span ) ) ,
109
+ traits:: SizedArgumentType ( Some ( ty_span ) ) ,
111
110
) ;
112
111
}
113
112
} else {
@@ -123,7 +122,7 @@ impl<'a, 'tcx> Visitor<'tcx> for GatherLocalsVisitor<'a, 'tcx> {
123
122
var_ty
124
123
) ;
125
124
}
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 ( ) ;
127
126
intravisit:: walk_pat ( self , p) ;
128
127
self . outermost_fn_param_pat = old_outermost_fn_param_pat;
129
128
}
0 commit comments