-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-trait-systemArea: Trait systemArea: Trait systemC-bugCategory: This is a bug.Category: This is a bug.
Description
This code compiles fine until you'll uncomment BAssoc = ()
.
pub trait A {
type AAssoc: B</*BAssoc = ()*/>;
}
pub trait B
where
Self: Into<<Self as B>::BAssoc>
{
type BAssoc;
}
fn test<T: A>(x: T::AAssoc) -> <T::AAssoc as B>::BAssoc {
x.into()
}
With BAssoc = ()
the code fails to compile with the following error:
error[E0277]: the trait bound `(): From<<T as A>::AAssoc>` is not satisfied
--> src/lib.rs:13:5
|
5 | pub trait B
| - required by a bound in this
6 | where
7 | Self: Into<<Self as B>::BAssoc>
| ------------------------- required by this bound in `B`
...
13 | x.into()
| ^^^^^^^^ the trait `From<<T as A>::AAssoc>` is not implemented for `()`
|
= note: required because of the requirements on the impl of `Into<()>` for `<T as A>::AAssoc`
error[E0308]: mismatched types
--> src/lib.rs:13:5
|
12 | fn test<T: A>(x: T::AAssoc) -> <T::AAssoc as B>::BAssoc {
| ------------------------ expected `()` because of return type
13 | x.into()
| ^^^^^^^^- help: try adding a semicolon: `;`
| |
| expected `()`, found associated type
|
= note: expected unit type `()`
found associated type `<<T as A>::AAssoc as B>::BAssoc`
= help: consider constraining the associated type `<<T as A>::AAssoc as B>::BAssoc` to `()`
= note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html
That seems really weird - how making type less generic makes code that should work for any type fail?
Meta
Tested on stable 1.46.0
and 1.48.0
-nightly (2020-09-20 1fd5b9d)
Metadata
Metadata
Assignees
Labels
A-trait-systemArea: Trait systemArea: Trait systemC-bugCategory: This is a bug.Category: This is a bug.