Closed
Description
Code
struct Lol {
x: Option<String>,
}
fn lmao(lol: &mut Lol, x: Option<&String>) {
lol.x = x.clone();
}
Current output
error[E0308]: mismatched types
--> src/lib.rs:6:13
|
6 | lol.x = x.clone();
| ----- ^^^^^^^^^ expected `Option<String>`, found `Option<&String>`
| |
| expected due to the type of this binding
|
= note: expected enum `Option<String>`
found enum `Option<&String>`
help: use `Option::as_ref` to convert `Option<String>` to `Option<&String>`
|
6 | lol.x.as_ref() = x.clone();
| +++++++++
For more information about this error, try `rustc --explain E0308`.
error: could not compile `playground` (lib) due to previous error
Desired output
error[E0308]: mismatched types
--> src/lib.rs:6:13
|
6 | lol.x = x.clone();
| ----- ^^^^^^^^^ expected `Option<String>`, found `Option<&String>`
| |
| expected due to the type of this binding
|
= note: expected enum `Option<String>`
found enum `Option<&String>`
help: use `Option::cloned` to clone the value inside the `Option`
|
6 | lol.x = x.clone().cloned();
| +++++++++
For more information about this error, try `rustc --explain E0308`.
error: could not compile `playground` (lib) due to previous error
Rationale and extra context
Playground link: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=6f5723a2dea54642823935b3683d3480
Anything else?
That’s a regression from stable to nightly. Playground’s stable (1.71.1) gives the desired output, but playground’s nightly (1.73.0-nightly (2023-08-16 07438b0)) does not.
Metadata
Metadata
Assignees
Labels
Area: Messages for errors, warnings, and lintsArea: Suggestions generated by the compiler applied by `cargo fix`Diagnostics: A structured suggestion resulting in incorrect code.Medium priorityRelevant to the compiler team, which will review and decide on the PR/issue.Performance or correctness regression from stable to nightly.