Skip to content

Commit d90f2a0

Browse files
committed
translations(rustc_session): migrate check_expected_reuse
This commit migrates the errors in the function check_expected_reuse to use the new SessionDiagnostic. It also does some small refactor for the IncorrectCguReuseType to include the 'at least' word in the fluent translation file
1 parent 77b01ac commit d90f2a0

File tree

4 files changed

+17
-22
lines changed

4 files changed

+17
-22
lines changed

compiler/rustc_codegen_ssa/src/back/write.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1892,7 +1892,7 @@ impl<B: ExtraBackendMethods> OngoingCodegen<B> {
18921892
}
18931893
});
18941894

1895-
sess.cgu_reuse_tracker.check_expected_reuse(sess.diagnostic());
1895+
sess.cgu_reuse_tracker.check_expected_reuse(sess);
18961896

18971897
sess.abort_if_errors();
18981898

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
session_incorrect_cgu_reuse_type =
2-
CGU-reuse for `{$cgu_user_name}` is `{$actual_reuse}` but should be `{$at_least}``${expected_reuse}`
2+
CGU-reuse for `{$cgu_user_name}` is `{$actual_reuse}` but should be {$at_least ->
3+
[one] {"at least "}
4+
*[other] {""}
5+
}`{$expected_reuse}`
36
47
session_cgu_not_recorded =
58
CGU-reuse for `{$cgu_user_name}` is (mangled: `{$cgu_name}`) was not recorded`

compiler/rustc_session/src/cgu_reuse_tracker.rs

+5-12
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
//! compilation. This is used for incremental compilation tests and debug
33
//! output.
44
5-
use crate::errors::IncorrectCguReuseType;
5+
use crate::errors::{CguNotRecorded, IncorrectCguReuseType};
6+
use crate::Session;
67
use rustc_data_structures::fx::FxHashMap;
78
use rustc_errors::{DiagnosticArgValue, IntoDiagnosticArg};
89
use rustc_span::{Span, Symbol};
@@ -104,7 +105,7 @@ impl CguReuseTracker {
104105
}
105106
}
106107

107-
pub fn check_expected_reuse(&self, diag: &rustc_errors::Handler) {
108+
pub fn check_expected_reuse(&self, sess: &Session) {
108109
if let Some(ref data) = self.data {
109110
let data = data.lock().unwrap();
110111

@@ -118,7 +119,7 @@ impl CguReuseTracker {
118119
};
119120

120121
if error {
121-
let at_least = if at_least { "at least " } else { "" };
122+
let at_least = if at_least { 1 } else { 0 };
122123
IncorrectCguReuseType {
123124
span: error_span.0,
124125
cgu_user_name: &cgu_user_name,
@@ -128,15 +129,7 @@ impl CguReuseTracker {
128129
};
129130
}
130131
} else {
131-
//FIXME: Remove this once PR #100694 that implements `[fatal(..)]` is merged
132-
let msg = format!(
133-
"CGU-reuse for `{cgu_user_name}` (mangled: `{cgu_name}`) was \
134-
not recorded"
135-
);
136-
diag.span_fatal(error_span.0, &msg)
137-
138-
//FIXME: Uncomment this once PR #100694 that implements `[fatal(..)]` is merged
139-
// CguNotRecorded { cgu_user_name, cgu_name };
132+
sess.emit_fatal(CguNotRecorded { cgu_user_name, cgu_name });
140133
}
141134
}
142135
}

compiler/rustc_session/src/errors.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,15 @@ pub struct IncorrectCguReuseType<'a> {
1414
pub cgu_user_name: &'a str,
1515
pub actual_reuse: CguReuse,
1616
pub expected_reuse: CguReuse,
17-
pub at_least: &'a str,
17+
pub at_least: u8,
1818
}
1919

20-
//FIXME: Uncomment this once PR #100694 that implements `[fatal(..)]` is merged
21-
// #[derive(SessionDiagnostic)]
22-
// #[fatal(session::cgu_not_recorded)]
23-
// pub struct CguNotRecorded<'a> {
24-
// pub cgu_user_name: &'a str,
25-
// pub cgu_name: &'a str,
26-
// }
20+
#[derive(SessionDiagnostic)]
21+
#[diag(session::cgu_not_recorded)]
22+
pub struct CguNotRecorded<'a> {
23+
pub cgu_user_name: &'a str,
24+
pub cgu_name: &'a str,
25+
}
2726

2827
#[derive(SessionDiagnostic)]
2928
#[diag(session::feature_gate_error, code = "E0658")]

0 commit comments

Comments
 (0)