Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit bbed968

Browse files
authoredAug 27, 2022
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 2910abe + 3becaaf commit bbed968

File tree

14 files changed

+611
-253
lines changed

14 files changed

+611
-253
lines changed
 
Lines changed: 106 additions & 0 deletions
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/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ fluent_messages! {
4040
const_eval => "../locales/en-US/const_eval.ftl",
4141
driver => "../locales/en-US/driver.ftl",
4242
expand => "../locales/en-US/expand.ftl",
43+
incremental => "../locales/en-US/incremental.ftl",
4344
interface => "../locales/en-US/interface.ftl",
4445
lint => "../locales/en-US/lint.ftl",
4546
parser => "../locales/en-US/parser.ftl",

‎compiler/rustc_incremental/src/assert_dep_graph.rs

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
//! fn baz() { foo(); }
3434
//! ```
3535
36+
use crate::errors;
3637
use rustc_ast as ast;
3738
use rustc_data_structures::fx::FxHashSet;
3839
use rustc_data_structures::graph::implementation::{Direction, NodeIndex, INCOMING, OUTGOING};
@@ -133,12 +134,10 @@ impl<'tcx> IfThisChanged<'tcx> {
133134
Some(n) => {
134135
match DepNode::from_label_string(self.tcx, n.as_str(), def_path_hash) {
135136
Ok(n) => n,
136-
Err(()) => {
137-
self.tcx.sess.span_fatal(
138-
attr.span,
139-
&format!("unrecognized DepNode variant {:?}", n),
140-
);
141-
}
137+
Err(()) => self.tcx.sess.emit_fatal(errors::UnrecognizedDepNode {
138+
span: attr.span,
139+
name: n,
140+
}),
142141
}
143142
}
144143
};
@@ -149,16 +148,14 @@ impl<'tcx> IfThisChanged<'tcx> {
149148
Some(n) => {
150149
match DepNode::from_label_string(self.tcx, n.as_str(), def_path_hash) {
151150
Ok(n) => n,
152-
Err(()) => {
153-
self.tcx.sess.span_fatal(
154-
attr.span,
155-
&format!("unrecognized DepNode variant {:?}", n),
156-
);
157-
}
151+
Err(()) => self.tcx.sess.emit_fatal(errors::UnrecognizedDepNode {
152+
span: attr.span,
153+
name: n,
154+
}),
158155
}
159156
}
160157
None => {
161-
self.tcx.sess.span_fatal(attr.span, "missing DepNode variant");
158+
self.tcx.sess.emit_fatal(errors::MissingDepNode { span: attr.span });
162159
}
163160
};
164161
self.then_this_would_need.push((
@@ -204,7 +201,7 @@ fn check_paths<'tcx>(tcx: TyCtxt<'tcx>, if_this_changed: &Sources, then_this_wou
204201
// Return early here so as not to construct the query, which is not cheap.
205202
if if_this_changed.is_empty() {
206203
for &(target_span, _, _, _) in then_this_would_need {
207-
tcx.sess.span_err(target_span, "no `#[rustc_if_this_changed]` annotation detected");
204+
tcx.sess.emit_err(errors::MissingIfThisChanged { span: target_span });
208205
}
209206
return;
210207
}
@@ -213,16 +210,13 @@ fn check_paths<'tcx>(tcx: TyCtxt<'tcx>, if_this_changed: &Sources, then_this_wou
213210
let dependents = query.transitive_predecessors(source_dep_node);
214211
for &(target_span, ref target_pass, _, ref target_dep_node) in then_this_would_need {
215212
if !dependents.contains(&target_dep_node) {
216-
tcx.sess.span_err(
217-
target_span,
218-
&format!(
219-
"no path from `{}` to `{}`",
220-
tcx.def_path_str(source_def_id),
221-
target_pass
222-
),
223-
);
213+
tcx.sess.emit_err(errors::NoPath {
214+
span: target_span,
215+
source: tcx.def_path_str(source_def_id),
216+
target: *target_pass,
217+
});
224218
} else {
225-
tcx.sess.span_err(target_span, "OK");
219+
tcx.sess.emit_err(errors::Ok { span: target_span });
226220
}
227221
}
228222
}

‎compiler/rustc_incremental/src/assert_module_sources.rs

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
//! allows for doing a more fine-grained check to see if pre- or post-lto data
2323
//! was re-used.
2424
25+
use crate::errors;
2526
use rustc_ast as ast;
2627
use rustc_data_structures::fx::FxHashSet;
2728
use rustc_hir::def_id::LOCAL_CRATE;
@@ -66,21 +67,17 @@ impl<'tcx> AssertModuleSource<'tcx> {
6667
sym::post_dash_lto => (CguReuse::PostLto, ComparisonKind::Exact),
6768
sym::any => (CguReuse::PreLto, ComparisonKind::AtLeast),
6869
other => {
69-
self.tcx.sess.span_fatal(
70-
attr.span,
71-
&format!("unknown cgu-reuse-kind `{}` specified", other),
72-
);
70+
self.tcx
71+
.sess
72+
.emit_fatal(errors::UnknownReuseKind { span: attr.span, kind: other });
7373
}
7474
}
7575
} else {
7676
return;
7777
};
7878

7979
if !self.tcx.sess.opts.unstable_opts.query_dep_graph {
80-
self.tcx.sess.span_fatal(
81-
attr.span,
82-
"found CGU-reuse attribute but `-Zquery-dep-graph` was not specified",
83-
);
80+
self.tcx.sess.emit_fatal(errors::MissingQueryDepGraph { span: attr.span });
8481
}
8582

8683
if !self.check_config(attr) {
@@ -92,13 +89,11 @@ impl<'tcx> AssertModuleSource<'tcx> {
9289
let crate_name = self.tcx.crate_name(LOCAL_CRATE).to_string();
9390

9491
if !user_path.starts_with(&crate_name) {
95-
let msg = format!(
96-
"Found malformed codegen unit name `{}`. \
97-
Codegen units names must always start with the name of the \
98-
crate (`{}` in this case).",
99-
user_path, crate_name
100-
);
101-
self.tcx.sess.span_fatal(attr.span, &msg);
92+
self.tcx.sess.emit_fatal(errors::MalformedCguName {
93+
span: attr.span,
94+
user_path,
95+
crate_name,
96+
});
10297
}
10398

10499
// Split of the "special suffix" if there is one.
@@ -125,15 +120,12 @@ impl<'tcx> AssertModuleSource<'tcx> {
125120
let mut cgu_names: Vec<&str> =
126121
self.available_cgus.iter().map(|cgu| cgu.as_str()).collect();
127122
cgu_names.sort();
128-
self.tcx.sess.span_err(
129-
attr.span,
130-
&format!(
131-
"no module named `{}` (mangled: {}). Available modules: {}",
132-
user_path,
133-
cgu_name,
134-
cgu_names.join(", ")
135-
),
136-
);
123+
self.tcx.sess.emit_err(errors::NoModuleNamed {
124+
span: attr.span,
125+
user_path,
126+
cgu_name,
127+
cgu_names: cgu_names.join(", "),
128+
});
137129
}
138130

139131
self.tcx.sess.cgu_reuse_tracker.set_expectation(
@@ -151,15 +143,15 @@ impl<'tcx> AssertModuleSource<'tcx> {
151143
if let Some(value) = item.value_str() {
152144
return value;
153145
} else {
154-
self.tcx.sess.span_fatal(
155-
item.span(),
156-
&format!("associated value expected for `{}`", name),
157-
);
146+
self.tcx.sess.emit_fatal(errors::FieldAssociatedValueExpected {
147+
span: item.span(),
148+
name,
149+
});
158150
}
159151
}
160152
}
161153

162-
self.tcx.sess.span_fatal(attr.span, &format!("no field `{}`", name));
154+
self.tcx.sess.emit_fatal(errors::NoField { span: attr.span, name });
163155
}
164156

165157
/// Scan for a `cfg="foo"` attribute and check whether we have a
Lines changed: 364 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,364 @@
1+
use rustc_macros::SessionDiagnostic;
2+
use rustc_span::{symbol::Ident, Span, Symbol};
3+
use std::path::{Path, PathBuf};
4+
5+
#[derive(SessionDiagnostic)]
6+
#[diag(incremental::unrecognized_depnode)]
7+
pub struct UnrecognizedDepNode {
8+
#[primary_span]
9+
pub span: Span,
10+
pub name: Symbol,
11+
}
12+
13+
#[derive(SessionDiagnostic)]
14+
#[diag(incremental::missing_depnode)]
15+
pub struct MissingDepNode {
16+
#[primary_span]
17+
pub span: Span,
18+
}
19+
20+
#[derive(SessionDiagnostic)]
21+
#[diag(incremental::missing_if_this_changed)]
22+
pub struct MissingIfThisChanged {
23+
#[primary_span]
24+
pub span: Span,
25+
}
26+
27+
#[derive(SessionDiagnostic)]
28+
#[diag(incremental::ok)]
29+
pub struct Ok {
30+
#[primary_span]
31+
pub span: Span,
32+
}
33+
34+
#[derive(SessionDiagnostic)]
35+
#[diag(incremental::no_path)]
36+
pub struct NoPath {
37+
#[primary_span]
38+
pub span: Span,
39+
pub target: Symbol,
40+
pub source: String,
41+
}
42+
43+
#[derive(SessionDiagnostic)]
44+
#[diag(incremental::unknown_reuse_kind)]
45+
pub struct UnknownReuseKind {
46+
#[primary_span]
47+
pub span: Span,
48+
pub kind: Symbol,
49+
}
50+
51+
#[derive(SessionDiagnostic)]
52+
#[diag(incremental::missing_query_depgraph)]
53+
pub struct MissingQueryDepGraph {
54+
#[primary_span]
55+
pub span: Span,
56+
}
57+
58+
#[derive(SessionDiagnostic)]
59+
#[diag(incremental::malformed_cgu_name)]
60+
pub struct MalformedCguName {
61+
#[primary_span]
62+
pub span: Span,
63+
pub user_path: String,
64+
pub crate_name: String,
65+
}
66+
67+
#[derive(SessionDiagnostic)]
68+
#[diag(incremental::no_module_named)]
69+
pub struct NoModuleNamed<'a> {
70+
#[primary_span]
71+
pub span: Span,
72+
pub user_path: &'a str,
73+
pub cgu_name: Symbol,
74+
pub cgu_names: String,
75+
}
76+
77+
#[derive(SessionDiagnostic)]
78+
#[diag(incremental::field_associated_value_expected)]
79+
pub struct FieldAssociatedValueExpected {
80+
#[primary_span]
81+
pub span: Span,
82+
pub name: Symbol,
83+
}
84+
85+
#[derive(SessionDiagnostic)]
86+
#[diag(incremental::no_field)]
87+
pub struct NoField {
88+
#[primary_span]
89+
pub span: Span,
90+
pub name: Symbol,
91+
}
92+
93+
#[derive(SessionDiagnostic)]
94+
#[diag(incremental::assertion_auto)]
95+
pub struct AssertionAuto<'a> {
96+
#[primary_span]
97+
pub span: Span,
98+
pub name: &'a str,
99+
pub e: &'a str,
100+
}
101+
102+
#[derive(SessionDiagnostic)]
103+
#[diag(incremental::undefined_clean_dirty_assertions_item)]
104+
pub struct UndefinedCleanDirtyItem {
105+
#[primary_span]
106+
pub span: Span,
107+
pub kind: String,
108+
}
109+
110+
#[derive(SessionDiagnostic)]
111+
#[diag(incremental::undefined_clean_dirty_assertions)]
112+
pub struct UndefinedCleanDirty {
113+
#[primary_span]
114+
pub span: Span,
115+
pub kind: String,
116+
}
117+
118+
#[derive(SessionDiagnostic)]
119+
#[diag(incremental::repeated_depnode_label)]
120+
pub struct RepeatedDepNodeLabel<'a> {
121+
#[primary_span]
122+
pub span: Span,
123+
pub label: &'a str,
124+
}
125+
126+
#[derive(SessionDiagnostic)]
127+
#[diag(incremental::unrecognized_depnode_label)]
128+
pub struct UnrecognizedDepNodeLabel<'a> {
129+
#[primary_span]
130+
pub span: Span,
131+
pub label: &'a str,
132+
}
133+
134+
#[derive(SessionDiagnostic)]
135+
#[diag(incremental::not_dirty)]
136+
pub struct NotDirty<'a> {
137+
#[primary_span]
138+
pub span: Span,
139+
pub dep_node_str: &'a str,
140+
}
141+
142+
#[derive(SessionDiagnostic)]
143+
#[diag(incremental::not_clean)]
144+
pub struct NotClean<'a> {
145+
#[primary_span]
146+
pub span: Span,
147+
pub dep_node_str: &'a str,
148+
}
149+
150+
#[derive(SessionDiagnostic)]
151+
#[diag(incremental::not_loaded)]
152+
pub struct NotLoaded<'a> {
153+
#[primary_span]
154+
pub span: Span,
155+
pub dep_node_str: &'a str,
156+
}
157+
158+
#[derive(SessionDiagnostic)]
159+
#[diag(incremental::unknown_item)]
160+
pub struct UnknownItem {
161+
#[primary_span]
162+
pub span: Span,
163+
pub name: Symbol,
164+
}
165+
166+
#[derive(SessionDiagnostic)]
167+
#[diag(incremental::no_cfg)]
168+
pub struct NoCfg {
169+
#[primary_span]
170+
pub span: Span,
171+
}
172+
173+
#[derive(SessionDiagnostic)]
174+
#[diag(incremental::associated_value_expected_for)]
175+
pub struct AssociatedValueExpectedFor {
176+
#[primary_span]
177+
pub span: Span,
178+
pub ident: Ident,
179+
}
180+
181+
#[derive(SessionDiagnostic)]
182+
#[diag(incremental::associated_value_expected)]
183+
pub struct AssociatedValueExpected {
184+
#[primary_span]
185+
pub span: Span,
186+
}
187+
188+
#[derive(SessionDiagnostic)]
189+
#[diag(incremental::unchecked_clean)]
190+
pub struct UncheckedClean {
191+
#[primary_span]
192+
pub span: Span,
193+
}
194+
195+
#[derive(SessionDiagnostic)]
196+
#[diag(incremental::delete_old)]
197+
pub struct DeleteOld<'a> {
198+
pub name: &'a str,
199+
pub path: PathBuf,
200+
pub err: std::io::Error,
201+
}
202+
203+
#[derive(SessionDiagnostic)]
204+
#[diag(incremental::create_new)]
205+
pub struct CreateNew<'a> {
206+
pub name: &'a str,
207+
pub path: PathBuf,
208+
pub err: std::io::Error,
209+
}
210+
211+
#[derive(SessionDiagnostic)]
212+
#[diag(incremental::write_new)]
213+
pub struct WriteNew<'a> {
214+
pub name: &'a str,
215+
pub path: PathBuf,
216+
pub err: std::io::Error,
217+
}
218+
219+
#[derive(SessionDiagnostic)]
220+
#[diag(incremental::canonicalize_path)]
221+
pub struct CanonicalizePath {
222+
pub path: PathBuf,
223+
pub err: std::io::Error,
224+
}
225+
226+
#[derive(SessionDiagnostic)]
227+
#[diag(incremental::create_incr_comp_dir)]
228+
pub struct CreateIncrCompDir<'a> {
229+
pub tag: &'a str,
230+
pub path: &'a Path,
231+
pub err: std::io::Error,
232+
}
233+
234+
#[derive(SessionDiagnostic)]
235+
#[diag(incremental::create_lock)]
236+
pub struct CreateLock<'a> {
237+
pub lock_err: std::io::Error,
238+
pub session_dir: &'a Path,
239+
#[note(incremental::lock_unsupported)]
240+
pub is_unsupported_lock: Option<()>,
241+
#[help(incremental::cargo_help_1)]
242+
#[help(incremental::cargo_help_2)]
243+
pub is_cargo: Option<()>,
244+
}
245+
246+
#[derive(SessionDiagnostic)]
247+
#[diag(incremental::delete_lock)]
248+
pub struct DeleteLock<'a> {
249+
pub path: &'a Path,
250+
pub err: std::io::Error,
251+
}
252+
253+
#[derive(SessionDiagnostic)]
254+
#[diag(incremental::hard_link_failed)]
255+
pub struct HardLinkFailed<'a> {
256+
pub path: &'a Path,
257+
}
258+
259+
#[derive(SessionDiagnostic)]
260+
#[diag(incremental::delete_partial)]
261+
pub struct DeletePartial<'a> {
262+
pub path: &'a Path,
263+
pub err: std::io::Error,
264+
}
265+
266+
#[derive(SessionDiagnostic)]
267+
#[diag(incremental::delete_full)]
268+
pub struct DeleteFull<'a> {
269+
pub path: &'a Path,
270+
pub err: std::io::Error,
271+
}
272+
273+
#[derive(SessionDiagnostic)]
274+
#[diag(incremental::finalize)]
275+
pub struct Finalize<'a> {
276+
pub path: &'a Path,
277+
pub err: std::io::Error,
278+
}
279+
280+
#[derive(SessionDiagnostic)]
281+
#[diag(incremental::invalid_gc_failed)]
282+
pub struct InvalidGcFailed<'a> {
283+
pub path: &'a Path,
284+
pub err: std::io::Error,
285+
}
286+
287+
#[derive(SessionDiagnostic)]
288+
#[diag(incremental::finalized_gc_failed)]
289+
pub struct FinalizedGcFailed<'a> {
290+
pub path: &'a Path,
291+
pub err: std::io::Error,
292+
}
293+
294+
#[derive(SessionDiagnostic)]
295+
#[diag(incremental::session_gc_failed)]
296+
pub struct SessionGcFailed<'a> {
297+
pub path: &'a Path,
298+
pub err: std::io::Error,
299+
}
300+
301+
#[derive(SessionDiagnostic)]
302+
#[diag(incremental::assert_not_loaded)]
303+
pub struct AssertNotLoaded;
304+
305+
#[derive(SessionDiagnostic)]
306+
#[diag(incremental::assert_loaded)]
307+
pub struct AssertLoaded;
308+
309+
#[derive(SessionDiagnostic)]
310+
#[diag(incremental::delete_incompatible)]
311+
pub struct DeleteIncompatible {
312+
pub path: PathBuf,
313+
pub err: std::io::Error,
314+
}
315+
316+
#[derive(SessionDiagnostic)]
317+
#[diag(incremental::load_dep_graph)]
318+
pub struct LoadDepGraph {
319+
pub path: PathBuf,
320+
pub err: std::io::Error,
321+
}
322+
323+
#[derive(SessionDiagnostic)]
324+
#[diag(incremental::decode_incr_cache)]
325+
pub struct DecodeIncrCache {
326+
pub err: String,
327+
}
328+
329+
#[derive(SessionDiagnostic)]
330+
#[diag(incremental::write_dep_graph)]
331+
pub struct WriteDepGraph<'a> {
332+
pub path: &'a Path,
333+
pub err: std::io::Error,
334+
}
335+
336+
#[derive(SessionDiagnostic)]
337+
#[diag(incremental::move_dep_graph)]
338+
pub struct MoveDepGraph<'a> {
339+
pub from: &'a Path,
340+
pub to: &'a Path,
341+
pub err: std::io::Error,
342+
}
343+
344+
#[derive(SessionDiagnostic)]
345+
#[diag(incremental::create_dep_graph)]
346+
pub struct CreateDepGraph<'a> {
347+
pub path: &'a Path,
348+
pub err: std::io::Error,
349+
}
350+
351+
#[derive(SessionDiagnostic)]
352+
#[diag(incremental::copy_workproduct_to_cache)]
353+
pub struct CopyWorkProductToCache<'a> {
354+
pub from: &'a Path,
355+
pub to: &'a Path,
356+
pub err: std::io::Error,
357+
}
358+
359+
#[derive(SessionDiagnostic)]
360+
#[diag(incremental::delete_workproduct)]
361+
pub struct DeleteWorkProduct<'a> {
362+
pub path: &'a Path,
363+
pub err: std::io::Error,
364+
}

