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

Errorneous suggestion with map + Arc::clone of custom expression #12560

Open
ProgramCrafter opened this issue Mar 25, 2024 · 0 comments · May be fixed by #12647
Open

Errorneous suggestion with map + Arc::clone of custom expression #12560

ProgramCrafter opened this issue Mar 25, 2024 · 0 comments · May be fixed by #12647
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@ProgramCrafter
Copy link

Summary

Clippy didn't recognize that .cloned() method will have behaviour different from existing map + Arc::clone. It seems that it interpreted Arc::clone(&t.track) as Arc::clone(t).

Lint Name

clippy::map_clone

Reproducer

I tried to run Clippy on webrtc-rs repository. It created a false positive result (full log).

The following errors were reported:
error[E0308]: mismatched types
   --> webrtc\src\rtp_transceiver\rtp_receiver\mod.rs:496:13
    |
496 |             tracks.first().cloned()
    |             ^^^^^^^^^^^^^^^^^^^^^^^ expected `Option<Arc<TrackRemote>>`, found `Option<TrackStreams>`
    |
    = note: expected enum `std::option::Option<std::sync::Arc<track::track_remote::TrackRemote>>`
               found enum `std::option::Option<track::TrackStreams>`

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0308`.
Original diagnostics will follow.

warning: you are explicitly cloning with `.map()`
   --> webrtc\src\rtp_transceiver\rtp_receiver\mod.rs:496:13
    |
496 |             tracks.first().map(|t| Arc::clone(&t.track))
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `cloned` method: `tracks.first().cloned()`
    |
    = 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 explicitly cloning with `.map()`
   --> webrtc\src\rtp_transceiver\mod.rs:304:9
    |
304 |         self.mid.get().map(Clone::clone)
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `cloned` method: `self.mid.get().cloned()`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#map_clone

Version

rustc 1.77.0 (aedd173a2 2024-03-17)
binary: rustc
commit-hash: aedd173a2c086e558c2b66d3743b344f977621a7
commit-date: 2024-03-17
host: x86_64-pc-windows-msvc
release: 1.77.0
LLVM version: 17.0.6

Additional Labels

@rustbot label +l-suggestion-causes-error

@ProgramCrafter ProgramCrafter added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Mar 25, 2024
@GuillaumeGomez GuillaumeGomez linked a pull request Apr 8, 2024 that will close this issue
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-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant