Closed glaeqen closed 5 months ago
This seems to be down to the fact that lints in expanded code doesn't fire.
If I make one crate that has this:
pub trait Val {
const VAL: [u8; 8];
}
impl Val for u8 {
const VAL: [u8; 8] = [0u8; 8];
}
impl Val for u16 {
const VAL: [u8; 8] = [1u8; 8];
}
#[macro_export]
macro_rules! example {
($val: ident, $($name:ty),*) => {
// We want this macro to fire if there are dupes
#[deny(unreachable_patterns)]
match $val {
$(
<$name as Val>::VAL => println!("$name"),
)*
_ => println!("Other"),
}
};
}
And another crate that does this:
#![deny(unreachable_patterns)]
use macro_source::Val;
fn main() {
let val = [2u8; 8];
macro_source::example!(val, u8, u8, u16);
}
I don't get the lint to fire at all, even though the expanded code looks like this:
#![feature(prelude_import)]
#![deny(unreachable_patterns)]
#[prelude_import]
use std::prelude::rust_2021::*;
#[macro_use]
extern crate std;
use macro_source::Val;
fn main() {
let val = [2u8; 8];
#[deny(unreachable_patterns)]
match val {
<u8 as Val>::VAL => {
::std::io::_print(format_args!("$name\n"));
}
<u8 as Val>::VAL => {
::std::io::_print(format_args!("$name\n"));
}
<u16 as Val>::VAL => {
::std::io::_print(format_args!("$name\n"));
}
_ => {
::std::io::_print(format_args!("Other\n"));
}
};
}
Addressed by #35, released in v0.5.1
To reproduce:
firmware
crateExpected behaviour
Compilation failure