Skip to content

Commit

Permalink
Rollup merge of #114051 - Enselic:const-local-var, r=cjgillot
Browse files Browse the repository at this point in the history
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.

Closes #69016
  • Loading branch information
matthiaskrgr authored Jul 25, 2023
2 parents 91d1d7a + 5d32fd1 commit 99f404a
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions tests/ui/lint/unused/const-local-var.rs
Original file line number Diff line number Diff line change
@@ -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() {}

0 comments on commit 99f404a

Please sign in to comment.