Skip to content

some uses of macros cause "variable does not need to be mutable" #21384

@mi2ebi

Description

@mi2ebi

rust-analyzer version: rust-analyzer 1.94.0-nightly (fcd6309 2026-01-01)

rustc version: rustc 1.94.0-nightly (fcd630976 2026-01-01)

editor or extension: Helix and Emacs

relevant settings:

[language-server.rust-analyzer.config]
check.overrideCommand = ["cargo", "xnitpick"]
# check.overrideCommand = ["cargo", "clippy"]
cargo.features = "all"
diagnostics = {experimental.enable = true, styleLints.enable = true}
inlayHints = {closureCaptureHints.enable = true, closureReturnTypeHints.enable = "always"}

and identical settings in Emacs

repository link (if public, optional): https://github.com/latkerlo/latkerlo-jvotci/blob/main/rs/src/tools.rs

code snippet to reproduce: I couldn't find a minimal reproduction, but the linked file produces these warnings for me starting at line 170

Image Image

none of the other uses of format! or strin! in the project cause the warnings.

#[macro_export]
/// Pythonic `str`ing `in`dexing.
macro_rules! strin {
    ($s:expr, $i:expr) => {{
        let mut chars = ($s).chars();
        let len = chars.clone().count();
        let positive = |i| -> Option<usize> {
            let j = if i < 0 { len as isize + i } else { i } as usize;
            (j < len).then_some(j)
        };
        positive($i).map(|i| (&mut chars).nth(i).unwrap()).unwrap_or_default()
    }};
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions