@@ -930,58 +930,60 @@ impl<'a, 'tcx> Visitor<'tcx> for Checker<'a, 'tcx> {
930
930
context : PlaceContext ,
931
931
location : Location ) {
932
932
debug ! ( "visit_place: place={:?} context={:?} location={:?}" , place, context, location) ;
933
- self . super_place ( place, context, location) ;
934
- match * place {
935
- Place :: Base ( PlaceBase :: Local ( _) ) => { }
936
- Place :: Base ( PlaceBase :: Static ( box Static { kind : StaticKind :: Promoted ( _) , .. } ) ) => {
937
- unreachable ! ( )
938
- }
939
- Place :: Base ( PlaceBase :: Static ( box Static { kind : StaticKind :: Static ( def_id) , .. } ) ) => {
940
- if self . tcx
941
- . get_attrs ( def_id)
942
- . iter ( )
943
- . any ( |attr| attr. check_name ( sym:: thread_local) ) {
944
- if self . mode != Mode :: Fn {
945
- span_err ! ( self . tcx. sess, self . span, E0625 ,
946
- "thread-local statics cannot be \
947
- accessed at compile-time") ;
948
- }
949
- return ;
933
+ place. iterate ( |place_base, place_projections| {
934
+ match place_base {
935
+ PlaceBase :: Local ( _) => { }
936
+ PlaceBase :: Static ( box Static { kind : StaticKind :: Promoted ( _) , .. } ) => {
937
+ unreachable ! ( )
950
938
}
939
+ PlaceBase :: Static ( box Static { kind : StaticKind :: Static ( def_id) , .. } ) => {
940
+ if self . tcx
941
+ . get_attrs ( * def_id)
942
+ . iter ( )
943
+ . any ( |attr| attr. check_name ( sym:: thread_local) ) {
944
+ if self . mode != Mode :: Fn {
945
+ span_err ! ( self . tcx. sess, self . span, E0625 ,
946
+ "thread-local statics cannot be \
947
+ accessed at compile-time") ;
948
+ }
949
+ return ;
950
+ }
951
951
952
- // Only allow statics (not consts) to refer to other statics.
953
- if self . mode == Mode :: Static || self . mode == Mode :: StaticMut {
954
- if self . mode == Mode :: Static && context. is_mutating_use ( ) {
955
- // this is not strictly necessary as miri will also bail out
956
- // For interior mutability we can't really catch this statically as that
957
- // goes through raw pointers and intermediate temporaries, so miri has
958
- // to catch this anyway
959
- self . tcx . sess . span_err (
960
- self . span ,
961
- "cannot mutate statics in the initializer of another static" ,
962
- ) ;
952
+ // Only allow statics (not consts) to refer to other statics.
953
+ if self . mode == Mode :: Static || self . mode == Mode :: StaticMut {
954
+ if self . mode == Mode :: Static && context. is_mutating_use ( ) {
955
+ // this is not strictly necessary as miri will also bail out
956
+ // For interior mutability we can't really catch this statically as that
957
+ // goes through raw pointers and intermediate temporaries, so miri has
958
+ // to catch this anyway
959
+ self . tcx . sess . span_err (
960
+ self . span ,
961
+ "cannot mutate statics in the initializer of another static" ,
962
+ ) ;
963
+ }
964
+ return ;
963
965
}
964
- return ;
965
- }
966
- unleash_miri ! ( self ) ;
966
+ unleash_miri ! ( self ) ;
967
967
968
- if self . mode != Mode :: Fn {
969
- let mut err = struct_span_err ! ( self . tcx. sess, self . span, E0013 ,
970
- "{}s cannot refer to statics, use \
971
- a constant instead", self . mode) ;
972
- if self . tcx . sess . teach ( & err. get_code ( ) . unwrap ( ) ) {
973
- err. note (
974
- "Static and const variables can refer to other const variables. But a \
975
- const variable cannot refer to a static variable."
976
- ) ;
977
- err. help (
978
- "To fix this, the value can be extracted as a const and then used."
979
- ) ;
968
+ if self . mode != Mode :: Fn {
969
+ let mut err = struct_span_err ! ( self . tcx. sess, self . span, E0013 ,
970
+ "{}s cannot refer to statics, use \
971
+ a constant instead", self . mode) ;
972
+ if self . tcx . sess . teach ( & err. get_code ( ) . unwrap ( ) ) {
973
+ err. note (
974
+ "Static and const variables can refer to other const variables. \
975
+ But a const variable cannot refer to a static variable."
976
+ ) ;
977
+ err. help (
978
+ "To fix this, the value can be extracted as a const and then used."
979
+ ) ;
980
+ }
981
+ err. emit ( )
980
982
}
981
- err. emit ( )
982
983
}
983
984
}
984
- Place :: Projection ( ref proj) => {
985
+
986
+ for proj in place_projections {
985
987
match proj. elem {
986
988
ProjectionElem :: Deref => {
987
989
if context. is_mutating_use ( ) {
@@ -1041,7 +1043,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Checker<'a, 'tcx> {
1041
1043
}
1042
1044
}
1043
1045
}
1044
- }
1046
+ } ) ;
1045
1047
}
1046
1048
1047
1049
fn visit_operand ( & mut self , operand : & Operand < ' tcx > , location : Location ) {
0 commit comments