forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#88036 - nbdd0121:const3, r=petrochenkov
Fix dead code warning when inline const is used in pattern Fixes rust-lang#78171
- Loading branch information
Showing
2 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |