Make MIR pass name a compile-time constant.
This commit is contained in:
parent
227abacaef
commit
ad25f0eb2c
@ -2,9 +2,11 @@
|
|||||||
#![deny(rustc::diagnostic_outside_of_impl)]
|
#![deny(rustc::diagnostic_outside_of_impl)]
|
||||||
#![feature(assert_matches)]
|
#![feature(assert_matches)]
|
||||||
#![feature(box_patterns)]
|
#![feature(box_patterns)]
|
||||||
|
#![feature(const_type_name)]
|
||||||
#![feature(cow_is_borrowed)]
|
#![feature(cow_is_borrowed)]
|
||||||
#![feature(decl_macro)]
|
#![feature(decl_macro)]
|
||||||
#![feature(impl_trait_in_assoc_type)]
|
#![feature(impl_trait_in_assoc_type)]
|
||||||
|
#![feature(inline_const)]
|
||||||
#![feature(is_sorted)]
|
#![feature(is_sorted)]
|
||||||
#![feature(let_chains)]
|
#![feature(let_chains)]
|
||||||
#![feature(map_try_insert)]
|
#![feature(map_try_insert)]
|
||||||
|
@ -7,8 +7,20 @@
|
|||||||
/// Just like `MirPass`, except it cannot mutate `Body`.
|
/// Just like `MirPass`, except it cannot mutate `Body`.
|
||||||
pub trait MirLint<'tcx> {
|
pub trait MirLint<'tcx> {
|
||||||
fn name(&self) -> &'static str {
|
fn name(&self) -> &'static str {
|
||||||
let name = std::any::type_name::<Self>();
|
// FIXME Simplify the implementation once more `str` methods get const-stable.
|
||||||
if let Some((_, tail)) = name.rsplit_once(':') { tail } else { name }
|
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 {
|
fn is_enabled(&self, _sess: &Session) -> bool {
|
||||||
|
Loading…
Reference in New Issue
Block a user