Skip to content

.as_ref().map(|x| *x) is no longer warned #12142

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

Open
y21 opened this issue Jan 13, 2024 · 1 comment
Open

.as_ref().map(|x| *x) is no longer warned #12142

y21 opened this issue Jan 13, 2024 · 1 comment
Assignees
Labels
C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't

Comments

@y21
Copy link
Member

y21 commented Jan 13, 2024

Summary

We used to lint on Some(1).as_ref().map(|x| *x), but no longer do. The interaction between the two lints useless_asref and map_clone is important here.
Some more context (where this was found and probably for why this is): #12136 (comment).

Lint Name

map_clone / useless_asref

Reproducer

I tried this code:

fn main() {
  Some(1).as_ref().map(|x| *x);
  Some(1).as_ref().map(|&x| x);
}

I expected to see this happen:

warning: you are using an explicit closure for copying elements
 --> src/main.rs:2:3
  |
2 |   Some(1).as_ref().map(|x| *x);
  |   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `copied` method: `Some(1).as_ref().copied()`
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#map_clone
  = note: `#[warn(clippy::map_clone)]` on by default

warning: you are using an explicit closure for copying elements
 --> src/main.rs:3:3
  |
3 |   Some(1).as_ref().map(|&x| x);
  |   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `copied` method: `Some(1).as_ref().copied()`
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#map_clone

Instead, this happened:
no warnings

Version

commit a71211d0b52c01f1b37fe544e0e13fd1bdc31979 (Jan 12)
@y21 y21 added C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't labels Jan 13, 2024
@Jacherr
Copy link
Contributor

Jacherr commented Jun 2, 2024

@rustbot claim

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 I-false-negative Issue: The lint should have been triggered on code, but wasn't
Projects
None yet
Development

No branches or pull requests

2 participants