Skip to content

Commit 02e43ff

Browse files
authored
Rollup merge of rust-lang#100754 - davidtwco:translation-incremental, 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
2 parents 00fcc82 + b058e41 commit 02e43ff

File tree

33 files changed

+831
-323
lines changed

33 files changed

+831
-323
lines changed

compiler/rustc_borrowck/src/diagnostics/region_name.rs

+6
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,12 @@ impl Display for RegionName {
187187
}
188188
}
189189

190+
impl rustc_errors::IntoDiagnosticArg for RegionName {
191+
fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue<'static> {
192+
self.to_string().into_diagnostic_arg()
193+
}
194+
}
195+
190196
impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
191197
pub(crate) fn mir_def_id(&self) -> hir::def_id::LocalDefId {
192198
self.body.source.def_id().expect_local()

compiler/rustc_borrowck/src/session_diagnostics.rs

+1-13
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use rustc_errors::{IntoDiagnosticArg, MultiSpan};
1+
use rustc_errors::MultiSpan;
22
use rustc_macros::{LintDiagnostic, SessionDiagnostic, SessionSubdiagnostic};
33
use rustc_middle::ty::Ty;
44
use rustc_span::Span;
@@ -137,18 +137,6 @@ pub(crate) enum LifetimeReturnCategoryErr<'a> {
137137
},
138138
}
139139

