Allow references to interior mutable data behind a feature gate

This commit is contained in:
oli
2020-12-27 17:33:56 +00:00
parent a609fb45ef
commit 0b841846ba
23 changed files with 171 additions and 41 deletions

View File

@@ -208,9 +208,29 @@ impl NonConstOp for LiveDrop {
}
}
#[derive(Debug)]
pub struct CellBorrowBehindRef;
impl NonConstOp for CellBorrowBehindRef {
fn status_in_item(&self, _: &ConstCx<'_, '_>) -> Status {
Status::Unstable(sym::const_refs_to_cell)
}
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
feature_err(
&ccx.tcx.sess.parse_sess,
sym::const_refs_to_cell,
span,
"cannot borrow here, since the borrowed element may contain interior mutability",
)
}
}
#[derive(Debug)]
pub struct CellBorrow;
impl NonConstOp for CellBorrow {
fn importance(&self) -> DiagnosticImportance {
// The problematic cases will already emit a `CellBorrowBehindRef`
DiagnosticImportance::Secondary
}
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
struct_span_err!(
ccx.tcx.sess,