Skip to content

Commit 498ef48

Browse files
committed
Make MIR pass name a compile-time constant.
1 parent 227abac commit 498ef48

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

compiler/rustc_mir_transform/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
#![deny(rustc::diagnostic_outside_of_impl)]
33
#![feature(assert_matches)]
44
#![feature(box_patterns)]
5+
#![feature(const_type_name)]
56
#![feature(cow_is_borrowed)]
67
#![feature(decl_macro)]
78
#![feature(impl_trait_in_assoc_type)]
9+
#![feature(inline_const)]
810
#![feature(is_sorted)]
911
#![feature(let_chains)]
1012
#![feature(map_try_insert)]

compiler/rustc_mir_transform/src/pass_manager.rs

+17-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,23 @@ use crate::{lint::lint_body, validate, MirPass};
77
/// Just like `MirPass`, except it cannot mutate `Body`.
88
pub trait MirLint<'tcx> {
99
fn name(&self) -> &'static str {
10-
let name = std::any::type_name::<Self>();
11-
if let Some((_, tail)) = name.rsplit_once(':') { tail } else { name }
10+
// FIXME Simplify the implementation once more `str` methods get const-stable.
11+
const {
12+
let name = std::any::type_name::<Self>();
13+
let bytes = name.as_bytes();
14+
let mut i = name.len();
15+
while i > 0 {
16+
i = i - 1;
17+
if bytes[i] == b':' {
18+
break;
19+
}
20+
}
21+
let (_, bytes) = bytes.split_at(i);
22+
match std::str::from_utf8(bytes) {
23+
Ok(name) => name,
24+
Err(_) => name,
25+
}
26+
}
1227
}
1328

1429
fn is_enabled(&self, _sess: &Session) -> bool {

0 commit comments

Comments
 (0)