‎compiler/rustc_incremental/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
#![deny(missing_docs)]
44
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
55
#![feature(let_else)]
6+
#![feature(never_type)]
67
#![recursion_limit = "256"]
78
#![allow(rustc::potential_query_instability)]
9+
#![deny(rustc::untranslatable_diagnostic)]
10+
#![deny(rustc::diagnostic_outside_of_impl)]
811

912
#[macro_use]
1013
extern crate rustc_middle;
@@ -13,6 +16,7 @@ extern crate tracing;
1316

1417
mod assert_dep_graph;
1518
pub mod assert_module_sources;
19+
mod errors;
1620
mod persist;
1721

1822
use assert_dep_graph::assert_dep_graph;

‎compiler/rustc_incremental/src/persist/dirty_clean.rs

Lines changed: 26 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
//! Errors are reported if we are in the suitable configuration but
2020
//! the required condition is not met.
2121
22+
use crate::errors;
2223
use rustc_ast::{self as ast, Attribute, NestedMetaItem};
2324
use rustc_data_structures::fx::FxHashSet;
2425
use rustc_hir::def_id::LocalDefId;
@@ -198,11 +199,7 @@ impl<'tcx> DirtyCleanVisitor<'tcx> {
198199
let loaded_from_disk = self.loaded_from_disk(attr);
199200
for e in except.iter() {
200201
if !auto.remove(e) {
201-
let msg = format!(
202-
"`except` specified DepNodes that can not be affected for \"{}\": \"{}\"",
203-
name, e
204-
);
205-
self.tcx.sess.span_fatal(attr.span, &msg);
202+
self.tcx.sess.emit_fatal(errors::AssertionAuto { span: attr.span, name, e });
206203
}
207204
}
208205
Assertion { clean: auto, dirty: except, loaded_from_disk }
@@ -284,14 +281,10 @@ impl<'tcx> DirtyCleanVisitor<'tcx> {
284281
// An implementation, eg `impl<A> Trait for Foo { .. }`
285282
HirItem::Impl { .. } => ("ItemKind::Impl", LABELS_IMPL),
286283

287-
_ => self.tcx.sess.span_fatal(
288-
attr.span,
289-
&format!(
290-
"clean/dirty auto-assertions not yet defined \
291-
for Node::Item.node={:?}",
292-
item.kind
293-
),
294-
),
284+
_ => self.tcx.sess.emit_fatal(errors::UndefinedCleanDirtyItem {
285+
span: attr.span,
286+
kind: format!("{:?}", item.kind),
287+
}),
295288
}
296289
}
297290
HirNode::TraitItem(item) => match item.kind {
@@ -304,10 +297,10 @@ impl<'tcx> DirtyCleanVisitor<'tcx> {
304297
ImplItemKind::Const(..) => ("NodeImplConst", LABELS_CONST_IN_IMPL),
305298
ImplItemKind::TyAlias(..) => ("NodeImplType", LABELS_CONST_IN_IMPL),
306299
},
307-
_ => self.tcx.sess.span_fatal(
308-
attr.span,
309-
&format!("clean/dirty auto-assertions not yet defined for {:?}", node),
310-
),
300+
_ => self.tcx.sess.emit_fatal(errors::UndefinedCleanDirty {
301+
span: attr.span,
302+
kind: format!("{:?}", node),
303+
}),
311304
};
312305
let labels =
313306
Labels::from_iter(labels.iter().flat_map(|s| s.iter().map(|l| (*l).to_string())));
@@ -320,16 +313,15 @@ impl<'tcx> DirtyCleanVisitor<'tcx> {
320313
let label = label.trim();
321314
if DepNode::has_label_string(label) {
322315
if out.contains(label) {
323-
self.tcx.sess.span_fatal(
324-
item.span(),
325-
&format!("dep-node label `{}` is repeated", label),
326-
);
316+
self.tcx
317+
.sess
318+
.emit_fatal(errors::RepeatedDepNodeLabel { span: item.span(), label });
327319
}
328320
out.insert(label.to_string());
329321
} else {
330322
self.tcx
331323
.sess
332-
.span_fatal(item.span(), &format!("dep-node label `{}` not recognized", label));
324+
.emit_fatal(errors::UnrecognizedDepNodeLabel { span: item.span(), label });
333325
}
334326
}
335327
out
@@ -350,7 +342,7 @@ impl<'tcx> DirtyCleanVisitor<'tcx> {
350342
let dep_node_str = self.dep_node_str(&dep_node);
351343
self.tcx
352344
.sess
353-
.span_err(item_span, &format!("`{}` should be dirty but is not", dep_node_str));
345+
.emit_err(errors::NotDirty { span: item_span, dep_node_str: &dep_node_str });
354346
}
355347
}
356348

