Skip to content

Commit

Permalink
Unrolled build for rust-lang#133402
Browse files Browse the repository at this point in the history
Rollup merge of rust-lang#133402 - compiler-errors:drop-and-destruct, r=lcnr

Constify `Drop` and `Destruct`

r? `@lcnr` or `@fee1-dead`
  • Loading branch information
rust-timer authored Nov 27, 2024
2 parents dd2837e + bd44b63 commit ca891c1
Show file tree
Hide file tree
Showing 23 changed files with 113 additions and 675 deletions.
1 change: 1 addition & 0 deletions library/core/src/marker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/ops/drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down
28 changes: 6 additions & 22 deletions tests/ui/consts/const-block-const-bound.stderr
Original file line number Diff line number Diff line change
@@ -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<T: ~const Destruct>(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<T: ~const Destruct>(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<T: ~const Destruct>(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`.
126 changes: 24 additions & 102 deletions tests/ui/consts/fn_trait_refs.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
|
Expand All @@ -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
|
Expand All @@ -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
|
Expand Down Expand Up @@ -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
|
Expand All @@ -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
|
Expand All @@ -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
Expand All @@ -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<T>(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
|
Expand All @@ -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<T>(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
|
Expand All @@ -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<T>(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<T>(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`.
1 change: 0 additions & 1 deletion tests/ui/consts/promoted-const-drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
}

Expand Down
15 changes: 3 additions & 12 deletions tests/ui/consts/promoted-const-drop.stderr
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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`.
11 changes: 1 addition & 10 deletions tests/ui/consts/promoted_const_call.stderr
Original file line number Diff line number Diff line change
@@ -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
|
Expand Down Expand Up @@ -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`.
8 changes: 0 additions & 8 deletions tests/ui/dropck/const_drop_is_valid.rs

This file was deleted.

31 changes: 0 additions & 31 deletions tests/ui/dropck/const_drop_is_valid.stderr

This file was deleted.

Loading

0 comments on commit ca891c1

Please sign in to comment.