Closed
Description
openedon Jan 5, 2019
The const_mut_refs
feature gate allows the following in const context:
&mut
arguments- mutable (re)borrows and raw pointers (
&mut
andaddr_of_mut!
expressions) - dereferencing mutable references and raw pointers (
*
expressions)
Remaining work
- Anonymous allocations in statics get duplicated for multiple codegen units #79738
static mut FOO: &'static mut i32 = &mut 42;
is problematic, because LLVM currently duplicates the inner mutable reference when you dostatic mut BAR: &'static mut i32 = FOO;
. It would probably suffice to give all nested allocations in a static names relative to their original static item. Named allocations are neither deduplicated nor duplicated. - Currently the interning of the final result of the
const
relies on types more than it should, given thattransmute
is available in consts. Fixed in const-eval interning: get rid of type-driven traversal #119044. - Mutable reference protected by a mutex in static context is considered UB #120450
- Figure out what to do with regression: encountered mutable pointer in final value when "outer scope" rule applies in const/static with interior mutability #121610: that's happening in const-eval interning: accept interior mutable pointers in final value #128543
- Adjust documentation: const_eval: update for const_mut_refs and const_refs_to_cell stabilization reference#1590
- Stabilization PR: Stabilize
&mut
(and*mut
) as well as&Cell
(and*const Cell
) in const #129195
Open questions
- can we stabilize this without figuring out the const heap story? -> yes, no reason this has to wait for const_heap
- can we stabilize this without cranelift and codegen_gcc support? ICE: hir:
index out of bounds: the len is 5 but the index is 5
#122399, ICE: hir: index out of bounds: the len is 5 but the index is 5 rustc_codegen_gcc#473
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Metadata
Assignees
Labels
Area: Constant evaluation (MIR interpretation)Area: const fn foo(..) {..}. Pure functions which can be applied at compile time.Blocker: Implemented in the nightly compiler and unstable.Category: A tracking issue for an RFC or an unstable feature.`#![feature(const_mut_refs)]`Relevant to the language team, which will review and decide on the PR/issue.