From 698f8c2f01ea549d77d7dc3338a12e04c11057b9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:02:58 +0200 Subject: Adding upstream version 1.64.0+dfsg1. Signed-off-by: Daniel Baumann --- .../ui/consts/qualif-indirect-mutation-fail.rs | 64 ++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 src/test/ui/consts/qualif-indirect-mutation-fail.rs (limited to 'src/test/ui/consts/qualif-indirect-mutation-fail.rs') diff --git a/src/test/ui/consts/qualif-indirect-mutation-fail.rs b/src/test/ui/consts/qualif-indirect-mutation-fail.rs new file mode 100644 index 000000000..f74a25a34 --- /dev/null +++ b/src/test/ui/consts/qualif-indirect-mutation-fail.rs @@ -0,0 +1,64 @@ +// compile-flags: --crate-type=lib +#![feature(const_mut_refs)] +#![feature(const_precise_live_drops)] +#![feature(const_swap)] +#![feature(raw_ref_op)] + +// Mutable borrow of a field with drop impl. +pub const fn f() { + let mut a: (u32, Option) = (0, None); //~ ERROR destructors cannot be evaluated + let _ = &mut a.1; +} + +// Mutable borrow of a type with drop impl. +pub const A1: () = { + let mut x = None; //~ ERROR destructors cannot be evaluated + let mut y = Some(String::new()); + let a = &mut x; + let b = &mut y; + std::mem::swap(a, b); + std::mem::forget(y); +}; + +// Mutable borrow of a type with drop impl. +pub const A2: () = { + let mut x = None; + let mut y = Some(String::new()); + let a = &mut x; + let b = &mut y; + std::mem::swap(a, b); + std::mem::forget(y); + let _z = x; //~ ERROR destructors cannot be evaluated +}; + +// Shared borrow of a type that might be !Freeze and Drop. +pub const fn g1() { + let x: Option = None; //~ ERROR destructors cannot be evaluated + let _ = x.is_some(); +} + +// Shared borrow of a type that might be !Freeze and Drop. +pub const fn g2() { + let x: Option = None; + let _ = x.is_some(); + let _y = x; //~ ERROR destructors cannot be evaluated +} + +// Mutable raw reference to a Drop type. +pub const fn address_of_mut() { + let mut x: Option = None; //~ ERROR destructors cannot be evaluated + &raw mut x; + + let mut y: Option = None; //~ ERROR destructors cannot be evaluated + std::ptr::addr_of_mut!(y); +} + +// Const raw reference to a Drop type. Conservatively assumed to allow mutation +// until resolution of https://github.com/rust-lang/rust/issues/56604. +pub const fn address_of_const() { + let x: Option = None; //~ ERROR destructors cannot be evaluated + &raw const x; + + let y: Option = None; //~ ERROR destructors cannot be evaluated + std::ptr::addr_of!(y); +} -- cgit v1.2.3