@@ -224,7 +224,8 @@ impl NonConstOp for CellBorrow {
224
224
}
225
225
226
226
#[ derive( Debug ) ]
227
- pub struct MutBorrow ;
227
+ pub struct MutBorrow ( pub hir:: BorrowKind ) ;
228
+
228
229
impl NonConstOp for MutBorrow {
229
230
fn status_in_item ( & self , ccx : & ConstCx < ' _ , ' _ > ) -> Status {
230
231
// Forbid everywhere except in const fn with a feature gate
@@ -236,22 +237,28 @@ impl NonConstOp for MutBorrow {
236
237
}
237
238
238
239
fn build_error ( & self , ccx : & ConstCx < ' _ , ' tcx > , span : Span ) -> DiagnosticBuilder < ' tcx > {
240
+ let raw = match self . 0 {
241
+ hir:: BorrowKind :: Raw => "raw " ,
242
+ hir:: BorrowKind :: Ref => "" ,
243
+ } ;
244
+
239
245
let mut err = if ccx. const_kind ( ) == hir:: ConstContext :: ConstFn {
240
246
feature_err (
241
247
& ccx. tcx . sess . parse_sess ,
242
248
sym:: const_mut_refs,
243
249
span,
244
- & format ! ( "mutable references are not allowed in {}s" , ccx. const_kind( ) ) ,
250
+ & format ! ( "{} mutable references are not allowed in {}s" , raw , ccx. const_kind( ) ) ,
245
251
)
246
252
} else {
247
253
let mut err = struct_span_err ! (
248
254
ccx. tcx. sess,
249
255
span,
250
256
E0764 ,
251
- "mutable references are not allowed in {}s" ,
257
+ "{}mutable references are not allowed in {}s" ,
258
+ raw,
252
259
ccx. const_kind( ) ,
253
260
) ;
254
- err. span_label ( span, format ! ( "`&mut` is only allowed in `const fn`" ) ) ;
261
+ err. span_label ( span, format ! ( "`&{} mut` is only allowed in `const fn`" , raw ) ) ;
255
262
err
256
263
} ;
257
264
if ccx. tcx . sess . teach ( & err. get_code ( ) . unwrap ( ) ) {
@@ -270,29 +277,6 @@ impl NonConstOp for MutBorrow {
270
277
}
271
278
}
272
279
273
- // FIXME(ecstaticmorse): Unify this with `MutBorrow`. It has basically the same issues.
274
- #[ derive( Debug ) ]
275
- pub struct MutAddressOf ;
276
- impl NonConstOp for MutAddressOf {
277
- fn status_in_item ( & self , ccx : & ConstCx < ' _ , ' _ > ) -> Status {
278
- // Forbid everywhere except in const fn with a feature gate
279
- if ccx. const_kind ( ) == hir:: ConstContext :: ConstFn {
280
- Status :: Unstable ( sym:: const_mut_refs)
281
- } else {
282
- Status :: Forbidden
283
- }
284
- }
285
-
286
- fn build_error ( & self , ccx : & ConstCx < ' _ , ' tcx > , span : Span ) -> DiagnosticBuilder < ' tcx > {
287
- feature_err (
288
- & ccx. tcx . sess . parse_sess ,
289
- sym:: const_mut_refs,
290
- span,
291
- & format ! ( "`&raw mut` is not allowed in {}s" , ccx. const_kind( ) ) ,
292
- )
293
- }
294
- }
295
-
296
280
#[ derive( Debug ) ]
297
281
pub struct MutDeref ;
298
282
impl NonConstOp for MutDeref {
0 commit comments