Closed
Description
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