From 8acdb369f18f5f040bbf3d3d53bbc40cd9d9f293 Mon Sep 17 00:00:00 2001 From: Lars Schumann Date: Tue, 21 Apr 2026 20:04:28 +0000 Subject: [PATCH] constify array try from vec --- library/alloc/src/lib.rs | 1 + library/alloc/src/raw_vec/mod.rs | 6 +- library/alloc/src/vec/mod.rs | 15 +++-- ...ated_loop.PreCodegen.after.panic-abort.mir | 36 ++++++----- ...ward_loop.PreCodegen.after.panic-abort.mir | 29 ++++----- ...ange_loop.PreCodegen.after.panic-abort.mir | 6 ++ ...erse_loop.PreCodegen.after.panic-abort.mir | 28 ++++----- ..._is_empty.PreCodegen.after.panic-abort.mir | 12 ++-- ...next_back.PreCodegen.after.panic-abort.mir | 16 ++--- ...iter_next.PreCodegen.after.panic-abort.mir | 44 +++++++------ .../consts/bad-array-size-in-type-err.stderr | 4 ++ .../const-eval/issue-65394.stock.stderr | 4 ++ tests/ui/consts/const-eval/livedrop.stderr | 4 ++ .../control-flow/drop-fail.precise.stderr | 10 +-- tests/ui/consts/control-flow/drop-fail.rs | 25 +++++--- .../control-flow/drop-fail.stock.stderr | 22 +++---- tests/ui/consts/miri_unleashed/assoc_const.rs | 15 +++-- .../consts/miri_unleashed/assoc_const.stderr | 24 +++---- tests/ui/consts/miri_unleashed/drop.rs | 15 +++-- tests/ui/consts/miri_unleashed/drop.stderr | 10 +-- tests/ui/consts/promote-not.stderr | 4 ++ tests/ui/consts/promoted_const_call3.stderr | 8 +++ tests/ui/consts/promoted_const_call5.stderr | 4 ++ .../consts/qualif-indirect-mutation-fail.rs | 24 ++++--- .../qualif-indirect-mutation-fail.stderr | 62 +++++++++---------- tests/ui/drop/repeat-drop-2.stderr | 4 ++ ...op-elaboration-after-borrowck-error.stderr | 8 +++ ...-indestructible-indestructible.next.stderr | 12 ++-- ...h-indestructible-indestructible.old.stderr | 12 ++-- ...sure-with-indestructible-indestructible.rs | 14 ++++- 30 files changed, 286 insertions(+), 192 deletions(-) diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs index d85a63999fe03..e53e3b928c8a9 100644 --- a/library/alloc/src/lib.rs +++ b/library/alloc/src/lib.rs @@ -104,6 +104,7 @@ #![feature(const_convert)] #![feature(const_default)] #![feature(const_destruct)] +#![feature(const_drop_in_place)] #![feature(const_eval_select)] #![feature(const_heap)] #![feature(const_index)] diff --git a/library/alloc/src/raw_vec/mod.rs b/library/alloc/src/raw_vec/mod.rs index cabf6accf3b53..cdb06f1c027a7 100644 --- a/library/alloc/src/raw_vec/mod.rs +++ b/library/alloc/src/raw_vec/mod.rs @@ -417,7 +417,8 @@ impl RawVec { } } -unsafe impl<#[may_dangle] T, A: Allocator> Drop for RawVec { +#[rustc_const_unstable(feature = "const_heap", issue = "79597")] +unsafe impl<#[may_dangle] T, A: [const] Allocator> const Drop for RawVec { /// Frees the memory owned by the `RawVec` *without* trying to drop its contents. fn drop(&mut self) { // SAFETY: We are in a Drop impl, self.inner will not be used again. @@ -861,7 +862,10 @@ impl RawVecInner { } Ok(()) } +} +#[rustc_const_unstable(feature = "const_heap", issue = "79597")] +const impl RawVecInner { /// # Safety /// /// This function deallocates the owned allocation, but does not update `ptr` or `cap` to diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index b633beae89136..20f4918606106 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -79,9 +79,7 @@ use core::cmp::Ordering; use core::hash::{Hash, Hasher}; #[cfg(not(no_global_oom_handling))] use core::iter; -#[cfg(not(no_global_oom_handling))] -use core::marker::Destruct; -use core::marker::{Freeze, PhantomData}; +use core::marker::{Destruct, Freeze, PhantomData}; use core::mem::{self, Assume, ManuallyDrop, MaybeUninit, SizedTypeProperties, TransmuteFrom}; use core::ops::{self, Index, IndexMut, Range, RangeBounds}; use core::ptr::{self, NonNull}; @@ -2184,7 +2182,8 @@ impl Vec { /// [`spare_capacity_mut()`]: Vec::spare_capacity_mut #[inline] #[stable(feature = "rust1", since = "1.0.0")] - pub unsafe fn set_len(&mut self, new_len: usize) { + #[rustc_const_unstable(feature = "const_heap", issue = "79597")] + pub const unsafe fn set_len(&mut self, new_len: usize) { ub_checks::assert_unsafe_precondition!( check_library_ub, "Vec::set_len requires that new_len <= capacity()", @@ -4245,7 +4244,8 @@ impl Ord for Vec { } #[stable(feature = "rust1", since = "1.0.0")] -unsafe impl<#[may_dangle] T, A: Allocator> Drop for Vec { +#[rustc_const_unstable(feature = "const_heap", issue = "79597")] +unsafe impl<#[may_dangle] T: [const] Destruct, A: Allocator> const Drop for Vec { fn drop(&mut self) { unsafe { // use drop for [T] @@ -4464,7 +4464,10 @@ impl From<&str> for Vec { } #[stable(feature = "array_try_from_vec", since = "1.48.0")] -impl TryFrom> for [T; N] { +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] +impl const + TryFrom> for [T; N] +{ type Error = Vec; /// Gets the entire contents of the `Vec` as an array, diff --git a/tests/mir-opt/pre-codegen/slice_iter.enumerated_loop.PreCodegen.after.panic-abort.mir b/tests/mir-opt/pre-codegen/slice_iter.enumerated_loop.PreCodegen.after.panic-abort.mir index 6d3519846023a..575659e6d0ded 100644 --- a/tests/mir-opt/pre-codegen/slice_iter.enumerated_loop.PreCodegen.after.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/slice_iter.enumerated_loop.PreCodegen.after.panic-abort.mir @@ -180,23 +180,20 @@ fn enumerated_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () { bb4: { StorageLive(_32); - StorageLive(_29); StorageLive(_30); StorageLive(_27); - StorageLive(_13); - StorageLive(_14); - StorageLive(_20); StorageLive(_24); - StorageLive(_15); - StorageLive(_26); StorageLive(_16); + StorageLive(_13); _13 = copy _8; + StorageLive(_14); _14 = copy _11; switchInt(const ::IS_ZST) -> [0: bb5, otherwise: bb8]; } bb5: { StorageLive(_18); + StorageLive(_15); _15 = copy _14 as std::ptr::NonNull (Transmute); _16 = copy _13 as *mut T (Transmute); StorageLive(_17); @@ -207,6 +204,7 @@ fn enumerated_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () { } bb6: { + StorageDead(_15); StorageDead(_18); StorageLive(_19); _19 = Offset(copy _16, const 1_usize); @@ -216,27 +214,27 @@ fn enumerated_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () { } bb7: { + StorageDead(_15); StorageDead(_18); goto -> bb10; } bb8: { + StorageLive(_20); _20 = copy _14 as usize (Transmute); switchInt(copy _20) -> [0: bb9, otherwise: bb12]; } bb9: { + StorageDead(_20); goto -> bb10; } bb10: { - StorageDead(_16); - StorageDead(_26); - StorageDead(_15); - StorageDead(_24); - StorageDead(_20); StorageDead(_14); StorageDead(_13); + StorageDead(_16); + StorageDead(_24); StorageDead(_27); StorageLive(_21); StorageLive(_23); @@ -246,7 +244,6 @@ fn enumerated_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () { StorageDead(_23); StorageDead(_21); StorageDead(_30); - StorageDead(_29); StorageDead(_32); StorageDead(_12); drop(_2) -> [return: bb11, unwind unreachable]; @@ -259,24 +256,25 @@ fn enumerated_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () { bb12: { _24 = SubUnchecked(copy _20, const 1_usize); _11 = copy _24 as *const T (Transmute); + StorageDead(_20); goto -> bb13; } bb13: { + StorageLive(_26); StorageLive(_25); _25 = copy _13 as *const T (Transmute); _26 = &(*_25); StorageDead(_25); _27 = Option::<&T>::Some(copy _26); - StorageDead(_16); StorageDead(_26); - StorageDead(_15); - StorageDead(_24); - StorageDead(_20); StorageDead(_14); StorageDead(_13); + StorageDead(_16); + StorageDead(_24); _28 = copy ((_27 as Some).0: &T); StorageDead(_27); + StorageLive(_29); _29 = copy _12; _30 = AddWithOverflow(copy _12, const 1_usize); assert(!move (_30.1: bool), "attempt to compute `{} + {}`, which would overflow", copy _12, const 1_usize) -> [success: bb14, unwind unreachable]; @@ -288,9 +286,11 @@ fn enumerated_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () { _31 = (copy _29, copy _28); _32 = Option::<(usize, &T)>::Some(move _31); StorageDead(_31); - StorageDead(_30); StorageDead(_29); + StorageDead(_30); + StorageLive(_33); _33 = copy (((_32 as Some).0: (usize, &T)).0: usize); + StorageLive(_34); _34 = copy (((_32 as Some).0: (usize, &T)).1: &T); StorageLive(_35); _35 = &_2; @@ -302,6 +302,8 @@ fn enumerated_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () { bb15: { StorageDead(_36); StorageDead(_35); + StorageDead(_34); + StorageDead(_33); StorageDead(_32); goto -> bb4; } diff --git a/tests/mir-opt/pre-codegen/slice_iter.forward_loop.PreCodegen.after.panic-abort.mir b/tests/mir-opt/pre-codegen/slice_iter.forward_loop.PreCodegen.after.panic-abort.mir index 6e27d02641687..f41dbd567003e 100644 --- a/tests/mir-opt/pre-codegen/slice_iter.forward_loop.PreCodegen.after.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/slice_iter.forward_loop.PreCodegen.after.panic-abort.mir @@ -142,20 +142,18 @@ fn forward_loop(_1: &[T], _2: impl Fn(&T)) -> () { bb4: { StorageLive(_23); - StorageLive(_12); - StorageLive(_13); - StorageLive(_19); StorageLive(_20); - StorageLive(_14); - StorageLive(_22); StorageLive(_15); + StorageLive(_12); _12 = copy _8; + StorageLive(_13); _13 = copy _11; switchInt(const ::IS_ZST) -> [0: bb5, otherwise: bb8]; } bb5: { StorageLive(_17); + StorageLive(_14); _14 = copy _13 as std::ptr::NonNull (Transmute); _15 = copy _12 as *mut T (Transmute); StorageLive(_16); @@ -166,6 +164,7 @@ fn forward_loop(_1: &[T], _2: impl Fn(&T)) -> () { } bb6: { + StorageDead(_14); StorageDead(_17); StorageLive(_18); _18 = Offset(copy _15, const 1_usize); @@ -175,27 +174,27 @@ fn forward_loop(_1: &[T], _2: impl Fn(&T)) -> () { } bb7: { + StorageDead(_14); StorageDead(_17); goto -> bb10; } bb8: { + StorageLive(_19); _19 = copy _13 as usize (Transmute); switchInt(copy _19) -> [0: bb9, otherwise: bb12]; } bb9: { + StorageDead(_19); goto -> bb10; } bb10: { - StorageDead(_15); - StorageDead(_22); - StorageDead(_14); - StorageDead(_20); - StorageDead(_19); StorageDead(_13); StorageDead(_12); + StorageDead(_15); + StorageDead(_20); StorageDead(_23); drop(_2) -> [return: bb11, unwind unreachable]; } @@ -207,22 +206,23 @@ fn forward_loop(_1: &[T], _2: impl Fn(&T)) -> () { bb12: { _20 = SubUnchecked(copy _19, const 1_usize); _11 = copy _20 as *const T (Transmute); + StorageDead(_19); goto -> bb13; } bb13: { + StorageLive(_22); StorageLive(_21); _21 = copy _12 as *const T (Transmute); _22 = &(*_21); StorageDead(_21); _23 = Option::<&T>::Some(copy _22); - StorageDead(_15); StorageDead(_22); - StorageDead(_14); - StorageDead(_20); - StorageDead(_19); StorageDead(_13); StorageDead(_12); + StorageDead(_15); + StorageDead(_20); + StorageLive(_24); _24 = copy ((_23 as Some).0: &T); StorageLive(_25); _25 = &_2; @@ -234,6 +234,7 @@ fn forward_loop(_1: &[T], _2: impl Fn(&T)) -> () { bb14: { StorageDead(_26); StorageDead(_25); + StorageDead(_24); StorageDead(_23); goto -> bb4; } diff --git a/tests/mir-opt/pre-codegen/slice_iter.range_loop.PreCodegen.after.panic-abort.mir b/tests/mir-opt/pre-codegen/slice_iter.range_loop.PreCodegen.after.panic-abort.mir index 145375990710b..43e2d24674d96 100644 --- a/tests/mir-opt/pre-codegen/slice_iter.range_loop.PreCodegen.after.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/slice_iter.range_loop.PreCodegen.after.panic-abort.mir @@ -72,11 +72,15 @@ fn range_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () { } bb4: { + StorageLive(_7); _7 = copy _4; _4 = AddUnchecked(copy _7, const 1_usize); _8 = Option::::Some(copy _7); + StorageDead(_7); StorageDead(_6); + StorageLive(_9); _9 = copy ((_8 as Some).0: usize); + StorageLive(_11); _10 = Lt(copy _9, copy _3); assert(move _10, "index out of bounds: the length is {} but the index is {}", copy _3, copy _9) -> [success: bb5, unwind unreachable]; } @@ -93,6 +97,8 @@ fn range_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () { bb6: { StorageDead(_13); StorageDead(_12); + StorageDead(_11); + StorageDead(_9); StorageDead(_8); goto -> bb1; } diff --git a/tests/mir-opt/pre-codegen/slice_iter.reverse_loop.PreCodegen.after.panic-abort.mir b/tests/mir-opt/pre-codegen/slice_iter.reverse_loop.PreCodegen.after.panic-abort.mir index ac2b0f23b9f90..1f96a8e14a5b2 100644 --- a/tests/mir-opt/pre-codegen/slice_iter.reverse_loop.PreCodegen.after.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/slice_iter.reverse_loop.PreCodegen.after.panic-abort.mir @@ -132,10 +132,10 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () { bb0: { StorageLive(_12); - StorageLive(_3); - StorageLive(_8); StorageLive(_11); + StorageLive(_3); _3 = PtrMetadata(copy _1); + StorageLive(_8); StorageLive(_5); StorageLive(_4); _4 = &raw const (*_1); @@ -170,9 +170,9 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () { bb3: { _12 = std::slice::Iter::<'_, T> { ptr: copy _8, end_or_len: copy _11, _marker: const ZeroSized: PhantomData<&T> }; - StorageDead(_11); StorageDead(_8); StorageDead(_3); + StorageDead(_11); _13 = Rev::> { iter: copy _12 }; StorageDead(_12); StorageLive(_14); @@ -182,15 +182,12 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () { bb4: { StorageLive(_35); - StorageLive(_22); - StorageLive(_21); - StorageLive(_16); - StorageLive(_34); StorageLive(_20); switchInt(const ::IS_ZST) -> [0: bb5, otherwise: bb6]; } bb5: { + StorageLive(_16); StorageLive(_15); _15 = copy ((_14.0: std::slice::Iter<'_, T>).1: *const T); _16 = copy _15 as std::ptr::NonNull (Transmute); @@ -205,13 +202,18 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () { _20 = Eq(copy _18, copy _19); StorageDead(_19); StorageDead(_18); + StorageDead(_16); goto -> bb7; } bb6: { + StorageLive(_22); + StorageLive(_21); _21 = copy ((_14.0: std::slice::Iter<'_, T>).1: *const T); _22 = copy _21 as usize (Transmute); + StorageDead(_21); _20 = Eq(copy _22, const 0_usize); + StorageDead(_22); goto -> bb7; } @@ -220,6 +222,7 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () { } bb8: { + StorageLive(_34); StorageLive(_28); StorageLive(_30); StorageLive(_24); @@ -279,11 +282,9 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () { StorageDead(_33); StorageDead(_28); _35 = Option::<&T>::Some(copy _34); - StorageDead(_20); StorageDead(_34); - StorageDead(_16); - StorageDead(_21); - StorageDead(_22); + StorageDead(_20); + StorageLive(_36); _36 = copy ((_35 as Some).0: &T); StorageLive(_37); _37 = &_2; @@ -295,16 +296,13 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () { bb14: { StorageDead(_38); StorageDead(_37); + StorageDead(_36); StorageDead(_35); goto -> bb4; } bb15: { StorageDead(_20); - StorageDead(_34); - StorageDead(_16); - StorageDead(_21); - StorageDead(_22); StorageDead(_35); StorageDead(_14); drop(_2) -> [return: bb16, unwind unreachable]; diff --git a/tests/mir-opt/pre-codegen/slice_iter.slice_iter_generic_is_empty.PreCodegen.after.panic-abort.mir b/tests/mir-opt/pre-codegen/slice_iter.slice_iter_generic_is_empty.PreCodegen.after.panic-abort.mir index 9b510380b10b2..04f78fa3e7e3b 100644 --- a/tests/mir-opt/pre-codegen/slice_iter.slice_iter_generic_is_empty.PreCodegen.after.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/slice_iter.slice_iter_generic_is_empty.PreCodegen.after.panic-abort.mir @@ -30,13 +30,11 @@ fn slice_iter_generic_is_empty(_1: &std::slice::Iter<'_, T>) -> bool { } bb0: { - StorageLive(_8); - StorageLive(_7); - StorageLive(_3); switchInt(const ::IS_ZST) -> [0: bb1, otherwise: bb2]; } bb1: { + StorageLive(_3); StorageLive(_2); _2 = copy ((*_1).1: *const T); _3 = copy _2 as std::ptr::NonNull (Transmute); @@ -51,20 +49,22 @@ fn slice_iter_generic_is_empty(_1: &std::slice::Iter<'_, T>) -> bool { _0 = Eq(copy _5, copy _6); StorageDead(_6); StorageDead(_5); + StorageDead(_3); goto -> bb3; } bb2: { + StorageLive(_8); + StorageLive(_7); _7 = copy ((*_1).1: *const T); _8 = copy _7 as usize (Transmute); + StorageDead(_7); _0 = Eq(copy _8, const 0_usize); + StorageDead(_8); goto -> bb3; } bb3: { - StorageDead(_3); - StorageDead(_7); - StorageDead(_8); return; } } diff --git a/tests/mir-opt/pre-codegen/slice_iter.slice_iter_mut_next_back.PreCodegen.after.panic-abort.mir b/tests/mir-opt/pre-codegen/slice_iter.slice_iter_mut_next_back.PreCodegen.after.panic-abort.mir index 99f793ea67249..94471cbb157c5 100644 --- a/tests/mir-opt/pre-codegen/slice_iter.slice_iter_mut_next_back.PreCodegen.after.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/slice_iter.slice_iter_mut_next_back.PreCodegen.after.panic-abort.mir @@ -73,16 +73,13 @@ fn slice_iter_mut_next_back(_1: &mut std::slice::IterMut<'_, T>) -> Option<&mut } bb0: { - StorageLive(_9); - StorageLive(_8); - StorageLive(_3); StorageLive(_2); - StorageLive(_21); StorageLive(_7); switchInt(const ::IS_ZST) -> [0: bb1, otherwise: bb2]; } bb1: { + StorageLive(_3); _2 = copy ((*_1).1: *mut T); _3 = copy _2 as std::ptr::NonNull (Transmute); StorageLive(_5); @@ -95,13 +92,18 @@ fn slice_iter_mut_next_back(_1: &mut std::slice::IterMut<'_, T>) -> Option<&mut _7 = Eq(copy _5, copy _6); StorageDead(_6); StorageDead(_5); + StorageDead(_3); goto -> bb3; } bb2: { + StorageLive(_9); + StorageLive(_8); _8 = copy ((*_1).1: *mut T); _9 = copy _8 as usize (Transmute); + StorageDead(_8); _7 = Eq(copy _9, const 0_usize); + StorageDead(_9); goto -> bb3; } @@ -110,6 +112,7 @@ fn slice_iter_mut_next_back(_1: &mut std::slice::IterMut<'_, T>) -> Option<&mut } bb4: { + StorageLive(_21); StorageLive(_15); StorageLive(_17); StorageLive(_11); @@ -169,6 +172,7 @@ fn slice_iter_mut_next_back(_1: &mut std::slice::IterMut<'_, T>) -> Option<&mut StorageDead(_20); StorageDead(_15); _0 = Option::<&mut T>::Some(copy _21); + StorageDead(_21); goto -> bb11; } @@ -179,11 +183,7 @@ fn slice_iter_mut_next_back(_1: &mut std::slice::IterMut<'_, T>) -> Option<&mut bb11: { StorageDead(_7); - StorageDead(_21); StorageDead(_2); - StorageDead(_3); - StorageDead(_8); - StorageDead(_9); return; } } diff --git a/tests/mir-opt/pre-codegen/slice_iter.slice_iter_next.PreCodegen.after.panic-abort.mir b/tests/mir-opt/pre-codegen/slice_iter.slice_iter_next.PreCodegen.after.panic-abort.mir index 5711b556203ac..70e21435cc18f 100644 --- a/tests/mir-opt/pre-codegen/slice_iter.slice_iter_next.PreCodegen.after.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/slice_iter.slice_iter_next.PreCodegen.after.panic-abort.mir @@ -53,20 +53,18 @@ fn slice_iter_next(_1: &mut std::slice::Iter<'_, T>) -> Option<&T> { } bb0: { - StorageLive(_2); - StorageLive(_3); - StorageLive(_10); StorageLive(_11); - StorageLive(_4); - StorageLive(_13); StorageLive(_5); + StorageLive(_2); _2 = copy ((*_1).0: std::ptr::NonNull); + StorageLive(_3); _3 = copy ((*_1).1: *const T); switchInt(const ::IS_ZST) -> [0: bb1, otherwise: bb4]; } bb1: { StorageLive(_7); + StorageLive(_4); _4 = copy _3 as std::ptr::NonNull (Transmute); _5 = copy _2 as *mut T (Transmute); StorageLive(_6); @@ -77,6 +75,7 @@ fn slice_iter_next(_1: &mut std::slice::Iter<'_, T>) -> Option<&T> { } bb2: { + StorageDead(_4); StorageDead(_7); StorageLive(_9); StorageLive(_8); @@ -85,48 +84,57 @@ fn slice_iter_next(_1: &mut std::slice::Iter<'_, T>) -> Option<&T> { StorageDead(_8); ((*_1).0: std::ptr::NonNull) = move _9; StorageDead(_9); - goto -> bb7; + goto -> bb8; } bb3: { + StorageDead(_4); _0 = const {transmute(0x0000000000000000): Option<&T>}; StorageDead(_7); - goto -> bb8; + goto -> bb6; } bb4: { + StorageLive(_10); _10 = copy _3 as usize (Transmute); - switchInt(copy _10) -> [0: bb5, otherwise: bb6]; + switchInt(copy _10) -> [0: bb5, otherwise: bb7]; } bb5: { _0 = const {transmute(0x0000000000000000): Option<&T>}; - goto -> bb8; + StorageDead(_10); + goto -> bb6; } bb6: { + StorageDead(_3); + StorageDead(_2); + goto -> bb9; + } + + bb7: { _11 = SubUnchecked(copy _10, const 1_usize); ((*_1).1: *const T) = copy _11 as *const T (Transmute); - goto -> bb7; + StorageDead(_10); + goto -> bb8; } - bb7: { + bb8: { + StorageLive(_13); StorageLive(_12); _12 = copy _2 as *const T (Transmute); _13 = &(*_12); StorageDead(_12); _0 = Option::<&T>::Some(copy _13); - goto -> bb8; + StorageDead(_13); + StorageDead(_3); + StorageDead(_2); + goto -> bb9; } - bb8: { + bb9: { StorageDead(_5); - StorageDead(_13); - StorageDead(_4); StorageDead(_11); - StorageDead(_10); - StorageDead(_3); - StorageDead(_2); return; } } diff --git a/tests/ui/consts/bad-array-size-in-type-err.stderr b/tests/ui/consts/bad-array-size-in-type-err.stderr index 84e16f8d931ea..13b0b6c4f4a65 100644 --- a/tests/ui/consts/bad-array-size-in-type-err.stderr +++ b/tests/ui/consts/bad-array-size-in-type-err.stderr @@ -57,6 +57,10 @@ LL | pub const fn i(_: Wrap) {} | ^ - value is dropped here | | | the destructor for this type cannot be evaluated in constant functions + | + = note: see issue #133214 for more information + = help: add `#![feature(const_destruct)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error: aborting due to 7 previous errors diff --git a/tests/ui/consts/const-eval/issue-65394.stock.stderr b/tests/ui/consts/const-eval/issue-65394.stock.stderr index f33593862a763..514d454df3dc0 100644 --- a/tests/ui/consts/const-eval/issue-65394.stock.stderr +++ b/tests/ui/consts/const-eval/issue-65394.stock.stderr @@ -6,6 +6,10 @@ LL | let mut x = Vec::::new(); ... LL | }; | - value is dropped here + | + = note: see issue #133214 for more information + = help: add `#![feature(const_destruct)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error: aborting due to 1 previous error diff --git a/tests/ui/consts/const-eval/livedrop.stderr b/tests/ui/consts/const-eval/livedrop.stderr index 1add814060370..b090e35f07e3f 100644 --- a/tests/ui/consts/const-eval/livedrop.stderr +++ b/tests/ui/consts/const-eval/livedrop.stderr @@ -6,6 +6,10 @@ LL | let mut always_returned = None; ... LL | always_returned = never_returned; | --------------- value is dropped here + | + = note: see issue #133214 for more information + = help: add `#![feature(const_destruct)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error: aborting due to 1 previous error diff --git a/tests/ui/consts/control-flow/drop-fail.precise.stderr b/tests/ui/consts/control-flow/drop-fail.precise.stderr index 32afc51c3ee34..6f07d2329615b 100644 --- a/tests/ui/consts/control-flow/drop-fail.precise.stderr +++ b/tests/ui/consts/control-flow/drop-fail.precise.stderr @@ -1,14 +1,14 @@ -error[E0493]: destructor of `Option>` cannot be evaluated at compile-time - --> $DIR/drop-fail.rs:9:9 +error[E0493]: destructor of `Option` cannot be evaluated at compile-time + --> $DIR/drop-fail.rs:16:9 | -LL | let x = Some(Vec::new()); +LL | let x = Some(NotConstDestruct); | ^ the destructor for this type cannot be evaluated in constants ... LL | }; | - value is dropped here -error[E0493]: destructor of `Option>` cannot be evaluated at compile-time - --> $DIR/drop-fail.rs:40:9 +error[E0493]: destructor of `Option` cannot be evaluated at compile-time + --> $DIR/drop-fail.rs:47:9 | LL | let mut tmp = None; | ^^^^^^^ the destructor for this type cannot be evaluated in constants diff --git a/tests/ui/consts/control-flow/drop-fail.rs b/tests/ui/consts/control-flow/drop-fail.rs index 2b73e37b23d03..3593e5af26b00 100644 --- a/tests/ui/consts/control-flow/drop-fail.rs +++ b/tests/ui/consts/control-flow/drop-fail.rs @@ -3,10 +3,17 @@ #![feature(const_destruct)] #![cfg_attr(precise, feature(const_precise_live_drops))] + +struct NotConstDestruct; + +impl Drop for NotConstDestruct { + fn drop(&mut self) {} +} + // `x` is *not* always moved into the final value and may be dropped inside the initializer. -const _: Option> = { - let y: Option> = None; - let x = Some(Vec::new()); +const _: Option = { + let y: Option = None; + let x = Some(NotConstDestruct); //[stock,precise]~^ ERROR destructor of if true { @@ -18,16 +25,16 @@ const _: Option> = { // We only clear `NeedsDrop` if a local is moved from in entirely. This is a shortcoming of the // existing analysis. -const _: Vec = { - let vec_tuple = (Vec::new(),); +const _: NotConstDestruct = { + let vec_tuple = (NotConstDestruct,); //[stock]~^ ERROR destructor of vec_tuple.0 }; // This applies to single-field enum variants as well. -const _: Vec = { - let x: Result<_, Vec> = Ok(Vec::new()); +const _: NotConstDestruct = { + let x: Result<_, NotConstDestruct> = Ok(NotConstDestruct); //[stock]~^ ERROR destructor of match x { @@ -35,8 +42,8 @@ const _: Vec = { } }; -const _: Option> = { - let mut some = Some(Vec::new()); +const _: Option = { + let mut some = Some(NotConstDestruct); let mut tmp = None; //[stock,precise]~^ ERROR destructor of diff --git a/tests/ui/consts/control-flow/drop-fail.stock.stderr b/tests/ui/consts/control-flow/drop-fail.stock.stderr index 8fe60fd736765..3caef5810939c 100644 --- a/tests/ui/consts/control-flow/drop-fail.stock.stderr +++ b/tests/ui/consts/control-flow/drop-fail.stock.stderr @@ -1,32 +1,32 @@ -error[E0493]: destructor of `Option>` cannot be evaluated at compile-time - --> $DIR/drop-fail.rs:9:9 +error[E0493]: destructor of `Option` cannot be evaluated at compile-time + --> $DIR/drop-fail.rs:16:9 | -LL | let x = Some(Vec::new()); +LL | let x = Some(NotConstDestruct); | ^ the destructor for this type cannot be evaluated in constants ... LL | }; | - value is dropped here -error[E0493]: destructor of `(Vec,)` cannot be evaluated at compile-time - --> $DIR/drop-fail.rs:22:9 +error[E0493]: destructor of `(NotConstDestruct,)` cannot be evaluated at compile-time + --> $DIR/drop-fail.rs:29:9 | -LL | let vec_tuple = (Vec::new(),); +LL | let vec_tuple = (NotConstDestruct,); | ^^^^^^^^^ the destructor for this type cannot be evaluated in constants ... LL | }; | - value is dropped here -error[E0493]: destructor of `Result, Vec>` cannot be evaluated at compile-time - --> $DIR/drop-fail.rs:30:9 +error[E0493]: destructor of `Result` cannot be evaluated at compile-time + --> $DIR/drop-fail.rs:37:9 | -LL | let x: Result<_, Vec> = Ok(Vec::new()); +LL | let x: Result<_, NotConstDestruct> = Ok(NotConstDestruct); | ^ the destructor for this type cannot be evaluated in constants ... LL | }; | - value is dropped here -error[E0493]: destructor of `Option>` cannot be evaluated at compile-time - --> $DIR/drop-fail.rs:40:9 +error[E0493]: destructor of `Option` cannot be evaluated at compile-time + --> $DIR/drop-fail.rs:47:9 | LL | let mut tmp = None; | ^^^^^^^ the destructor for this type cannot be evaluated in constants diff --git a/tests/ui/consts/miri_unleashed/assoc_const.rs b/tests/ui/consts/miri_unleashed/assoc_const.rs index 812207ee80900..753a53077e086 100644 --- a/tests/ui/consts/miri_unleashed/assoc_const.rs +++ b/tests/ui/consts/miri_unleashed/assoc_const.rs @@ -4,6 +4,13 @@ // a test demonstrating why we do need to run static const qualification on associated constants // instead of just checking the final constant + +struct NotConstDestruct; + +impl Drop for NotConstDestruct { + fn drop(&mut self) {} +} + trait Foo { const X: T; } @@ -15,18 +22,18 @@ trait Bar> { impl Foo for () { const X: u32 = 42; } -impl Foo> for String { - const X: Vec = Vec::new(); +impl Foo for NotConstDestruct { + const X: NotConstDestruct = NotConstDestruct; } impl Bar for () {} -impl Bar, String> for String {} +impl Bar for NotConstDestruct {} fn main() { // this is fine, but would have been forbidden by the static checks on `F` let x = <() as Bar>::F; // this test only causes errors due to the line below, so post-monomorphization - let y = , String>>::F; + let y = >::F; } //~? WARN skipping const checks diff --git a/tests/ui/consts/miri_unleashed/assoc_const.stderr b/tests/ui/consts/miri_unleashed/assoc_const.stderr index 1ba4f3b2896ef..fabfc285472d5 100644 --- a/tests/ui/consts/miri_unleashed/assoc_const.stderr +++ b/tests/ui/consts/miri_unleashed/assoc_const.stderr @@ -1,32 +1,32 @@ -error[E0080]: calling non-const function ` as Drop>::drop` - --> $DIR/assoc_const.rs:12:31 +error[E0080]: calling non-const function `::drop` + --> $DIR/assoc_const.rs:19:31 | LL | const F: u32 = (U::X, 42).1; - | ^ evaluation of `, std::string::String>>::F` failed inside this call + | ^ evaluation of `>::F` failed inside this call | -note: inside `drop_in_place::<(Vec, u32)> - shim(Some((Vec, u32)))` +note: inside `drop_in_place::<(NotConstDestruct, u32)> - shim(Some((NotConstDestruct, u32)))` --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL -note: inside `drop_in_place::> - shim(Some(Vec))` +note: inside `drop_in_place:: - shim(Some(NotConstDestruct))` --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL note: erroneous constant encountered - --> $DIR/assoc_const.rs:29:13 + --> $DIR/assoc_const.rs:36:13 | -LL | let y = , String>>::F; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | let y = >::F; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ note: erroneous constant encountered - --> $DIR/assoc_const.rs:29:13 + --> $DIR/assoc_const.rs:36:13 | -LL | let y = , String>>::F; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | let y = >::F; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` warning: skipping const checks | help: skipping check that does not even have a feature gate - --> $DIR/assoc_const.rs:12:20 + --> $DIR/assoc_const.rs:19:20 | LL | const F: u32 = (U::X, 42).1; | ^^^^^^^^^^ diff --git a/tests/ui/consts/miri_unleashed/drop.rs b/tests/ui/consts/miri_unleashed/drop.rs index 46af3388a96ef..962d8be9344bd 100644 --- a/tests/ui/consts/miri_unleashed/drop.rs +++ b/tests/ui/consts/miri_unleashed/drop.rs @@ -2,19 +2,26 @@ use std::mem::ManuallyDrop; + +struct NotConstDestruct; + +impl Drop for NotConstDestruct { + fn drop(&mut self) {} +} + fn main() {} static TEST_OK: () = { - let v: Vec = Vec::new(); + let v: NotConstDestruct = NotConstDestruct; let _v = ManuallyDrop::new(v); }; // Make sure we catch executing bad drop functions. // The actual error is tested by the error-pattern above. static TEST_BAD: () = { - let _v: Vec = Vec::new(); + let _v: NotConstDestruct = NotConstDestruct; }; //~ NOTE failed inside this call - //~| ERROR calling non-const function ` as Drop>::drop` - //~| NOTE inside `drop_in_place::> - shim(Some(Vec))` + //~| ERROR calling non-const function `::drop` + //~| NOTE inside `drop_in_place:: - shim(Some(NotConstDestruct))` //~? WARN skipping const checks diff --git a/tests/ui/consts/miri_unleashed/drop.stderr b/tests/ui/consts/miri_unleashed/drop.stderr index a66422956bee3..26be6fa3d403a 100644 --- a/tests/ui/consts/miri_unleashed/drop.stderr +++ b/tests/ui/consts/miri_unleashed/drop.stderr @@ -1,18 +1,18 @@ -error[E0080]: calling non-const function ` as Drop>::drop` - --> $DIR/drop.rs:16:1 +error[E0080]: calling non-const function `::drop` + --> $DIR/drop.rs:23:1 | LL | }; | ^ evaluation of `TEST_BAD` failed inside this call | -note: inside `drop_in_place::> - shim(Some(Vec))` +note: inside `drop_in_place:: - shim(Some(NotConstDestruct))` --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL warning: skipping const checks | help: skipping check that does not even have a feature gate - --> $DIR/drop.rs:15:9 + --> $DIR/drop.rs:22:9 | -LL | let _v: Vec = Vec::new(); +LL | let _v: NotConstDestruct = NotConstDestruct; | ^^ error: aborting due to 1 previous error; 1 warning emitted diff --git a/tests/ui/consts/promote-not.stderr b/tests/ui/consts/promote-not.stderr index ec552d9dd7d48..ebe2a963a74b1 100644 --- a/tests/ui/consts/promote-not.stderr +++ b/tests/ui/consts/promote-not.stderr @@ -46,6 +46,10 @@ LL | let x = &String::new(); ... LL | }; | - value is dropped here + | + = note: see issue #133214 for more information + = help: add `#![feature(const_destruct)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0716]: temporary value dropped while borrowed --> $DIR/promote-not.rs:60:33 diff --git a/tests/ui/consts/promoted_const_call3.stderr b/tests/ui/consts/promoted_const_call3.stderr index 34c833d5bb77c..22d017abe6111 100644 --- a/tests/ui/consts/promoted_const_call3.stderr +++ b/tests/ui/consts/promoted_const_call3.stderr @@ -6,6 +6,10 @@ LL | let _: &'static _ = &String::new(); LL | LL | }; | - value is dropped here + | + = note: see issue #133214 for more information + = help: add `#![feature(const_destruct)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0493]: destructor of `String` cannot be evaluated at compile-time --> $DIR/promoted_const_call3.rs:8:30 @@ -14,6 +18,10 @@ LL | let _: &'static _ = &id(&String::new()); | ^^^^^^^^^^^^^ - value is dropped here | | | the destructor for this type cannot be evaluated in constants + | + = note: see issue #133214 for more information + = help: add `#![feature(const_destruct)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0716]: temporary value dropped while borrowed --> $DIR/promoted_const_call3.rs:13:26 diff --git a/tests/ui/consts/promoted_const_call5.stderr b/tests/ui/consts/promoted_const_call5.stderr index 1b5fa4352837e..b65422e44a510 100644 --- a/tests/ui/consts/promoted_const_call5.stderr +++ b/tests/ui/consts/promoted_const_call5.stderr @@ -5,6 +5,10 @@ LL | let _: &'static _ = &id(&new_string()); | ^^^^^^^^^^^^ - value is dropped here | | | the destructor for this type cannot be evaluated in constants + | + = note: see issue #133214 for more information + = help: add `#![feature(const_destruct)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0716]: temporary value dropped while borrowed --> $DIR/promoted_const_call5.rs:31:26 diff --git a/tests/ui/consts/qualif-indirect-mutation-fail.rs b/tests/ui/consts/qualif-indirect-mutation-fail.rs index b70fca7b86430..00c9d4900f5f6 100644 --- a/tests/ui/consts/qualif-indirect-mutation-fail.rs +++ b/tests/ui/consts/qualif-indirect-mutation-fail.rs @@ -1,32 +1,38 @@ //@ compile-flags: --crate-type=lib #![feature(const_precise_live_drops)] +struct NotConstDestruct; + +impl Drop for NotConstDestruct { + fn drop(&mut self) {} +} + // Mutable borrow of a field with drop impl. pub const fn f() { - let mut a: (u32, Option) = (0, None); //~ ERROR destructor of + let mut a: (u32, Option) = (0, None); //~ ERROR destructor of let _ = &mut a.1; } // Mutable borrow of a type with drop impl. pub const A1: () = { let mut x = None; //~ ERROR destructor of - let mut y = Some(String::new()); + let mut y = Some(NotConstDestruct); let a = &mut x; let b = &mut y; std::mem::swap(a, b); std::mem::forget(y); -}; //~ ERROR calling non-const function ` as Drop>::drop` +}; //~ ERROR calling non-const function `::drop` // Mutable borrow of a type with drop impl. pub const A2: () = { let mut x = None; - let mut y = Some(String::new()); + let mut y = Some(NotConstDestruct); let a = &mut x; let b = &mut y; std::mem::swap(a, b); std::mem::forget(y); let _z = x; //~ ERROR destructor of -}; //~ ERROR calling non-const function ` as Drop>::drop` +}; //~ ERROR calling non-const function `::drop` // Shared borrow of a type that might be !Freeze and Drop. pub const fn g1() { @@ -43,19 +49,19 @@ pub const fn g2() { // Mutable raw reference to a Drop type. pub const fn address_of_mut() { - let mut x: Option = None; //~ ERROR destructor of + let mut x: Option = None; //~ ERROR destructor of &raw mut x; - let mut y: Option = None; //~ ERROR destructor of + let mut y: Option = None; //~ ERROR destructor of 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 destructor of + let x: Option = None; //~ ERROR destructor of &raw const x; - let y: Option = None; //~ ERROR destructor of + let y: Option = None; //~ ERROR destructor of std::ptr::addr_of!(y); } diff --git a/tests/ui/consts/qualif-indirect-mutation-fail.stderr b/tests/ui/consts/qualif-indirect-mutation-fail.stderr index 79724ee8d6a17..55ae395e3e3b0 100644 --- a/tests/ui/consts/qualif-indirect-mutation-fail.stderr +++ b/tests/ui/consts/qualif-indirect-mutation-fail.stderr @@ -1,5 +1,5 @@ -error[E0493]: destructor of `Option` cannot be evaluated at compile-time - --> $DIR/qualif-indirect-mutation-fail.rs:12:9 +error[E0493]: destructor of `Option` cannot be evaluated at compile-time + --> $DIR/qualif-indirect-mutation-fail.rs:18:9 | LL | let mut x = None; | ^^^^^ the destructor for this type cannot be evaluated in constants @@ -7,51 +7,47 @@ LL | let mut x = None; LL | }; | - value is dropped here -error[E0080]: calling non-const function ` as Drop>::drop` - --> $DIR/qualif-indirect-mutation-fail.rs:18:1 +error[E0080]: calling non-const function `::drop` + --> $DIR/qualif-indirect-mutation-fail.rs:24:1 | LL | }; | ^ evaluation of `A1` failed inside this call | -note: inside `drop_in_place::> - shim(Some(Option))` - --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL -note: inside `drop_in_place:: - shim(Some(String))` +note: inside `drop_in_place::> - shim(Some(Option))` --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL -note: inside `drop_in_place::> - shim(Some(Vec))` +note: inside `drop_in_place:: - shim(Some(NotConstDestruct))` --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL -error[E0493]: destructor of `Option` cannot be evaluated at compile-time - --> $DIR/qualif-indirect-mutation-fail.rs:28:9 +error[E0493]: destructor of `Option` cannot be evaluated at compile-time + --> $DIR/qualif-indirect-mutation-fail.rs:34:9 | LL | let _z = x; | ^^ the destructor for this type cannot be evaluated in constants LL | }; | - value is dropped here -error[E0080]: calling non-const function ` as Drop>::drop` - --> $DIR/qualif-indirect-mutation-fail.rs:29:1 +error[E0080]: calling non-const function `::drop` + --> $DIR/qualif-indirect-mutation-fail.rs:35:1 | LL | }; | ^ evaluation of `A2` failed inside this call | -note: inside `drop_in_place::> - shim(Some(Option))` +note: inside `drop_in_place::> - shim(Some(Option))` --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL -note: inside `drop_in_place:: - shim(Some(String))` - --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL -note: inside `drop_in_place::> - shim(Some(Vec))` +note: inside `drop_in_place:: - shim(Some(NotConstDestruct))` --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL -error[E0493]: destructor of `(u32, Option)` cannot be evaluated at compile-time - --> $DIR/qualif-indirect-mutation-fail.rs:6:9 +error[E0493]: destructor of `(u32, Option)` cannot be evaluated at compile-time + --> $DIR/qualif-indirect-mutation-fail.rs:12:9 | -LL | let mut a: (u32, Option) = (0, None); +LL | let mut a: (u32, Option) = (0, None); | ^^^^^ the destructor for this type cannot be evaluated in constant functions LL | let _ = &mut a.1; LL | } | - value is dropped here error[E0493]: destructor of `Option` cannot be evaluated at compile-time - --> $DIR/qualif-indirect-mutation-fail.rs:33:9 + --> $DIR/qualif-indirect-mutation-fail.rs:39:9 | LL | let x: Option = None; | ^ the destructor for this type cannot be evaluated in constant functions @@ -60,44 +56,44 @@ LL | } | - value is dropped here error[E0493]: destructor of `Option` cannot be evaluated at compile-time - --> $DIR/qualif-indirect-mutation-fail.rs:41:9 + --> $DIR/qualif-indirect-mutation-fail.rs:47:9 | LL | let _y = x; | ^^ the destructor for this type cannot be evaluated in constant functions LL | } | - value is dropped here -error[E0493]: destructor of `Option` cannot be evaluated at compile-time - --> $DIR/qualif-indirect-mutation-fail.rs:49:9 +error[E0493]: destructor of `Option` cannot be evaluated at compile-time + --> $DIR/qualif-indirect-mutation-fail.rs:55:9 | -LL | let mut y: Option = None; +LL | let mut y: Option = None; | ^^^^^ the destructor for this type cannot be evaluated in constant functions LL | std::ptr::addr_of_mut!(y); LL | } | - value is dropped here -error[E0493]: destructor of `Option` cannot be evaluated at compile-time - --> $DIR/qualif-indirect-mutation-fail.rs:46:9 +error[E0493]: destructor of `Option` cannot be evaluated at compile-time + --> $DIR/qualif-indirect-mutation-fail.rs:52:9 | -LL | let mut x: Option = None; +LL | let mut x: Option = None; | ^^^^^ the destructor for this type cannot be evaluated in constant functions ... LL | } | - value is dropped here -error[E0493]: destructor of `Option` cannot be evaluated at compile-time - --> $DIR/qualif-indirect-mutation-fail.rs:59:9 +error[E0493]: destructor of `Option` cannot be evaluated at compile-time + --> $DIR/qualif-indirect-mutation-fail.rs:65:9 | -LL | let y: Option = None; +LL | let y: Option = None; | ^ the destructor for this type cannot be evaluated in constant functions LL | std::ptr::addr_of!(y); LL | } | - value is dropped here -error[E0493]: destructor of `Option` cannot be evaluated at compile-time - --> $DIR/qualif-indirect-mutation-fail.rs:56:9 +error[E0493]: destructor of `Option` cannot be evaluated at compile-time + --> $DIR/qualif-indirect-mutation-fail.rs:62:9 | -LL | let x: Option = None; +LL | let x: Option = None; | ^ the destructor for this type cannot be evaluated in constant functions ... LL | } diff --git a/tests/ui/drop/repeat-drop-2.stderr b/tests/ui/drop/repeat-drop-2.stderr index cea7baf697664..ff2bc7fe6bf1d 100644 --- a/tests/ui/drop/repeat-drop-2.stderr +++ b/tests/ui/drop/repeat-drop-2.stderr @@ -6,6 +6,10 @@ LL | const _: [String; 0] = [String::new(); 0]; | || | |the destructor for this type cannot be evaluated in constants | value is dropped here + | + = note: see issue #133214 for more information + = help: add `#![feature(const_destruct)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0382]: use of moved value: `foo` --> $DIR/repeat-drop-2.rs:4:17 diff --git a/tests/ui/mir/drop-elaboration-after-borrowck-error.stderr b/tests/ui/mir/drop-elaboration-after-borrowck-error.stderr index 22d05fa4ddab0..a3b8b97b3ac0c 100644 --- a/tests/ui/mir/drop-elaboration-after-borrowck-error.stderr +++ b/tests/ui/mir/drop-elaboration-after-borrowck-error.stderr @@ -6,6 +6,10 @@ LL | a[0] = String::new(); | | | the destructor for this type cannot be evaluated in statics | value is dropped here + | + = note: see issue #133214 for more information + = help: add `#![feature(const_destruct)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0493]: destructor of `[String; 1]` cannot be evaluated at compile-time --> $DIR/drop-elaboration-after-borrowck-error.rs:5:9 @@ -15,6 +19,10 @@ LL | let a: [String; 1]; ... LL | }; | - value is dropped here + | + = note: see issue #133214 for more information + = help: add `#![feature(const_destruct)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0493]: destructor of `T` cannot be evaluated at compile-time --> $DIR/drop-elaboration-after-borrowck-error.rs:17:9 diff --git a/tests/ui/traits/const-traits/const-closure-with-indestructible-indestructible.next.stderr b/tests/ui/traits/const-traits/const-closure-with-indestructible-indestructible.next.stderr index 8b5c4f59fbdee..62d9091c50b10 100644 --- a/tests/ui/traits/const-traits/const-closure-with-indestructible-indestructible.next.stderr +++ b/tests/ui/traits/const-traits/const-closure-with-indestructible-indestructible.next.stderr @@ -1,20 +1,20 @@ -error[E0277]: the trait bound `Vec: const Destruct` is not satisfied - --> $DIR/const-closure-with-indestructible-indestructible.rs:10:16 +error[E0277]: the trait bound `NotConstDestruct: const Destruct` is not satisfied + --> $DIR/const-closure-with-indestructible-indestructible.rs:18:16 | LL | i_need(const || { | _________------_^ | | | | | required by a bound introduced by this call LL | | -LL | | let y = v; +LL | | let y = n; LL | | }) | |_________^ | note: required by a bound in `i_need` - --> $DIR/const-closure-with-indestructible-indestructible.rs:5:20 + --> $DIR/const-closure-with-indestructible-indestructible.rs:13:20 | -LL | const fn i_need(x: F) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `i_need` +LL | const fn i_need(x: F) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `i_need` error: aborting due to 1 previous error diff --git a/tests/ui/traits/const-traits/const-closure-with-indestructible-indestructible.old.stderr b/tests/ui/traits/const-traits/const-closure-with-indestructible-indestructible.old.stderr index 8b5c4f59fbdee..62d9091c50b10 100644 --- a/tests/ui/traits/const-traits/const-closure-with-indestructible-indestructible.old.stderr +++ b/tests/ui/traits/const-traits/const-closure-with-indestructible-indestructible.old.stderr @@ -1,20 +1,20 @@ -error[E0277]: the trait bound `Vec: const Destruct` is not satisfied - --> $DIR/const-closure-with-indestructible-indestructible.rs:10:16 +error[E0277]: the trait bound `NotConstDestruct: const Destruct` is not satisfied + --> $DIR/const-closure-with-indestructible-indestructible.rs:18:16 | LL | i_need(const || { | _________------_^ | | | | | required by a bound introduced by this call LL | | -LL | | let y = v; +LL | | let y = n; LL | | }) | |_________^ | note: required by a bound in `i_need` - --> $DIR/const-closure-with-indestructible-indestructible.rs:5:20 + --> $DIR/const-closure-with-indestructible-indestructible.rs:13:20 | -LL | const fn i_need(x: F) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `i_need` +LL | const fn i_need(x: F) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `i_need` error: aborting due to 1 previous error diff --git a/tests/ui/traits/const-traits/const-closure-with-indestructible-indestructible.rs b/tests/ui/traits/const-traits/const-closure-with-indestructible-indestructible.rs index d26260dd2d078..c6dcd119347d4 100644 --- a/tests/ui/traits/const-traits/const-closure-with-indestructible-indestructible.rs +++ b/tests/ui/traits/const-traits/const-closure-with-indestructible-indestructible.rs @@ -2,14 +2,22 @@ //@ ignore-compare-mode-next-solver (explicit revisions) //@[next] compile-flags: -Znext-solver #![feature(const_trait_impl, const_closures, const_destruct)] -const fn i_need(x: F) {} + + +struct NotConstDestruct; + +impl Drop for NotConstDestruct { + fn drop(&mut self) {} +} + +const fn i_need(x: F) {} fn main() { const { - let v = Vec::::new(); + let n = NotConstDestruct; i_need(const || { //~^ ERROR the trait bound - let y = v; + let y = n; }) }; }