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

Can't disable no_effect #7171

Closed
vihdzp opened this issue May 5, 2021 · 1 comment · Fixed by #7282
Closed

Can't disable no_effect #7171

vihdzp opened this issue May 5, 2021 · 1 comment · Fixed by #7282
Labels
C-bug Category: Clippy is not doing the correct thing E-medium Call for participation: Medium difficulty level problem and requires some initial experience. I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@vihdzp
Copy link

vihdzp commented May 5, 2021

I'm using a struct with a custom DerefMut implementation that internally updates the object every time it's mutably de-referenced, as a way to check whether it has changed. To force an update, I'm using the following code:

#[allow(clippy::no_effect)]
&mut *custom_deref;

Despite appearances, the second line is not actually a no-op. I can't blame Clippy for not being able to figure that out. However, I'm not able to disable the lint warning, even with the #[allow(clippy::no_effect)] line.

The following code replicates this bug. Note how &mut *custom_deref; is not a no-op, and note how the warning still shows despite disabling it.

struct CustomDeref(i32);

impl std::ops::Deref for CustomDeref {
    type Target = i32;

    fn deref(&self) -> &Self::Target {
        println!("Derefenced!");
        &self.0
    }
}

impl std::ops::DerefMut for CustomDeref {
    fn deref_mut(&mut self) -> &mut Self::Target {
        println!("Mutably dereferenced!");
        &mut self.0
    }
}

fn main() {
    let mut custom_deref = CustomDeref(0);

    #[allow(clippy::no_effect)]
    &mut *custom_deref;
}

Output after cargo clippy:

warning: statement with no effect
  --> src\main.rs:23:5
   |
23 |     &mut *custom_deref;
   |     ^^^^^^^^^^^^^^^^^^^
   |
   = note: `#[warn(clippy::no_effect)]` on by default
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#no_effect

warning: 1 warning emitted
@vihdzp vihdzp 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 May 5, 2021
vihdzp added a commit to vihdzp/miratope-rs that referenced this issue May 5, 2021
@camsteffen
Copy link
Contributor

I can't blame Clippy for not being able to figure that out.

Actually you can. We can detected custom derefs.

@camsteffen camsteffen added the E-medium Call for participation: Medium difficulty level problem and requires some initial experience. label May 5, 2021
@bors bors closed this as completed in 8066f83 May 27, 2021
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 E-medium Call for participation: Medium difficulty level problem and requires some initial experience. 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.

2 participants