Fix cell checks in const fn

This commit is contained in:
oli 2020-12-28 01:09:55 +00:00
parent 3a44a20ed1
commit 354e510f7d
2 changed files with 9 additions and 0 deletions

View File

@ -227,6 +227,13 @@ impl NonConstOp for CellBorrowBehindRef {
#[derive(Debug)] #[derive(Debug)]
pub struct CellBorrow; pub struct CellBorrow;
impl NonConstOp for CellBorrow { impl NonConstOp for CellBorrow {
fn status_in_item(&self, ccx: &ConstCx<'_, '_>) -> Status {
match ccx.const_kind() {
// The borrow checker does a much better job at handling these than we do
hir::ConstContext::ConstFn => Status::Allowed,
_ => Status::Forbidden,
}
}
fn importance(&self) -> DiagnosticImportance { fn importance(&self) -> DiagnosticImportance {
// The problematic cases will already emit a `CellBorrowBehindRef` // The problematic cases will already emit a `CellBorrowBehindRef`
DiagnosticImportance::Secondary DiagnosticImportance::Secondary

View File

@ -36,4 +36,6 @@ unsafe impl<T> Sync for Wrap<T> {}
static BAR_PTR: Wrap<*mut u32> = Wrap(BAR.0.get()); static BAR_PTR: Wrap<*mut u32> = Wrap(BAR.0.get());
const fn fst_ref<T, U>(x: &(T, U)) -> &T { &x.0 }
fn main() {} fn main() {}