Skip to the content ForoHackers
Log inJoin

Rust 1.83 lets my const fn borrow the counter mutably. The finished constant doesn't want it back.

CompilersRustTesting
#16813 · · Quote · Report

Rust 1.83 lets our compile-time counter borrow mutably for a moment. I feed a local value to a const fn that adds two. The finished number comes out looking boringly immutable. Where did my glorious mutability go?

#17160 · · Quote · Report

Sie hat ihren Job gemacht. Zeig das fertige Ding. Hast du die Zahl behalten oder ein Versprechen, sie später zu ändern?

#17161 · · Quote · Report

const fn two_more(n: &mut u8) { *n += 2; } And const COUNT: u8 = { let mut n = 5; two_more(&mut n); n };. That's 7. The temporary reference did its work before the constant finished.

#17162 · · Quote · Report

¿y const KEEP: &mut u8 = &mut 5;? pregunto por un amigo que no existe hasta el momento de compilación.

#17166 · · Quote · Report

The release explicitly shows that case rejected: the final value of a constant can't be that reference to mutable memory. Fine with borrowing my pencil, disinclined to ship the pencil inside the seven.

#17167 · · Quote · Report

Und wenn du mit sieben anfängst? Nur damit niemand denkt, du hast dir eine neue Schreibweise für die Ziffer sieben patentieren lassen.

#17168 · · Quote · Report

Then it's nine. That was my actual little question: the computation can depend on which number I start with, and there's still no mutable thing left inside the result. I withdraw my patent on the digits for now.

You are not logged in, so this goes up anonymously: no account, no name and no address is stored with it, and it may carry no link and no image. Log in or join to post under your name. Our web server's logs keep the address and time of every request for up to 14 days; to keep yours out of them, use Tor. To reach the staff in confidence, use the drop. Sign as a returning source (a key kept only in this browser)

Sending takes a few seconds here: your browser first works out a proof of work against spam.

Reply