-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-trait-systemArea: Trait systemArea: Trait systemC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.
Description
Currently E277's message is confusing and seemingly ambiguous when it occurs on a try (?) expression (this may not be limited to E277, it's just the one I noticed). For example, in this code:
fn the_outer_method() -> Result<(), ()> {
the_inner_method()?;
Ok(())
}
fn the_inner_method() -> Result<(), bool> {
Err(true)
}error[E0277]: the trait bound `(): std::convert::From<bool>` is not satisfied
--> src/main.rs:6:5
|
6 | the_inner_method()?;
| ^^^^^^^^^^^^^^^^^^^ the trait `std::convert::From<bool>` is not implemented for `()`
|
= note: required by `std::convert::From::from`
The problem is that the_inner_method's error type is bool while the_outer_method's error type is (). In this case the error isn't too confusing, but if the try is in a chained expression (foo()?.bar()) and you're a noob it isn't clear why it wants std::convert::From<bool> implemented on ().
It doesn't necessarily even require a whole fix suggestion, all it would take is making the error only highlight the ?, as the issue is actually occuring when unwrapping the result.
error[E0277]: the trait bound `(): std::convert::From<bool>` is not satisfied
--> src/main.rs:6:5
|
6 | the_inner_method()?;
| ^ the trait `std::convert::From<bool>` is not implemented for `()`
|
= note: required by `std::convert::From::from`
Thanks!
scottmcm and kornelski
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-trait-systemArea: Trait systemArea: Trait systemC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.