@@ -209,11 +209,18 @@ impl NonConstOp for LiveDrop {
209209}
210210
211211#[ derive( Debug ) ]
212- pub struct CellBorrowBehindRef ;
213- impl NonConstOp for CellBorrowBehindRef {
212+ /// A borrow of a type that contains an `UnsafeCell` somewhere. The borrow never escapes to
213+ /// the final value of the constant.
214+ pub struct TransientCellBorrow ;
215+ impl NonConstOp for TransientCellBorrow {
214216 fn status_in_item ( & self , _: & ConstCx < ' _ , ' _ > ) -> Status {
215217 Status :: Unstable ( sym:: const_refs_to_cell)
216218 }
219+ fn importance ( & self ) -> DiagnosticImportance {
220+ // The cases that cannot possibly work will already emit a `CellBorrow`, so we should
221+ // not additionally emit a feature gate error if activating the feature gate won't work.
222+ DiagnosticImportance :: Secondary
223+ }
217224 fn build_error ( & self , ccx : & ConstCx < ' _ , ' tcx > , span : Span ) -> DiagnosticBuilder < ' tcx > {
218225 feature_err (
219226 & ccx. tcx . sess . parse_sess ,
@@ -225,19 +232,18 @@ impl NonConstOp for CellBorrowBehindRef {
225232}
226233
227234#[ derive( Debug ) ]
235+ /// A borrow of a type that contains an `UnsafeCell` somewhere. The borrow escapes to
236+ /// the final value of the constant, and thus we cannot allow this (for now). We may allow
237+ /// it in the future for static items.
228238pub struct CellBorrow ;
229239impl NonConstOp for CellBorrow {
230240 fn status_in_item ( & self , ccx : & ConstCx < ' _ , ' _ > ) -> Status {
231241 match ccx. const_kind ( ) {
232- // The borrow checker does a much better job at handling these than we do
233- hir:: ConstContext :: ConstFn => Status :: Allowed ,
242+ // The borrow checker does a much better job at handling these than we do.
243+ hir:: ConstContext :: ConstFn => Status :: Unstable ( sym :: const_refs_to_cell ) ,
234244 _ => Status :: Forbidden ,
235245 }
236246 }
237- fn importance ( & self ) -> DiagnosticImportance {
238- // The problematic cases will already emit a `CellBorrowBehindRef`
239- DiagnosticImportance :: Secondary
240- }
241247 fn build_error ( & self , ccx : & ConstCx < ' _ , ' tcx > , span : Span ) -> DiagnosticBuilder < ' tcx > {
242248 struct_span_err ! (
243249 ccx. tcx. sess,
0 commit comments