Skip to content

Commit

Permalink
Rollup merge of rust-lang#100754 - davidtwco:translation-incremental,…
Browse files Browse the repository at this point in the history
… r=compiler-errors

incremental: migrate diagnostics

- Apply the diagnostic migration lints to more functions on `Session`, namely: `span_warn`, `span_warn_with_code`, `warn` `note_without_error`, `span_note_without_error`, `struct_note_without_error`.
- Add impls of `IntoDiagnosticArg` for `std::io::Error`, `std::path::Path` and `std::path::PathBuf`.
- Migrate the `rustc_incremental` crate's diagnostics to translatable diagnostic structs.

r? ``@compiler-errors``
cc rust-lang#100717
  • Loading branch information
Dylan-DPC authored Sep 15, 2022
2 parents 00fcc82 + b058e41 commit 0138758
Show file tree
Hide file tree
Showing 33 changed files with 831 additions and 323 deletions.
6 changes: 6 additions & 0 deletions compiler/rustc_borrowck/src/diagnostics/region_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,12 @@ impl Display for RegionName {
}
}

impl rustc_errors::IntoDiagnosticArg for RegionName {
fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue<'static> {
self.to_string().into_diagnostic_arg()
}
}

impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
pub(crate) fn mir_def_id(&self) -> hir::def_id::LocalDefId {
self.body.source.def_id().expect_local()
Expand Down
14 changes: 1 addition & 13 deletions compiler/rustc_borrowck/src/session_diagnostics.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use rustc_errors::{IntoDiagnosticArg, MultiSpan};
use rustc_errors::MultiSpan;
use rustc_macros::{LintDiagnostic, SessionDiagnostic, SessionSubdiagnostic};
use rustc_middle::ty::Ty;
use rustc_span::Span;
Expand Down Expand Up @@ -137,18 +137,6 @@ pub(crate) enum LifetimeReturnCategoryErr<'a> {
},
}

impl IntoDiagnosticArg for &RegionName {
fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue<'static> {
format!("{}", self).into_diagnostic_arg()
}
}

impl IntoDiagnosticArg for RegionName {
fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue<'static> {
format!("{}", self).into_diagnostic_arg()
}
}

