diff options
| author | Dylan MacKenzie <ecstaticmorse@gmail.com> | 2021-11-11 14:55:58 -0800 |
|---|---|---|
| committer | Dylan MacKenzie <ecstaticmorse@gmail.com> | 2021-11-13 11:30:52 -0800 |
| commit | 22d937ddfc64bdf1f8724a27a782f2da2ae72be0 (patch) | |
| tree | a86d25c5c343a58fc450413613c225c1055fb9e0 | |
| parent | ece0e6ae6d29aa8c8b1fea06986840a4609f43b8 (diff) | |
| download | rust-22d937ddfc64bdf1f8724a27a782f2da2ae72be0.tar.gz rust-22d937ddfc64bdf1f8724a27a782f2da2ae72be0.zip | |
Sanity check for move from an uninit variable whose address is taken
| -rw-r--r-- | src/test/ui/moves/move-of-addr-of-mut.rs | 12 | ||||
| -rw-r--r-- | src/test/ui/moves/move-of-addr-of-mut.stderr | 11 |
2 files changed, 23 insertions, 0 deletions
diff --git a/src/test/ui/moves/move-of-addr-of-mut.rs b/src/test/ui/moves/move-of-addr-of-mut.rs new file mode 100644 index 00000000000..f2f64e43cd2 --- /dev/null +++ b/src/test/ui/moves/move-of-addr-of-mut.rs @@ -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); +} diff --git a/src/test/ui/moves/move-of-addr-of-mut.stderr b/src/test/ui/moves/move-of-addr-of-mut.stderr new file mode 100644 index 00000000000..ce8fb028316 --- /dev/null +++ b/src/test/ui/moves/move-of-addr-of-mut.stderr @@ -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`. |
