-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
Code
static DANGLING: &mut () = unsafe { &mut *(1 as *mut ()) };
const WUT: &mut () = DANGLING;
Current output
error[E0596]: cannot borrow `*DANGLING` as mutable, as `DANGLING` is an immutable static item
--> src/lib.rs:2:22
|
2 | const WUT: &mut () = DANGLING;
| ^^^^^^^^ cannot borrow as mutable
For more information about this error, try `rustc --explain E0596`.
error: could not compile `playground` (lib) due to 1 previous error
Desired output
Mention the fact that &mut T doesn't implement Copy.
Rationale and extra context
Found while investigating #140123
Other cases
Rust Version
Reproducible on the playground with version 1.89.0-nightly (2025-06-11 e703dff8fe220b78195c)
Anything else?
No response
estebank
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
[-]Assigning a `&mut` from a `static` to a `const` gives confusing error[/-][+]Trying to move a `&mut` out of a `static` gives confusing error[/+]theemathas commentedon Jun 20, 2025
A similar error occurs when moving out of a
static
into a variable with a type annotation: