Skip to content

Allow dead assignments in macros by default. #17427

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

Closed
mahkoh opened this issue Sep 21, 2014 · 0 comments
Closed

Allow dead assignments in macros by default. #17427

mahkoh opened this issue Sep 21, 2014 · 0 comments
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. A-syntaxext Area: Syntax extensions

Comments

@mahkoh
Copy link
Contributor

mahkoh commented Sep 21, 2014

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
@thestinger thestinger added A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. A-syntaxext Area: Syntax extensions labels Sep 22, 2014
@mahkoh mahkoh closed this as completed Apr 11, 2015
@rust-lang rust-lang locked and limited conversation to collaborators Apr 11, 2015
lnicola pushed a commit to lnicola/rust that referenced this issue Oct 17, 2024
feat: handle self-param outside of methods when renaming

close rust-lang#17427
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. A-syntaxext Area: Syntax extensions
Projects
None yet
Development

No branches or pull requests

2 participants