@@ -235,7 +235,8 @@ impl NonConstOp for CellBorrow {
235235}
236236
237237#[ derive( Debug ) ]
238- pub struct MutBorrow ;
238+ pub struct MutBorrow ( pub hir:: BorrowKind ) ;
239+
239240impl NonConstOp for MutBorrow {
240241 fn status_in_item ( & self , ccx : & ConstCx < ' _ , ' _ > ) -> Status {
241242 // Forbid everywhere except in const fn with a feature gate
@@ -247,22 +248,28 @@ impl NonConstOp for MutBorrow {
247248 }
248249
249250 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+
250256 let mut err = if ccx. const_kind ( ) == hir:: ConstContext :: ConstFn {
251257 feature_err (
252258 & ccx. tcx . sess . parse_sess ,
253259 sym:: const_mut_refs,
254260 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( ) ) ,
256262 )
257263 } else {
258264 let mut err = struct_span_err ! (
259265 ccx. tcx. sess,
260266 span,
261267 E0764 ,
262- "mutable references are not allowed in {}s" ,
268+ "{}mutable references are not allowed in {}s" ,
269+ raw,
263270 ccx. const_kind( ) ,
264271 ) ;
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 ) ) ;
266273 err
267274 } ;
268275 if ccx. tcx . sess . teach ( & err. get_code ( ) . unwrap ( ) ) {
@@ -281,29 +288,6 @@ impl NonConstOp for MutBorrow {
281288 }
282289}
283290
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-
307291#[ derive( Debug ) ]
308292pub struct MutDeref ;
309293impl NonConstOp for MutDeref {
0 commit comments