Open
Description
The diagnostics that check whether the concrete return type of an -> impl Trait
function meets the : Trait
bound should special-case the error when the concrete type is ()
to suggest removing the semicolon. Without this, the errors for a misplaced semicolon are misleading:
Without impl Trait
:
trait Bar {}
impl Bar for u8 {}
fn foo() -> u8 {
5;
}
error[E0308]: mismatched types
--> src/main.rs:3:16
|
3 | fn foo() -> u8 {
| ________________^
4 | | 5;
| | - help: consider removing this semicolon
5 | | }
| |_^ expected u8, found ()
|
= note: expected type `u8`
found type `()`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0308`.
error: Could not compile `playground`.
With impl Trait
:
trait Bar {}
impl Bar for u8 {}
fn foo() -> impl Bar {
5;
}
error[E0277]: the trait bound `(): Bar` is not satisfied
--> src/main.rs:3:13
|
3 | fn foo() -> impl Bar {
| ^^^^^^^^ the trait `Bar` is not implemented for `()`
|
= note: the return type of a function must have a statically known size
error: aborting due to previous error
For more information about this error, try `rustc --explain E0277`.
error: Could not compile `playground`.
Metadata
Metadata
Assignees
Labels
Area: Closures (`|…| { … }`)Area: Messages for errors, warnings, and lintsArea: Suggestions generated by the compiler applied by `cargo fix`Category: An issue proposing an enhancement or a PR with one.Call for participation: Hard difficulty. Experience needed to fix: A lot.Medium priorityRelevant to the compiler team, which will review and decide on the PR/issue.