-
Couldn't load subscription status.
- Fork 13.9k
Description
related to rust-lang/trait-system-refactor-initiative#173, see added tests in #139789
trait Trait {
// desugars to
// type Assoc: Sized + Send;
// fn foo(b: bool) -> Self::Assoc;
fn foo(b: bool) -> impl Sized + Send;
}
impl Trait for u32 {
// desugars to
// type Assoc = impl_rpit::<Self>;
// fn foo(b: bool) -> Self::Assoc { .. }
fn foo(b: bool) -> impl Sized {
if b {
u32::foo(false)
} else {
1u32
}
}
}This currently results in a query cycle:
type_of(impl::Assoc)collect_return_position_impl_trait_in_trait_tysimpl_rpit: Sendtype_of(impl_rpit)// auto trait leakagetypeck(impl::foo)normalize(<u32 as Trait>::Assoc)type_of(impl::Assoc)
I believe that this query cycle should not be there and can be avoided.
collect_return_position_impl_trait_in_trait_tys currently adds the item bounds of the RPITIT when replacing it with fresh infer vars. I believe this is not necessary to guide inference as the method signature is fully concrete.
We could therefore split this in two:
collect_return_position_impl_trait_in_trait_tysinstantiates RPITIT with infer vars but does not check the item bounds of the RPITIT trait assoc typecompare_type_predicate_entailment(or a separate query, idk and idc :3) then usescollect_return_position_impl_trait_in_trait_tysand actually checks the item bounds
This means normalizing impl::Assoc no longer has to prove the item bounds of the RPITIT, allowing the above example to compile and fixing rust-lang/trait-system-refactor-initiative#173