Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions library/core/src/mem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#![stable(feature = "rust1", since = "1.0.0")]

use crate::alloc::Layout;
use crate::marker::DiscriminantKind;
use crate::marker::{Destruct, DiscriminantKind};
use crate::panic::const_assert;
use crate::{clone, cmp, fmt, hash, intrinsics, ptr};

Expand Down Expand Up @@ -958,8 +958,13 @@ pub const fn replace<T>(dest: &mut T, src: T) -> T {
/// [`RefCell`]: crate::cell::RefCell
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_destruct", issue = "133214")]
#[rustc_diagnostic_item = "mem_drop"]
pub fn drop<T>(_x: T) {}
pub const fn drop<T>(_x: T)
where
T: [const] Destruct,
{
}

/// Bitwise-copies a value.
///
Expand Down
6 changes: 5 additions & 1 deletion tests/ui/traits/next-solver/alias-bound-unsound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

#![feature(trivial_bounds)]

// we use identity instead of drop because the presence of [const] Destruct means that there
// are additional bounds on the function, which result in additional errors
use std::convert::identity;

trait Foo {
type Item: Copy
where
Expand All @@ -21,7 +25,7 @@ impl Foo for () {

fn main() {
let x = String::from("hello, world");
drop(<() as Foo>::copy_me(&x));
let _ = identity(<() as Foo>::copy_me(&x));
//~^ ERROR overflow evaluating the requirement `String <: <() as Foo>::Item`
//~| ERROR overflow evaluating the requirement `<() as Foo>::Item well-formed`
//~| ERROR overflow evaluating the requirement `&<() as Foo>::Item well-formed`
Expand Down
46 changes: 23 additions & 23 deletions tests/ui/traits/next-solver/alias-bound-unsound.stderr
Original file line number Diff line number Diff line change
@@ -1,62 +1,62 @@
error[E0275]: overflow evaluating the requirement `String: Copy`
--> $DIR/alias-bound-unsound.rs:18:38
--> $DIR/alias-bound-unsound.rs:22:38
|
LL | type Item = String where String: Copy;
| ^^^^
|
note: the requirement `String: Copy` appears on the `impl`'s associated type `Item` but not on the corresponding trait's associated type
--> $DIR/alias-bound-unsound.rs:8:10
--> $DIR/alias-bound-unsound.rs:12:10
|
LL | trait Foo {
| --- in this trait
LL | type Item: Copy
| ^^^^ this trait's associated type doesn't have the requirement `String: Copy`

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

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

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

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

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

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

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

error: aborting due to 8 previous errors

Expand Down
Loading