A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/rust-lang/rust/issues/71212 below:

Static checks for `&mut` in final value of constant with `#![feature(const_mut_refs)]` · Issue #71212 · rust-lang/rust · GitHub

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.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4