@@ -361,7 +353,7 @@ impl<'tcx> DirtyCleanVisitor<'tcx> {
361353
let dep_node_str = self.dep_node_str(&dep_node);
362354
self.tcx
363355
.sess
364-
.span_err(item_span, &format!("`{}` should be clean but is not", dep_node_str));
356+
.emit_err(errors::NotClean { span: item_span, dep_node_str: &dep_node_str });
365357
}
366358
}
367359

@@ -370,10 +362,9 @@ impl<'tcx> DirtyCleanVisitor<'tcx> {
370362

371363
if !self.tcx.dep_graph.debug_was_loaded_from_disk(dep_node) {
372364
let dep_node_str = self.dep_node_str(&dep_node);
373-
self.tcx.sess.span_err(
374-
item_span,
375-
&format!("`{}` should have been loaded from disk but it was not", dep_node_str),
376-
);
365+
self.tcx
366+
.sess
367+
.emit_err(errors::NotLoaded { span: item_span, dep_node_str: &dep_node_str });
377368
}
378369
}
379370

@@ -414,12 +405,12 @@ fn check_config(tcx: TyCtxt<'_>, attr: &Attribute) -> bool {
414405
debug!("check_config: searching for cfg {:?}", value);
415406
cfg = Some(config.contains(&(value, None)));
416407
} else if !(item.has_name(EXCEPT) || item.has_name(LOADED_FROM_DISK)) {
417-
tcx.sess.span_err(attr.span, &format!("unknown item `{}`", item.name_or_empty()));
408+
tcx.sess.emit_err(errors::UnknownItem { span: attr.span, name: item.name_or_empty() });
418409
}
419410
}
420411

