rust/tests/ui/sized-hierarchy/pointee-supertrait.rs
David Wood 86ab2b60cd
hir_analysis: add {Meta,Pointee}Sized bounds
Opting-out of `Sized` with `?Sized` is now equivalent to adding a
`MetaSized` bound, and adding a `MetaSized` or `PointeeSized` bound
is equivalent to removing the default `Sized` bound - this commit
implements this change in `rustc_hir_analysis::hir_ty_lowering`.

`MetaSized` is also added as a supertrait of all traits, as this is
necessary to preserve backwards compatibility.

Unfortunately, non-global where clauses being preferred over item bounds
(where `PointeeSized` bounds would be proven) - which can result in
errors when a `PointeeSized` supertrait/bound/predicate is added to some
items. Rather than `PointeeSized` being a bound on everything, it can
be the absence of a bound on everything, as `?Sized` was.
2025-06-16 23:04:33 +00:00

29 lines
660 B
Rust

//@ check-pass
#![feature(sized_hierarchy)]
// This is a reduction of some code in `library/core/src/cmp.rs` that would ICE if a default
// `Pointee` bound is added - motivating the current status quo of `PointeeSized` being syntactic
// sugar for an absense of any bounds whatsoever.
use std::marker::PhantomData;
pub trait Bar<'a> {
type Foo;
}
pub struct Foo<'a, T: Bar<'a>> {
phantom: PhantomData<&'a T>,
}
impl<'a, 'b, T> PartialEq<Foo<'b, T>> for Foo<'a, T>
where
T: for<'c> Bar<'c>,
<T as Bar<'a>>::Foo: PartialEq<<T as Bar<'b>>::Foo>,
{
fn eq(&self, _: &Foo<'b, T>) -> bool {
loop {}
}
}
fn main() { }