-
Notifications
You must be signed in to change notification settings - Fork 13.7k
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
fn foo() -> Result<Option<String>, ()> {
todo!()
}
fn main() {
assert_eq!(Ok(Some("hi")), foo());
}
Current output
error[E0308]: mismatched types
--> src/main.rs:6:32
|
6 | assert_eq!(Ok(Some("hi")), foo());
| ^^^^^ expected `Result<Option<&str>, _>`, found `Result<Option<String>, ()>`
|
= note: expected enum `Result<Option<&str>, _>`
found enum `Result<Option<String>, ()>`
help: try wrapping the expression in `Err`
|
6 | assert_eq!(Ok(Some("hi")), Err(foo()));
| ++++ +
Desired output
error[E0308]: mismatched types
--> src/main.rs:6:32
|
6 | assert_eq!(Ok(Some("hi")), foo());
| ^^^^^ expected `Result<Option<&str>, _>`, found `Result<Option<String>, ()>`
|
= note: expected enum `Result<Option<&str>, _>`
-- or ideally:
help: try converting &str into String
|
6 | assert_eq!(Ok(Some("hi".into()), foo());
| +++++++
Rationale and extra context
No response
Other cases
Rust Version
nightly-2025-08-11
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.