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

debug_assert_with_mut_call: false positive on immutable method call #4737

Open
taiki-e opened this issue Oct 26, 2019 · 2 comments
Open

debug_assert_with_mut_call: false positive on immutable method call #4737

taiki-e opened this issue Oct 26, 2019 · 2 comments
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 L-nursery Lint: Currently in the nursery group

Comments

@taiki-e
Copy link
Member

taiki-e commented Oct 26, 2019

Code:

pub fn f() {
    let v = &mut &mut Vec::<()>::new();
    debug_assert!(v.is_empty()); //~ ERROR do not call a function with mutable arguments inside of `debug_assert!`
}

Error:

error: do not call a function with mutable arguments inside of `debug_assert!`
  --> rust/src/lib.rs:17:19
   |
17 |     debug_assert!(v.is_empty());
   |                   ^^^^^^^^^^^^
   |
   = note: `#[deny(clippy::debug_assert_with_mut_call)]` on by default
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#debug_assert_with_mut_call
@flip1995 flip1995 added E-medium Call for participation: Medium difficulty level problem and requires some initial experience. C-bug Category: Clippy is not doing the correct thing labels Oct 26, 2019
@flip1995
Copy link
Member

A workaround for this is to deref the vector once:

debug_assert!((*v).is_empty());

@philipc
Copy link

philipc commented Jan 11, 2020

Similar issue for code:

use core::cell::{Ref, RefCell};

pub fn f() {
    let mut x = (true,);
    let cell = RefCell::new((&mut x,));
    let r = Ref::map(cell.borrow(), |x| &x.0);
    debug_assert!(r.0);
}

Error:

error: do not call a function with mutable arguments inside of `debug_assert!`
 --> src/lib.rs:7:19
  |
7 |     debug_assert!(r.0);
  |                   ^^^
  |
  = note: `#[deny(clippy::debug_assert_with_mut_call)]` on by default
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#debug_assert_with_mut_call

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 L-nursery Lint: Currently in the nursery group
Projects
None yet
Development

No branches or pull requests

5 participants