Skip to content

Commit 8c00f02

Browse files
committed
Warn about invalid mir-enable-passes pass names
1 parent 71042b4 commit 8c00f02

File tree

5 files changed

+37
-2
lines changed

5 files changed

+37
-2
lines changed

compiler/rustc_mir_transform/messages.ftl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,5 @@ mir_transform_undefined_transmute = pointers cannot be transmuted to integers du
3434
.note = at compile-time, pointers do not have an integer value
3535
.note2 = avoiding this restriction via `union` or raw pointers leads to compile-time undefined behavior
3636
.help = for more information, see https://doc.rust-lang.org/std/mem/fn.transmute.html
37+
38+
mir_transform_unknown_pass_name = MIR pass `{$name}` is unknown and will be ignored

compiler/rustc_mir_transform/src/errors.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ pub(crate) struct UnalignedPackedRef {
3838
pub span: Span,
3939
}
4040

41+
#[derive(Diagnostic)]
42+
#[diag(mir_transform_unknown_pass_name)]
43+
pub(crate) struct UnknownPassName<'a> {
44+
pub(crate) name: &'a str,
45+
}
46+
4147
pub(crate) struct AssertLint<P> {
4248
pub span: Span,
4349
pub assert_kind: AssertKind<P>,

compiler/rustc_mir_transform/src/pass_manager.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
use std::cell::RefCell;
22
use std::collections::hash_map::Entry;
33

4-
use rustc_data_structures::fx::FxHashMap;
4+
use rustc_data_structures::fx::{FxHashMap, FxIndexSet};
55
use rustc_middle::mir::{self, Body, MirPhase, RuntimePhase};
66
use rustc_middle::ty::TyCtxt;
77
use rustc_session::Session;
88
use tracing::trace;
99

1010
use crate::lint::lint_body;
11-
use crate::validate;
11+
use crate::{errors, validate};
1212

1313
thread_local! {
1414
static PASS_NAMES: RefCell<FxHashMap<&'static str, &'static str>> = {
@@ -197,6 +197,12 @@ fn run_passes_inner<'tcx>(
197197
) {
198198
let overridden_passes = &tcx.sess.opts.unstable_opts.mir_enable_passes;
199199
trace!(?overridden_passes);
200+
let named_passes =
201+
overridden_passes.iter().map(|(name, _)| name.as_str()).collect::<FxIndexSet<_>>();
202+
let known_passes = passes.iter().map(|p| p.name()).collect::<FxIndexSet<_>>();
203+
for &name in named_passes.difference(&known_passes) {
204+
tcx.dcx().emit_warn(errors::UnknownPassName { name });
205+
}
200206

201207
let prof_arg = tcx.sess.prof.enabled().then(|| format!("{:?}", body.source.def_id()));
202208

tests/ui/mir/invalid_pass_name.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//@ check-pass
2+
//@ compile-flags: -Zmir-enable-passes=+ThisPass,-DoesNotExist
3+
//! Ensure a warning is emitted if unknown pass names are requested
4+
5+
//@ error-pattern: warning: MIR pass `ThisPass` is unknown and will be ignored
6+
//@ error-pattern: warning: MIR pass `DoesNotExist` is unknown and will be ignored
7+
fn main() {}

tests/ui/mir/invalid_pass_name.stderr

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
warning: MIR pass `ThisPass` is unknown and will be ignored
2+
3+
warning: MIR pass `DoesNotExist` is unknown and will be ignored
4+
5+
warning: MIR pass `ThisPass` is unknown and will be ignored
6+
|
7+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
8+
9+
warning: MIR pass `DoesNotExist` is unknown and will be ignored
10+
|
11+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
12+
13+
warning: 4 warnings emitted
14+

0 commit comments

Comments
 (0)