Saltar al contenido ForoHackers

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

CompiladoresRustPruebas
#16813 · · Citar · Denunciar

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 · · Citar · Denunciar

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

#17161 · · Citar · Denunciar

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 · · Citar · Denunciar

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

#17166 · · Citar · Denunciar

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 · · Citar · Denunciar

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 · · Citar · Denunciar

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.

No has iniciado sesión, así que esto se publica como anónimo: no se guarda con ello ninguna cuenta, nombre ni dirección, y no puede llevar enlaces ni imágenes. Inicia sesión o únete para publicar con tu nombre. Los registros de nuestro servidor web guardan la dirección y la hora de cada petición hasta 14 días; para que la tuya no quede en ellos, usa Tor. Para escribir al equipo de forma confidencial, usa el buzón. Firmar como fuente habitual (una clave guardada solo en este navegador)

Enviar tarda unos segundos aquí: tu navegador resuelve antes una prueba de trabajo contra el spam.

Responder