Allow moving out of `&'static mut T`
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Hello, it is perfectly sound to move out of &'static mut T and have that reference consumed, as no safe code can access T under the reference after that point.
struct NotDefaultNotCopy([u8; 20]);
fn main() {
let foo: &'static mut NotDefaultNotCopy = Box::leak(Box::new(NotDefaultNotCopy([0; 20])));
let foo_taken = *foo;
println!("{:?}", foo_taken.0);
}
For example, miri is happy with that code if take in unsafely written (but detects leak) playground
Here is code with more unsafe but with no miri leak warnings: playground
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue provides Rust reproductions and Rust Playground links demonstrating the proposed move from &'static mut T. Start by investigating the compiler's handling of moves out of mutable references and determine what focused compiler tests are needed; done means the demonstrated non-Copy move is accepted with sound behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100