Skip to content

Commit 2ff4664

Browse files
committed
incremental: migrate diagnostics
Migrate the `rustc_incremental` crate's diagnostics to translatable diagnostic structs. Signed-off-by: David Wood <[email protected]>
1 parent 2575b1a commit 2ff4664

File tree

13 files changed

+617
-253
lines changed

13 files changed

+617
-253
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
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 =
14+
found CGU-reuse attribute but `-Zquery-dep-graph` was not specified
15+
16+
incremental_malformed_cgu_name =
17+
found malformed codegen unit name `{$user_path}`. codegen units names must always start with the name of the crate (`{$crate_name}` in this case).
18+
19+
incremental_no_module_named =
20+
no module named `{$user_path}` (mangled: {$cgu_name}). available modules: {$cgu_names}
21+
22+
incremental_field_associated_value_expected = associated value expected for `{$name}`
23+
24+
incremental_no_field = no field `{$name}`
25+
26+
incremental_assertion_auto =
27+
`except` specified DepNodes that can not be affected for \"{$name}\": \"{$e}\"
28+
29+
incremental_undefined_clean_dirty_assertions_item =
30+
clean/dirty auto-assertions not yet defined for Node::Item.node={$kind}
31+
32+
incremental_undefined_clean_dirty_assertions =
33+
clean/dirty auto-assertions not yet defined for {$kind}
34+
35+
incremental_repeated_depnode_label = dep-node label `{$label}` is repeated
36+
37+
incremental_unrecognized_depnode_label = dep-node label `{$label}` not recognized
38+
39+
incremental_not_dirty = `{$dep_node_str}` should be dirty but is not
40+
41+
incremental_not_clean = `{$dep_node_str}` should be clean but is not
42+
43+
incremental_not_loaded = `{$dep_node_str}` should have been loaded from disk but it was not
44+
45+
incremental_unknown_item = unknown item `{$name}`
46+
47+
incremental_no_cfg = no cfg attribute
48+
49+
incremental_associated_value_expected_for = associated value expected for `{$ident}`
50+
51+
incremental_associated_value_expected = expected an associated value
52+
53+
incremental_unchecked_clean = found unchecked `#[rustc_clean]` attribute
54+
55+
incremental_delete_old = unable to delete old {$name} at `{$path}`: {$err}
56+
57+
incremental_create_new = failed to create {$name} at `{$path}`: {$err}
58+
59+
incremental_write_new = failed to write {$name} to `{$path}`: {$err}
60+
61+
incremental_canonicalize_path = incremental compilation: error canonicalizing path `{$path}`: {$err}
62+
63+
incremental_create_incr_comp_dir =
64+
could not create incremental compilation {$tag} directory `{$path}`: {$err}
65+
66+
incremental_create_lock =
67+
incremental compilation: could not create session directory lock file: {$lock_err}
68+
incremental_lock_unsupported =
69+
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
70+
incremental_cargo_help_1 =
71+
incremental compilation can be disabled by setting the environment variable CARGO_INCREMENTAL=0 (see https://doc.rust-lang.org/cargo/reference/profiles.html#incremental)
72+
incremental_cargo_help_2 =
73+
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)
74+
75+
incremental_delete_lock =
76+
error deleting lock file for incremental compilation session directory `{$path}`: {$err}
77+
78+
incremental_hard_link_failed =
79+
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}`
80+
81+
incremental_delete_partial = failed to delete partly initialized session dir `{$path}`: {$err}
82+
83+
incremental_delete_full = error deleting incremental compilation session directory `{$path}`: {$err}
84+
85+
incremental_finalize = error finalizing incremental compilation session directory `{$path}`: {$err}
86+
87+
incremental_invalid_gc_failed =
88+
failed to garbage collect invalid incremental compilation session directory `{$path}`: {$err}
89+
90+
incremental_finalized_gc_failed =
91+
failed to garbage collect finalized incremental compilation session directory `{$path}`: {$err}
92+
93+
incremental_session_gc_failed =
94+
failed to garbage collect incremental compilation session directory `{$path}`: {$err}
95+
96+
incremental_assert_not_loaded =
97+
we asserted that the incremental cache should not be loaded, but it was loaded
98+
99+
incremental_assert_loaded =
100+
we asserted that an existing incremental cache directory should be successfully loaded, but it was not
101+
102+
incremental_delete_incompatible =
103+
failed to delete invalidated or incompatible incremental compilation session directory contents `{$path}`: {$err}
104+
105+
incremental_load_dep_graph = could not load dep-graph from `{$path}`: {$err}
106+
107+
incremental_decode_incr_cache = could not decode incremental cache: {$err}
108+
109+
incremental_write_dep_graph = failed to write dependency graph to `{$path}`: {$err}
110+
111+
incremental_move_dep_graph = failed to move dependency graph from `{$from}` to `{$to}`: {$err}
112+
113+
incremental_create_dep_graph = failed to create dependency graph at `{$path}`: {$err}
114+
115+
incremental_copy_workproduct_to_cache =
116+
error copying object file `{$from}` to incremental directory as `{$to}`: {$err}
117+
118+
incremental_delete_workproduct = file-system error deleting outdated file `{$path}`: {$err}

compiler/rustc_error_messages/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ fluent_messages! {
5252
expand => "../locales/en-US/expand.ftl",
5353
hir_analysis => "../locales/en-US/hir_analysis.ftl",
5454
hir_typeck => "../locales/en-US/hir_typeck.ftl",
55+
incremental => "../locales/en-US/incremental.ftl",
5556
infer => "../locales/en-US/infer.ftl",
5657
interface => "../locales/en-US/interface.ftl",
5758
lint => "../locales/en-US/lint.ftl",

compiler/rustc_incremental/src/assert_dep_graph.rs

+17-23
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

+21-29
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

0 commit comments

Comments
 (0)