Open
Description
Code
#![feature(specialization)]
trait Other<A> {}
trait MyTrait {
type T;
fn foo(self);
}
impl<X: Other<()>> MyTrait for X {
default type T = Self;
fn foo(self) {
let _: Self::T = self;
}
}
Current output
warning: the feature `specialization` is incomplete and may not be safe to use and/or cause compiler crashes
--> src/lib.rs:1:12
|
1 | #![feature(specialization)]
| ^^^^^^^^^^^^^^
|
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
= help: consider using `min_specialization` instead, which is more stable and complete
= note: `#[warn(incomplete_features)]` on by default
error[E0308]: mismatched types
--> src/lib.rs:13:20
|
10 | impl<X: Other<()>> MyTrait for X {
| - found this type parameter
...
13 | let _: Self::T = self;
| ------- ^^^^ expected associated type, found type parameter `X`
| |
| expected due to this
|
= note: expected associated type `<X as MyTrait>::T`
found type parameter `X`
help: consider further restricting this bound
|
10 | impl<X: Other<()><T = X>> MyTrait for X {
| +++++++
For more information about this error, try `rustc --explain E0308`.
warning: `playground` (lib) generated 1 warning
error: could not compile `playground` (lib) due to previous error; 1 warning emitted
Desired output
warning: the feature `specialization` is incomplete and may not be safe to use and/or cause compiler crashes
--> src/lib.rs:1:12
|
1 | #![feature(specialization)]
| ^^^^^^^^^^^^^^
|
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
= help: consider using `min_specialization` instead, which is more stable and complete
= note: `#[warn(incomplete_features)]` on by default
error[E0308]: mismatched types
--> src/lib.rs:13:20
|
10 | impl<X: Other<()>> MyTrait for X {
| - found this type parameter
...
13 | let _: Self::T = self;
| ------- ^^^^ expected associated type, found type parameter `X`
| |
| expected due to this
|
= note: expected associated type `<X as MyTrait>::T`
found type parameter `X`
help: consider further restricting this bound
|
10 | impl<X: Other<()> + MyTrait<T = X>> MyTrait for X {
| +++++++++++++++++
For more information about this error, try `rustc --explain E0308`.
warning: `playground` (lib) generated 1 warning
error: could not compile `playground` (lib) due to previous error; 1 warning emitted
Rationale and extra context
The compiler incorrectly handles specialized associated type bounds in diagnostic messages, which leads to certain incorrect help suggestions.
Other cases
// suggests `<X: <T = X>>` which is syntactically incorrect
#![feature(specialization)]
trait MyTrait {
type T;
fn foo(self);
}
impl<X> MyTrait for X {
default type T = Self;
fn foo(self) {
let _: Self::T = self;
}
}
// suggests `<X: Other<T = X>>` which is logically incorrect
#![feature(specialization)]
trait Other {}
trait MyTrait {
type T;
fn foo(self);
}
impl<X: Other> MyTrait for X {
default type T = Self;
fn foo(self) {
let _: Self::T = self;
}
}
Anything else?
No response