From bd44b632a84030138a5f0133fa2ae7ad30fe8266 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sun, 24 Nov 2024 00:30:16 +0000 Subject: [PATCH] Constify Drop and Destruct --- library/core/src/marker.rs | 1 + library/core/src/ops/drop.rs | 2 +- .../ui/consts/const-block-const-bound.stderr | 28 +--- tests/ui/consts/fn_trait_refs.stderr | 126 ++++-------------- tests/ui/consts/promoted-const-drop.rs | 1 - tests/ui/consts/promoted-const-drop.stderr | 15 +-- tests/ui/consts/promoted_const_call.stderr | 11 +- tests/ui/dropck/const_drop_is_valid.rs | 8 -- tests/ui/dropck/const_drop_is_valid.stderr | 31 ----- .../impl-trait/normalize-tait-in-const.stderr | 29 +--- .../const-traits/const-drop-bound.stderr | 56 +------- .../const-drop-fail-2.precise.stderr | 33 ++--- .../traits/const-traits/const-drop-fail-2.rs | 11 +- .../const-traits/const-drop-fail-2.stderr | 41 ------ .../const-drop-fail-2.stock.stderr | 33 ++--- .../const-drop-fail.precise.stderr | 69 +--------- .../ui/traits/const-traits/const-drop-fail.rs | 6 +- .../const-traits/const-drop-fail.stock.stderr | 50 ++++--- .../const-traits/const-drop.precise.stderr | 100 -------------- tests/ui/traits/const-traits/const-drop.rs | 7 +- .../const-traits/const-drop.stock.stderr | 100 -------------- tests/ui/traits/const-traits/issue-92111.rs | 5 +- .../ui/traits/const-traits/issue-92111.stderr | 25 ---- 23 files changed, 113 insertions(+), 675 deletions(-) delete mode 100644 tests/ui/dropck/const_drop_is_valid.rs delete mode 100644 tests/ui/dropck/const_drop_is_valid.stderr delete mode 100644 tests/ui/traits/const-traits/const-drop-fail-2.stderr delete mode 100644 tests/ui/traits/const-traits/const-drop.precise.stderr delete mode 100644 tests/ui/traits/const-traits/const-drop.stock.stderr delete mode 100644 tests/ui/traits/const-traits/issue-92111.stderr diff --git a/library/core/src/marker.rs b/library/core/src/marker.rs index acbad07746bb9..1620b949590d0 100644 --- a/library/core/src/marker.rs +++ b/library/core/src/marker.rs @@ -957,6 +957,7 @@ marker_impls! { #[lang = "destruct"] #[rustc_on_unimplemented(message = "can't drop `{Self}`", append_const_msg)] #[rustc_deny_explicit_impl(implement_via_object = false)] +#[cfg_attr(not(bootstrap), const_trait)] pub trait Destruct {} /// A marker for tuple types. diff --git a/library/core/src/ops/drop.rs b/library/core/src/ops/drop.rs index a6f63ad68d695..f3314364e5428 100644 --- a/library/core/src/ops/drop.rs +++ b/library/core/src/ops/drop.rs @@ -203,7 +203,7 @@ /// [nomicon]: ../../nomicon/phantom-data.html#an-exception-the-special-case-of-the-standard-library-and-its-unstable-may_dangle #[lang = "drop"] #[stable(feature = "rust1", since = "1.0.0")] -// FIXME(const_trait_impl) #[const_trait] +#[cfg_attr(not(bootstrap), const_trait)] pub trait Drop { /// Executes the destructor for this type. /// diff --git a/tests/ui/consts/const-block-const-bound.stderr b/tests/ui/consts/const-block-const-bound.stderr index 5e24959146b83..b2b2f62c58f27 100644 --- a/tests/ui/consts/const-block-const-bound.stderr +++ b/tests/ui/consts/const-block-const-bound.stderr @@ -1,25 +1,9 @@ -error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/const-block-const-bound.rs:8:15 +error[E0277]: the trait bound `UnconstDrop: const Destruct` is not satisfied + --> $DIR/const-block-const-bound.rs:18:9 | -LL | const fn f(x: T) {} - | ^^^^^^ +LL | f(UnconstDrop); + | ^^^^^^^^^^^^^^ -error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/const-block-const-bound.rs:8:15 - | -LL | const fn f(x: T) {} - | ^^^^^^ - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error[E0493]: destructor of `T` cannot be evaluated at compile-time - --> $DIR/const-block-const-bound.rs:8:32 - | -LL | const fn f(x: T) {} - | ^ - value is dropped here - | | - | the destructor for this type cannot be evaluated in constant functions - -error: aborting due to 3 previous errors +error: aborting due to 1 previous error -For more information about this error, try `rustc --explain E0493`. +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/consts/fn_trait_refs.stderr b/tests/ui/consts/fn_trait_refs.stderr index dc601fbe48897..108500217139e 100644 --- a/tests/ui/consts/fn_trait_refs.stderr +++ b/tests/ui/consts/fn_trait_refs.stderr @@ -16,12 +16,6 @@ error: `~const` can only be applied to `#[const_trait]` traits LL | T: ~const Fn<()> + ~const Destruct, | ^^^^^^ -error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/fn_trait_refs.rs:14:24 - | -LL | T: ~const Fn<()> + ~const Destruct, - | ^^^^^^ - error: `~const` can only be applied to `#[const_trait]` traits --> $DIR/fn_trait_refs.rs:14:8 | @@ -38,26 +32,12 @@ LL | T: ~const Fn<()> + ~const Destruct, | = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/fn_trait_refs.rs:14:24 - | -LL | T: ~const Fn<()> + ~const Destruct, - | ^^^^^^ - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - error: `~const` can only be applied to `#[const_trait]` traits --> $DIR/fn_trait_refs.rs:21:8 | LL | T: ~const FnMut<()> + ~const Destruct, | ^^^^^^ -error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/fn_trait_refs.rs:21:27 - | -LL | T: ~const FnMut<()> + ~const Destruct, - | ^^^^^^ - error: `~const` can only be applied to `#[const_trait]` traits --> $DIR/fn_trait_refs.rs:21:8 | @@ -74,14 +54,6 @@ LL | T: ~const FnMut<()> + ~const Destruct, | = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/fn_trait_refs.rs:21:27 - | -LL | T: ~const FnMut<()> + ~const Destruct, - | ^^^^^^ - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - error: `~const` can only be applied to `#[const_trait]` traits --> $DIR/fn_trait_refs.rs:28:8 | @@ -110,12 +82,6 @@ error: `~const` can only be applied to `#[const_trait]` traits LL | T: ~const Fn<()> + ~const Destruct, | ^^^^^^ -error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/fn_trait_refs.rs:35:24 - | -LL | T: ~const Fn<()> + ~const Destruct, - | ^^^^^^ - error: `~const` can only be applied to `#[const_trait]` traits --> $DIR/fn_trait_refs.rs:35:8 | @@ -132,26 +98,12 @@ LL | T: ~const Fn<()> + ~const Destruct, | = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/fn_trait_refs.rs:35:24 - | -LL | T: ~const Fn<()> + ~const Destruct, - | ^^^^^^ - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - error: `~const` can only be applied to `#[const_trait]` traits --> $DIR/fn_trait_refs.rs:49:8 | LL | T: ~const FnMut<()> + ~const Destruct, | ^^^^^^ -error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/fn_trait_refs.rs:49:27 - | -LL | T: ~const FnMut<()> + ~const Destruct, - | ^^^^^^ - error: `~const` can only be applied to `#[const_trait]` traits --> $DIR/fn_trait_refs.rs:49:8 | @@ -168,29 +120,35 @@ LL | T: ~const FnMut<()> + ~const Destruct, | = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/fn_trait_refs.rs:49:27 - | -LL | T: ~const FnMut<()> + ~const Destruct, - | ^^^^^^ +error[E0277]: the trait bound `fn() -> i32 {one}: const Destruct` is not satisfied + --> $DIR/fn_trait_refs.rs:70:24 | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` +LL | let test_one = test_fn(one); + | ^^^^^^^^^^^^ -error[E0015]: cannot call non-const operator in constants - --> $DIR/fn_trait_refs.rs:71:17 +error[E0277]: the trait bound `fn() -> i32 {two}: const Destruct` is not satisfied + --> $DIR/fn_trait_refs.rs:73:24 | -LL | assert!(test_one == (1, 1, 1)); - | ^^^^^^^^^^^^^^^^^^^^^ +LL | let test_two = test_fn_mut(two); + | ^^^^^^^^^^^^^^^^ + +error[E0277]: the trait bound `&T: ~const Destruct` is not satisfied + --> $DIR/fn_trait_refs.rs:39:9 | - = note: calls in constants are limited to constant functions, tuple structs and tuple variants +LL | tester_fn(&f), + | ^^^^^^^^^^^^^ -error[E0015]: cannot call non-const operator in constants - --> $DIR/fn_trait_refs.rs:74:17 +error[E0277]: the trait bound `&T: ~const Destruct` is not satisfied + --> $DIR/fn_trait_refs.rs:41:9 | -LL | assert!(test_two == (2, 2)); - | ^^^^^^^^^^^^^^^^^^ +LL | tester_fn_mut(&f), + | ^^^^^^^^^^^^^^^^^ + +error[E0277]: the trait bound `&mut T: ~const Destruct` is not satisfied + --> $DIR/fn_trait_refs.rs:53:9 | - = note: calls in constants are limited to constant functions, tuple structs and tuple variants +LL | tester_fn_mut(&mut f), + | ^^^^^^^^^^^^^^^^^^^^^ error[E0015]: cannot call non-const closure in constant functions --> $DIR/fn_trait_refs.rs:16:5 @@ -204,15 +162,6 @@ help: consider further restricting this bound LL | T: ~const Fn<()> + ~const Destruct + ~const Fn(), | +++++++++++++ -error[E0493]: destructor of `T` cannot be evaluated at compile-time - --> $DIR/fn_trait_refs.rs:12:23 - | -LL | const fn tester_fn(f: T) -> T::Output - | ^ the destructor for this type cannot be evaluated in constant functions -... -LL | } - | - value is dropped here - error[E0015]: cannot call non-const closure in constant functions --> $DIR/fn_trait_refs.rs:23:5 | @@ -225,15 +174,6 @@ help: consider further restricting this bound LL | T: ~const FnMut<()> + ~const Destruct + ~const FnMut(), | ++++++++++++++++ -error[E0493]: destructor of `T` cannot be evaluated at compile-time - --> $DIR/fn_trait_refs.rs:19:27 - | -LL | const fn tester_fn_mut(mut f: T) -> T::Output - | ^^^^^ the destructor for this type cannot be evaluated in constant functions -... -LL | } - | - value is dropped here - error[E0015]: cannot call non-const closure in constant functions --> $DIR/fn_trait_refs.rs:30:5 | @@ -246,25 +186,7 @@ help: consider further restricting this bound LL | T: ~const FnOnce<()> + ~const FnOnce(), | +++++++++++++++++ -error[E0493]: destructor of `T` cannot be evaluated at compile-time - --> $DIR/fn_trait_refs.rs:33:21 - | -LL | const fn test_fn(mut f: T) -> (T::Output, T::Output, T::Output) - | ^^^^^ the destructor for this type cannot be evaluated in constant functions -... -LL | } - | - value is dropped here - -error[E0493]: destructor of `T` cannot be evaluated at compile-time - --> $DIR/fn_trait_refs.rs:47:25 - | -LL | const fn test_fn_mut(mut f: T) -> (T::Output, T::Output) - | ^^^^^ the destructor for this type cannot be evaluated in constant functions -... -LL | } - | - value is dropped here - -error: aborting due to 34 previous errors +error: aborting due to 25 previous errors -Some errors have detailed explanations: E0015, E0493, E0635. +Some errors have detailed explanations: E0015, E0277, E0635. For more information about an error, try `rustc --explain E0015`. diff --git a/tests/ui/consts/promoted-const-drop.rs b/tests/ui/consts/promoted-const-drop.rs index c6ea0d0c924da..e09c30ea7857b 100644 --- a/tests/ui/consts/promoted-const-drop.rs +++ b/tests/ui/consts/promoted-const-drop.rs @@ -3,7 +3,6 @@ struct A(); impl const Drop for A { - //~^ ERROR const `impl` for trait `Drop` which is not marked with `#[const_trait]` fn drop(&mut self) {} } diff --git a/tests/ui/consts/promoted-const-drop.stderr b/tests/ui/consts/promoted-const-drop.stderr index e015f75620690..3f2182e7d4105 100644 --- a/tests/ui/consts/promoted-const-drop.stderr +++ b/tests/ui/consts/promoted-const-drop.stderr @@ -1,14 +1,5 @@ -error: const `impl` for trait `Drop` which is not marked with `#[const_trait]` - --> $DIR/promoted-const-drop.rs:5:12 - | -LL | impl const Drop for A { - | ^^^^ - | - = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const` - = note: adding a non-const method body in the future would be a breaking change - error[E0716]: temporary value dropped while borrowed - --> $DIR/promoted-const-drop.rs:13:26 + --> $DIR/promoted-const-drop.rs:12:26 | LL | let _: &'static A = &A(); | ---------- ^^^ creates a temporary value which is freed while still in use @@ -19,7 +10,7 @@ LL | } | - temporary value is freed at the end of this statement error[E0716]: temporary value dropped while borrowed - --> $DIR/promoted-const-drop.rs:14:28 + --> $DIR/promoted-const-drop.rs:13:28 | LL | let _: &'static [A] = &[C]; | ------------ ^^^ creates a temporary value which is freed while still in use @@ -28,6 +19,6 @@ LL | let _: &'static [A] = &[C]; LL | } | - temporary value is freed at the end of this statement -error: aborting due to 3 previous errors +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0716`. diff --git a/tests/ui/consts/promoted_const_call.stderr b/tests/ui/consts/promoted_const_call.stderr index 7a96b6e770582..dd70bb601c47d 100644 --- a/tests/ui/consts/promoted_const_call.stderr +++ b/tests/ui/consts/promoted_const_call.stderr @@ -1,12 +1,3 @@ -error: const `impl` for trait `Drop` which is not marked with `#[const_trait]` - --> $DIR/promoted_const_call.rs:6:12 - | -LL | impl const Drop for Panic { fn drop(&mut self) { panic!(); } } - | ^^^^ - | - = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const` - = note: adding a non-const method body in the future would be a breaking change - error[E0493]: destructor of `Panic` cannot be evaluated at compile-time --> $DIR/promoted_const_call.rs:10:30 | @@ -57,7 +48,7 @@ LL | let _: &'static _ = &&(Panic, 0).1; LL | } | - temporary value is freed at the end of this statement -error: aborting due to 6 previous errors +error: aborting due to 5 previous errors Some errors have detailed explanations: E0493, E0716. For more information about an error, try `rustc --explain E0493`. diff --git a/tests/ui/dropck/const_drop_is_valid.rs b/tests/ui/dropck/const_drop_is_valid.rs deleted file mode 100644 index 26ef2d61deb69..0000000000000 --- a/tests/ui/dropck/const_drop_is_valid.rs +++ /dev/null @@ -1,8 +0,0 @@ -struct A(); - -impl const Drop for A {} -//~^ ERROR: const trait impls are experimental -//~| const `impl` for trait `Drop` which is not marked with `#[const_trait]` -//~| not all trait items implemented, missing: `drop` - -fn main() {} diff --git a/tests/ui/dropck/const_drop_is_valid.stderr b/tests/ui/dropck/const_drop_is_valid.stderr deleted file mode 100644 index 5837e1623a170..0000000000000 --- a/tests/ui/dropck/const_drop_is_valid.stderr +++ /dev/null @@ -1,31 +0,0 @@ -error[E0658]: const trait impls are experimental - --> $DIR/const_drop_is_valid.rs:3:6 - | -LL | impl const Drop for A {} - | ^^^^^ - | - = note: see issue #67792 for more information - = help: add `#![feature(const_trait_impl)]` 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: const `impl` for trait `Drop` which is not marked with `#[const_trait]` - --> $DIR/const_drop_is_valid.rs:3:12 - | -LL | impl const Drop for A {} - | ^^^^ - | - = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const` - = note: adding a non-const method body in the future would be a breaking change - -error[E0046]: not all trait items implemented, missing: `drop` - --> $DIR/const_drop_is_valid.rs:3:1 - | -LL | impl const Drop for A {} - | ^^^^^^^^^^^^^^^^^^^^^ missing `drop` in implementation - | - = help: implement the missing item: `fn drop(&mut self) { todo!() }` - -error: aborting due to 3 previous errors - -Some errors have detailed explanations: E0046, E0658. -For more information about an error, try `rustc --explain E0046`. diff --git a/tests/ui/impl-trait/normalize-tait-in-const.stderr b/tests/ui/impl-trait/normalize-tait-in-const.stderr index f9142664f1b82..bb874cbe41b33 100644 --- a/tests/ui/impl-trait/normalize-tait-in-const.stderr +++ b/tests/ui/impl-trait/normalize-tait-in-const.stderr @@ -4,12 +4,6 @@ error: `~const` can only be applied to `#[const_trait]` traits LL | const fn with_positive ~const Fn(&'a Alias<'a>) + ~const Destruct>(fun: F) { | ^^^^^^ -error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/normalize-tait-in-const.rs:26:62 - | -LL | const fn with_positive ~const Fn(&'a Alias<'a>) + ~const Destruct>(fun: F) { - | ^^^^^^ - error: `~const` can only be applied to `#[const_trait]` traits --> $DIR/normalize-tait-in-const.rs:26:35 | @@ -18,13 +12,11 @@ LL | const fn with_positive ~const Fn(&'a Alias<'a>) + ~const Destruc | = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/normalize-tait-in-const.rs:26:62 - | -LL | const fn with_positive ~const Fn(&'a Alias<'a>) + ~const Destruct>(fun: F) { - | ^^^^^^ +error[E0277]: the trait bound `for<'a, 'b> fn(&'a foo::Alias<'b>) {foo}: const Destruct` is not satisfied + --> $DIR/normalize-tait-in-const.rs:33:5 | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` +LL | with_positive(foo); + | ^^^^^^^^^^^^^^^^^^ error[E0015]: cannot call non-const closure in constant functions --> $DIR/normalize-tait-in-const.rs:27:5 @@ -38,16 +30,7 @@ help: consider further restricting this bound LL | const fn with_positive ~const Fn(&'a Alias<'a>) + ~const Destruct + ~const Fn(&foo::Alias<'_>)>(fun: F) { | ++++++++++++++++++++++++++++ -error[E0493]: destructor of `F` cannot be evaluated at compile-time - --> $DIR/normalize-tait-in-const.rs:26:79 - | -LL | const fn with_positive ~const Fn(&'a Alias<'a>) + ~const Destruct>(fun: F) { - | ^^^ the destructor for this type cannot be evaluated in constant functions -LL | fun(filter_positive()); -LL | } - | - value is dropped here - -error: aborting due to 6 previous errors +error: aborting due to 4 previous errors -Some errors have detailed explanations: E0015, E0493. +Some errors have detailed explanations: E0015, E0277. For more information about an error, try `rustc --explain E0015`. diff --git a/tests/ui/traits/const-traits/const-drop-bound.stderr b/tests/ui/traits/const-traits/const-drop-bound.stderr index eba39f859af52..60718cc84c101 100644 --- a/tests/ui/traits/const-traits/const-drop-bound.stderr +++ b/tests/ui/traits/const-traits/const-drop-bound.stderr @@ -1,53 +1,9 @@ -error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/const-drop-bound.rs:9:61 +error[E0277]: the trait bound `Foo: ~const Destruct` is not satisfied + --> $DIR/const-drop-bound.rs:23:5 | -LL | const fn foo(res: Result) -> Option where E: ~const Destruct { - | ^^^^^^ +LL | foo(res) + | ^^^^^^^^ -error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/const-drop-bound.rs:9:61 - | -LL | const fn foo(res: Result) -> Option where E: ~const Destruct { - | ^^^^^^ - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/const-drop-bound.rs:20:8 - | -LL | T: ~const Destruct, - | ^^^^^^ - -error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/const-drop-bound.rs:21:8 - | -LL | E: ~const Destruct, - | ^^^^^^ - -error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/const-drop-bound.rs:20:8 - | -LL | T: ~const Destruct, - | ^^^^^^ - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/const-drop-bound.rs:21:8 - | -LL | E: ~const Destruct, - | ^^^^^^ - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error[E0493]: destructor of `E` cannot be evaluated at compile-time - --> $DIR/const-drop-bound.rs:12:13 - | -LL | Err(_e) => None, - | ^^ - value is dropped here - | | - | the destructor for this type cannot be evaluated in constant functions - -error: aborting due to 7 previous errors +error: aborting due to 1 previous error -For more information about this error, try `rustc --explain E0493`. +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/traits/const-traits/const-drop-fail-2.precise.stderr b/tests/ui/traits/const-traits/const-drop-fail-2.precise.stderr index 7529af9293d44..bb9966c7ec393 100644 --- a/tests/ui/traits/const-traits/const-drop-fail-2.precise.stderr +++ b/tests/ui/traits/const-traits/const-drop-fail-2.precise.stderr @@ -1,26 +1,13 @@ -error: const `impl` for trait `Drop` which is not marked with `#[const_trait]` - --> $DIR/const-drop-fail-2.rs:23:25 +error[E0277]: the trait bound `ConstDropImplWithBounds: const Destruct` is not satisfied + --> $DIR/const-drop-fail-2.rs:31:15 | -LL | impl const Drop for ConstDropImplWithBounds { - | ^^^^ - | - = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const` - = note: adding a non-const method body in the future would be a breaking change - -error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/const-drop-fail-2.rs:29:26 - | -LL | const fn check(_: T) {} - | ^^^^^^^^ - -error: const `impl` for trait `Drop` which is not marked with `#[const_trait]` - --> $DIR/const-drop-fail-2.rs:39:25 - | -LL | impl const Drop for ConstDropImplWithNonConstBounds { - | ^^^^ - | - = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const` - = note: adding a non-const method body in the future would be a breaking change +LL | const _: () = check::>( + | _______________^ +LL | | +LL | | ConstDropImplWithBounds(PhantomData) +LL | | ); + | |_^ -error: aborting due to 3 previous errors +error: aborting due to 1 previous error +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/traits/const-traits/const-drop-fail-2.rs b/tests/ui/traits/const-traits/const-drop-fail-2.rs index ed4faa95bd049..1bcc87e907037 100644 --- a/tests/ui/traits/const-traits/const-drop-fail-2.rs +++ b/tests/ui/traits/const-traits/const-drop-fail-2.rs @@ -1,6 +1,7 @@ -//@ known-bug: #110395 +//@ revisions: stock precise + #![feature(const_trait_impl, const_destruct)] -// #![cfg_attr(precise, feature(const_precise_live_drops))] +#![cfg_attr(precise, feature(const_precise_live_drops))] use std::marker::{Destruct, PhantomData}; @@ -19,9 +20,7 @@ impl A for NonTrivialDrop {} const fn check(_: T) {} - -/* FIXME(const_trait_impl) -struct ConstDropImplWithBounds(PhantomData); +struct ConstDropImplWithBounds(PhantomData); impl const Drop for ConstDropImplWithBounds { fn drop(&mut self) { @@ -30,9 +29,9 @@ impl const Drop for ConstDropImplWithBounds { } const _: () = check::>( + //~^ ERROR the trait bound ConstDropImplWithBounds(PhantomData) ); -*/ struct ConstDropImplWithNonConstBounds(PhantomData); diff --git a/tests/ui/traits/const-traits/const-drop-fail-2.stderr b/tests/ui/traits/const-traits/const-drop-fail-2.stderr deleted file mode 100644 index fde106599c236..0000000000000 --- a/tests/ui/traits/const-traits/const-drop-fail-2.stderr +++ /dev/null @@ -1,41 +0,0 @@ -error: const `impl` for trait `Drop` which is not marked with `#[const_trait]` - --> $DIR/const-drop-fail-2.rs:39:25 - | -LL | impl const Drop for ConstDropImplWithNonConstBounds { - | ^^^^ - | - = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const` - = note: adding a non-const method body in the future would be a breaking change - -error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/const-drop-fail-2.rs:20:19 - | -LL | const fn check(_: T) {} - | ^^^^^^ - -error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/const-drop-fail-2.rs:20:19 - | -LL | const fn check(_: T) {} - | ^^^^^^ - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error[E0277]: the trait bound `T: ~const A` is not satisfied - --> $DIR/const-drop-fail-2.rs:41:9 - | -LL | T::a(); - | ^^^^^^ - -error[E0493]: destructor of `T` cannot be evaluated at compile-time - --> $DIR/const-drop-fail-2.rs:20:36 - | -LL | const fn check(_: T) {} - | ^ - value is dropped here - | | - | the destructor for this type cannot be evaluated in constant functions - -error: aborting due to 5 previous errors - -Some errors have detailed explanations: E0277, E0493. -For more information about an error, try `rustc --explain E0277`. diff --git a/tests/ui/traits/const-traits/const-drop-fail-2.stock.stderr b/tests/ui/traits/const-traits/const-drop-fail-2.stock.stderr index 7529af9293d44..bb9966c7ec393 100644 --- a/tests/ui/traits/const-traits/const-drop-fail-2.stock.stderr +++ b/tests/ui/traits/const-traits/const-drop-fail-2.stock.stderr @@ -1,26 +1,13 @@ -error: const `impl` for trait `Drop` which is not marked with `#[const_trait]` - --> $DIR/const-drop-fail-2.rs:23:25 +error[E0277]: the trait bound `ConstDropImplWithBounds: const Destruct` is not satisfied + --> $DIR/const-drop-fail-2.rs:31:15 | -LL | impl const Drop for ConstDropImplWithBounds { - | ^^^^ - | - = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const` - = note: adding a non-const method body in the future would be a breaking change - -error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/const-drop-fail-2.rs:29:26 - | -LL | const fn check(_: T) {} - | ^^^^^^^^ - -error: const `impl` for trait `Drop` which is not marked with `#[const_trait]` - --> $DIR/const-drop-fail-2.rs:39:25 - | -LL | impl const Drop for ConstDropImplWithNonConstBounds { - | ^^^^ - | - = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const` - = note: adding a non-const method body in the future would be a breaking change +LL | const _: () = check::>( + | _______________^ +LL | | +LL | | ConstDropImplWithBounds(PhantomData) +LL | | ); + | |_^ -error: aborting due to 3 previous errors +error: aborting due to 1 previous error +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/traits/const-traits/const-drop-fail.precise.stderr b/tests/ui/traits/const-traits/const-drop-fail.precise.stderr index 91ca60b750d81..67e774fbd0597 100644 --- a/tests/ui/traits/const-traits/const-drop-fail.precise.stderr +++ b/tests/ui/traits/const-traits/const-drop-fail.precise.stderr @@ -1,47 +1,4 @@ -error: const `impl` for trait `Drop` which is not marked with `#[const_trait]` - --> $DIR/const-drop-fail.rs:19:12 - | -LL | impl const Drop for ConstImplWithDropGlue { - | ^^^^ - | - = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const` - = note: adding a non-const method body in the future would be a breaking change - -error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/const-drop-fail.rs:23:19 - | -LL | const fn check(_: T) {} - | ^^^^^^ - -error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/const-drop-fail.rs:23:19 - | -LL | const fn check(_: T) {} - | ^^^^^^ - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error[E0493]: destructor of `T` cannot be evaluated at compile-time - --> $DIR/const-drop-fail.rs:23:36 - | -LL | const fn check(_: T) {} - | ^ - value is dropped here - | | - | the destructor for this type cannot be evaluated in constant functions - -error[E0080]: evaluation of constant value failed - --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL - | - = note: calling non-const function `::drop` - | -note: inside `std::ptr::drop_in_place:: - shim(Some(NonTrivialDrop))` - --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL -note: inside `check::` - --> $DIR/const-drop-fail.rs:23:43 - | -LL | const fn check(_: T) {} - | ^ -note: inside `_` +error[E0277]: the trait bound `NonTrivialDrop: const Destruct` is not satisfied --> $DIR/const-drop-fail.rs:27:23 | LL | const _: () = check($exp); @@ -52,23 +9,10 @@ LL | | NonTrivialDrop, LL | | ConstImplWithDropGlue(NonTrivialDrop), LL | | } | |_- in this macro invocation + | = note: this error originates in the macro `check_all` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0080]: evaluation of constant value failed - --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL - | - = note: calling non-const function `::drop` - | -note: inside `std::ptr::drop_in_place:: - shim(Some(NonTrivialDrop))` - --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL -note: inside `std::ptr::drop_in_place:: - shim(Some(ConstImplWithDropGlue))` - --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL -note: inside `check::` - --> $DIR/const-drop-fail.rs:23:43 - | -LL | const fn check(_: T) {} - | ^ -note: inside `_` +error[E0277]: the trait bound `NonTrivialDrop: const Destruct` is not satisfied --> $DIR/const-drop-fail.rs:27:23 | LL | const _: () = check($exp); @@ -79,9 +23,10 @@ LL | | NonTrivialDrop, LL | | ConstImplWithDropGlue(NonTrivialDrop), LL | | } | |_- in this macro invocation + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` = note: this error originates in the macro `check_all` (in Nightly builds, run with -Z macro-backtrace for more info) -error: aborting due to 6 previous errors +error: aborting due to 2 previous errors -Some errors have detailed explanations: E0080, E0493. -For more information about an error, try `rustc --explain E0080`. +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/traits/const-traits/const-drop-fail.rs b/tests/ui/traits/const-traits/const-drop-fail.rs index c61afc0e17a3b..08435266e1f80 100644 --- a/tests/ui/traits/const-traits/const-drop-fail.rs +++ b/tests/ui/traits/const-traits/const-drop-fail.rs @@ -1,6 +1,6 @@ -//@ known-bug: #110395 - +//@ compile-flags: -Znext-solver //@ revisions: stock precise + #![feature(const_trait_impl, const_destruct)] #![cfg_attr(precise, feature(const_precise_live_drops))] @@ -25,6 +25,8 @@ const fn check(_: T) {} macro_rules! check_all { ($($exp:expr),*$(,)?) => {$( const _: () = check($exp); + //~^ ERROR the trait bound `NonTrivialDrop: const Destruct` is not satisfied + //~| ERROR the trait bound `NonTrivialDrop: const Destruct` is not satisfied )*}; } diff --git a/tests/ui/traits/const-traits/const-drop-fail.stock.stderr b/tests/ui/traits/const-traits/const-drop-fail.stock.stderr index 20dea28922b6a..67e774fbd0597 100644 --- a/tests/ui/traits/const-traits/const-drop-fail.stock.stderr +++ b/tests/ui/traits/const-traits/const-drop-fail.stock.stderr @@ -1,34 +1,32 @@ -error: const `impl` for trait `Drop` which is not marked with `#[const_trait]` - --> $DIR/const-drop-fail.rs:19:12 +error[E0277]: the trait bound `NonTrivialDrop: const Destruct` is not satisfied + --> $DIR/const-drop-fail.rs:27:23 | -LL | impl const Drop for ConstImplWithDropGlue { - | ^^^^ +LL | const _: () = check($exp); + | ^^^^^^^^^^^ +... +LL | / check_all! { +LL | | NonTrivialDrop, +LL | | ConstImplWithDropGlue(NonTrivialDrop), +LL | | } + | |_- in this macro invocation | - = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const` - = note: adding a non-const method body in the future would be a breaking change + = note: this error originates in the macro `check_all` (in Nightly builds, run with -Z macro-backtrace for more info) -error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/const-drop-fail.rs:23:19 +error[E0277]: the trait bound `NonTrivialDrop: const Destruct` is not satisfied + --> $DIR/const-drop-fail.rs:27:23 | -LL | const fn check(_: T) {} - | ^^^^^^ - -error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/const-drop-fail.rs:23:19 - | -LL | const fn check(_: T) {} - | ^^^^^^ +LL | const _: () = check($exp); + | ^^^^^^^^^^^ +... +LL | / check_all! { +LL | | NonTrivialDrop, +LL | | ConstImplWithDropGlue(NonTrivialDrop), +LL | | } + | |_- in this macro invocation | = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + = note: this error originates in the macro `check_all` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0493]: destructor of `T` cannot be evaluated at compile-time - --> $DIR/const-drop-fail.rs:23:36 - | -LL | const fn check(_: T) {} - | ^ - value is dropped here - | | - | the destructor for this type cannot be evaluated in constant functions - -error: aborting due to 4 previous errors +error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0493`. +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/traits/const-traits/const-drop.precise.stderr b/tests/ui/traits/const-traits/const-drop.precise.stderr deleted file mode 100644 index 51a66396c4b42..0000000000000 --- a/tests/ui/traits/const-traits/const-drop.precise.stderr +++ /dev/null @@ -1,100 +0,0 @@ -error: const `impl` for trait `Drop` which is not marked with `#[const_trait]` - --> $DIR/const-drop.rs:12:16 - | -LL | impl<'a> const Drop for S<'a> { - | ^^^^ - | - = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const` - = note: adding a non-const method body in the future would be a breaking change - -error: const `impl` for trait `Drop` which is not marked with `#[const_trait]` - --> $DIR/const-drop.rs:46:16 - | -LL | impl const Drop for ConstDrop { - | ^^^^ - | - = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const` - = note: adding a non-const method body in the future would be a breaking change - -error: const `impl` for trait `Drop` which is not marked with `#[const_trait]` - --> $DIR/const-drop.rs:67:37 - | -LL | impl const Drop for ConstDropWithBound { - | ^^^^ - | - = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const` - = note: adding a non-const method body in the future would be a breaking change - -error: const `impl` for trait `Drop` which is not marked with `#[const_trait]` - --> $DIR/const-drop.rs:75:30 - | -LL | impl const Drop for ConstDropWithNonconstBound { - | ^^^^ - | - = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const` - = note: adding a non-const method body in the future would be a breaking change - -error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/const-drop.rs:18:15 - | -LL | const fn a(_: T) {} - | ^^^^^^ - -error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/const-drop.rs:18:15 - | -LL | const fn a(_: T) {} - | ^^^^^^ - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error[E0277]: the trait bound `T: const SomeTrait` is not satisfied - --> $DIR/const-drop.rs:67:46 - | -LL | impl const Drop for ConstDropWithBound { - | ^^^^^^^^^^^^^^^^^^^^^ - | -note: required by a bound in `t::ConstDropWithBound` - --> $DIR/const-drop.rs:65:38 - | -LL | pub struct ConstDropWithBound(pub core::marker::PhantomData); - | ^^^^^ required by this bound in `ConstDropWithBound` - -error[E0277]: the trait bound `T: const SomeTrait` is not satisfied - --> $DIR/const-drop.rs:68:22 - | -LL | fn drop(&mut self) { - | ^^^^ - | -note: required by a bound in `t::ConstDropWithBound` - --> $DIR/const-drop.rs:65:38 - | -LL | pub struct ConstDropWithBound(pub core::marker::PhantomData); - | ^^^^^ required by this bound in `ConstDropWithBound` - -error[E0493]: destructor of `S<'_>` cannot be evaluated at compile-time - --> $DIR/const-drop.rs:23:13 - | -LL | let _ = S(&mut c); - | ^^^^^^^^^- value is dropped here - | | - | the destructor for this type cannot be evaluated in constant functions - -error[E0493]: destructor of `T` cannot be evaluated at compile-time - --> $DIR/const-drop.rs:18:32 - | -LL | const fn a(_: T) {} - | ^ - value is dropped here - | | - | the destructor for this type cannot be evaluated in constant functions - -error[E0277]: the trait bound `T: ~const SomeTrait` is not satisfied - --> $DIR/const-drop.rs:69:13 - | -LL | T::foo(); - | ^^^^^^^^ - -error: aborting due to 11 previous errors - -Some errors have detailed explanations: E0277, E0493. -For more information about an error, try `rustc --explain E0277`. diff --git a/tests/ui/traits/const-traits/const-drop.rs b/tests/ui/traits/const-traits/const-drop.rs index 8bf1dd68b5c0a..e2d87aeff47fb 100644 --- a/tests/ui/traits/const-traits/const-drop.rs +++ b/tests/ui/traits/const-traits/const-drop.rs @@ -1,6 +1,7 @@ -// FIXME run-pass -//@ known-bug: #110395 +//@ run-pass +//@ compile-flags: -Znext-solver //@ revisions: stock precise + #![feature(const_trait_impl, const_destruct)] #![feature(never_type)] #![cfg_attr(precise, feature(const_precise_live_drops))] @@ -64,7 +65,7 @@ mod t { pub struct ConstDropWithBound(pub core::marker::PhantomData); - impl const Drop for ConstDropWithBound { + impl const Drop for ConstDropWithBound { fn drop(&mut self) { T::foo(); } diff --git a/tests/ui/traits/const-traits/const-drop.stock.stderr b/tests/ui/traits/const-traits/const-drop.stock.stderr deleted file mode 100644 index 51a66396c4b42..0000000000000 --- a/tests/ui/traits/const-traits/const-drop.stock.stderr +++ /dev/null @@ -1,100 +0,0 @@ -error: const `impl` for trait `Drop` which is not marked with `#[const_trait]` - --> $DIR/const-drop.rs:12:16 - | -LL | impl<'a> const Drop for S<'a> { - | ^^^^ - | - = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const` - = note: adding a non-const method body in the future would be a breaking change - -error: const `impl` for trait `Drop` which is not marked with `#[const_trait]` - --> $DIR/const-drop.rs:46:16 - | -LL | impl const Drop for ConstDrop { - | ^^^^ - | - = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const` - = note: adding a non-const method body in the future would be a breaking change - -error: const `impl` for trait `Drop` which is not marked with `#[const_trait]` - --> $DIR/const-drop.rs:67:37 - | -LL | impl const Drop for ConstDropWithBound { - | ^^^^ - | - = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const` - = note: adding a non-const method body in the future would be a breaking change - -error: const `impl` for trait `Drop` which is not marked with `#[const_trait]` - --> $DIR/const-drop.rs:75:30 - | -LL | impl const Drop for ConstDropWithNonconstBound { - | ^^^^ - | - = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const` - = note: adding a non-const method body in the future would be a breaking change - -error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/const-drop.rs:18:15 - | -LL | const fn a(_: T) {} - | ^^^^^^ - -error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/const-drop.rs:18:15 - | -LL | const fn a(_: T) {} - | ^^^^^^ - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error[E0277]: the trait bound `T: const SomeTrait` is not satisfied - --> $DIR/const-drop.rs:67:46 - | -LL | impl const Drop for ConstDropWithBound { - | ^^^^^^^^^^^^^^^^^^^^^ - | -note: required by a bound in `t::ConstDropWithBound` - --> $DIR/const-drop.rs:65:38 - | -LL | pub struct ConstDropWithBound(pub core::marker::PhantomData); - | ^^^^^ required by this bound in `ConstDropWithBound` - -error[E0277]: the trait bound `T: const SomeTrait` is not satisfied - --> $DIR/const-drop.rs:68:22 - | -LL | fn drop(&mut self) { - | ^^^^ - | -note: required by a bound in `t::ConstDropWithBound` - --> $DIR/const-drop.rs:65:38 - | -LL | pub struct ConstDropWithBound(pub core::marker::PhantomData); - | ^^^^^ required by this bound in `ConstDropWithBound` - -error[E0493]: destructor of `S<'_>` cannot be evaluated at compile-time - --> $DIR/const-drop.rs:23:13 - | -LL | let _ = S(&mut c); - | ^^^^^^^^^- value is dropped here - | | - | the destructor for this type cannot be evaluated in constant functions - -error[E0493]: destructor of `T` cannot be evaluated at compile-time - --> $DIR/const-drop.rs:18:32 - | -LL | const fn a(_: T) {} - | ^ - value is dropped here - | | - | the destructor for this type cannot be evaluated in constant functions - -error[E0277]: the trait bound `T: ~const SomeTrait` is not satisfied - --> $DIR/const-drop.rs:69:13 - | -LL | T::foo(); - | ^^^^^^^^ - -error: aborting due to 11 previous errors - -Some errors have detailed explanations: E0277, E0493. -For more information about an error, try `rustc --explain E0277`. diff --git a/tests/ui/traits/const-traits/issue-92111.rs b/tests/ui/traits/const-traits/issue-92111.rs index 64bf0f20e91d6..c8db5cc9e7ad8 100644 --- a/tests/ui/traits/const-traits/issue-92111.rs +++ b/tests/ui/traits/const-traits/issue-92111.rs @@ -1,7 +1,4 @@ -// Regression test for #92111. -// -//@ known-bug: #110395 -// FIXME check-pass +//@ check-pass #![feature(const_trait_impl, const_destruct)] diff --git a/tests/ui/traits/const-traits/issue-92111.stderr b/tests/ui/traits/const-traits/issue-92111.stderr deleted file mode 100644 index 51c6a22b43b3d..0000000000000 --- a/tests/ui/traits/const-traits/issue-92111.stderr +++ /dev/null @@ -1,25 +0,0 @@ -error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/issue-92111.rs:20:15 - | -LL | const fn a(t: T) {} - | ^^^^^^ - -error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/issue-92111.rs:20:15 - | -LL | const fn a(t: T) {} - | ^^^^^^ - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error[E0493]: destructor of `T` cannot be evaluated at compile-time - --> $DIR/issue-92111.rs:20:32 - | -LL | const fn a(t: T) {} - | ^ - value is dropped here - | | - | the destructor for this type cannot be evaluated in constant functions - -error: aborting due to 3 previous errors - -For more information about this error, try `rustc --explain E0493`.