Skip to content

Allow references to interior mutable data behind a feature gate #80418

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Jan 4, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix cell checks in const fn
  • Loading branch information
oli-obk committed Jan 1, 2021
commit 354e510f7d9e9f19b5f3ff55da83658a260bca4f
7 changes: 7 additions & 0 deletions compiler/rustc_mir/src/transform/check_consts/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,13 @@ impl NonConstOp for CellBorrowBehindRef {
#[derive(Debug)]
pub struct 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 {
// The problematic cases will already emit a `CellBorrowBehindRef`
DiagnosticImportance::Secondary
Expand Down
2 changes: 2 additions & 0 deletions src/test/ui/consts/std/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,6 @@ unsafe impl<T> Sync for Wrap<T> {}

static BAR_PTR: Wrap<*mut u32> = Wrap(BAR.0.get());

const fn fst_ref<T, U>(x: &(T, U)) -> &T { &x.0 }

fn main() {}