421412
match cfg {
422-
None => tcx.sess.span_fatal(attr.span, "no cfg attribute"),
413+
None => tcx.sess.emit_fatal(errors::NoCfg { span: attr.span }),
423414
Some(c) => c,
424415
}
425416
}
@@ -428,13 +419,11 @@ fn expect_associated_value(tcx: TyCtxt<'_>, item: &NestedMetaItem) -> Symbol {
428419
if let Some(value) = item.value_str() {
429420
value
430421
} else {
431-
let msg = if let Some(ident) = item.ident() {
432-
format!("associated value expected for `{}`", ident)
422+
if let Some(ident) = item.ident() {
423+
tcx.sess.emit_fatal(errors::AssociatedValueExpectedFor { span: item.span(), ident });
433424
} else {
434-
"expected an associated value".to_string()
435-
};
436-
437-
tcx.sess.span_fatal(item.span(), &msg);
425+
tcx.sess.emit_fatal(errors::AssociatedValueExpected { span: item.span() });
426+
}
438427
}
439428
}
440429

@@ -458,7 +447,7 @@ impl<'tcx> FindAllAttrs<'tcx> {
458447
fn report_unchecked_attrs(&self, mut checked_attrs: FxHashSet<ast::AttrId>) {
459448
for attr in &self.found_attrs {
460449
if !checked_attrs.contains(&attr.id) {
461-
self.tcx.sess.span_err(attr.span, "found unchecked `#[rustc_clean]` attribute");
450+
self.tcx.sess.emit_err(errors::UncheckedClean { span: attr.span });
462451
checked_attrs.insert(attr.id);
463452
}
464453
}

‎compiler/rustc_incremental/src/persist/file_format.rs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99
//! compiler versions don't change frequently for the typical user, being
1010
//! conservative here practically has no downside.
1111
12-
use std::env;
13-
use std::fs;
14-
use std::io::{self, Read};
15-
use std::path::{Path, PathBuf};
16-
12+
use crate::errors;
1713
use rustc_data_structures::memmap::Mmap;
1814
use rustc_serialize::opaque::{FileEncodeResult, FileEncoder};
1915
use rustc_serialize::Encoder;
2016
use rustc_session::Session;
17+
use std::env;
18+
use std::fs;
19+
use std::io::{self, Read};
20+
use std::path::{Path, PathBuf};
2121

2222
/// The first few bytes of files generated by incremental compilation.
2323
const FILE_MAGIC: &[u8] = b"RSIC";
@@ -60,20 +60,15 @@ where
6060
}
6161
Err(err) if err.kind() == io::ErrorKind::NotFound => (),
6262
Err(err) => {
63-
sess.err(&format!(
64-
"unable to delete old {} at `{}`: {}",
65-
name,
66-
path_buf.display(),
67-
err
68-
));
63+
sess.emit_err(errors::DeleteOld { name, path: path_buf, err });
6964
return;
7065
}
7166
}
7267

