Repository navigation
Tracking issue for &mut T in const contexts (const_mut_refs) #57349
Copy link
Copy link
Closed
rust-lang/reference
#1590Closed
Copy link
Labels
A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)B-unstableBlocker: Implemented in the nightly compiler and unstable.Blocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCF-const_mut_refs`#![feature(const_mut_refs)]``#![feature(const_mut_refs)]`T-langRelevant to the language teamRelevant to the language team
Description
The const_mut_refs feature gate allows the following in const context:
&mutarguments- mutable (re)borrows and raw pointers (
&mutandaddr_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
constrelies on types more than it should, given thattransmuteis 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
Reacted by Elichai Turkel, Lokathor, Stanislav Tkach, Donough Liu, Shane F. Carr, José Luis Cruz, jon-chuang, rodrimati1992, Leandro Aguiar, phlopsi and 39 more
Reacted by Mazdak Farrokhzad, Marco Quinten, Etherian, Elichai Turkel, Eric Shimizu Karbstein, Shane F. Carr, Sympatron GmbH, 为世人降下祝福, rodrimati1992, Sayan and 18 more
Reacted by Jérémy Audiger
Reacted by Ryo Onodera, ben, Ricardo Fernández Serrata and Johanna Sörngård
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, ...)B-unstableBlocker: Implemented in the nightly compiler and unstable.Blocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCF-const_mut_refs`#![feature(const_mut_refs)]``#![feature(const_mut_refs)]`T-langRelevant to the language teamRelevant to the language team
Activity
[-]Mutation in const fn[/-][+]Tracking issue for `&mut T` in const fn[/+]Centril commentedon Jan 5, 2019
alercah commentedon Jan 9, 2019
eddyb commentedon Feb 13, 2019
Make ilog64 const
elichai commentedon Sep 5, 2019
tema3210 commentedon Sep 29, 2019
cramertj commentedon Mar 11, 2020
125 remaining items
bjoernager commentedon Sep 19, 2024
There's also
char::encode_utf8: #130512RalfJung commentedon Sep 19, 2024
This has just been implemented. Let's maybe let it bake on nightly for a bit?
onestacked commentedon Sep 19, 2024
#67456 needs an FCP started for Stabilization PR #130403
Auto merge of rust-lang#130697 - bjoernager:const-char-make-ascii, r=…
Auto merge of #130697 - bjoernager:const-char-make-ascii, r=dtolnay
Auto merge of #130697 - bjoernager:const-char-make-ascii, r=dtolnay
Rollup merge of rust-lang#130403 - eduardosm:stabilize-const_slice_fr…
Rollup merge of rust-lang#130403 - eduardosm:stabilize-const_slice_fr…
Auto merge of rust-lang#130403 - eduardosm:stabilize-const_slice_from…
Rollup merge of rust-lang#130403 - eduardosm:stabilize-const_slice_fr…
Unrolled build for rust-lang#130403
Rudxain commentedon Oct 29, 2024
Is there a discussion thread for this? I've searched multiple RFCs, but I can't find a single one mentioning iterators. If I'm not mistaken, this feature is a big step forward to support
constiteration. We already haveconstloops, so I can feelcore::iteris soon becomingconsttoo!Lokathor commentedon Oct 29, 2024
requiring const trait impls means that normal iterators are most likely rather far out.
RalfJung commentedon Oct 29, 2024
Iterators are still blocked on being able to call trait functions in const, which is unfortunately quite tricky. See:
impl const Trait for Tyand[const](conditionally const) syntax (const_trait_impl) #67792for-loops in constants #87575Also, closed issue are not a support forum, so I'll lock this -- too many people get notifications in this one to make it a good place for support questions.