You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Cannot borrow from generic Copy types in a const context #120119
A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)C-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language team
I expected the Copy bounds to be sufficient to allow this to compile. Copy is an imperfect analog for a lack of interior mutability, much like it is an imperfect analog for !Drop.
Instead, this happened:
error[E0492]: constants cannot refer to interior mutable data
--> src/lib.rs:10:32
|
10 | const VAL: &'static Self = &FooGen(T::S);
| ^^^^^^^^^^^^^ this borrow of an interior mutable value may end up in the final value
error[E0492]: constants cannot refer to interior mutable data
--> src/lib.rs:21:32
|
21 | const VAL: &'static Self = &FooAssoc(T::VAL);
| ^^^^^^^^^^^^^^^^^ this borrow of an interior mutable value may end up in the final value
Ideally, stable code would be able to bound on a lack of interior mutability (like a NoCell/Freeze trait) to allow this sort of generic code to work without needing const_refs_to_cell stabilized, as it's a useful property to be able to bound on for unsafe code.
Copy is an imperfect analog for a lack of interior mutability
It is not, and anyone relying on this is risking breakage in future versions of Rust. It is quite probable that we will eventually allow people to do something like unsafe impl Copy for, at which point one can easily have Freeze + Copy types.
A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)C-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language team
Activity
fmease commentedon Mar 1, 2024
cc #121675, #121840
oli-obk commentedon Mar 1, 2024
Duplicate of #60715
std::marker::Freezepub again #60715RalfJung commentedon Jun 17, 2024
It is not, and anyone relying on this is risking breakage in future versions of Rust. It is quite probable that we will eventually allow people to do something like
unsafe impl Copy for, at which point one can easily haveFreeze + Copytypes.