rust-lang / rust-lang/rust-clippy

debug_assert_with_mut_call: false positive on immutable method call

Open
#4,737 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug E-medium I-false-positive L-nursery
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the reported example with cargo clippy and search the debug_assert_with_mut_call lint implementation and its tests. Check how the lint treats the immutable is_empty call through nested mutable references; done means this example is no longer flagged while genuine mutable calls remain diagnosed.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.