Skip to content

Commit

Permalink
Auto merge of rust-lang#120161 - cjgillot:static-pass-name, r=<try>
Browse files Browse the repository at this point in the history
Make MIR pass name a compile-time constant.

r? `@ghost`
  • Loading branch information
bors committed Jan 20, 2024
2 parents 227abac + 498ef48 commit db13a70
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
2 changes: 2 additions & 0 deletions compiler/rustc_mir_transform/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
#![deny(rustc::diagnostic_outside_of_impl)]
#![feature(assert_matches)]
#![feature(box_patterns)]
#![feature(const_type_name)]
#![feature(cow_is_borrowed)]
#![feature(decl_macro)]
#![feature(impl_trait_in_assoc_type)]
#![feature(inline_const)]
#![feature(is_sorted)]
#![feature(let_chains)]
#![feature(map_try_insert)]
Expand Down
19 changes: 17 additions & 2 deletions compiler/rustc_mir_transform/src/pass_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,23 @@ 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 = name.len();
while i > 0 {
i = i - 1;
if bytes[i] == b':' {
break;
}
}
let (_, bytes) = bytes.split_at(i);
match std::str::from_utf8(bytes) {
Ok(name) => name,
Err(_) => name,
}
}
}

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

0 comments on commit db13a70

Please sign in to comment.