mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
Sanity check for move from an uninit variable whose address is taken
This commit is contained in:
parent
ece0e6ae6d
commit
22d937ddfc
12
src/test/ui/moves/move-of-addr-of-mut.rs
Normal file
12
src/test/ui/moves/move-of-addr-of-mut.rs
Normal file
@ -0,0 +1,12 @@
|
||||
// Ensure that taking a mutable raw ptr to an uninitialized variable does not change its
|
||||
// initializedness.
|
||||
|
||||
struct S;
|
||||
|
||||
fn main() {
|
||||
let mut x: S;
|
||||
std::ptr::addr_of_mut!(x); //~ borrow of
|
||||
|
||||
let y = x; // Should error here if `addr_of_mut` is ever allowed on uninitialized variables
|
||||
drop(y);
|
||||
}
|
11
src/test/ui/moves/move-of-addr-of-mut.stderr
Normal file
11
src/test/ui/moves/move-of-addr-of-mut.stderr
Normal file
@ -0,0 +1,11 @@
|
||||
error[E0381]: borrow of possibly-uninitialized variable: `x`
|
||||
--> $DIR/move-of-addr-of-mut.rs:8:5
|
||||
|
|
||||
LL | std::ptr::addr_of_mut!(x);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ use of possibly-uninitialized `x`
|
||||
|
|
||||
= note: this error originates in the macro `std::ptr::addr_of_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0381`.
|
Loading…
Reference in New Issue
Block a user