Skip to content

Commit 3a31f72

Browse files
authored
Unrolled build for #147708
Rollup merge of #147708 - clarfonthey:const-drop, r=oli-obk const `mem::drop` I'm putting this under the `const Destruct` feature flag since it doesn't really feel relevant to put it elsewhere… it's just an empty function body, so, it doesn't have any particular weirdness attached to it (unlike `drop_in_place`, for example). r? wg-const-eval
2 parents 57ef8d6 + 491bc50 commit 3a31f72

File tree

3 files changed

+35
-26
lines changed

3 files changed

+35
-26
lines changed

library/core/src/mem/mod.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#![stable(feature = "rust1", since = "1.0.0")]
77

88
use crate::alloc::Layout;
9-
use crate::marker::DiscriminantKind;
9+
use crate::marker::{Destruct, DiscriminantKind};
1010
use crate::panic::const_assert;
1111
use crate::{clone, cmp, fmt, hash, intrinsics, ptr};
1212

@@ -958,8 +958,13 @@ pub const fn replace<T>(dest: &mut T, src: T) -> T {
958958
/// [`RefCell`]: crate::cell::RefCell
959959
#[inline]
960960
#[stable(feature = "rust1", since = "1.0.0")]
961+
#[rustc_const_unstable(feature = "const_destruct", issue = "133214")]
961962
#[rustc_diagnostic_item = "mem_drop"]
962-
pub fn drop<T>(_x: T) {}
963+
pub const fn drop<T>(_x: T)
964+
where
965+
T: [const] Destruct,
966+
{
967+
}
963968

964969
/// Bitwise-copies a value.
965970
///

tests/ui/traits/next-solver/alias-bound-unsound.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
#![feature(trivial_bounds)]
66

7+
// we use identity instead of drop because the presence of [const] Destruct means that there
8+
// are additional bounds on the function, which result in additional errors
9+
use std::convert::identity;
10+
711
trait Foo {
812
type Item: Copy
913
where
@@ -21,7 +25,7 @@ impl Foo for () {
2125

2226
fn main() {
2327
let x = String::from("hello, world");
24-
drop(<() as Foo>::copy_me(&x));
28+
let _ = identity(<() as Foo>::copy_me(&x));
2529
//~^ ERROR overflow evaluating the requirement `String <: <() as Foo>::Item`
2630
//~| ERROR overflow evaluating the requirement `<() as Foo>::Item well-formed`
2731
//~| ERROR overflow evaluating the requirement `&<() as Foo>::Item well-formed`

tests/ui/traits/next-solver/alias-bound-unsound.stderr

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,62 @@
11
error[E0275]: overflow evaluating the requirement `String: Copy`
2-
--> $DIR/alias-bound-unsound.rs:18:38
2+
--> $DIR/alias-bound-unsound.rs:22:38
33
|
44
LL | type Item = String where String: Copy;
55
| ^^^^
66
|
77
note: the requirement `String: Copy` appears on the `impl`'s associated type `Item` but not on the corresponding trait's associated type
8-
--> $DIR/alias-bound-unsound.rs:8:10
8+
--> $DIR/alias-bound-unsound.rs:12:10
99
|
1010
LL | trait Foo {
1111
| --- in this trait
1212
LL | type Item: Copy
1313
| ^^^^ this trait's associated type doesn't have the requirement `String: Copy`
1414

1515
error[E0275]: overflow evaluating the requirement `String <: <() as Foo>::Item`
16-
--> $DIR/alias-bound-unsound.rs:24:31
16+
--> $DIR/alias-bound-unsound.rs:28:43
1717
|
18-
LL | drop(<() as Foo>::copy_me(&x));
19-
| ^^
18+
LL | let _ = identity(<() as Foo>::copy_me(&x));
19+
| ^^
2020

2121
error[E0275]: overflow evaluating the requirement `<() as Foo>::Item == _`
22-
--> $DIR/alias-bound-unsound.rs:24:10
22+
--> $DIR/alias-bound-unsound.rs:28:22
2323
|
24-
LL | drop(<() as Foo>::copy_me(&x));
25-
| ^^^^^^^^^^^^^^^^^^^^^^^^
24+
LL | let _ = identity(<() as Foo>::copy_me(&x));
25+
| ^^^^^^^^^^^^^^^^^^^^^^^^
2626

2727
error[E0275]: overflow evaluating the requirement `<() as Foo>::Item == _`
28-
--> $DIR/alias-bound-unsound.rs:24:10
28+
--> $DIR/alias-bound-unsound.rs:28:22
2929
|
30-
LL | drop(<() as Foo>::copy_me(&x));
31-
| ^^^^^^^^^^^^^^^^^^^^^^^^
30+
LL | let _ = identity(<() as Foo>::copy_me(&x));
31+
| ^^^^^^^^^^^^^^^^^^^^^^^^
3232
|
3333
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
3434

3535
error[E0275]: overflow evaluating the requirement `&<() as Foo>::Item well-formed`
36-
--> $DIR/alias-bound-unsound.rs:24:31
36+
--> $DIR/alias-bound-unsound.rs:28:43
3737
|
38-
LL | drop(<() as Foo>::copy_me(&x));
39-
| ^^
38+
LL | let _ = identity(<() as Foo>::copy_me(&x));
39+
| ^^
4040

4141
error[E0275]: overflow evaluating the requirement `<() as Foo>::Item well-formed`
42-
--> $DIR/alias-bound-unsound.rs:24:10
42+
--> $DIR/alias-bound-unsound.rs:28:22
4343
|
44-
LL | drop(<() as Foo>::copy_me(&x));
45-
| ^^^^^^^^^^^^^^^^^^^^^^^^
44+
LL | let _ = identity(<() as Foo>::copy_me(&x));
45+
| ^^^^^^^^^^^^^^^^^^^^^^^^
4646

4747
error[E0275]: overflow evaluating the requirement `<() as Foo>::Item == _`
48-
--> $DIR/alias-bound-unsound.rs:24:10
48+
--> $DIR/alias-bound-unsound.rs:28:22
4949
|
50-
LL | drop(<() as Foo>::copy_me(&x));
51-
| ^^^^^^^^^^^^^^^^^^^^^^^^
50+
LL | let _ = identity(<() as Foo>::copy_me(&x));
51+
| ^^^^^^^^^^^^^^^^^^^^^^^^
5252
|
5353
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
5454

5555
error[E0275]: overflow evaluating the requirement `<() as Foo>::Item == _`
56-
--> $DIR/alias-bound-unsound.rs:24:31
56+
--> $DIR/alias-bound-unsound.rs:28:43
5757
|
58-
LL | drop(<() as Foo>::copy_me(&x));
59-
| ^^
58+
LL | let _ = identity(<() as Foo>::copy_me(&x));
59+
| ^^
6060

6161
error: aborting due to 8 previous errors
6262

0 commit comments

Comments
 (0)