-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-closuresArea: Closures (`|…| { … }`)Area: Closures (`|…| { … }`)A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`Area: Suggestions generated by the compiler applied by `cargo fix`C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.E-hardCall for participation: Hard difficulty. Experience needed to fix: A lot.Call for participation: Hard difficulty. Experience needed to fix: A lot.P-mediumMedium priorityMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
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`.
runiq
Metadata
Metadata
Assignees
Labels
A-closuresArea: Closures (`|…| { … }`)Area: Closures (`|…| { … }`)A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`Area: Suggestions generated by the compiler applied by `cargo fix`C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.E-hardCall for participation: Hard difficulty. Experience needed to fix: A lot.Call for participation: Hard difficulty. Experience needed to fix: A lot.P-mediumMedium priorityMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.