140-
impl IntoDiagnosticArg for &RegionName {
141-
fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue<'static> {
142-
format!("{}", self).into_diagnostic_arg()
143-
}
144-
}
145-
146-
impl IntoDiagnosticArg for RegionName {
147-
fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue<'static> {
148-
format!("{}", self).into_diagnostic_arg()
149-
}
150-
}
151-
152140
#[derive(SessionSubdiagnostic)]
153141
pub(crate) enum RequireStaticErr {
154142
#[note(borrowck::used_impl_require_static)]

compiler/rustc_driver/src/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1205,6 +1205,9 @@ static DEFAULT_HOOK: LazyLock<Box<dyn Fn(&panic::PanicInfo<'_>) + Sync + Send +
12051205
///
12061206
/// When `install_ice_hook` is called, this function will be called as the panic
12071207
/// hook.
1208+
// FIXME(translation): need struct diagnostics implemented on `Handler`
1209+
#[allow(rustc::untranslatable_diagnostic)]
1210+
#[allow(rustc::diagnostic_outside_of_impl)]
12081211
pub fn report_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) {
12091212
let fallback_bundle =
12101213
rustc_errors::fallback_fluent_bundle(rustc_errors::DEFAULT_LOCALE_RESOURCES, false);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
incremental_unrecognized_depnode = unrecognized `DepNode` variant: {$name}
2+
3+
incremental_missing_depnode = missing `DepNode` variant
4+
5+
incremental_missing_if_this_changed = no `#[rustc_if_this_changed]` annotation detected
6+
7+
incremental_no_path = no path from `{$source}` to `{$target}`
8+
9+
incremental_ok = OK
10+
11+
incremental_unknown_reuse_kind = unknown cgu-reuse-kind `{$kind}` specified
12+
13+
incremental_missing_query_depgraph = found CGU-reuse attribute but `-Zquery-dep-graph` was not specified
14+
15+
incremental_malformed_cgu_name =
16+
found malformed codegen unit name `{$user_path}`. codegen units names must always start with the name of the crate (`{$crate_name}` in this case).
17+
18+
incremental_no_module_named = no module named `{$user_path}` (mangled: {$cgu_name}). available modules: {$cgu_names}
19+
20+
incremental_field_associated_value_expected = associated value expected for `{$name}`
21+
22+
incremental_no_field = no field `{$name}`
23+
24+
incremental_assertion_auto = `except` specified DepNodes that can not be affected for \"{$name}\": \"{$e}\"
25+
26+
incremental_undefined_clean_dirty_assertions_item = clean/dirty auto-assertions not yet defined for Node::Item.node={$kind}
27+
28+
incremental_undefined_clean_dirty_assertions = clean/dirty auto-assertions not yet defined for {$kind}
29+
30+
incremental_repeated_depnode_label = dep-node label `{$label}` is repeated
31+
32+
incremental_unrecognized_depnode_label = dep-node label `{$label}` not recognized
33+
34+
incremental_not_dirty = `{$dep_node_str}` should be dirty but is not
35+
36+
incremental_not_clean = `{$dep_node_str}` should be clean but is not
37+
38+
incremental_not_loaded = `{$dep_node_str}` should have been loaded from disk but it was not
39+
40+
incremental_unknown_item = unknown item `{$name}`
41+
42+
incremental_no_cfg = no cfg attribute
43+
44+
incremental_associated_value_expected_for = associated value expected for `{$ident}`
45+
46+
incremental_associated_value_expected = expected an associated value
47+
48+
incremental_unchecked_clean = found unchecked `#[rustc_clean]` attribute
49+
50+
incremental_delete_old = unable to delete old {$name} at `{$path}`: {$err}
51+
52+
incremental_create_new = failed to create {$name} at `{$path}`: {$err}
53+
54+
incremental_write_new = failed to write {$name} to `{$path}`: {$err}
55+
56+
incremental_canonicalize_path = incremental compilation: error canonicalizing path `{$path}`: {$err}
57+
58+
incremental_create_incr_comp_dir = could not create incremental compilation {$tag} directory `{$path}`: {$err}
59+
60+
incremental_create_lock = incremental compilation: could not create session directory lock file: {$lock_err}
61+
.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
62+
.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)
63+
.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)
64+
65+
incremental_delete_lock = error deleting lock file for incremental compilation session directory `{$path}`: {$err}
66+
67+
incremental_hard_link_failed =
68+
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}`
69+
70+
incremental_delete_partial = failed to delete partly initialized session dir `{$path}`: {$err}
71+
72+
incremental_delete_full = error deleting incremental compilation session directory `{$path}`: {$err}
73+
74+
incremental_finalize = error finalizing incremental compilation session directory `{$path}`: {$err}
75+
76+
incremental_invalid_gc_failed =
77+
failed to garbage collect invalid incremental compilation session directory `{$path}`: {$err}
78+
79+
incremental_finalized_gc_failed =
80+
failed to garbage collect finalized incremental compilation session directory `{$path}`: {$err}
81+
82+
incremental_session_gc_failed =
83+
failed to garbage collect incremental compilation session directory `{$path}`: {$err}
84+
85+
incremental_assert_not_loaded =
86+
we asserted that the incremental cache should not be loaded, but it was loaded
87+
88+
incremental_assert_loaded =
89+
we asserted that an existing incremental cache directory should be successfully loaded, but it was not
90+
91+
incremental_delete_incompatible =
92+
failed to delete invalidated or incompatible incremental compilation session directory contents `{$path}`: {$err}
93+
94+
incremental_load_dep_graph = could not load dep-graph from `{$path}`: {$err}
95+
96+
incremental_decode_incr_cache = could not decode incremental cache: {$err}
97+
98+
incremental_write_dep_graph = failed to write dependency graph to `{$path}`: {$err}
99+
100+
incremental_move_dep_graph = failed to move dependency graph from `{$from}` to `{$to}`: {$err}
101+
102+
incremental_create_dep_graph = failed to create dependency graph at `{$path}`: {$err}
103+
104+
incremental_copy_workproduct_to_cache = error copying object file `{$from}` to incremental directory as `{$to}`: {$err}
105+
106+
incremental_delete_workproduct = file-system error deleting outdated file `{$path}`: {$err}

compiler/rustc_error_messages/locales/en-US/interface.ftl

+10
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,13 @@ interface_rustc_error_unexpected_annotation =
4141
4242
interface_failed_writing_file =
4343
failed to write file {$path}: {$error}"
44+
45+
interface_unsupported_crate_type_for_target =
46+
dropping unsupported crate type `{$crate_type}` for target `{$target_triple}`
47+
48+
interface_multiple_output_types_adaption =
49+
due to multiple output types requested, the explicitly specified output file name will be adapted for each output type
50+
51+
interface_ignoring_extra_filename = ignoring -C extra-filename flag due to -o flag
52+
53+
interface_ignoring_out_dir = ignoring --out-dir flag due to -o flag

compiler/rustc_error_messages/locales/en-US/monomorphize.ftl

+6
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,9 @@ monomorphize_large_assignments =
2424
2525
monomorphize_requires_lang_item =
2626
requires `{$lang_item}` lang_item
27+
28+
monomorphize_encountered_error_while_instantiating =
29+
the above error was encountered while instantiating `{$formatted_item}`
30+
31+
monomorphize_unknown_cgu_collection_mode =
32+
unknown codegen-item collection mode '{$mode}', falling back to 'lazy' mode

compiler/rustc_error_messages/locales/en-US/session.ftl

+2
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,5 @@ session_crate_name_invalid = crate names cannot start with a `-`, but `{$s}` has
6666
session_crate_name_empty = crate name must not be empty
6767
6868
session_invalid_character_in_create_name = invalid character `{$character}` in crate name: `{$crate_name}`
69+
70+
session_optimization_fuel_exhausted = optimization-fuel-exhausted: {$msg}

compiler/rustc_error_messages/src/lib.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -43,24 +43,25 @@ fluent_messages! {
4343
const_eval => "../locales/en-US/const_eval.ftl",
4444
driver => "../locales/en-US/driver.ftl",
4545
expand => "../locales/en-US/expand.ftl",
46-
session => "../locales/en-US/session.ftl",
47-
interface => "../locales/en-US/interface.ftl",
46+
incremental => "../locales/en-US/incremental.ftl",
4847
infer => "../locales/en-US/infer.ftl",
48+
interface => "../locales/en-US/interface.ftl",
4949
lint => "../locales/en-US/lint.ftl",
50+
metadata => "../locales/en-US/metadata.ftl",
5051
middle => "../locales/en-US/middle.ftl",
52+
mir_dataflow => "../locales/en-US/mir_dataflow.ftl",
5153
monomorphize => "../locales/en-US/monomorphize.ftl",
52-
metadata => "../locales/en-US/metadata.ftl",
5354
parser => "../locales/en-US/parser.ftl",
5455
passes => "../locales/en-US/passes.ftl",
5556
plugin_impl => "../locales/en-US/plugin_impl.ftl",
5657
privacy => "../locales/en-US/privacy.ftl",
5758
query_system => "../locales/en-US/query_system.ftl",
58-
trait_selection => "../locales/en-US/trait_selection.ftl",
5959
save_analysis => "../locales/en-US/save_analysis.ftl",
60+
session => "../locales/en-US/session.ftl",
61+
symbol_mangling => "../locales/en-US/symbol_mangling.ftl",
62+
trait_selection => "../locales/en-US/trait_selection.ftl",
6063
ty_utils => "../locales/en-US/ty_utils.ftl",
6164
typeck => "../locales/en-US/typeck.ftl",
62-
mir_dataflow => "../locales/en-US/mir_dataflow.ftl",
63-
symbol_mangling => "../locales/en-US/symbol_mangling.ftl",
6465
}
6566

6667
pub use fluent_generated::{self as fluent, DEFAULT_LOCALE_RESOURCES};

compiler/rustc_errors/Cargo.toml

+10-10
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,22 @@ edition = "2021"
77
doctest = false
88

99
[dependencies]
10-
tracing = "0.1"
10+
annotate-snippets = "0.9"
11+
atty = "0.2"
12+
rustc_data_structures = { path = "../rustc_data_structures" }
1113
rustc_error_messages = { path = "../rustc_error_messages" }
14+
rustc_hir = { path = "../rustc_hir" }
15+
rustc_lint_defs = { path = "../rustc_lint_defs" }
16+
rustc_macros = { path = "../rustc_macros" }
1217
rustc_serialize = { path = "../rustc_serialize" }
1318
rustc_span = { path = "../rustc_span" }
14-
rustc_macros = { path = "../rustc_macros" }
15-
rustc_data_structures = { path = "../rustc_data_structures" }
1619
rustc_target = { path = "../rustc_target" }
17-
rustc_hir = { path = "../rustc_hir" }
18-
rustc_lint_defs = { path = "../rustc_lint_defs" }
19-
unicode-width = "0.1.4"
20-
atty = "0.2"
21-
termcolor = "1.0"
22-
annotate-snippets = "0.9"
23-
termize = "0.1.1"
2420
serde = { version = "1.0.125", features = [ "derive" ] }
2521
serde_json = "1.0.59"
22+
termcolor = "1.0"
23+
termize = "0.1.1"
24+
tracing = "0.1"
25+
unicode-width = "0.1.4"
2626

2727
[target.'cfg(windows)'.dependencies]
2828
winapi = { version = "0.3", features = [ "handleapi", "synchapi", "winbase" ] }

compiler/rustc_errors/src/diagnostic.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ pub trait IntoDiagnosticArg {
4343
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static>;
4444
}
4545

46+
impl<'a, T: Clone + IntoDiagnosticArg> IntoDiagnosticArg for &'a T {
47+
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
48+
self.clone().into_diagnostic_arg()
49+
}
50+
}
51+
4652
pub struct DiagnosticArgFromDisplay<'a>(pub &'a dyn fmt::Display);
4753

4854
impl IntoDiagnosticArg for DiagnosticArgFromDisplay<'_> {
@@ -94,7 +100,7 @@ into_diagnostic_arg_using_display!(
94100
MacroRulesNormalizedIdent,
95101
ParseIntError,
96102
StackProtector,
97-
&TargetTriple,
103+
TargetTriple,
98104
SplitDebuginfo
99105
);
100106

compiler/rustc_errors/src/diagnostic_builder.rs

+50
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,56 @@ impl EmissionGuarantee for () {
232232
}
233233
}
234234

235+
/// Marker type which enables implementation of `create_note` and `emit_note` functions for
236+
/// note-without-error struct diagnostics.
237+
#[derive(Copy, Clone)]
238+
pub struct Noted;
239+
240+
impl<'a> DiagnosticBuilder<'a, Noted> {
241+
/// Convenience function for internal use, clients should use one of the
242+
/// `struct_*` methods on [`Handler`].
243+
pub(crate) fn new_note(handler: &'a Handler, message: impl Into<DiagnosticMessage>) -> Self {
244+
let diagnostic = Diagnostic::new_with_code(Level::Note, None, message);
245+
Self::new_diagnostic_note(handler, diagnostic)
246+
}
247+
248+
/// Creates a new `DiagnosticBuilder` with an already constructed
249+
/// diagnostic.
250+
pub(crate) fn new_diagnostic_note(handler: &'a Handler, diagnostic: Diagnostic) -> Self {
251+
debug!("Created new diagnostic");
252+
Self {
253+
inner: DiagnosticBuilderInner {
254+
state: DiagnosticBuilderState::Emittable(handler),
255+
diagnostic: Box::new(diagnostic),
256+
},
257+
_marker: PhantomData,
258+
}
259+
}
260+
}
261+
262+
impl EmissionGuarantee for Noted {
263+
fn diagnostic_builder_emit_producing_guarantee(db: &mut DiagnosticBuilder<'_, Self>) -> Self {
264+
match db.inner.state {
265+
// First `.emit()` call, the `&Handler` is still available.
266+
DiagnosticBuilderState::Emittable(handler) => {
267+
db.inner.state = DiagnosticBuilderState::AlreadyEmittedOrDuringCancellation;
268+
handler.emit_diagnostic(&mut db.inner.diagnostic);
269+
}
270+
// `.emit()` was previously called, disallowed from repeating it.
271+
DiagnosticBuilderState::AlreadyEmittedOrDuringCancellation => {}
272+
}
273+
274+
Noted
275+
}
276+
277+
fn make_diagnostic_builder(
278+
handler: &Handler,
279+
msg: impl Into<DiagnosticMessage>,
280+
) -> DiagnosticBuilder<'_, Self> {
281+
DiagnosticBuilder::new_note(handler, msg)
282+
}
283+
}
284+
235285
impl<'a> DiagnosticBuilder<'a, !> {
236286
/// Convenience function for internal use, clients should use one of the
237287
/// `struct_*` methods on [`Handler`].

compiler/rustc_errors/src/lib.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ pub use diagnostic::{
373373
AddSubdiagnostic, DecorateLint, Diagnostic, DiagnosticArg, DiagnosticArgFromDisplay,
374374
DiagnosticArgValue, DiagnosticId, DiagnosticStyledString, IntoDiagnosticArg, SubDiagnostic,
375375
};
376-
pub use diagnostic_builder::{DiagnosticBuilder, EmissionGuarantee, LintDiagnosticBuilder};
376+
pub use diagnostic_builder::{DiagnosticBuilder, EmissionGuarantee, LintDiagnosticBuilder, Noted};
377377
use std::backtrace::Backtrace;
378378

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

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

948+
#[rustc_lint_diagnostics]
947949
pub fn span_note_diag(
948950
&self,
949951
span: Span,
@@ -955,19 +957,23 @@ impl Handler {
955957
}
956958

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

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

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

976+
#[rustc_lint_diagnostics]
971977
pub fn note_without_error(&self, msg: impl Into<DiagnosticMessage>) {
972978
DiagnosticBuilder::new(self, Note, msg).emit();
973979
}

0 commit comments

Comments
 (0)