Redundant Bound breaks const-generics Builders
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.2k
- PR merge metrics
- PR metrics pending
Description
The following code produces 3 errors (at the bottom in the impl of Foo):
pub trait Builder {
type Wrapped;
// in my project this wraps something but that isn't needed for the bug
fn wrap(&self, inner: ()) -> Self::Wrapped;
}
pub trait BuilderUnion<T: Builder>: Builder {
type Union: Builder;
fn union(self, other: T) -> Self::Union;
}
pub struct WrapperBuilder<const D: usize>;
impl<const D: usize> Builder for WrapperBuilder<D> {
type Wrapped = Wrapper<D>;
fn wrap(&self, _: ()) -> Self::Wrapped {
Wrapper()
}
}
impl<const D: usize> BuilderUnion<WrapperBuilder<D>> for WrapperBuilder<D> {
type Union = Self;
fn union(self, _: WrapperBuilder<D>) -> Self::Union {
self
}
}
// in my project this wraps something but that isn't needed for the bug
pub struct Wrapper<const D: usize>();
pub trait Bar {
fn is_bar(&self) -> () {}
}
impl<const D: usize> Bar for Wrapper<D> {}
pub trait Foo<T> {
fn foo(self, rhs: T);
}
impl<const D: usize> Foo<WrapperBuilder<D>> for WrapperBuilder<D>
where
Self: BuilderUnion<Self>,
{
// the error is here, each `is_bar` produces an error because Rust doesn't think Bar is impl'd
fn foo(self, rhs: WrapperBuilder<D>) {
(self).wrap(()).is_bar();
(rhs).wrap(()).is_bar();
(self.union(rhs)).wrap(()).is_bar();
}
}
I expected to see this happen: No errors produced
Instead, this happened: 1 error produced for each is_bar call because the type doesn't implement Bar (even though it does because it is ultimately just Wrapper<D>)
Extra Notes:
- removing the
Self: BuilderUnion<Self>bound causes it to function correctly (even though its true in both cases and irrelevent to the first 2 calls) - removing the const generics causes it to function correctly
Meta
rustc --version --verbose:
rustc 1.93.0 (254b59607 2026-01-19)
binary: rustc
commit-hash: 254b59607d4417e9dffbc307138ae5c86280fe4c
commit-date: 2026-01-19
host: aarch64-apple-darwin
release: 1.93.0
LLVM version: 21.1.8
(also fails on rustc 1.95.0-nightly (e96bb7e44 2026-01-27))
Backtrace
Compiling bug_tests v0.1.0 ([...]/bug_tests)
error[E0599]: no method named `is_bar` found for associated type `<WrapperBuilder<D> as Builder>::Wrapped` in the current scope
--> src/lib.rs:49:25
|
49 | (self).wrap(()).is_bar();
| ^^^^^^ method not found in `<WrapperBuilder<D> as Builder>::Wrapped`
|
= help: items from traits can only be used if the trait is implemented and in scope
note: `Bar` defines an item `is_bar`, perhaps you need to implement it
--> src/lib.rs:34:1
|
34 | pub trait Bar {
| ^^^^^^^^^^^^^
error[E0599]: no method named `is_bar` found for associated type `<WrapperBuilder<D> as Builder>::Wrapped` in the current scope
--> src/lib.rs:50:24
|
50 | (rhs).wrap(()).is_bar();
| ^^^^^^ method not found in `<WrapperBuilder<D> as Builder>::Wrapped`
|
= help: items from traits can only be used if the trait is implemented and in scope
note: `Bar` defines an item `is_bar`, perhaps you need to implement it
--> src/lib.rs:34:1
|
34 | pub trait Bar {
| ^^^^^^^^^^^^^
error[E0599]: no method named `is_bar` found for associated type `<<WrapperBuilder<D> as BuilderUnion<WrapperBuilder<D>>>::Union as Builder>::Wrapped` in the current scope
--> src/lib.rs:51:36
|
51 | (self.union(rhs)).wrap(()).is_bar();
| ^^^^^^ method not found in `<<WrapperBuilder<D> as BuilderUnion<WrapperBuilder<D>>>::Union as Builder>::Wrapped`
|
= help: items from traits can only be used if the trait is implemented and in scope
note: `Bar` defines an item `is_bar`, perhaps you need to implement it
--> src/lib.rs:34:1
|
34 | pub trait Bar {
| ^^^^^^^^^^^^^
For more information about this error, try `rustc --explain E0599`.
error: could not compile `bug_tests` (lib) due to 3 previous errors
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue from the provided example in src/lib.rs using the reported rustc versions, focusing on the three is_bar calls in Foo. Compare behavior with and without the Self: BuilderUnion bound and with const generics removed; done means the reproducer compiles without errors and has regression coverage for the original case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100