Skip to content

Clippy reports warnings twice on suggestion errors #6235

@jyn514

Description

@jyn514
Member

I tried the code from #6234.
I expected to see one error, from the incorrect 'fixed' code, and one warning from the original code.

Instead, this happened: I saw one error and two warnings:

Original diagnostics will follow.

warning: immediately dereferencing a reference
 --> src/lib.rs:2:26
  |
2 |     ($visitor: expr) => (*&$visitor)
  |                          ^^^^^^^^^^ help: try this: `self`
...
8 |         m!(self)
  |         -------- in this macro invocation
  |
  = note: `#[warn(clippy::deref_addrof)]` on by default
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#deref_addrof
  = note: this warning originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

warning: immediately dereferencing a reference
 --> src/lib.rs:2:26
  |
2 |     ($visitor: expr) => (*&$visitor)
  |                          ^^^^^^^^^^ help: try this: `self`
...
8 |         m!(self)
  |         -------- in this macro invocation
  |
  = note: `#[warn(clippy::deref_addrof)]` on by default
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#deref_addrof
  = note: this warning originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

warning: 1 warning emitted

warning: 1 warning emitted

Meta

  • cargo clippy -V: clippy 0.0.212 (ffa2e7a 2020-10-24)

Activity

added
C-bugCategory: Clippy is not doing the correct thing
on Oct 27, 2020
jyn514

jyn514 commented on Oct 27, 2020

@jyn514
MemberAuthor

@rustbot modify labels: +A-suggestion

added
L-suggestionLint: Improving, adding or fixing lint suggestions
on Oct 27, 2020
added
A-uiArea: Clippy interface, usage and configuration
on Feb 23, 2021
matthiaskrgr

matthiaskrgr commented on Jan 8, 2024

@matthiaskrgr
Member

Still a problem:

use std::cell::Cell;

fn main() {
    unsafe {
        let root0 = Cell::new(42);
        let wildcard = &root0 as *const Cell<i32> as usize as *const Cell<i32>;

        // Now new refs start being inserted at idx 0, pushing the unique_range up.
        let _refn = &*&*&*&*&*(wildcard.cast::<i32>());
    }
}
warning: immediately dereferencing a reference
 --> src/main.rs:9:22
  |
9 |         let _refn = &*&*&*&*&*(wildcard.cast::<i32>());
  |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `*&*&*&*(wildcard.cast::<i32>())`
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#deref_addrof
  = note: `#[warn(clippy::deref_addrof)]` on by default

warning: immediately dereferencing a reference
 --> src/main.rs:9:24
  |
9 |         let _refn = &*&*&*&*&*(wildcard.cast::<i32>());
  |                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `*&*&*(wildcard.cast::<i32>())`
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#deref_addrof

warning: immediately dereferencing a reference
 --> src/main.rs:9:26
  |
9 |         let _refn = &*&*&*&*&*(wildcard.cast::<i32>());
  |                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `*&*(wildcard.cast::<i32>())`
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#deref_addrof

warning: immediately dereferencing a reference
 --> src/main.rs:9:28
  |
9 |         let _refn = &*&*&*&*&*(wildcard.cast::<i32>());
  |                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `*(wildcard.cast::<i32>())`
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#deref_addrof

warning: deref on an immutable reference
 --> src/main.rs:9:21
  |
9 |         let _refn = &*&*&*&*&*(wildcard.cast::<i32>());
  |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: if you would like to reborrow, try removing `&*`: `&*&*&*&*(wildcard.cast::<i32>())`
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#borrow_deref_ref
  = note: `#[warn(clippy::borrow_deref_ref)]` on by default

warning: `m` (bin "m") generated 5 warnings (run `cargo clippy --fix --bin "m"` to apply 5 suggestions)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-uiArea: Clippy interface, usage and configurationC-bugCategory: Clippy is not doing the correct thingL-suggestionLint: Improving, adding or fixing lint suggestions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @matthiaskrgr@camsteffen@jyn514@rustbot

        Issue actions

          Clippy reports warnings twice on suggestion errors · Issue #6235 · rust-lang/rust-clippy