I seem to have hit some strange compiler edge case, in the following example (playground)
const fn test() -> usize {
0
}
trait Test {}
impl Test for [u8; test()] {}
// NOTE: this constitutes a use
//trait _Test2 {
// type Ty;
//}
//
//impl _Test2 for String {
// type Ty = [u8; test()];
//}
fn test2<T: Test>() {}
fn main() {
test2::<[u8; 0]>();
// NOTE: this constitutes a use
//let _x: [u8; test()] = [];
}
This results in a dead_code
warning, because the use of the test
function in the impl Test
block is not detected. Strangely enough, it is detected in the two alternative scenarios that I commented out. Am I missing something, or is this a bug?
Edit: likely related to False positive `dead_code` for const used as const generic argument during impl marker trait · Issue #128617 · rust-lang/rust · GitHub (although this particular example has been fixed)