Closed
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 error
Desired 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 error
Rationale and extra context
The suggestion is invalid
Other cases
No response
Anything else?
No response