Code
#[diagnostic::on_unimplemented(message = "Very important message!")]
trait TheImportantOne {}
trait ImplementationDetail {
type Restriction;
}
impl<T: ImplementationDetail<Restriction = ()>> TheImportantOne for T {}
// Comment out this `impl` to show the expected error message.
impl ImplementationDetail for u8 {
type Restriction = u8;
}
fn verify<T: TheImportantOne>() {}
pub fn main() {
verify::<u8>();
}
Current output
error[E0271]: type mismatch resolving `<u8 as ImplementationDetail>::Restriction == ()`
--> src/main.rs:18:14
|
18 | verify::<u8>();
| ^^ type mismatch resolving `<u8 as ImplementationDetail>::Restriction == ()`
|
note: expected this to be `()`
--> src/main.rs:12:24
|
12 | type Restriction = u8;
| ^^
note: required for `u8` to implement `TheImportantOne`
--> src/main.rs:8:49
|
8 | impl<T: ImplementationDetail<Restriction = ()>> TheImportantOne for T {}
| ---------------- ^^^^^^^^^^^^^^^ ^
| |
| unsatisfied trait bound introduced here
note: required by a bound in `verify`
--> src/main.rs:15:14
|
15 | fn verify<T: TheImportantOne>() {}
| ^^^^^^^^^^^^^^^ required by this bound in `verify`
For more information about this error, try `rustc --explain E0271`.
Desired output
The "Very important message!" should be shown somewhere in the output (similar to what is shown if impl ImplementationDetail for u8 is missing entirely).
Rationale and extra context
The fundamental error is required for `u8` to implement `TheImportantOne` in both cases (impl ImplementationDetail for u8 completely missing and impl ImplementationDetail for u8 having the wrong Restriction type). As such, I would expect the on_unimplemented message to display in both cases.
Other cases
No response
Rust Version
Playground nightly (`1.80.0-nightly (2024-05-16 8c127df75fde3d5ad8ef)`) and stable (`1.78.0`).
Anything else?
No response
Code
Current output
Desired output
The "Very important message!" should be shown somewhere in the output (similar to what is shown if
impl ImplementationDetail for u8is missing entirely).Rationale and extra context
The fundamental error is
required for `u8` to implement `TheImportantOne`in both cases (impl ImplementationDetail for u8completely missing andimpl ImplementationDetail for u8having the wrongRestrictiontype). As such, I would expect theon_unimplementedmessage to display in both cases.Other cases
No response
Rust Version
Anything else?
No response