Skip to content

Allow dead assignments in macros by default. #17427

Closed
@mahkoh

Description

@mahkoh

Consider the following code:

fn g(x: u8) -> u8 {
    1 - x
}

fn main() {
    let mut x = 1u8;

    macro_rules! m {
        () => {{
            x = g(x);
            if x == 0 {
                x = 1;
            }
        }}
    }

    m!();
    g(1/x);
    m!();
}
test.rs:252:17: 252:18 warning: value assigned to `x` is never read, #[warn(dead_assignment)] on by default
test.rs:252                 x = 1;
                            ^
test.rs:248:5: 257:6 note: in expansion of m!
test.rs:259:5: 259:10 note: expansion site

And after removing the dead assignment:

task '<main>' failed at 'attempted to divide by zero', test.rs:257

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.A-syntaxextArea: Syntax extensions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions