Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nightly Rust suggests .as_ref() on the left-hand side of the assignment #114925

Closed
GoldsteinE opened this issue Aug 17, 2023 · 5 comments · Fixed by #114931
Closed

Nightly Rust suggests .as_ref() on the left-hand side of the assignment #114925

GoldsteinE opened this issue Aug 17, 2023 · 5 comments · Fixed by #114931
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. P-medium Medium priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@GoldsteinE
Copy link
Contributor

GoldsteinE commented Aug 17, 2023

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.

@GoldsteinE GoldsteinE added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 17, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Aug 17, 2023
@fmease
Copy link
Member

fmease commented Aug 17, 2023

@rustbot label -needs-triage A-suggestion-diagnostics D-invalid-suggestion regression-from-stable-to-nightly E-needs-bisection

@rustbot rustbot added A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. E-needs-bisection Call for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. I-prioritize Issue: Indicates that prioritization has been requested for this issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Aug 17, 2023
@GoldsteinE
Copy link
Contributor Author

It’s not present in beta, so the left bound of the bisection is 1.72.0-beta.8 (2023-08-12 598a0a3). I’ll try to run it later today.

@Urgau
Copy link
Member

Urgau commented Aug 17, 2023

The regression most probably comes from #114052

@apiraino
Copy link
Contributor

I'm trying to bisect but cargo cargo-bisect dies on me :/ So far, I'm also seeing commit 18fa7b9 as probably culprit so #114052 seems to make sense

cc: @clubby789

@apiraino
Copy link
Contributor

WG-prioritization assigning priority (Zulip discussion).

@rustbot label -I-prioritize +P-medium -E-needs-bisection

@rustbot rustbot added P-medium Medium priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. E-needs-bisection Call for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc labels Aug 17, 2023
@bors bors closed this as completed in 5861815 Aug 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. P-medium Medium priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants