Skip to content
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

Inconsistent unused warning for local const inside unused methods (but not functions) #69016

Closed
dbdr opened this issue Feb 10, 2020 · 0 comments · Fixed by #114051
Closed

Inconsistent unused warning for local const inside unused methods (but not functions) #69016

dbdr opened this issue Feb 10, 2020 · 0 comments · Fixed by #114051
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug.

Comments

@dbdr
Copy link

dbdr commented Feb 10, 2020

fn _unused1(x: i32) -> i32 {
    const F: i32 = 2;
    let g = 1;
    x * F + g
} 

pub struct Foo {}

impl Foo {
    fn _unused2(x: i32) -> i32 {
        const F: i32 = 2;
        let g = 1;
        x * F + g
    } 
}

(Playground)

There is a warning about F being unused in method _unused2, while there isn't about the same situation in function _unused1:

   Compiling playground v0.0.1 (/playground)
warning: constant item is never used: `F`
  --> src/lib.rs:11:9
   |
11 |         const F: i32 = 2;
   |         ^^^^^^^^^^^^^^^^^
   |
   = note: `#[warn(dead_code)]` on by default

    Finished dev [unoptimized + debuginfo] target(s) in 0.54s

Local variable g is also not reported as unused in either case. Unless I'm mistaken, F and g are similar in that they are local to the function/method. I would expect no warning for this code.

Note that this is different from #47133 because here the const is local, which I think makes the case more clear-cut.

@dbdr dbdr changed the title Inconsistent unused warning for const inside unused methods (but not functions) Inconsistent unused warning for local const inside unused methods (but not functions) Feb 10, 2020
@jonas-schievink jonas-schievink added A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. labels Feb 10, 2020
@bors bors closed this as completed in 99f404a Jul 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants