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

Issue with map(clone) on Option in latest nightly #12148

Closed
amircodota opened this issue Jan 14, 2024 · 5 comments · Fixed by rust-lang/rust#120345
Closed

Issue with map(clone) on Option in latest nightly #12148

amircodota opened this issue Jan 14, 2024 · 5 comments · Fixed by rust-lang/rust#120345
Labels
C-bug Category: Clippy is not doing the correct thing

Comments

@amircodota
Copy link

Summary

I'm getting many many clippy warnings in the latest nightly.

They all stem from the fact that I'm using the map method on an Option to invoke a clone method on some intenral part of the value, but not on the entire Option value. Clippy tells me to just clone the entire option variable.

Here are a few examples

warning: this call to `as_ref.map(...)` does nothing
  --> base/git_utils/src/git_stats.rs:98:24
   |
98 |             repo_name: git_url.as_ref().map(|git_url| git_url.name.clone()),
   |                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `git_url.clone()`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_asref
   = note: `#[warn(clippy::useless_asref)]` on by default
warning: this call to `as_ref.map(...)` does nothing
  --> shared/models_api_singleton/src/lib.rs:67:37
   |
67 |                 update_access_token(user_option.as_ref().map(|user| user.id_token.clone()));
   |                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `user_option.clone()`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_asref
   = note: `#[warn(clippy::useless_asref)]` on by default
warning: this call to `as_ref.map(...)` does nothing
   --> tabnine/lunar_connection/src/lib.rs:948:40
    |
948 |     if let Some(Some(log_file_path)) = process.as_ref().map(|p| p.log_file_path().clone()) {
    |                                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `process.clone()`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_asref
    = note: `#[warn(clippy::useless_asref)]` on by default

Reproducer

I tried this code:

<code>

I expected to see this happen:

Instead, this happened:

Version

cargo 1.77.0-nightly (84976cd69 2024-01-12)

Additional Labels

No response

@amircodota amircodota added the C-bug Category: Clippy is not doing the correct thing label Jan 14, 2024
@y21
Copy link
Member

y21 commented Jan 14, 2024

Duplicate of #12135. #12136 fixes this.

@nazar-pc
Copy link

I don't think it was fixed yet, still happening on latest nightly:

clippy 0.1.77 (25f8d01 2024-01-18)

@y21
Copy link
Member

y21 commented Jan 19, 2024

The fix is not in nightly yet. Clippy gets synced with upstream rust only every ~14 days, so it'll be in nightly on the 25th. (The fix was merged 5 days ago but the last sync was on the 11th)

@amircodota
Copy link
Author

Still happens to me on the latest nightly

@y21
Copy link
Member

y21 commented Jan 26, 2024

Upstream PR for the sync: rust-lang/rust#120345, looks like it didn't get merged in time to be in today's nightly. Once that PR is merged, it should be in the next day's nightly.

You can also verify that this is fixed by cloning the clippy repo locally and running cargo dev lint path/to/crate-or-workspace and see if the warning is still there.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 26, 2024
…Manishearth

Clippy subtree update

r? `@Manishearth`

Closes rust-lang/rust-clippy#12148
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Jan 26, 2024
Rollup merge of rust-lang#120345 - flip1995:clippy-subtree-update, r=Manishearth

Clippy subtree update

r? `@Manishearth`

Closes rust-lang/rust-clippy#12148
flip1995 pushed a commit to flip1995/rust-clippy that referenced this issue Feb 8, 2024
lnicola pushed a commit to lnicola/rust-analyzer that referenced this issue Apr 7, 2024
RalfJung pushed a commit to RalfJung/rust-analyzer that referenced this issue Apr 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants