From 5d32fd1b0623651cca15acd71ecc901324f3170c Mon Sep 17 00:00:00 2001 From: Martin Nordholts Date: Tue, 25 Jul 2023 12:42:54 +0200 Subject: [PATCH] Add regression test for invalid unused const in method The warning can be reproduced with 1.63 but not with 1.64. $ rustc +1.63 tests/ui/lint/unused/const-local-var.rs warning: constant `F` is never used --> tests/ui/lint/unused/const-local-var.rs:14:9 | 14 | const F: i32 = 2; | ^^^^^^^^^^^^^^^^^ | = note: `#[warn(dead_code)]` on by default $ rustc +1.64 tests/ui/lint/unused/const-local-var.rs Add a regression test to prevent the problem from re-appearing. --- tests/ui/lint/unused/const-local-var.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 tests/ui/lint/unused/const-local-var.rs diff --git a/tests/ui/lint/unused/const-local-var.rs b/tests/ui/lint/unused/const-local-var.rs new file mode 100644 index 0000000000000..89ca16fe003e9 --- /dev/null +++ b/tests/ui/lint/unused/const-local-var.rs @@ -0,0 +1,23 @@ +// regression test for https://github.com/rust-lang/rust/issues/69016 +// check-pass + +#![warn(unused)] +#![deny(warnings)] + +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 + } +} + +fn main() {}