#[derive(SessionSubdiagnostic)]
pub(crate) enum RequireStaticErr {
#[note(borrowck::used_impl_require_static)]
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1205,6 +1205,9 @@ static DEFAULT_HOOK: LazyLock<Box<dyn Fn(&panic::PanicInfo<'_>) + Sync + Send +
///
/// When `install_ice_hook` is called, this function will be called as the panic
/// hook.
// FIXME(translation): need struct diagnostics implemented on `Handler`
#[allow(rustc::untranslatable_diagnostic)]
#[allow(rustc::diagnostic_outside_of_impl)]
pub fn report_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) {
let fallback_bundle =
rustc_errors::fallback_fluent_bundle(rustc_errors::DEFAULT_LOCALE_RESOURCES, false);
Expand Down
106 changes: 106 additions & 0 deletions compiler/rustc_error_messages/locales/en-US/incremental.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
incremental_unrecognized_depnode = unrecognized `DepNode` variant: {$name}
incremental_missing_depnode = missing `DepNode` variant
incremental_missing_if_this_changed = no `#[rustc_if_this_changed]` annotation detected
incremental_no_path = no path from `{$source}` to `{$target}`
incremental_ok = OK
incremental_unknown_reuse_kind = unknown cgu-reuse-kind `{$kind}` specified
incremental_missing_query_depgraph = found CGU-reuse attribute but `-Zquery-dep-graph` was not specified
incremental_malformed_cgu_name =
found malformed codegen unit name `{$user_path}`. codegen units names must always start with the name of the crate (`{$crate_name}` in this case).
incremental_no_module_named = no module named `{$user_path}` (mangled: {$cgu_name}). available modules: {$cgu_names}
incremental_field_associated_value_expected = associated value expected for `{$name}`
incremental_no_field = no field `{$name}`
incremental_assertion_auto = `except` specified DepNodes that can not be affected for \"{$name}\": \"{$e}\"
incremental_undefined_clean_dirty_assertions_item = clean/dirty auto-assertions not yet defined for Node::Item.node={$kind}
incremental_undefined_clean_dirty_assertions = clean/dirty auto-assertions not yet defined for {$kind}
incremental_repeated_depnode_label = dep-node label `{$label}` is repeated
incremental_unrecognized_depnode_label = dep-node label `{$label}` not recognized
incremental_not_dirty = `{$dep_node_str}` should be dirty but is not
incremental_not_clean = `{$dep_node_str}` should be clean but is not
incremental_not_loaded = `{$dep_node_str}` should have been loaded from disk but it was not
incremental_unknown_item = unknown item `{$name}`
incremental_no_cfg = no cfg attribute
incremental_associated_value_expected_for = associated value expected for `{$ident}`
incremental_associated_value_expected = expected an associated value
incremental_unchecked_clean = found unchecked `#[rustc_clean]` attribute
incremental_delete_old = unable to delete old {$name} at `{$path}`: {$err}
incremental_create_new = failed to create {$name} at `{$path}`: {$err}
incremental_write_new = failed to write {$name} to `{$path}`: {$err}
incremental_canonicalize_path = incremental compilation: error canonicalizing path `{$path}`: {$err}
incremental_create_incr_comp_dir = could not create incremental compilation {$tag} directory `{$path}`: {$err}
incremental_create_lock = incremental compilation: could not create session directory lock file: {$lock_err}
.lock_unsupported = the filesystem for the incremental path at {$session_dir} does not appear to support locking, consider changing the incremental path to a filesystem that supports locking or disable incremental compilation
.cargo_help_1 = incremental compilation can be disabled by setting the environment variable CARGO_INCREMENTAL=0 (see https://doc.rust-lang.org/cargo/reference/profiles.html#incremental)
.cargo_help_2 = the entire build directory can be changed to a different filesystem by setting the environment variable CARGO_TARGET_DIR to a different path (see https://doc.rust-lang.org/cargo/reference/config.html#buildtarget-dir)
incremental_delete_lock = error deleting lock file for incremental compilation session directory `{$path}`: {$err}
incremental_hard_link_failed =
hard linking files in the incremental compilation cache failed. copying files instead. consider moving the cache directory to a file system which supports hard linking in session dir `{$path}`
incremental_delete_partial = failed to delete partly initialized session dir `{$path}`: {$err}
incremental_delete_full = error deleting incremental compilation session directory `{$path}`: {$err}
incremental_finalize = error finalizing incremental compilation session directory `{$path}`: {$err}
incremental_invalid_gc_failed =
failed to garbage collect invalid incremental compilation session directory `{$path}`: {$err}
incremental_finalized_gc_failed =
failed to garbage collect finalized incremental compilation session directory `{$path}`: {$err}
incremental_session_gc_failed =
failed to garbage collect incremental compilation session directory `{$path}`: {$err}
incremental_assert_not_loaded =
we asserted that the incremental cache should not be loaded, but it was loaded
incremental_assert_loaded =
we asserted that an existing incremental cache directory should be successfully loaded, but it was not
incremental_delete_incompatible =
failed to delete invalidated or incompatible incremental compilation session directory contents `{$path}`: {$err}
incremental_load_dep_graph = could not load dep-graph from `{$path}`: {$err}
incremental_decode_incr_cache = could not decode incremental cache: {$err}
incremental_write_dep_graph = failed to write dependency graph to `{$path}`: {$err}
incremental_move_dep_graph = failed to move dependency graph from `{$from}` to `{$to}`: {$err}
incremental_create_dep_graph = failed to create dependency graph at `{$path}`: {$err}
incremental_copy_workproduct_to_cache = error copying object file `{$from}` to incremental directory as `{$to}`: {$err}
incremental_delete_workproduct = file-system error deleting outdated file `{$path}`: {$err}
10 changes: 10 additions & 0 deletions compiler/rustc_error_messages/locales/en-US/interface.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,13 @@ interface_rustc_error_unexpected_annotation =
interface_failed_writing_file =
failed to write file {$path}: {$error}"
interface_unsupported_crate_type_for_target =
dropping unsupported crate type `{$crate_type}` for target `{$target_triple}`
interface_multiple_output_types_adaption =
due to multiple output types requested, the explicitly specified output file name will be adapted for each output type
interface_ignoring_extra_filename = ignoring -C extra-filename flag due to -o flag
interface_ignoring_out_dir = ignoring --out-dir flag due to -o flag
6 changes: 6 additions & 0 deletions compiler/rustc_error_messages/locales/en-US/monomorphize.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,9 @@ monomorphize_large_assignments =
monomorphize_requires_lang_item =
requires `{$lang_item}` lang_item
monomorphize_encountered_error_while_instantiating =
the above error was encountered while instantiating `{$formatted_item}`
monomorphize_unknown_cgu_collection_mode =
unknown codegen-item collection mode '{$mode}', falling back to 'lazy' mode
2 changes: 2 additions & 0 deletions compiler/rustc_error_messages/locales/en-US/session.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,5 @@ session_crate_name_invalid = crate names cannot start with a `-`, but `{$s}` has
session_crate_name_empty = crate name must not be empty
session_invalid_character_in_create_name = invalid character `{$character}` in crate name: `{$crate_name}`
session_optimization_fuel_exhausted = optimization-fuel-exhausted: {$msg}
13 changes: 7 additions & 6 deletions compiler/rustc_error_messages/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,25 @@ fluent_messages! {
const_eval => "../locales/en-US/const_eval.ftl",
driver => "../locales/en-US/driver.ftl",
expand => "../locales/en-US/expand.ftl",
session => "../locales/en-US/session.ftl",
interface => "../locales/en-US/interface.ftl",
incremental => "../locales/en-US/incremental.ftl",
infer => "../locales/en-US/infer.ftl",
interface => "../locales/en-US/interface.ftl",
lint => "../locales/en-US/lint.ftl",
metadata => "../locales/en-US/metadata.ftl",
middle => "../locales/en-US/middle.ftl",
mir_dataflow => "../locales/en-US/mir_dataflow.ftl",
monomorphize => "../locales/en-US/monomorphize.ftl",
metadata => "../locales/en-US/metadata.ftl",
parser => "../locales/en-US/parser.ftl",
passes => "../locales/en-US/passes.ftl",
plugin_impl => "../locales/en-US/plugin_impl.ftl",
privacy => "../locales/en-US/privacy.ftl",
query_system => "../locales/en-US/query_system.ftl",
trait_selection => "../locales/en-US/trait_selection.ftl",
save_analysis => "../locales/en-US/save_analysis.ftl",
session => "../locales/en-US/session.ftl",
symbol_mangling => "../locales/en-US/symbol_mangling.ftl",
trait_selection => "../locales/en-US/trait_selection.ftl",
ty_utils => "../locales/en-US/ty_utils.ftl",
typeck => "../locales/en-US/typeck.ftl",
mir_dataflow => "../locales/en-US/mir_dataflow.ftl",
symbol_mangling => "../locales/en-US/symbol_mangling.ftl",
}

pub use fluent_generated::{self as fluent, DEFAULT_LOCALE_RESOURCES};
Expand Down
20 changes: 10 additions & 10 deletions compiler/rustc_errors/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@ edition = "2021"
doctest = false

[dependencies]
tracing = "0.1"
annotate-snippets = "0.9"
atty = "0.2"
rustc_data_structures = { path = "../rustc_data_structures" }
rustc_error_messages = { path = "../rustc_error_messages" }
rustc_hir = { path = "../rustc_hir" }
rustc_lint_defs = { path = "../rustc_lint_defs" }
rustc_macros = { path = "../rustc_macros" }
rustc_serialize = { path = "../rustc_serialize" }
rustc_span = { path = "../rustc_span" }
rustc_macros = { path = "../rustc_macros" }
rustc_data_structures = { path = "../rustc_data_structures" }
rustc_target = { path = "../rustc_target" }
rustc_hir = { path = "../rustc_hir" }
rustc_lint_defs = { path = "../rustc_lint_defs" }
unicode-width = "0.1.4"
atty = "0.2"
termcolor = "1.0"
annotate-snippets = "0.9"
termize = "0.1.1"
serde = { version = "1.0.125", features = [ "derive" ] }
serde_json = "1.0.59"
termcolor = "1.0"
termize = "0.1.1"
tracing = "0.1"
unicode-width = "0.1.4"

[target.'cfg(windows)'.dependencies]
winapi = { version = "0.3", features = [ "handleapi", "synchapi", "winbase" ] }
8 changes: 7 additions & 1 deletion compiler/rustc_errors/src/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ pub trait IntoDiagnosticArg {
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static>;
}

impl<'a, T: Clone + IntoDiagnosticArg> IntoDiagnosticArg for &'a T {
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
self.clone().into_diagnostic_arg()
}
}

pub struct DiagnosticArgFromDisplay<'a>(pub &'a dyn fmt::Display);

impl IntoDiagnosticArg for DiagnosticArgFromDisplay<'_> {
Expand Down Expand Up @@ -94,7 +100,7 @@ into_diagnostic_arg_using_display!(
MacroRulesNormalizedIdent,
ParseIntError,
StackProtector,
&TargetTriple,
TargetTriple,
SplitDebuginfo
);

Expand Down
50 changes: 50 additions & 0 deletions compiler/rustc_errors/src/diagnostic_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,56 @@ impl EmissionGuarantee for () {
}
}

/// Marker type which enables implementation of `create_note` and `emit_note` functions for
/// note-without-error struct diagnostics.
#[derive(Copy, Clone)]
pub struct Noted;

impl<'a> DiagnosticBuilder<'a, Noted> {
/// Convenience function for internal use, clients should use one of the
/// `struct_*` methods on [`Handler`].
pub(crate) fn new_note(handler: &'a Handler, message: impl Into<DiagnosticMessage>) -> Self {
let diagnostic = Diagnostic::new_with_code(Level::Note, None, message);
Self::new_diagnostic_note(handler, diagnostic)
}

/// Creates a new `DiagnosticBuilder` with an already constructed
/// diagnostic.
pub(crate) fn new_diagnostic_note(handler: &'a Handler, diagnostic: Diagnostic) -> Self {
debug!("Created new diagnostic");
Self {
inner: DiagnosticBuilderInner {
state: DiagnosticBuilderState::Emittable(handler),
diagnostic: Box::new(diagnostic),
},
_marker: PhantomData,
}
}
}

impl EmissionGuarantee for Noted {
fn diagnostic_builder_emit_producing_guarantee(db: &mut DiagnosticBuilder<'_, Self>) -> Self {
match db.inner.state {
// First `.emit()` call, the `&Handler` is still available.
DiagnosticBuilderState::Emittable(handler) => {
db.inner.state = DiagnosticBuilderState::AlreadyEmittedOrDuringCancellation;
handler.emit_diagnostic(&mut db.inner.diagnostic);
}
// `.emit()` was previously called, disallowed from repeating it.
DiagnosticBuilderState::AlreadyEmittedOrDuringCancellation => {}
}

Noted
}

fn make_diagnostic_builder(
handler: &Handler,
msg: impl Into<DiagnosticMessage>,
) -> DiagnosticBuilder<'_, Self> {
DiagnosticBuilder::new_note(handler, msg)
}
}