7368
let mut encoder = match FileEncoder::new(&path_buf) {
7469
Ok(encoder) => encoder,
7570
Err(err) => {
76-
sess.err(&format!("failed to create {} at `{}`: {}", name, path_buf.display(), err));
71+
sess.emit_err(errors::CreateNew { name, path: path_buf, err });
7772
return;
7873
}
7974
};
@@ -90,7 +85,7 @@ where
9085
debug!("save: data written to disk successfully");
9186
}
9287
Err(err) => {
93-
sess.err(&format!("failed to write {} to `{}`: {}", name, path_buf.display(), err));
88+
sess.emit_err(errors::WriteNew { name, path: path_buf, err });
9489
}
9590
}
9691
}

‎compiler/rustc_incremental/src/persist/fs.rs

Lines changed: 18 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@
103103
//! unsupported file system and emit a warning in that case. This is not yet
104104
//! implemented.
105105
106+
use crate::errors;
106107
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
107108
use rustc_data_structures::svh::Svh;
108109
use rustc_data_structures::{base_n, flock};
@@ -225,12 +226,7 @@ pub fn prepare_session_directory(
225226
let crate_dir = match crate_dir.canonicalize() {
226227
Ok(v) => v,
227228
Err(err) => {
228-
let reported = sess.err(&format!(
229-
"incremental compilation: error canonicalizing path `{}`: {}",
230-
crate_dir.display(),
231-
err
232-
));
233-
return Err(reported);
229+
return Err(sess.emit_err(errors::CanonicalizePath { path: crate_dir, err }));
234230
}
235231
};
236232

@@ -273,14 +269,7 @@ pub fn prepare_session_directory(
273269
debug!("successfully copied data from: {}", source_directory.display());
274270

275271
if !allows_links {
276-
sess.warn(&format!(
277-
"Hard linking files in the incremental \
278-
compilation cache failed. Copying files \
279-
instead. Consider moving the cache \
280-
directory to a file system which supports \
281-
hard linking in session dir `{}`",
282-
session_dir.display()
283-
));
272+
sess.emit_warning(errors::HardLinkFailed { path: &session_dir });
284273
}
285274

286275
sess.init_incr_comp_session(session_dir, directory_lock, true);
@@ -295,12 +284,7 @@ pub fn prepare_session_directory(
295284
// Try to remove the session directory we just allocated. We don't
296285
// know if there's any garbage in it from the failed copy action.
297286
if let Err(err) = safe_remove_dir_all(&session_dir) {
298-
sess.warn(&format!(
299-
"Failed to delete partly initialized \
300-
session dir `{}`: {}",
301-
session_dir.display(),
302-
err
303-
));
287+
sess.emit_warning(errors::DeletePartial { path: &session_dir, err });
304288
}
305289

306290
delete_session_dir_lock_file(sess, &lock_file_path);
@@ -332,12 +316,7 @@ pub fn finalize_session_directory(sess: &Session, svh: Svh) {
332316
);
333317

334318
if let Err(err) = safe_remove_dir_all(&*incr_comp_session_dir) {
335-
sess.warn(&format!(
336-
"Error deleting incremental compilation \
337-
session directory `{}`: {}",
338-
incr_comp_session_dir.display(),
339-
err
340-
));
319+
sess.emit_warning(errors::DeleteFull { path: &incr_comp_session_dir, err });
341320
}
342321

343322
let lock_file_path = lock_file_path(&*incr_comp_session_dir);
@@ -380,12 +359,7 @@ pub fn finalize_session_directory(sess: &Session, svh: Svh) {
380359
}
381360
Err(e) => {
382361
// Warn about the error. However, no need to abort compilation now.
383-
sess.warn(&format!(
384-
"Error finalizing incremental compilation \
385-
session directory `{}`: {}",
386-
incr_comp_session_dir.display(),
387-
e
388-
));
362+
sess.emit_warning(errors::Finalize { path: &incr_comp_session_dir, err: e });
389363

390364
debug!("finalize_session_directory() - error, marking as invalid");
391365
// Drop the file lock, so we can garage collect
@@ -488,16 +462,7 @@ fn create_dir(sess: &Session, path: &Path, dir_tag: &str) -> Result<(), ErrorGua
488462
debug!("{} directory created successfully", dir_tag);
489463
Ok(())
490464
}
491-
Err(err) => {
492-
let reported = sess.err(&format!(
493-
"Could not create incremental compilation {} \
494-
directory `{}`: {}",
495-
dir_tag,
496-
path.display(),
497-
err
498-
));
499-
Err(reported)
500-
}
465+
Err(err) => Err(sess.emit_err(errors::CreateIncrCompDir { tag: dir_tag, path, err })),
501466
}
502467
}
503468

@@ -518,46 +483,20 @@ fn lock_directory(
518483
// the lock should be exclusive
519484
Ok(lock) => Ok((lock, lock_file_path)),
520485
Err(lock_err) => {
521-
let mut err = sess.struct_err(&format!(
522-
"incremental compilation: could not create \
523-
session directory lock file: {}",
524-
lock_err
525-
));
526-
if flock::Lock::error_unsupported(&lock_err) {
527-
err.note(&format!(
528-
"the filesystem for the incremental path at {} \
529-
does not appear to support locking, consider changing the \
530-
incremental path to a filesystem that supports locking \
531-
or disable incremental compilation",
532-
session_dir.display()
533-
));
534-
if std::env::var_os("CARGO").is_some() {
535-
err.help(
536-
"incremental compilation can be disabled by setting the \
537-
environment variable CARGO_INCREMENTAL=0 (see \
538-
https://doc.rust-lang.org/cargo/reference/profiles.html#incremental)",
539-
);
540-
err.help(
541-
"the entire build directory can be changed to a different \
542-
filesystem by setting the environment variable CARGO_TARGET_DIR \
543-
to a different path (see \
544-
https://doc.rust-lang.org/cargo/reference/config.html#buildtarget-dir)",
545-
);
546-
}
547-
}
548-
Err(err.emit())
486+
let is_unsupported_lock = flock::Lock::error_unsupported(&lock_err).then_some(());
487+
Err(sess.emit_err(errors::CreateLock {
488+
lock_err,
489+
session_dir,
490+
is_unsupported_lock,
491+
is_cargo: std::env::var_os("CARGO").map(|_| ()),
492+
}))
549493
}
550494
}
551495
}
552496

553497
fn delete_session_dir_lock_file(sess: &Session, lock_file_path: &Path) {
554498
if let Err(err) = safe_remove_file(&lock_file_path) {
555-
sess.warn(&format!(
556-
"Error deleting lock file for incremental \
557-
compilation session directory `{}`: {}",
558-
lock_file_path.display(),
559-
err
560-
));
499+
sess.emit_warning(errors::DeleteLock { path: lock_file_path, err });
561500
}
562501
}
563502

@@ -774,12 +713,7 @@ pub fn garbage_collect_session_directories(sess: &Session) -> io::Result<()> {
774713
if !lock_file_to_session_dir.values().any(|dir| *dir == directory_name) {
775714
let path = crate_directory.join(directory_name);
776715
if let Err(err) = safe_remove_dir_all(&path) {
777-
sess.warn(&format!(
778-
"Failed to garbage collect invalid incremental \
779-
compilation session directory `{}`: {}",
780-
path.display(),
781-
err
782-
));
716+
sess.emit_warning(errors::InvalidGcFailed { path: &path, err });
783717
}
784718
}
785719
}
@@ -885,12 +819,7 @@ pub fn garbage_collect_session_directories(sess: &Session) -> io::Result<()> {
885819
debug!("garbage_collect_session_directories() - deleting `{}`", path.display());
886820

887821
if let Err(err) = safe_remove_dir_all(&path) {
888-
sess.warn(&format!(
889-
"Failed to garbage collect finalized incremental \
890-
compilation session directory `{}`: {}",
891-
path.display(),
892-
err
893-
));
822+
sess.emit_warning(errors::FinalizedGcFailed { path: &path, err });
894823
} else {
895824
delete_session_dir_lock_file(sess, &lock_file_path(&path));
896825
}
@@ -907,11 +836,7 @@ fn delete_old(sess: &Session, path: &Path) {
907836
debug!("garbage_collect_session_directories() - deleting `{}`", path.display());
908837

909838
if let Err(err) = safe_remove_dir_all(&path) {
910-
sess.warn(&format!(
911-
"Failed to garbage collect incremental compilation session directory `{}`: {}",
912-
path.display(),
913-
err
914-
));
839+
sess.emit_warning(errors::SessionGcFailed { path: &path, err });
915840
} else {
916841
delete_session_dir_lock_file(sess, &lock_file_path(&path));
917842
}

‎compiler/rustc_incremental/src/persist/load.rs

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Code to save/load the dep-graph from files.
22
3+
use crate::errors;
34
use rustc_data_structures::fx::FxHashMap;
45
use rustc_data_structures::memmap::Mmap;
56
use rustc_middle::dep_graph::{SerializedDepGraph, WorkProduct, WorkProductId};
@@ -8,7 +9,7 @@ use rustc_serialize::opaque::MemDecoder;
89
use rustc_serialize::Decodable;
910
use rustc_session::config::IncrementalStateAssertion;
1011
use rustc_session::Session;
11-
use std::path::Path;
12+
use std::path::{Path, PathBuf};
1213

1314
use super::data::*;
1415
use super::file_format;
@@ -27,11 +28,10 @@ pub enum LoadResult<T> {
2728
},
2829
/// The file either didn't exist or was produced by an incompatible compiler version.
2930
DataOutOfDate,
30-
/// An error occurred.
31-
Error {
32-
#[allow(missing_docs)]
33-
message: String,
34-
},
31+
/// Loading the dep graph failed.
32+
LoadDepGraph(PathBuf, std::io::Error),
33+
/// Decoding loaded incremental cache failed.
34+
DecodeIncrCache(Box<dyn std::any::Any + Send>),
3535
}
3636

3737
impl<T: Default> LoadResult<T> {
@@ -40,36 +40,31 @@ impl<T: Default> LoadResult<T> {
4040
// Check for errors when using `-Zassert-incremental-state`
4141
match (sess.opts.assert_incr_state, &self) {
4242
(Some(IncrementalStateAssertion::NotLoaded), LoadResult::Ok { .. }) => {
43-
sess.fatal(
44-
"We asserted that the incremental cache should not be loaded, \
45-
but it was loaded.",
46-
);
43+
sess.emit_fatal(errors::AssertNotLoaded);
4744
}
4845
(
4946
Some(IncrementalStateAssertion::Loaded),
50-
LoadResult::Error { .. } | LoadResult::DataOutOfDate,
47+
LoadResult::LoadDepGraph(..)
48+
| LoadResult::DecodeIncrCache(..)
49+
| LoadResult::DataOutOfDate,
5150
) => {
52-
sess.fatal(
53-
"We asserted that an existing incremental cache directory should \
54-
be successfully loaded, but it was not.",
55-
);
51+
sess.emit_fatal(errors::AssertLoaded);
5652
}
5753
_ => {}
5854
};
5955

6056
match self {
61-
LoadResult::Error { message } => {
62-
sess.warn(&message);
57+
LoadResult::LoadDepGraph(path, err) => {
58+
sess.emit_warning(errors::LoadDepGraph { path, err });
59+
Default::default()
60+
}
61+
LoadResult::DecodeIncrCache(err) => {
62+
sess.emit_warning(errors::DecodeIncrCache { err: format!("{err:?}") });
6363
Default::default()
6464
}
6565
LoadResult::DataOutOfDate => {
6666
if let Err(err) = delete_all_session_dir_contents(sess) {
67-
sess.err(&format!(
68-
"Failed to delete invalidated or incompatible \
69-
incremental compilation session directory contents `{}`: {}.",
70-
dep_graph_path(sess).display(),
71-
err
72-
));
67+
sess.emit_err(errors::DeleteIncompatible { path: dep_graph_path(sess), err });
7368
}
7469
Default::default()
7570
}
@@ -90,9 +85,7 @@ fn load_data(
9085
// compiler version. Neither is an error.
9186
LoadResult::DataOutOfDate
9287
}
93-
Err(err) => LoadResult::Error {
94-
message: format!("could not load dep-graph from `{}`: {}", path.display(), err),
95-
},
88+
Err(err) => LoadResult::LoadDepGraph(path.to_path_buf(), err),
9689
}
9790
}
9891

@@ -114,9 +107,9 @@ impl<T> MaybeAsync<LoadResult<T>> {
114107
pub fn open(self) -> LoadResult<T> {
115108
match self {
116109
MaybeAsync::Sync(result) => result,
117-
MaybeAsync::Async(handle) => handle.join().unwrap_or_else(|e| LoadResult::Error {
118-
message: format!("could not decode incremental cache: {:?}", e),
119-
}),
110+
MaybeAsync::Async(handle) => {
111+
handle.join().unwrap_or_else(|e| LoadResult::DecodeIncrCache(e))
112+
}
120113
}
121114
}
122115
}
@@ -185,7 +178,8 @@ pub fn load_dep_graph(sess: &Session) -> DepGraphFuture {
185178

186179
match load_data(report_incremental_info, &path, nightly_build) {
187180
LoadResult::DataOutOfDate => LoadResult::DataOutOfDate,
188-
LoadResult::Error { message } => LoadResult::Error { message },
181+
LoadResult::LoadDepGraph(path, err) => LoadResult::LoadDepGraph(path, err),
182+
LoadResult::DecodeIncrCache(err) => LoadResult::DecodeIncrCache(err),
189183
LoadResult::Ok { data: (bytes, start_pos) } => {
190184
let mut decoder = MemDecoder::new(&bytes, start_pos);
191185
let prev_commandline_args_hash = u64::decode(&mut decoder);

‎compiler/rustc_incremental/src/persist/save.rs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::errors;
12
use rustc_data_structures::fx::FxHashMap;
23
use rustc_data_structures::sync::join;
34
use rustc_middle::dep_graph::{DepGraph, SerializedDepGraph, WorkProduct, WorkProductId};
@@ -59,19 +60,14 @@ pub fn save_dep_graph(tcx: TyCtxt<'_>) {
5960
move || {
6061
sess.time("incr_comp_persist_dep_graph", || {
6162
if let Err(err) = tcx.dep_graph.encode(&tcx.sess.prof) {
62-
sess.err(&format!(
63-
"failed to write dependency graph to `{}`: {}",
64-
staging_dep_graph_path.display(),
65-
err
66-
));
63+
sess.emit_err(errors::WriteDepGraph { path: &staging_dep_graph_path, err });
6764
}
6865
if let Err(err) = fs::rename(&staging_dep_graph_path, &dep_graph_path) {
69-
sess.err(&format!(
70-
"failed to move dependency graph from `{}` to `{}`: {}",
71-
staging_dep_graph_path.display(),
72-
dep_graph_path.display(),
73-
err
74-
));
66+
sess.emit_err(errors::MoveDepGraph {
67+
from: &staging_dep_graph_path,
68+
to: &dep_graph_path,
69+
err,
70+
});
7571
}
7672
});
7773
},
@@ -163,11 +159,7 @@ pub fn build_dep_graph(
163159
let mut encoder = match FileEncoder::new(&path_buf) {
164160
Ok(encoder) => encoder,
165161
Err(err) => {
166-
sess.err(&format!(
167-
"failed to create dependency graph at `{}`: {}",
168-
path_buf.display(),
169-
err
170-
));
162+
sess.emit_err(errors::CreateDepGraph { path: &path_buf, err });
171163
return None;
172164
}
173165
};

‎compiler/rustc_incremental/src/persist/work_product.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
//!
33
//! [work products]: WorkProduct
44
5+
use crate::errors;
56
use crate::persist::fs::*;
67
use rustc_data_structures::fx::FxHashMap;
78
use rustc_fs_util::link_or_copy;
@@ -28,12 +29,11 @@ pub fn copy_cgu_workproduct_to_incr_comp_cache_dir(
2829
let _ = saved_files.insert(ext.to_string(), file_name);
2930
}
3031
Err(err) => {
31-
sess.warn(&format!(
32-
"error copying object file `{}` to incremental directory as `{}`: {}",
33-
path.display(),
34-
path_in_incr_dir.display(),
35-
err
36-
));
32+
sess.emit_warning(errors::CopyWorkProductToCache {
33+
from: &path,
34+
to: &path_in_incr_dir,
35+
err,
36+
});
3737
}
3838
}
3939
}
@@ -49,11 +49,7 @@ pub fn delete_workproduct_files(sess: &Session, work_product: &WorkProduct) {
4949
for (_, path) in &work_product.saved_files {
5050
let path = in_incr_comp_dir_sess(sess, path);
5151
if let Err(err) = std_fs::remove_file(&path) {
52-
sess.warn(&format!(
53-
"file-system error deleting outdated file `{}`: {}",
54-
path.display(),
55-
err
56-
));
52+
sess.emit_warning(errors::DeleteWorkProduct { path: &path, err });
5753
}
5854
}
5955
}

‎compiler/rustc_session/src/session.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,9 +528,11 @@ impl Session {
528528
Err(ErrorGuaranteed::unchecked_claim_error_was_emitted())
529529
}
530530
}
531+
#[rustc_lint_diagnostics]
531532
pub fn span_warn<S: Into<MultiSpan>>(&self, sp: S, msg: impl Into<DiagnosticMessage>) {
532533
self.diagnostic().span_warn(sp, msg)
533534
}
535+
#[rustc_lint_diagnostics]
534536
pub fn span_warn_with_code<S: Into<MultiSpan>>(
535537
&self,
536538
sp: S,
@@ -539,6 +541,7 @@ impl Session {
539541
) {
540542
self.diagnostic().span_warn_with_code(sp, msg, code)
541543
}
544+
#[rustc_lint_diagnostics]
542545
pub fn warn(&self, msg: impl Into<DiagnosticMessage>) {
543546
self.diagnostic().warn(msg)
544547
}
@@ -569,16 +572,19 @@ impl Session {
569572
self.diagnostic().delay_good_path_bug(msg)
570573
}
571574

575+
#[rustc_lint_diagnostics]
572576
pub fn note_without_error(&self, msg: impl Into<DiagnosticMessage>) {
573577
self.diagnostic().note_without_error(msg)
574578
}
579+
#[rustc_lint_diagnostics]
575580
pub fn span_note_without_error<S: Into<MultiSpan>>(
576581
&self,
577582
sp: S,
578583
msg: impl Into<DiagnosticMessage>,
579584
) {
580585
self.diagnostic().span_note_without_error(sp, msg)
581586
}
587+
#[rustc_lint_diagnostics]
582588
pub fn struct_note_without_error(
583589
&self,
584590
msg: impl Into<DiagnosticMessage>,

‎src/test/run-make/incremental-session-fail/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ all:
99
touch $(SESSION_DIR)
1010
# Check exit code is 1 for an error, and not 101 for ICE.
1111
$(RUSTC) foo.rs --crate-type=rlib -C incremental=$(SESSION_DIR) > $(OUTPUT_FILE) 2>&1; [ $$? -eq 1 ]
12-
$(CGREP) "Could not create incremental compilation crate directory" < $(OUTPUT_FILE)
12+
$(CGREP) "could not create incremental compilation crate directory" < $(OUTPUT_FILE)
1313
# -v tests are fragile, hopefully this text won't change
1414
$(CGREP) -v "internal compiler error" < $(OUTPUT_FILE)

0 commit comments

Comments
 (0)
Please sign in to comment.