Make MIR pass name a compile-time constant.

This commit is contained in:
Camille GILLOT
2024-01-20 14:56:09 +00:00
parent 227abacaef
commit ad25f0eb2c
2 changed files with 16 additions and 2 deletions

View File

@@ -7,8 +7,20 @@ use crate::{lint::lint_body, validate, MirPass};
/// Just like `MirPass`, except it cannot mutate `Body`.
pub trait MirLint<'tcx> {
fn name(&self) -> &'static str {
let name = std::any::type_name::<Self>();
if let Some((_, tail)) = name.rsplit_once(':') { tail } else { name }
// FIXME Simplify the implementation once more `str` methods get const-stable.
const {
let name = std::any::type_name::<Self>();
let bytes = name.as_bytes();
let mut i = bytes.len();
while i > 0 && bytes[i - 1] != b':' {
i = i - 1;
}
let (_, bytes) = bytes.split_at(i);
match std::str::from_utf8(bytes) {
Ok(name) => name,
Err(_) => name,
}
}
}
fn is_enabled(&self, _sess: &Session) -> bool {