-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)C-bugCategory: This is a bug.Category: This is a bug.F-const_mut_refs`#![feature(const_mut_refs)]``#![feature(const_mut_refs)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.glacierICE tracked in rust-lang/glacier.ICE tracked in rust-lang/glacier.requires-nightlyThis issue requires a nightly compiler in some way.This issue requires a nightly compiler in some way.
Description
On stable, we prevent users from creating an &mut
that points to memory inside a const
by forbidding the creation of mutable references during const-eval. This limitation is only temporary, see #57349. We have a feature flag, const_mut_refs
, that allows users to create mutable references, but no attempt is made to prevent &mut
from escaping into the final value of a const
like so:
#![feature(const_mut_refs)]
const FOO: &mut i32 = &mut 4;
fn main() {
*FOO = 2;
}
This errors on the current nightly, and if there were a feature gate that allowed it, we would get an ICE:
error: internal compiler error: src/librustc_mir/interpret/intern.rs:238: const qualif failed to prevent mutable references
I think we've not yet settled on the semantics we want. We're allowing them in const fn
and relying on the borrow checker to prevent references from escaping.
Metadata
Metadata
Assignees
Labels
A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)C-bugCategory: This is a bug.Category: This is a bug.F-const_mut_refs`#![feature(const_mut_refs)]``#![feature(const_mut_refs)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.glacierICE tracked in rust-lang/glacier.ICE tracked in rust-lang/glacier.requires-nightlyThis issue requires a nightly compiler in some way.This issue requires a nightly compiler in some way.