"downstream crates may implement trait" error for private type
⚓ Rust 📅 2026-03-20 👤 surdeus 👁️ 4I'm struggling to understand a "downstream crates may implement trait" error that reduces to the following example (playground):
/// Some trait dependent on a tuple of arguments.
pub trait Foo<Args> {}
/// Blanket implementation for async closures.
impl<F, Args> Foo<Args> for F
where
Args: Tuple,
F: AsyncFnOnce<Args>,
{
}
/// We also define our own private struct that implements the trait.
struct Bar {}
impl<Args> Foo<Args> for Bar where Args: Tuple {}
error[E0119]: conflicting implementations of trait `Foo<_>` for type `Bar`
--> src/lib.rs:22:1
|
11 | / impl<F, Args> Foo<Args> for F
12 | | where
13 | | Args: Tuple,
14 | | F: AsyncFnOnce<Args>,
| |_________________________- first implementation here
...
22 | impl<Args> Foo<Args> for Bar where Args: Tuple {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `Bar`
|
= note: downstream crates may implement trait `std::ops::AsyncFnOnce<_>` for type `Bar`
It's not true that downstream crates can implement AsyncFnOnce for Bar, right? They can't mention that type, which is private, and even if they could it is not a local type for them so they shouldn't be able to implement AsyncFnOnce for it.
How do I make this work? I feel like I should be able to use sealed traits, even though that seems like it should be unnecessary, but I can't find an arrangement that works.
3 posts - 3 participants
🏷️ Rust_feed