Skip to content

Error when using debug_assert! and async function #5105

@gliderkite

Description

@gliderkite

I'm getting an error with the following code:

use std::path::{Path, PathBuf};
use tokio::fs;

async fn exists(path: impl AsRef<Path>) -> bool {
    fs::metadata(path).await.is_ok()
}

#[tokio::main]
async fn main() {
    let path = PathBuf::from("");
    debug_assert!(!exists(&path).await);
}
error: do not call a function with mutable arguments inside of `debug_assert!`
  --> src/main.rs:11:20
   |
11 |     debug_assert!(!exists(&path).await);
   |                    ^^^^^^^^^^^^^^^^^^^
   |
   = 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

error: aborting due to previous error

Note that this doesn't occur with the equivalent blocking version:

use std::path::{Path, PathBuf};

fn exists(path: impl AsRef<Path>) -> bool {
    path.as_ref().exists()
}

fn main() {
    let path = PathBuf::from("");
    debug_assert!(!exists(&path));
}

Is this expected behaviour?

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingL-correctnessLint: Belongs in the correctness lint groupT-async-awaitType: Issues related to async/awaitgood first issueThese issues are a good way to get started with Clippy

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions