Closed
Description
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
}
}
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.