-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Suggest {Option,Result}::as_ref()
instead of cloned()
in some cases
#114052
Conversation
r? @jackh726 (rustbot has picked a reviewer for you, use r? to override) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, what happens in a &mut
case?
The original code explicitly checks for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
r=me with nits applied (namely method/closure rename and an added // run-rustfix
)
64630f7
to
c83dfe9
Compare
@bors r=WaffleLapkin |
…iaskrgr Rollup of 7 pull requests Successful merges: - rust-lang#114008 (coverage: Obtain the `__llvm_covfun` section name outside a per-function loop) - rust-lang#114014 (builtin_macros: expect raw strings too) - rust-lang#114043 (docs(LazyLock): add example pass local LazyLock variable to struct) - rust-lang#114051 (Add regression test for invalid "unused const" in method) - rust-lang#114052 (Suggest `{Option,Result}::as_ref()` instead of `cloned()` in some cases) - rust-lang#114058 (Add help for crate arg when crate name is invalid) - rust-lang#114060 (abi: unsized field in union - assert to delay bug ) r? `@ghost` `@rustbot` modify labels: rollup
Looking into handling fn main() {
let mut s = String::new();
let x = Some(s.clone());
let y = Some(&mut s);
println!("{}", x == y);
} must become fn main() {
let mut s = String::new();
let x = Some(s.clone());
let y = Some(&mut s);
println!("{}", x.as_ref() == y.as_deref());
} |
@clubby789 it can be simple for |
…ion, r=WaffleLapkin Refactor + improve diagnostics for `&mut T`/`T` mismatch inside Option/Result Follow up to rust-lang#114052. This also makes the diagnostics structured + translatable. r? `@WaffleLapkin`
…iaskrgr Rollup of 7 pull requests Successful merges: - rust-lang#114008 (coverage: Obtain the `__llvm_covfun` section name outside a per-function loop) - rust-lang#114014 (builtin_macros: expect raw strings too) - rust-lang#114043 (docs(LazyLock): add example pass local LazyLock variable to struct) - rust-lang#114051 (Add regression test for invalid "unused const" in method) - rust-lang#114052 (Suggest `{Option,Result}::as_ref()` instead of `cloned()` in some cases) - rust-lang#114058 (Add help for crate arg when crate name is invalid) - rust-lang#114060 (abi: unsized field in union - assert to delay bug ) r? `@ghost` `@rustbot` modify labels: rollup
…rors Revert PR rust-lang#114052 to fix invalid suggestion This PR reverts rust-lang#114052 to fix the invalid suggestion produced by the PR. Unfortunately the invalid suggestion cannot be improved from the current position where it's emitted since we lack enough information (is an assignment?, left or right?, ...) to be able to fix it here. Furthermore the previous wasn't wrong, just suboptimal, contrary to the current one which is just wrong. Added a regression test and commented out some code instead of removing it so we can use it later. Reopens rust-lang#114050 Fixes rust-lang#114925
Rollup of 5 pull requests Successful merges: - rust-lang#113715 (Unstable Book: update `lang_items` page and split it) - rust-lang#114897 (Partially revert rust-lang#107200) - rust-lang#114913 (Fix suggestion for attempting to define a string with single quotes) - rust-lang#114931 (Revert PR rust-lang#114052 to fix invalid suggestion) - rust-lang#114944 (update `thiserror` to version >= 1.0.46) r? `@ghost` `@rustbot` modify labels: rollup
Fixes #114050
When we have an expr available that produces the type expectation, we can suggest appending
.as_ref()
to the span, instead of cloning the expr producing the mismatch