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