@@ -401,8 +401,6 @@ impl<'tcx> Body<'tcx> {
401
401
LocalKind :: ReturnPointer
402
402
} else if index < self . arg_count + 1 {
403
403
LocalKind :: Arg
404
- } else if self . local_decls [ local] . is_user_variable ( ) {
405
- LocalKind :: Var
406
404
} else {
407
405
LocalKind :: Temp
408
406
}
@@ -572,6 +570,13 @@ impl<T> ClearCrossCrate<T> {
572
570
}
573
571
}
574
572
573
+ pub fn as_mut ( & mut self ) -> ClearCrossCrate < & mut T > {
574
+ match self {
575
+ ClearCrossCrate :: Clear => ClearCrossCrate :: Clear ,
576
+ ClearCrossCrate :: Set ( v) => ClearCrossCrate :: Set ( v) ,
577
+ }
578
+ }
579
+
575
580
pub fn assert_crate_local ( self ) -> T {
576
581
match self {
577
582
ClearCrossCrate :: Clear => bug ! ( "unwrapping cross-crate data" ) ,
@@ -661,9 +666,7 @@ impl Atom for Local {
661
666
/// Classifies locals into categories. See `Body::local_kind`.
662
667
#[ derive( Clone , Copy , PartialEq , Eq , Debug , HashStable ) ]
663
668
pub enum LocalKind {
664
- /// User-declared variable binding.
665
- Var ,
666
- /// Compiler-introduced temporary.
669
+ /// User-declared variable binding or compiler-introduced temporary.
667
670
Temp ,
668
671
/// Function argument.
669
672
Arg ,
@@ -760,7 +763,7 @@ pub struct LocalDecl<'tcx> {
760
763
pub mutability : Mutability ,
761
764
762
765
// FIXME(matthewjasper) Don't store in this in `Body`
763
- pub local_info : Option < Box < LocalInfo < ' tcx > > > ,
766
+ pub local_info : ClearCrossCrate < Box < LocalInfo < ' tcx > > > ,
764
767
765
768
/// `true` if this is an internal local.
766
769
///
@@ -778,13 +781,6 @@ pub struct LocalDecl<'tcx> {
778
781
/// generator.
779
782
pub internal : bool ,
780
783
781
- /// If this local is a temporary and `is_block_tail` is `Some`,
782
- /// then it is a temporary created for evaluation of some
783
- /// subexpression of some block's tail expression (with no
784
- /// intervening statement context).
785
- // FIXME(matthewjasper) Don't store in this in `Body`
786
- pub is_block_tail : Option < BlockTailInfo > ,
787
-
788
784
/// The type of this local.
789
785
pub ty : Ty < ' tcx > ,
790
786
@@ -890,21 +886,31 @@ pub enum LocalInfo<'tcx> {
890
886
/// The `BindingForm` is solely used for local diagnostics when generating
891
887
/// warnings/errors when compiling the current crate, and therefore it need
892
888
/// not be visible across crates.
893
- User ( ClearCrossCrate < BindingForm < ' tcx > > ) ,
889
+ User ( BindingForm < ' tcx > ) ,
894
890
/// A temporary created that references the static with the given `DefId`.
895
891
StaticRef { def_id : DefId , is_thread_local : bool } ,
896
892
/// A temporary created that references the const with the given `DefId`
897
893
ConstRef { def_id : DefId } ,
898
894
/// A temporary created during the creation of an aggregate
899
895
/// (e.g. a temporary for `foo` in `MyStruct { my_field: foo }`)
900
896
AggregateTemp ,
897
+ /// A temporary created for evaluation of some subexpression of some block's tail expression
898
+ /// (with no intervening statement context).
899
+ // FIXME(matthewjasper) Don't store in this in `Body`
900
+ BlockTailTemp ( BlockTailInfo ) ,
901
901
/// A temporary created during the pass `Derefer` to avoid it's retagging
902
902
DerefTemp ,
903
903
/// A temporary created for borrow checking.
904
904
FakeBorrow ,
905
+ /// A local without anything interesting about it.
906
+ Boring ,
905
907
}
906
908
907
909
impl < ' tcx > LocalDecl < ' tcx > {
910
+ pub fn local_info ( & self ) -> & LocalInfo < ' tcx > {
911
+ & * * self . local_info . as_ref ( ) . assert_crate_local ( )
912
+ }
913
+
908
914
/// Returns `true` only if local is a binding that can itself be
909
915
/// made mutable via the addition of the `mut` keyword, namely
910
916
/// something like the occurrences of `x` in:
@@ -913,15 +919,15 @@ impl<'tcx> LocalDecl<'tcx> {
913
919
/// - or `match ... { C(x) => ... }`
914
920
pub fn can_be_made_mutable ( & self ) -> bool {
915
921
matches ! (
916
- self . local_info,
917
- Some ( box LocalInfo :: User ( ClearCrossCrate :: Set (
922
+ self . local_info( ) ,
923
+ LocalInfo :: User (
918
924
BindingForm :: Var ( VarBindingForm {
919
925
binding_mode: ty:: BindingMode :: BindByValue ( _) ,
920
926
opt_ty_info: _,
921
927
opt_match_place: _,
922
928
pat_span: _,
923
929
} ) | BindingForm :: ImplicitSelf ( ImplicitSelfKind :: Imm ) ,
924
- ) ) )
930
+ )
925
931
)
926
932
}
927
933
@@ -930,54 +936,51 @@ impl<'tcx> LocalDecl<'tcx> {
930
936
/// mutable bindings, but the inverse does not necessarily hold).
931
937
pub fn is_nonref_binding ( & self ) -> bool {
932
938
matches ! (
933
- self . local_info,
934
- Some ( box LocalInfo :: User ( ClearCrossCrate :: Set (
939
+ self . local_info( ) ,
940
+ LocalInfo :: User (
935
941
BindingForm :: Var ( VarBindingForm {
936
942
binding_mode: ty:: BindingMode :: BindByValue ( _) ,
937
943
opt_ty_info: _,
938
944
opt_match_place: _,
939
945
pat_span: _,
940
946
} ) | BindingForm :: ImplicitSelf ( _) ,
941
- ) ) )
947
+ )
942
948
)
943
949
}
944
950
945
951
/// Returns `true` if this variable is a named variable or function
946
952
/// parameter declared by the user.
947
953
#[ inline]
948
954
pub fn is_user_variable ( & self ) -> bool {
949
- matches ! ( self . local_info, Some ( box LocalInfo :: User ( _) ) )
955
+ matches ! ( self . local_info( ) , LocalInfo :: User ( _) )
950
956
}
951
957
952
958
/// Returns `true` if this is a reference to a variable bound in a `match`
953
959
/// expression that is used to access said variable for the guard of the
954
960
/// match arm.
955
961
pub fn is_ref_for_guard ( & self ) -> bool {
956
- matches ! (
957
- self . local_info,
958
- Some ( box LocalInfo :: User ( ClearCrossCrate :: Set ( BindingForm :: RefForGuard ) ) )
959
- )
962
+ matches ! ( self . local_info( ) , LocalInfo :: User ( BindingForm :: RefForGuard ) )
960
963
}
961
964
962
965
/// Returns `Some` if this is a reference to a static item that is used to
963
966
/// access that static.
964
967
pub fn is_ref_to_static ( & self ) -> bool {
965
- matches ! ( self . local_info, Some ( box LocalInfo :: StaticRef { .. } ) )
968
+ matches ! ( self . local_info( ) , LocalInfo :: StaticRef { .. } )
966
969
}
967
970
968
971
/// Returns `Some` if this is a reference to a thread-local static item that is used to
969
972
/// access that static.
970
973
pub fn is_ref_to_thread_local ( & self ) -> bool {
971
- match self . local_info {
972
- Some ( box LocalInfo :: StaticRef { is_thread_local, .. } ) => is_thread_local,
974
+ match self . local_info ( ) {
975
+ LocalInfo :: StaticRef { is_thread_local, .. } => * is_thread_local,
973
976
_ => false ,
974
977
}
975
978
}
976
979
977
980
/// Returns `true` if this is a DerefTemp
978
981
pub fn is_deref_temp ( & self ) -> bool {
979
- match self . local_info {
980
- Some ( box LocalInfo :: DerefTemp ) => return true ,
982
+ match self . local_info ( ) {
983
+ LocalInfo :: DerefTemp => return true ,
981
984
_ => ( ) ,
982
985
}
983
986
return false ;
@@ -1001,9 +1004,8 @@ impl<'tcx> LocalDecl<'tcx> {
1001
1004
pub fn with_source_info ( ty : Ty < ' tcx > , source_info : SourceInfo ) -> Self {
1002
1005
LocalDecl {
1003
1006
mutability : Mutability :: Mut ,
1004
- local_info : None ,
1007
+ local_info : ClearCrossCrate :: Set ( Box :: new ( LocalInfo :: Boring ) ) ,
1005
1008
internal : false ,
1006
- is_block_tail : None ,
1007
1009
ty,
1008
1010
user_ty : None ,
1009
1011
source_info,
@@ -1023,14 +1025,6 @@ impl<'tcx> LocalDecl<'tcx> {
1023
1025
self . mutability = Mutability :: Not ;
1024
1026
self
1025
1027
}
1026
-
1027
- /// Converts `self` into same `LocalDecl` except tagged as internal temporary.
1028
- #[ inline]
1029
- pub fn block_tail ( mut self , info : BlockTailInfo ) -> Self {
1030
- assert ! ( self . is_block_tail. is_none( ) ) ;
1031
- self . is_block_tail = Some ( info) ;
1032
- self
1033
- }
1034
1028
}
1035
1029
1036
1030
#[ derive( Clone , TyEncodable , TyDecodable , HashStable , TypeFoldable , TypeVisitable ) ]
@@ -3091,7 +3085,7 @@ mod size_asserts {
3091
3085
use rustc_data_structures:: static_assert_size;
3092
3086
// tidy-alphabetical-start
3093
3087
static_assert_size ! ( BasicBlockData <' _>, 144 ) ;
3094
- static_assert_size ! ( LocalDecl <' _>, 56 ) ;
3088
+ static_assert_size ! ( LocalDecl <' _>, 40 ) ;
3095
3089
static_assert_size ! ( Statement <' _>, 32 ) ;
3096
3090
static_assert_size ! ( StatementKind <' _>, 16 ) ;
3097
3091
static_assert_size ! ( Terminator <' _>, 112 ) ;
0 commit comments