@@ -16,6 +16,7 @@ use rustc_index::bit_set::BitSet;
16
16
use rustc_middle:: middle:: region;
17
17
use rustc_middle:: mir:: * ;
18
18
use rustc_middle:: ty:: { self , CanonicalUserTypeAnnotation , Ty } ;
19
+ use rustc_session:: lint;
19
20
use rustc_span:: Span ;
20
21
use rustc_span:: symbol:: Symbol ;
21
22
use rustc_target:: abi:: VariantIdx ;
@@ -1980,6 +1981,31 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
1980
1981
BindingMode :: ByRef ( _) => ty:: BindingMode :: BindByReference ( mutability) ,
1981
1982
} ;
1982
1983
debug ! ( "declare_binding: user_ty={:?}" , user_ty) ;
1984
+
1985
+ let ref_for_guard = has_guard. 0 . then ( || {
1986
+ let local = self . local_decls . push ( LocalDecl :: < ' tcx > {
1987
+ // This variable isn't mutated but has a name, so has to be
1988
+ // immutable to avoid the unused mut lint.
1989
+ mutability : Mutability :: Not ,
1990
+ ty : tcx. mk_imm_ref ( tcx. lifetimes . re_erased , var_ty) ,
1991
+ user_ty : None ,
1992
+ source_info,
1993
+ internal : false ,
1994
+ is_block_tail : None ,
1995
+ local_info : Some ( box LocalInfo :: User ( ClearCrossCrate :: Set ( BindingForm :: RefForGuard ) ) ) ,
1996
+ } ) ;
1997
+ self . var_debug_info . push ( VarDebugInfo {
1998
+ name,
1999
+ source_info : debug_source_info,
2000
+ place : local. into ( ) ,
2001
+ } ) ;
2002
+ local
2003
+ } ) ;
2004
+
2005
+ let name = tcx. hir ( ) . name ( var_id) ;
2006
+ let is_shorthand_field_binding = false ;
2007
+ let unused_variables_lint_level = tcx. lint_level_at_node ( lint:: builtin:: UNUSED_VARIABLES , var_id) ;
2008
+ let unused_assignments_lint_level = tcx. lint_level_at_node ( lint:: builtin:: UNUSED_ASSIGNMENTS , var_id) ;
1983
2009
let local = LocalDecl :: < ' tcx > {
1984
2010
mutability,
1985
2011
ty : var_ty,
@@ -1988,6 +2014,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
1988
2014
internal : false ,
1989
2015
is_block_tail : None ,
1990
2016
local_info : Some ( box LocalInfo :: User ( ClearCrossCrate :: Set ( BindingForm :: Var ( VarBindingForm {
2017
+ unused_assignments_lint_level,
2018
+ unused_variables_lint_level,
2019
+ is_shorthand_field_binding,
2020
+ counterpart_in_guard : ref_for_guard,
2021
+ name,
1991
2022
binding_mode,
1992
2023
// hypothetically, `visit_primary_bindings` could try to unzip
1993
2024
// an outermost hir::Ty as we descend, matching up
@@ -2004,27 +2035,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
2004
2035
source_info : debug_source_info,
2005
2036
place : for_arm_body. into ( ) ,
2006
2037
} ) ;
2007
- let locals = if has_guard. 0 {
2008
- let ref_for_guard = self . local_decls . push ( LocalDecl :: < ' tcx > {
2009
- // This variable isn't mutated but has a name, so has to be
2010
- // immutable to avoid the unused mut lint.
2011
- mutability : Mutability :: Not ,
2012
- ty : tcx. mk_imm_ref ( tcx. lifetimes . re_erased , var_ty) ,
2013
- user_ty : None ,
2014
- source_info,
2015
- internal : false ,
2016
- is_block_tail : None ,
2017
- local_info : Some ( box LocalInfo :: User ( ClearCrossCrate :: Set ( BindingForm :: RefForGuard ) ) ) ,
2018
- } ) ;
2019
- self . var_debug_info . push ( VarDebugInfo {
2020
- name,
2021
- source_info : debug_source_info,
2022
- place : ref_for_guard. into ( ) ,
2023
- } ) ;
2024
- LocalsForNode :: ForGuard { ref_for_guard, for_arm_body }
2025
- } else {
2026
- LocalsForNode :: One ( for_arm_body)
2038
+
2039
+ let locals = match ref_for_guard {
2040
+ Some ( ref_for_guard) => LocalsForNode :: ForGuard { ref_for_guard, for_arm_body } ,
2041
+ None => LocalsForNode :: One ( for_arm_body) ,
2027
2042
} ;
2043
+
2028
2044
debug ! ( "declare_binding: vars={:?}" , locals) ;
2029
2045
self . var_indices . insert ( var_id, locals) ;
2030
2046
}
0 commit comments