Skip to content
Open
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
6 changes: 5 additions & 1 deletion compiler/rustc_ty_utils/src/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,11 @@ fn unsizing_params_for_adt<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> DenseBitSe
// Ensure none of the other fields mention the parameters used
// in unsizing.
for field in prefix_fields {
for arg in tcx.type_of(field.did).instantiate_identity().walk() {
let field_ty = tcx.type_of(field.did).instantiate_identity();
if field_ty.is_phantom_data() {
continue;
}
for arg in field_ty.walk() {
if let Some(i) = maybe_unsizing_param_idx(arg) {
unsizing_params.remove(i);
}
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/marker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ pub trait PointeeSized {
/// - Structs `Foo<..., T1, ..., Tn, ...>` implement `Unsize<Foo<..., U1, ..., Un, ...>>`
/// where any number of (type and const) parameters may be changed if all of these conditions
/// are met:
/// - Only the last field of `Foo` has a type involving the parameters `T1`, ..., `Tn`.
/// - Other than `PhantomData<_>` fields, only the last field of `Foo` has a type involving the parameters `T1`, ..., `Tn`.
/// - All other parameters of the struct are equal.
/// - `Field<T1, ..., Tn>: Unsize<Field<U1, ..., Un>>`, where `Field<...>` stands for the actual
/// type of the struct's last field.
Expand Down
12 changes: 12 additions & 0 deletions tests/ui/traits/dispatch-from-dyn-invalid-impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,16 @@ where
{
}

struct Ptr<T: ?Sized>(Box<T>);

impl<'a, T: ?Sized, U: ?Sized> DispatchFromDyn<&'a Ptr<U>> for &'a Ptr<T> {}
//~^ ERROR conflicting implementations of trait `DispatchFromDyn<&Ptr<_>>` for type `&Ptr<_>`

struct Inner<T: ?Sized>(T);
#[repr(transparent)]
struct Outer<T: ?Sized>(PhantomData<T>, Inner<T>);

impl<'a, T: Unsize<U> + ?Sized, U: ?Sized> DispatchFromDyn<&'a Outer<U>> for &'a Outer<T> {}
//~^ ERROR conflicting implementations of trait `DispatchFromDyn<&Outer<_>>` for type `&Outer<_>`

fn main() {}
27 changes: 24 additions & 3 deletions tests/ui/traits/dispatch-from-dyn-invalid-impls.stderr
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
error[E0119]: conflicting implementations of trait `DispatchFromDyn<&Ptr<_>>` for type `&Ptr<_>`
--> $DIR/dispatch-from-dyn-invalid-impls.rs:73:1
|
LL | impl<'a, T: ?Sized, U: ?Sized> DispatchFromDyn<&'a Ptr<U>> for &'a Ptr<T> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: conflicting implementation in crate `core`:
- impl<'a, T, U> DispatchFromDyn<&'a U> for &'a T
where T: Unsize<U>, T: ?Sized, U: ?Sized;
= note: downstream crates may implement trait `std::marker::Unsize<std::boxed::Box<_>>` for type `std::boxed::Box<_>`

error[E0119]: conflicting implementations of trait `DispatchFromDyn<&Outer<_>>` for type `&Outer<_>`
--> $DIR/dispatch-from-dyn-invalid-impls.rs:80:1
|
LL | impl<'a, T: Unsize<U> + ?Sized, U: ?Sized> DispatchFromDyn<&'a Outer<U>> for &'a Outer<T> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: conflicting implementation in crate `core`:
- impl<'a, T, U> DispatchFromDyn<&'a U> for &'a T
where T: Unsize<U>, T: ?Sized, U: ?Sized;

error[E0378]: the trait `DispatchFromDyn` may only be implemented for structs containing the field being coerced, ZST fields with 1 byte alignment that don't mention type/const generics, and nothing else
--> $DIR/dispatch-from-dyn-invalid-impls.rs:19:1
|
Expand Down Expand Up @@ -54,7 +75,7 @@ LL | | T: Unsize<U>
|
= note: extra field `1` of type `OverAlignedZst` is not allowed

error: aborting due to 5 previous errors
error: aborting due to 7 previous errors

Some errors have detailed explanations: E0374, E0375, E0378.
For more information about an error, try `rustc --explain E0374`.
Some errors have detailed explanations: E0119, E0374, E0375, E0378.
For more information about an error, try `rustc --explain E0119`.
Loading