@@ -224,7 +224,8 @@ impl NonConstOp for CellBorrow {
224224}
225225
226226#[ derive( Debug ) ]
227- pub struct MutBorrow ;
227+ pub struct MutBorrow ( pub hir:: BorrowKind ) ;
228+
228229impl NonConstOp for MutBorrow {
229230 fn status_in_item ( & self , ccx : & ConstCx < ' _ , ' _ > ) -> Status {
230231 // Forbid everywhere except in const fn with a feature gate
@@ -236,22 +237,28 @@ impl NonConstOp for MutBorrow {
236237 }
237238
238239 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+
239245 let mut err = if ccx. const_kind ( ) == hir:: ConstContext :: ConstFn {
240246 feature_err (
241247 & ccx. tcx . sess . parse_sess ,
242248 sym:: const_mut_refs,
243249 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( ) ) ,
245251 )
246252 } else {
247253 let mut err = struct_span_err ! (
248254 ccx. tcx. sess,
249255 span,
250256 E0764 ,
251- "mutable references are not allowed in {}s" ,
257+ "{}mutable references are not allowed in {}s" ,
258+ raw,
252259 ccx. const_kind( ) ,
253260 ) ;
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 ) ) ;
255262 err
256263 } ;
257264 if ccx. tcx . sess . teach ( & err. get_code ( ) . unwrap ( ) ) {
@@ -270,29 +277,6 @@ impl NonConstOp for MutBorrow {
270277 }
271278}
272279
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-
296280#[ derive( Debug ) ]
297281pub struct MutDeref ;
298282impl NonConstOp for MutDeref {
0 commit comments