Open
Description
When using crate-local traits with type parameters, it seems rust incorrectly thinks that downstream crates may implement the trait (which we know to be impossible as the traits are crate-local).
See this playground.
Also captured here for readability:
pub(crate) struct DummyCtx {}
pub(crate) trait FooContext<C> {}
trait LocalTrait {}
pub(crate) trait BarContext<C>: LocalTrait {}
impl<C> FooContext<C> for DummyCtx {}
// Doesn't work:
impl<C: BarContext<F>, F> FooContext<F> for C {}
// Works:
// impl<C: BarContext<F> + LocalTrait, F> FooContext<F> for C {}
Expected both impls to compile but only the impl that restricts C
to LocalTrait
compiles even though BarContext<F>
is a supertrait over LocalTrait
which (IIUC) makes the LocalTrait
restriction in C: BarContext<F> + LocalTrait
redundant.
Meta
Can observe failure on 2021 edition stable (see rust playground link)
This playground is another example of this but without a LocalTrait
.
Note that using crate-local traits without any type parameters work just fine playground.