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
4 changes: 2 additions & 2 deletions library/core/src/ops/unsize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use crate::marker::{PointeeSized, Unsize};
/// [nomicon-coerce]: ../../nomicon/coercions.html
#[unstable(feature = "coerce_unsized", issue = "18598")]
#[lang = "coerce_unsized"]
pub trait CoerceUnsized<T: PointeeSized> {
pub trait CoerceUnsized<T: PointeeSized>: Sized {
// Empty.
}

Expand Down Expand Up @@ -116,7 +116,7 @@ impl<T: PointeeSized + Unsize<U>, U: PointeeSized> CoerceUnsized<*const U> for *
/// [^1]: Formerly known as *object safety*.
#[unstable(feature = "dispatch_from_dyn", issue = "none")]
#[lang = "dispatch_from_dyn"]
pub trait DispatchFromDyn<T> {
pub trait DispatchFromDyn<T>: Sized {
// Empty.
}

Expand Down
21 changes: 21 additions & 0 deletions tests/ui/self/arbitrary-self-types-dyn-receiver.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//@ run-pass
#![feature(arbitrary_self_types)]

use std::ops::Receiver;

trait Trait {
fn foo(self: &dyn Receiver<Target=Self>);
}

struct Thing;
impl Trait for Thing {
fn foo(self: &dyn Receiver<Target=Self>) {
println!("huh???");
}
}

fn main() {
let x = Box::new(Thing);
let y: &dyn Receiver<Target=Thing> = &x;
y.foo();
}
16 changes: 16 additions & 0 deletions tests/ui/traits/dyn-coerce-unsized-ice.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Regression test for:
// https://github.com/rust-lang/rust/issues/149094#issuecomment-4191071539
#![feature(coerce_unsized, unsized_fn_params)]
#![expect(internal_features)]

use std::ops::CoerceUnsized;

pub trait Trait {}

pub fn foo(x: dyn CoerceUnsized<*const dyn Trait>) -> *const dyn Trait {
//~^ ERROR: the trait `CoerceUnsized` is not dyn compatible [E0038]
x
//~^ ERROR: the size for values of type `(dyn CoerceUnsized<*const (dyn Trait + 'static)> + 'static)` cannot be known at compilation time [E0277]
}

fn main() {}
23 changes: 23 additions & 0 deletions tests/ui/traits/dyn-coerce-unsized-ice.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
error[E0038]: the trait `CoerceUnsized` is not dyn compatible
--> $DIR/dyn-coerce-unsized-ice.rs:10:15
|
LL | pub fn foo(x: dyn CoerceUnsized<*const dyn Trait>) -> *const dyn Trait {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `CoerceUnsized` is not dyn compatible
|
= note: the trait is not dyn compatible because it requires `Self: Sized`
= note: for a trait to be dyn compatible it needs to allow building a vtable
for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>

error[E0277]: the size for values of type `(dyn CoerceUnsized<*const (dyn Trait + 'static)> + 'static)` cannot be known at compilation time
--> $DIR/dyn-coerce-unsized-ice.rs:12:5
|
LL | x
| ^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `(dyn CoerceUnsized<*const (dyn Trait + 'static)> + 'static)`
= note: required for the cast from `(dyn CoerceUnsized<*const (dyn Trait + 'static)> + 'static)` to `*const (dyn Trait + 'static)`

error: aborting due to 2 previous errors

Some errors have detailed explanations: E0038, E0277.
For more information about an error, try `rustc --explain E0038`.
Loading