impl<'a> DiagnosticBuilder<'a, !> {
/// Convenience function for internal use, clients should use one of the
/// `struct_*` methods on [`Handler`].
Expand Down
8 changes: 7 additions & 1 deletion compiler/rustc_errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ pub use diagnostic::{
AddSubdiagnostic, DecorateLint, Diagnostic, DiagnosticArg, DiagnosticArgFromDisplay,
DiagnosticArgValue, DiagnosticId, DiagnosticStyledString, IntoDiagnosticArg, SubDiagnostic,
};
pub use diagnostic_builder::{DiagnosticBuilder, EmissionGuarantee, LintDiagnosticBuilder};
pub use diagnostic_builder::{DiagnosticBuilder, EmissionGuarantee, LintDiagnosticBuilder, Noted};
use std::backtrace::Backtrace;

/// A handler deals with errors and other compiler output.
Expand Down Expand Up @@ -936,6 +936,7 @@ impl Handler {
self.emit_diag_at_span(Diagnostic::new(Bug, msg), span);
}

#[rustc_lint_diagnostics]
pub fn span_note_without_error(
&self,
span: impl Into<MultiSpan>,
Expand All @@ -944,6 +945,7 @@ impl Handler {
self.emit_diag_at_span(Diagnostic::new(Note, msg), span);
}

#[rustc_lint_diagnostics]
pub fn span_note_diag(
&self,
span: Span,
Expand All @@ -955,19 +957,23 @@ impl Handler {
}

// NOTE: intentionally doesn't raise an error so rustc_codegen_ssa only reports fatal errors in the main thread
#[rustc_lint_diagnostics]
pub fn fatal(&self, msg: impl Into<DiagnosticMessage>) -> FatalError {
self.inner.borrow_mut().fatal(msg)
}

#[rustc_lint_diagnostics]
pub fn err(&self, msg: impl Into<DiagnosticMessage>) -> ErrorGuaranteed {
self.inner.borrow_mut().err(msg)
}

#[rustc_lint_diagnostics]
pub fn warn(&self, msg: impl Into<DiagnosticMessage>) {
let mut db = DiagnosticBuilder::new(self, Warning(None), msg);
db.emit();
}

#[rustc_lint_diagnostics]
pub fn note_without_error(&self, msg: impl Into<DiagnosticMessage>) {
DiagnosticBuilder::new(self, Note, msg).emit();
}
Expand Down
Loading

0 comments on commit 0138758

Please sign in to comment.