Rollup merge of #151596 - sgasho:150910_SimplifyCfg_passes_warn, r=nnethercote,saethlin

Fix -Zmir-enable-passes to detect unregistered enum names in declare_passes macro

related: https://github.com/rust-lang/rust/issues/150910

I fixed declare_passes macro to detect unregistered enum names

### UI Results
+nightly --> before: no warnings
+stage1 --> after: detect SimplifyCfg as an unknown pass

<img width="591" height="199" alt="スクリーンショット 2026-01-24 23 53 41" src="https://github.com/user-attachments/assets/ddabaa58-b4c6-4e80-a3c9-f40d866db273" />
This commit is contained in:
Stuart Cook 2026-01-29 19:03:30 +11:00 committed by GitHub
commit 9f0483e5f0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 39 additions and 10 deletions

View file

@ -91,20 +91,32 @@ macro_rules! declare_passes {
)+
)*
static PASS_NAMES: LazyLock<FxIndexSet<&str>> = LazyLock::new(|| [
static PASS_NAMES: LazyLock<FxIndexSet<&str>> = LazyLock::new(|| {
let mut set = FxIndexSet::default();
// Fake marker pass
"PreCodegen",
set.insert("PreCodegen");
$(
$(
stringify!($pass_name),
$(
$(
$mod_name::$pass_name::$ident.name(),
)*
)?
set.extend(pass_names!($mod_name : $pass_name $( { $($ident),* } )? ));
)+
)*
].into_iter().collect());
set
});
};
}
macro_rules! pass_names {
// pass groups: only pass names inside are considered pass_names
($mod_name:ident : $pass_group:ident { $($pass_name:ident),* $(,)? }) => {
[
$(
$mod_name::$pass_group::$pass_name.name(),
)*
]
};
// lone pass names: stringify the struct or enum name
($mod_name:ident : $pass_name:ident) => {
[stringify!($pass_name)]
};
}

View file

@ -1,4 +1,4 @@
//@ compile-flags: --crate-type=lib -Zmir-enable-passes=+InstSimplify
//@ compile-flags: --crate-type=lib -Zmir-enable-passes=+InstSimplify-before-inline
//@ build-pass
#![feature(core_intrinsics)]

View file

@ -0,0 +1,8 @@
warning: MIR pass `SimplifyCfg` is unknown and will be ignored
warning: MIR pass `SimplifyCfg` is unknown and will be ignored
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
warning: 2 warnings emitted

View file

@ -1,4 +1,5 @@
//@ revisions: empty unprefixed all_unknown all_known mixed
//@ revisions: enum_not_in_pass_names enum_in_pass_names
//@[empty] compile-flags: -Zmir-enable-passes=
@ -13,6 +14,12 @@
//@[mixed] check-pass
//@[mixed] compile-flags: -Zmir-enable-passes=+ThisPassDoesNotExist,+CheckAlignment
//@[enum_not_in_pass_names] check-pass
//@[enum_not_in_pass_names] compile-flags: -Zmir-enable-passes=+SimplifyCfg
//@[enum_in_pass_names] check-pass
//@[enum_in_pass_names] compile-flags: -Zmir-enable-passes=+AddCallGuards
fn main() {}
//[empty]~? ERROR incorrect value `` for unstable option `mir-enable-passes`
@ -23,3 +30,5 @@ fn main() {}
//[all_unknown]~? WARN MIR pass `DoesNotExist` is unknown and will be ignored
//[all_unknown]~? WARN MIR pass `ThisPass` is unknown and will be ignored
//[all_unknown]~? WARN MIR pass `DoesNotExist` is unknown and will be ignored
//[enum_not_in_pass_names]~? WARN MIR pass `SimplifyCfg` is unknown and will be ignored
//[enum_not_in_pass_names]~? WARN MIR pass `SimplifyCfg` is unknown and will be ignored