@@ -1156,82 +1156,87 @@ impl<'a, 'tcx> Visitor<'tcx> for Checker<'a, 'tcx> {
11561156 }
11571157 }
11581158
1159- fn visit_projection (
1159+ fn visit_projection_elem (
11601160 & mut self ,
11611161 place_base : & PlaceBase < ' tcx > ,
1162- proj : & [ PlaceElem < ' tcx > ] ,
1162+ proj_base : & [ PlaceElem < ' tcx > ] ,
1163+ elem : & PlaceElem < ' tcx > ,
11631164 context : PlaceContext ,
11641165 location : Location ,
11651166 ) {
11661167 debug ! (
1167- "visit_place_projection: proj={:?} context={:?} location={:?}" ,
1168- proj, context, location,
1168+ "visit_projection_elem: place_base={:?} proj_base={:?} elem={:?} \
1169+ context={:?} location={:?}",
1170+ place_base,
1171+ proj_base,
1172+ elem,
1173+ context,
1174+ location,
11691175 ) ;
1170- self . super_projection ( place_base, proj, context, location) ;
11711176
1172- if let [ proj_base @ .. , elem] = proj {
1173- match elem {
1174- ProjectionElem :: Deref => {
1175- if context . is_mutating_use ( ) {
1176- // `not_const` errors out in const contexts
1177- self . not_const ( ops :: MutDeref )
1178- }
1179- let base_ty = Place :: ty_from ( place_base , proj_base , self . body , self . tcx ) . ty ;
1180- match self . mode {
1181- Mode :: NonConstFn => { }
1182- _ if self . suppress_errors => { }
1183- _ => {
1184- if let ty :: RawPtr ( _ ) = base_ty . kind {
1185- if ! self . tcx . features ( ) . const_raw_ptr_deref {
1186- self . record_error ( ops :: RawPtrDeref ) ;
1187- emit_feature_err (
1188- & self . tcx . sess . parse_sess , sym :: const_raw_ptr_deref ,
1189- self . span , GateIssue :: Language ,
1190- & format ! (
1191- "dereferencing raw pointers in {}s is unstable" ,
1192- self . mode ,
1193- ) ,
1194- ) ;
1195- }
1177+ self . super_projection_elem ( place_base , proj_base, elem, context , location ) ;
1178+
1179+ match elem {
1180+ ProjectionElem :: Deref => {
1181+ if context . is_mutating_use ( ) {
1182+ // `not_const` errors out in const contexts
1183+ self . not_const ( ops :: MutDeref )
1184+ }
1185+ let base_ty = Place :: ty_from ( place_base , proj_base , self . body , self . tcx ) . ty ;
1186+ match self . mode {
1187+ Mode :: NonConstFn => { }
1188+ _ if self . suppress_errors => { }
1189+ _ => {
1190+ if let ty :: RawPtr ( _ ) = base_ty . kind {
1191+ if ! self . tcx . features ( ) . const_raw_ptr_deref {
1192+ self . record_error ( ops :: RawPtrDeref ) ;
1193+ emit_feature_err (
1194+ & self . tcx . sess . parse_sess , sym :: const_raw_ptr_deref ,
1195+ self . span , GateIssue :: Language ,
1196+ & format ! (
1197+ "dereferencing raw pointers in {}s is unstable" ,
1198+ self . mode ,
1199+ ) ,
1200+ ) ;
11961201 }
11971202 }
11981203 }
11991204 }
1205+ }
12001206
1201- ProjectionElem :: ConstantIndex { ..} |
1202- ProjectionElem :: Subslice { ..} |
1203- ProjectionElem :: Field ( ..) |
1204- ProjectionElem :: Index ( _) => {
1205- let base_ty = Place :: ty_from ( place_base, proj_base, self . body , self . tcx ) . ty ;
1206- if let Some ( def) = base_ty. ty_adt_def ( ) {
1207- if def. is_union ( ) {
1208- match self . mode {
1209- Mode :: ConstFn => {
1210- if !self . tcx . features ( ) . const_fn_union
1211- && !self . suppress_errors
1212- {
1213- self . record_error ( ops:: UnionAccess ) ;
1214- emit_feature_err (
1215- & self . tcx . sess . parse_sess , sym:: const_fn_union,
1216- self . span , GateIssue :: Language ,
1217- "unions in const fn are unstable" ,
1218- ) ;
1219- }
1220- } ,
1207+ ProjectionElem :: ConstantIndex { ..} |
1208+ ProjectionElem :: Subslice { ..} |
1209+ ProjectionElem :: Field ( ..) |
1210+ ProjectionElem :: Index ( _) => {
1211+ let base_ty = Place :: ty_from ( place_base, proj_base, self . body , self . tcx ) . ty ;
1212+ if let Some ( def) = base_ty. ty_adt_def ( ) {
1213+ if def. is_union ( ) {
1214+ match self . mode {
1215+ Mode :: ConstFn => {
1216+ if !self . tcx . features ( ) . const_fn_union
1217+ && !self . suppress_errors
1218+ {
1219+ self . record_error ( ops:: UnionAccess ) ;
1220+ emit_feature_err (
1221+ & self . tcx . sess . parse_sess , sym:: const_fn_union,
1222+ self . span , GateIssue :: Language ,
1223+ "unions in const fn are unstable" ,
1224+ ) ;
1225+ }
1226+ } ,
12211227
1222- | Mode :: NonConstFn
1223- | Mode :: Static
1224- | Mode :: StaticMut
1225- | Mode :: Const
1226- => { } ,
1227- }
1228+ | Mode :: NonConstFn
1229+ | Mode :: Static
1230+ | Mode :: StaticMut
1231+ | Mode :: Const
1232+ => { } ,
12281233 }
12291234 }
12301235 }
1236+ }
12311237
1232- ProjectionElem :: Downcast ( ..) => {
1233- self . not_const ( ops:: Downcast )
1234- }
1238+ ProjectionElem :: Downcast ( ..) => {
1239+ self . not_const ( ops:: Downcast )
12351240 }
12361241 }
12371242 }
0 commit comments