Another form of the same issue AFAICT: #86510
On latest nightly, black_box(&x) prevents codegenning a constant return value, but it shouldn't.
This is possibly because of over pessimism about interior mutability, but we should be able to tell whether a type is interior mutable or not.
Godbolt
#![feature(bench_black_box)]
use std::hint::black_box;
pub fn foo() -> i32 {
let x = 1;
black_box(&x);
x
}
The return instruction moves from a location on the stack:
mov eax, dword ptr [rsp + 4]
Whereas for this:
#![feature(bench_black_box)]
use std::hint::black_box;
pub fn foo() -> i32 {
let x = 1;
let y = x;
black_box(&y);
x
}
It optimizes correctly.
Another form of the same issue AFAICT: #86510
On latest nightly,
black_box(&x)prevents codegenning a constant return value, but it shouldn't.This is possibly because of over pessimism about interior mutability, but we should be able to tell whether a type is interior mutable or not.
Godbolt
The return instruction moves from a location on the stack:
Whereas for this:
It optimizes correctly.