@@ -1156,82 +1156,87 @@ impl<'a, 'tcx> Visitor<'tcx> for Checker<'a, 'tcx> {
1156
1156
}
1157
1157
}
1158
1158
1159
- fn visit_projection (
1159
+ fn visit_projection_elem (
1160
1160
& mut self ,
1161
1161
place_base : & PlaceBase < ' tcx > ,
1162
- proj : & [ PlaceElem < ' tcx > ] ,
1162
+ proj_base : & [ PlaceElem < ' tcx > ] ,
1163
+ elem : & PlaceElem < ' tcx > ,
1163
1164
context : PlaceContext ,
1164
1165
location : Location ,
1165
1166
) {
1166
1167
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,
1169
1175
) ;
1170
- self . super_projection ( place_base, proj, context, location) ;
1171
1176
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
+ ) ;
1196
1201
}
1197
1202
}
1198
1203
}
1199
1204
}
1205
+ }
1200
1206
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
+ } ,
1221
1227
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
+ => { } ,
1228
1233
}
1229
1234
}
1230
1235
}
1236
+ }
1231
1237
1232
- ProjectionElem :: Downcast ( ..) => {
1233
- self . not_const ( ops:: Downcast )
1234
- }
1238
+ ProjectionElem :: Downcast ( ..) => {
1239
+ self . not_const ( ops:: Downcast )
1235
1240
}
1236
1241
}
1237
1242
}
0 commit comments