- 
                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 lintsT-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
Code
pub fn foo() -> Result<String, ()> {
    let out: Result<(), ()> = Ok(());
    out
}Current output
Compiling playground v0.0.1 (/playground)
error[E0308]: mismatched types
 --> src/lib.rs:3:5
  |
1 | pub fn foo() -> Result<String, ()> {
  |                 ------------------ expected `Result<String, ()>` because of return type
2 |     let out: Result<(), ()> = Ok(());
3 |     out
  |     ^^^ expected `Result<String, ()>`, found `Result<(), ()>`
  |
  = note: expected enum `Result<String, _>`
             found enum `Result<(), _>`
help: use `?` to coerce and return an appropriate `Err`, and wrap the resulting value in `Ok` so the expression remains of type `Result`
  |
3 |     Ok(out?)
  |     +++   ++
For more information about this error, try `rustc --explain E0308`.
error: could not compile `playground` (lib) due to previous errorDesired output
Compiling playground v0.0.1 (/playground)
error[E0308]: mismatched types
 --> src/lib.rs:3:5
  |
1 | pub fn foo() -> Result<String, ()> {
  |                 ------------------ expected `Result<String, ()>` because of return type
2 |     let out: Result<(), ()> = Ok(());
3 |     out
  |     ^^^ expected `Result<String, ()>`, found `Result<(), ()>`
  |
  = note: expected enum `Result<String, _>`
             found enum `Result<(), _>`
For more information about this error, try `rustc --explain E0308`.
error: could not compile `playground` (lib) due to previous errorRationale and extra context
The suggestion is invalid
Other cases
No response
Anything else?
No response
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsT-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.