From ee2b16100e2fad2c08f01f913b826c00024f85a8 Mon Sep 17 00:00:00 2001 From: 5225225 <5225225@mailbox.org> Date: Fri, 19 Aug 2022 10:21:14 +0100 Subject: [PATCH 1/3] Migrate rustc_mir_dataflow to diagnostic structs --- Cargo.lock | 3 + .../locales/en-US/rustc_mir_dataflow.ftl | 29 ++++++++ compiler/rustc_error_messages/src/lib.rs | 1 + compiler/rustc_mir_dataflow/Cargo.toml | 3 + compiler/rustc_mir_dataflow/src/errors.rs | 71 +++++++++++++++++++ .../src/framework/engine.rs | 13 ++-- compiler/rustc_mir_dataflow/src/lib.rs | 3 + compiler/rustc_mir_dataflow/src/rustc_peek.rs | 28 ++++---- 8 files changed, 129 insertions(+), 22 deletions(-) create mode 100644 compiler/rustc_error_messages/locales/en-US/rustc_mir_dataflow.ftl create mode 100644 compiler/rustc_mir_dataflow/src/errors.rs diff --git a/Cargo.lock b/Cargo.lock index ebacd32db4fc7..a7905a12e0feb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4213,11 +4213,14 @@ dependencies = [ "regex", "rustc_ast", "rustc_data_structures", + "rustc_errors", "rustc_graphviz", "rustc_hir", "rustc_index", + "rustc_macros", "rustc_middle", "rustc_serialize", + "rustc_session", "rustc_span", "rustc_target", "smallvec", diff --git a/compiler/rustc_error_messages/locales/en-US/rustc_mir_dataflow.ftl b/compiler/rustc_error_messages/locales/en-US/rustc_mir_dataflow.ftl new file mode 100644 index 0000000000000..bfc9470bbdf30 --- /dev/null +++ b/compiler/rustc_error_messages/locales/en-US/rustc_mir_dataflow.ftl @@ -0,0 +1,29 @@ +rustc_mir_dataflow_path_must_end_in_filename = + path must end in a filename + +rustc_mir_dataflow_unknown_formatter = + unknown formatter + +rustc_mir_dataflow_duplicate_values_for = + duplicate values for `{$name}` + +rustc_mir_dataflow_requires_an_argument = + `{$name}` requires an argument + +rustc_mir_dataflow_stop_after_dataflow_ended_compilation = + stop_after_dataflow ended compilation + +rustc_mir_dataflow_peek_must_be_place_or_ref_place = + rustc_peek: argument expression must be either `place` or `&place` + +rustc_mir_dataflow_peek_must_be_not_temporary = + dataflow::sanity_check cannot feed a non-temp to rustc_peek. + +rustc_mir_dataflow_peek_bit_not_set = + rustc_peek: bit not set + +rustc_mir_dataflow_peek_argument_not_a_local = + rustc_peek: argument was not a local + +rustc_mir_dataflow_peek_argument_untracked = + rustc_peek: argument untracked diff --git a/compiler/rustc_error_messages/src/lib.rs b/compiler/rustc_error_messages/src/lib.rs index 3569c7f063064..bcbaa649a01fc 100644 --- a/compiler/rustc_error_messages/src/lib.rs +++ b/compiler/rustc_error_messages/src/lib.rs @@ -43,6 +43,7 @@ fluent_messages! { passes => "../locales/en-US/passes.ftl", privacy => "../locales/en-US/privacy.ftl", typeck => "../locales/en-US/typeck.ftl", + rustc_mir_dataflow => "../locales/en-US/rustc_mir_dataflow.ftl", } pub use fluent_generated::{self as fluent, DEFAULT_LOCALE_RESOURCES}; diff --git a/compiler/rustc_mir_dataflow/Cargo.toml b/compiler/rustc_mir_dataflow/Cargo.toml index baf9735fbc846..385e9ba748fb9 100644 --- a/compiler/rustc_mir_dataflow/Cargo.toml +++ b/compiler/rustc_mir_dataflow/Cargo.toml @@ -13,10 +13,13 @@ smallvec = { version = "1.8.1", features = ["union", "may_dangle"] } tracing = "0.1" rustc_ast = { path = "../rustc_ast" } rustc_data_structures = { path = "../rustc_data_structures" } +rustc_errors = { path = "../rustc_errors" } rustc_graphviz = { path = "../rustc_graphviz" } rustc_hir = { path = "../rustc_hir" } rustc_index = { path = "../rustc_index" } +rustc_macros = { path = "../rustc_macros" } rustc_middle = { path = "../rustc_middle" } rustc_serialize = { path = "../rustc_serialize" } +rustc_session = { path = "../rustc_session" } rustc_target = { path = "../rustc_target" } rustc_span = { path = "../rustc_span" } diff --git a/compiler/rustc_mir_dataflow/src/errors.rs b/compiler/rustc_mir_dataflow/src/errors.rs new file mode 100644 index 0000000000000..a30bf35fa1a2d --- /dev/null +++ b/compiler/rustc_mir_dataflow/src/errors.rs @@ -0,0 +1,71 @@ +use rustc_macros::SessionDiagnostic; +use rustc_span::{Span, Symbol}; + +#[derive(SessionDiagnostic)] +#[diag(rustc_mir_dataflow::path_must_end_in_filename)] +pub(crate) struct PathMustEndInFilename { + #[primary_span] + pub span: Span, +} + +#[derive(SessionDiagnostic)] +#[diag(rustc_mir_dataflow::unknown_formatter)] +pub(crate) struct UnknownFormatter { + #[primary_span] + pub span: Span, +} + +#[derive(SessionDiagnostic)] +#[diag(rustc_mir_dataflow::duplicate_values_for)] +pub(crate) struct DuplicateValuesFor { + #[primary_span] + pub span: Span, + pub name: Symbol, +} + +#[derive(SessionDiagnostic)] +#[diag(rustc_mir_dataflow::requires_an_argument)] +pub(crate) struct RequiresAnArgument { + #[primary_span] + pub span: Span, + pub name: Symbol, +} + +#[derive(SessionDiagnostic)] +#[diag(rustc_mir_dataflow::stop_after_dataflow_ended_compilation)] +pub(crate) struct StopAfterDataFlowEndedCompilation; + +#[derive(SessionDiagnostic)] +#[diag(rustc_mir_dataflow::peek_must_be_place_or_ref_place)] +pub(crate) struct PeekMustBePlaceOrRefPlace { + #[primary_span] + pub span: Span, +} + +#[derive(SessionDiagnostic)] +#[diag(rustc_mir_dataflow::peek_must_be_not_temporary)] +pub(crate) struct PeekMustBeNotTemporary { + #[primary_span] + pub span: Span, +} + +#[derive(SessionDiagnostic)] +#[diag(rustc_mir_dataflow::peek_bit_not_set)] +pub(crate) struct PeekBitNotSet { + #[primary_span] + pub span: Span, +} + +#[derive(SessionDiagnostic)] +#[diag(rustc_mir_dataflow::peek_argument_not_a_local)] +pub(crate) struct PeekArgumentNotALocal { + #[primary_span] + pub span: Span, +} + +#[derive(SessionDiagnostic)] +#[diag(rustc_mir_dataflow::peek_argument_untracked)] +pub(crate) struct PeekArgumentUntracked { + #[primary_span] + pub span: Span, +} diff --git a/compiler/rustc_mir_dataflow/src/framework/engine.rs b/compiler/rustc_mir_dataflow/src/framework/engine.rs index f374658ceb691..112204c7599be 100644 --- a/compiler/rustc_mir_dataflow/src/framework/engine.rs +++ b/compiler/rustc_mir_dataflow/src/framework/engine.rs @@ -1,5 +1,8 @@ //! A solver for dataflow problems. +use crate::errors::{ + DuplicateValuesFor, PathMustEndInFilename, RequiresAnArgument, UnknownFormatter, +}; use crate::framework::BitSetExt; use std::ffi::OsString; @@ -347,7 +350,7 @@ impl RustcMirAttrs { match path.file_name() { Some(_) => Ok(path), None => { - tcx.sess.span_err(attr.span(), "path must end in a filename"); + tcx.sess.emit_err(PathMustEndInFilename { span: attr.span() }); Err(()) } } @@ -356,7 +359,7 @@ impl RustcMirAttrs { Self::set_field(&mut ret.formatter, tcx, &attr, |s| match s { sym::gen_kill | sym::two_phase => Ok(s), _ => { - tcx.sess.span_err(attr.span(), "unknown formatter"); + tcx.sess.emit_err(UnknownFormatter { span: attr.span() }); Err(()) } }) @@ -377,8 +380,7 @@ impl RustcMirAttrs { mapper: impl FnOnce(Symbol) -> Result, ) -> Result<(), ()> { if field.is_some() { - tcx.sess - .span_err(attr.span(), &format!("duplicate values for `{}`", attr.name_or_empty())); + tcx.sess.emit_err(DuplicateValuesFor { span: attr.span(), name: attr.name_or_empty() }); return Err(()); } @@ -387,8 +389,7 @@ impl RustcMirAttrs { *field = Some(mapper(s)?); Ok(()) } else { - tcx.sess - .span_err(attr.span(), &format!("`{}` requires an argument", attr.name_or_empty())); + tcx.sess.emit_err(RequiresAnArgument { span: attr.span(), name: attr.name_or_empty() }); Err(()) } } diff --git a/compiler/rustc_mir_dataflow/src/lib.rs b/compiler/rustc_mir_dataflow/src/lib.rs index 5793a286bd03d..62b712f7b8dbd 100644 --- a/compiler/rustc_mir_dataflow/src/lib.rs +++ b/compiler/rustc_mir_dataflow/src/lib.rs @@ -7,6 +7,8 @@ #![feature(stmt_expr_attributes)] #![feature(trusted_step)] #![recursion_limit = "256"] +#![deny(rustc::untranslatable_diagnostic)] +#![deny(rustc::diagnostic_outside_of_impl)] #[macro_use] extern crate tracing; @@ -33,6 +35,7 @@ use self::move_paths::MoveData; pub mod drop_flag_effects; pub mod elaborate_drops; +mod errors; mod framework; pub mod impls; pub mod move_paths; diff --git a/compiler/rustc_mir_dataflow/src/rustc_peek.rs b/compiler/rustc_mir_dataflow/src/rustc_peek.rs index f2471f37a5266..5fb7cb6584beb 100644 --- a/compiler/rustc_mir_dataflow/src/rustc_peek.rs +++ b/compiler/rustc_mir_dataflow/src/rustc_peek.rs @@ -6,6 +6,10 @@ use rustc_middle::mir::MirPass; use rustc_middle::mir::{self, Body, Local, Location}; use rustc_middle::ty::{self, Ty, TyCtxt}; +use crate::errors::{ + PeekArgumentNotALocal, PeekArgumentUntracked, PeekBitNotSet, PeekMustBeNotTemporary, + PeekMustBePlaceOrRefPlace, StopAfterDataFlowEndedCompilation, +}; use crate::framework::BitSetExt; use crate::impls::{ DefinitelyInitializedPlaces, MaybeInitializedPlaces, MaybeLiveLocals, MaybeUninitializedPlaces, @@ -64,7 +68,7 @@ impl<'tcx> MirPass<'tcx> for SanityCheck { } if has_rustc_mir_with(tcx, def_id, sym::stop_after_dataflow).is_some() { - tcx.sess.fatal("stop_after_dataflow ended compilation"); + tcx.sess.emit_fatal(StopAfterDataFlowEndedCompilation); } } } @@ -133,9 +137,7 @@ pub fn sanity_check_via_rustc_peek<'tcx, A>( } _ => { - let msg = "rustc_peek: argument expression \ - must be either `place` or `&place`"; - tcx.sess.span_err(call.span, msg); + tcx.sess.emit_err(PeekMustBePlaceOrRefPlace { span: call.span }); } } } @@ -204,18 +206,12 @@ impl PeekCall { if let Some(local) = place.as_local() { local } else { - tcx.sess.diagnostic().span_err( - span, - "dataflow::sanity_check cannot feed a non-temp to rustc_peek.", - ); + tcx.sess.emit_err(PeekMustBeNotTemporary { span }); return None; } } _ => { - tcx.sess.diagnostic().span_err( - span, - "dataflow::sanity_check cannot feed a non-temp to rustc_peek.", - ); + tcx.sess.emit_err(PeekMustBeNotTemporary { span }); return None; } }; @@ -255,12 +251,12 @@ where let bit_state = flow_state.contains(peek_mpi); debug!("rustc_peek({:?} = &{:?}) bit_state: {}", call.arg, place, bit_state); if !bit_state { - tcx.sess.span_err(call.span, "rustc_peek: bit not set"); + tcx.sess.emit_err(PeekBitNotSet { span: call.span }); } } LookupResult::Parent(..) => { - tcx.sess.span_err(call.span, "rustc_peek: argument untracked"); + tcx.sess.emit_err(PeekArgumentUntracked { span: call.span }); } } } @@ -276,12 +272,12 @@ impl<'tcx> RustcPeekAt<'tcx> for MaybeLiveLocals { ) { info!(?place, "peek_at"); let Some(local) = place.as_local() else { - tcx.sess.span_err(call.span, "rustc_peek: argument was not a local"); + tcx.sess.emit_err(PeekArgumentNotALocal { span: call.span }); return; }; if !flow_state.contains(local) { - tcx.sess.span_err(call.span, "rustc_peek: bit not set"); + tcx.sess.emit_err(PeekBitNotSet { span: call.span }); } } } From 7f125ed7d5645c7d2c7656d6303e6bdd499739a1 Mon Sep 17 00:00:00 2001 From: 5225225 <5225225@mailbox.org> Date: Tue, 23 Aug 2022 13:18:45 +0100 Subject: [PATCH 2/3] Remove full stop in diagnostic message --- .../rustc_error_messages/locales/en-US/rustc_mir_dataflow.ftl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_error_messages/locales/en-US/rustc_mir_dataflow.ftl b/compiler/rustc_error_messages/locales/en-US/rustc_mir_dataflow.ftl index bfc9470bbdf30..1bf654eb01aa0 100644 --- a/compiler/rustc_error_messages/locales/en-US/rustc_mir_dataflow.ftl +++ b/compiler/rustc_error_messages/locales/en-US/rustc_mir_dataflow.ftl @@ -17,7 +17,7 @@ rustc_mir_dataflow_peek_must_be_place_or_ref_place = rustc_peek: argument expression must be either `place` or `&place` rustc_mir_dataflow_peek_must_be_not_temporary = - dataflow::sanity_check cannot feed a non-temp to rustc_peek. + dataflow::sanity_check cannot feed a non-temp to rustc_peek rustc_mir_dataflow_peek_bit_not_set = rustc_peek: bit not set From f20cc9ae4ea6e9b5226680e93229a53468022350 Mon Sep 17 00:00:00 2001 From: 5225225 <5225225@mailbox.org> Date: Tue, 23 Aug 2022 13:48:15 +0100 Subject: [PATCH 3/3] Rename rustc_mir_dataflow diagnostic to mir_dataflow --- .../locales/en-US/mir_dataflow.ftl | 29 +++++++++++++++++++ .../locales/en-US/rustc_mir_dataflow.ftl | 29 ------------------- compiler/rustc_error_messages/src/lib.rs | 2 +- compiler/rustc_mir_dataflow/src/errors.rs | 20 ++++++------- 4 files changed, 40 insertions(+), 40 deletions(-) create mode 100644 compiler/rustc_error_messages/locales/en-US/mir_dataflow.ftl delete mode 100644 compiler/rustc_error_messages/locales/en-US/rustc_mir_dataflow.ftl diff --git a/compiler/rustc_error_messages/locales/en-US/mir_dataflow.ftl b/compiler/rustc_error_messages/locales/en-US/mir_dataflow.ftl new file mode 100644 index 0000000000000..9885415250883 --- /dev/null +++ b/compiler/rustc_error_messages/locales/en-US/mir_dataflow.ftl @@ -0,0 +1,29 @@ +mir_dataflow_path_must_end_in_filename = + path must end in a filename + +mir_dataflow_unknown_formatter = + unknown formatter + +mir_dataflow_duplicate_values_for = + duplicate values for `{$name}` + +mir_dataflow_requires_an_argument = + `{$name}` requires an argument + +mir_dataflow_stop_after_dataflow_ended_compilation = + stop_after_dataflow ended compilation + +mir_dataflow_peek_must_be_place_or_ref_place = + rustc_peek: argument expression must be either `place` or `&place` + +mir_dataflow_peek_must_be_not_temporary = + dataflow::sanity_check cannot feed a non-temp to rustc_peek + +mir_dataflow_peek_bit_not_set = + rustc_peek: bit not set + +mir_dataflow_peek_argument_not_a_local = + rustc_peek: argument was not a local + +mir_dataflow_peek_argument_untracked = + rustc_peek: argument untracked diff --git a/compiler/rustc_error_messages/locales/en-US/rustc_mir_dataflow.ftl b/compiler/rustc_error_messages/locales/en-US/rustc_mir_dataflow.ftl deleted file mode 100644 index 1bf654eb01aa0..0000000000000 --- a/compiler/rustc_error_messages/locales/en-US/rustc_mir_dataflow.ftl +++ /dev/null @@ -1,29 +0,0 @@ -rustc_mir_dataflow_path_must_end_in_filename = - path must end in a filename - -rustc_mir_dataflow_unknown_formatter = - unknown formatter - -rustc_mir_dataflow_duplicate_values_for = - duplicate values for `{$name}` - -rustc_mir_dataflow_requires_an_argument = - `{$name}` requires an argument - -rustc_mir_dataflow_stop_after_dataflow_ended_compilation = - stop_after_dataflow ended compilation - -rustc_mir_dataflow_peek_must_be_place_or_ref_place = - rustc_peek: argument expression must be either `place` or `&place` - -rustc_mir_dataflow_peek_must_be_not_temporary = - dataflow::sanity_check cannot feed a non-temp to rustc_peek - -rustc_mir_dataflow_peek_bit_not_set = - rustc_peek: bit not set - -rustc_mir_dataflow_peek_argument_not_a_local = - rustc_peek: argument was not a local - -rustc_mir_dataflow_peek_argument_untracked = - rustc_peek: argument untracked diff --git a/compiler/rustc_error_messages/src/lib.rs b/compiler/rustc_error_messages/src/lib.rs index bcbaa649a01fc..52451306bcd4c 100644 --- a/compiler/rustc_error_messages/src/lib.rs +++ b/compiler/rustc_error_messages/src/lib.rs @@ -43,7 +43,7 @@ fluent_messages! { passes => "../locales/en-US/passes.ftl", privacy => "../locales/en-US/privacy.ftl", typeck => "../locales/en-US/typeck.ftl", - rustc_mir_dataflow => "../locales/en-US/rustc_mir_dataflow.ftl", + mir_dataflow => "../locales/en-US/mir_dataflow.ftl", } pub use fluent_generated::{self as fluent, DEFAULT_LOCALE_RESOURCES}; diff --git a/compiler/rustc_mir_dataflow/src/errors.rs b/compiler/rustc_mir_dataflow/src/errors.rs index a30bf35fa1a2d..cc14257876c5c 100644 --- a/compiler/rustc_mir_dataflow/src/errors.rs +++ b/compiler/rustc_mir_dataflow/src/errors.rs @@ -2,21 +2,21 @@ use rustc_macros::SessionDiagnostic; use rustc_span::{Span, Symbol}; #[derive(SessionDiagnostic)] -#[diag(rustc_mir_dataflow::path_must_end_in_filename)] +#[diag(mir_dataflow::path_must_end_in_filename)] pub(crate) struct PathMustEndInFilename { #[primary_span] pub span: Span, } #[derive(SessionDiagnostic)] -#[diag(rustc_mir_dataflow::unknown_formatter)] +#[diag(mir_dataflow::unknown_formatter)] pub(crate) struct UnknownFormatter { #[primary_span] pub span: Span, } #[derive(SessionDiagnostic)] -#[diag(rustc_mir_dataflow::duplicate_values_for)] +#[diag(mir_dataflow::duplicate_values_for)] pub(crate) struct DuplicateValuesFor { #[primary_span] pub span: Span, @@ -24,7 +24,7 @@ pub(crate) struct DuplicateValuesFor { } #[derive(SessionDiagnostic)] -#[diag(rustc_mir_dataflow::requires_an_argument)] +#[diag(mir_dataflow::requires_an_argument)] pub(crate) struct RequiresAnArgument { #[primary_span] pub span: Span, @@ -32,39 +32,39 @@ pub(crate) struct RequiresAnArgument { } #[derive(SessionDiagnostic)] -#[diag(rustc_mir_dataflow::stop_after_dataflow_ended_compilation)] +#[diag(mir_dataflow::stop_after_dataflow_ended_compilation)] pub(crate) struct StopAfterDataFlowEndedCompilation; #[derive(SessionDiagnostic)] -#[diag(rustc_mir_dataflow::peek_must_be_place_or_ref_place)] +#[diag(mir_dataflow::peek_must_be_place_or_ref_place)] pub(crate) struct PeekMustBePlaceOrRefPlace { #[primary_span] pub span: Span, } #[derive(SessionDiagnostic)] -#[diag(rustc_mir_dataflow::peek_must_be_not_temporary)] +#[diag(mir_dataflow::peek_must_be_not_temporary)] pub(crate) struct PeekMustBeNotTemporary { #[primary_span] pub span: Span, } #[derive(SessionDiagnostic)] -#[diag(rustc_mir_dataflow::peek_bit_not_set)] +#[diag(mir_dataflow::peek_bit_not_set)] pub(crate) struct PeekBitNotSet { #[primary_span] pub span: Span, } #[derive(SessionDiagnostic)] -#[diag(rustc_mir_dataflow::peek_argument_not_a_local)] +#[diag(mir_dataflow::peek_argument_not_a_local)] pub(crate) struct PeekArgumentNotALocal { #[primary_span] pub span: Span, } #[derive(SessionDiagnostic)] -#[diag(rustc_mir_dataflow::peek_argument_untracked)] +#[diag(mir_dataflow::peek_argument_untracked)] pub(crate) struct PeekArgumentUntracked { #[primary_span] pub span: Span,