Skip to content

Commit

Permalink
Add a dead code test for using anon const in pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
nbdd0121 committed Aug 15, 2021
1 parent 2969aec commit e62ecdc
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/test/ui/lint/dead-code/anon-const-in-pat.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// check-pass
#![feature(inline_const)]
#![allow(incomplete_features)]
#![deny(dead_code)]

const fn one() -> i32 {
1
}

const fn two() -> i32 {
2
}

const fn three() -> i32 {
3
}

fn inline_const() {
// rust-lang/rust#78171: dead_code lint triggers even though function is used in const pattern
match 1 {
const { one() } => {}
_ => {}
}
}

fn inline_const_range() {
match 1 {
1 ..= const { two() } => {}
_ => {}
}
}

struct S<const C: i32>;

fn const_generic_arg() {
match S::<3> {
S::<{three()}> => {}
}
}

fn main() {
inline_const();
inline_const_range();
const_generic_arg();
}

0 comments on commit e62ecdc

Please sign in to comment.