1
Fork 0

MirPass: make name more const

This commit is contained in:
klensy 2024-02-07 10:47:52 +03:00
parent 94df917a74
commit c5e6df0c78
4 changed files with 25 additions and 12 deletions

View file

@ -8,18 +8,10 @@ use crate::{lint::lint_body, validate, MirPass};
pub trait MirLint<'tcx> {
fn name(&self) -> &'static str {
// FIXME Simplify the implementation once more `str` methods get const-stable.
// See copypaste in `MirPass`
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,
}
rustc_middle::util::common::c_name(name)
}
}