Skip to content

Commit 706452e

Browse files
committed
translations(rustc_session): migrate the file cgu_reuse_tracker
This commit migrates the errors that indicates an incorrect CGU type and the fatal error that indicates that a CGU has not been correctly recorded
1 parent 8a13871 commit 706452e

File tree

5 files changed

+60
-5
lines changed

5 files changed

+60
-5
lines changed
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
incorrect_cgu_reuse_type =
2+
CGU-reuse for `{$cgu_user_name}` is `{$actual_reuse}` but should be `{$at_least}``${expected_reuse}`
3+
4+
cgu_not_recorded =
5+
CGU-reuse for `{$cgu_user_name}` is (mangled: `{$cgu_name}`) was not recorded`

Diff for: compiler/rustc_error_messages/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ fluent_messages! {
3737
builtin_macros => "../locales/en-US/builtin_macros.ftl",
3838
const_eval => "../locales/en-US/const_eval.ftl",
3939
expand => "../locales/en-US/expand.ftl",
40+
session => "../locales/en-US/session.ftl",
4041
interface => "../locales/en-US/interface.ftl",
4142
lint => "../locales/en-US/lint.ftl",
4243
parser => "../locales/en-US/parser.ftl",

Diff for: compiler/rustc_session/src/cgu_reuse_tracker.rs

+29-5
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@
22
//! compilation. This is used for incremental compilation tests and debug
33
//! output.
44
5+
use crate::errors::IncorrectCguReuseType;
6+
// use crate::errors::{CguNotRecorded, IncorrectCguReuseType};
57
use rustc_data_structures::fx::FxHashMap;
8+
use rustc_errors::{DiagnosticArgValue, IntoDiagnosticArg};
69
use rustc_span::{Span, Symbol};
10+
use std::borrow::Cow;
11+
use std::fmt::{self};
712
use std::sync::{Arc, Mutex};
813
use tracing::debug;
914

@@ -14,6 +19,22 @@ pub enum CguReuse {
1419
PostLto,
1520
}
1621

22+
impl fmt::Display for CguReuse {
23+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
24+
match *self {
25+
CguReuse::No => write!(f, "No"),
26+
CguReuse::PreLto => write!(f, "PreLto "),
27+
CguReuse::PostLto => write!(f, "PostLto "),
28+
}
29+
}
30+
}
31+
32+
impl IntoDiagnosticArg for CguReuse {
33+
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
34+
DiagnosticArgValue::Str(Cow::Owned(self.to_string()))
35+
}
36+
}
37+
1738
#[derive(Copy, Clone, Debug, PartialEq)]
1839
pub enum ComparisonKind {
1940
Exact,
@@ -99,18 +120,21 @@ impl CguReuseTracker {
99120

100121
if error {
101122
let at_least = if at_least { "at least " } else { "" };
102-
let msg = format!(
103-
"CGU-reuse for `{cgu_user_name}` is `{actual_reuse:?}` but \
104-
should be {at_least}`{expected_reuse:?}`"
105-
);
106-
diag.span_err(error_span.0, &msg);
123+
IncorrectCguReuseType {
124+
span: error_span.0,
125+
cgu_user_name: &cgu_user_name,
126+
actual_reuse,
127+
expected_reuse,
128+
at_least,
129+
};
107130
}
108131
} else {
109132
let msg = format!(
110133
"CGU-reuse for `{cgu_user_name}` (mangled: `{cgu_name}`) was \
111134
not recorded"
112135
);
113136
diag.span_fatal(error_span.0, &msg)
137+
// CguNotRecorded { cgu_user_name, cgu_name };
114138
}
115139
}
116140
}

Diff for: compiler/rustc_session/src/errors.rs

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
use crate as rustc_session;
2+
use crate::cgu_reuse_tracker::CguReuse;
3+
use rustc_macros::SessionDiagnostic;
4+
use rustc_span::Span;
5+
6+
#[derive(SessionDiagnostic)]
7+
#[error(session::incorrect_cgu_reuse_type)]
8+
pub struct IncorrectCguReuseType<'a> {
9+
#[primary_span]
10+
pub span: Span,
11+
pub cgu_user_name: &'a str,
12+
pub actual_reuse: CguReuse,
13+
pub expected_reuse: CguReuse,
14+
pub at_least: &'a str,
15+
}
16+
17+
// #[derive(SessionDiagnostic)]
18+
// #[fatal(session::cgu_not_recorded)]
19+
// pub struct CguNotRecorded<'a> {
20+
// pub cgu_user_name: &'a str,
21+
// pub cgu_name: &'a str,
22+
// }

Diff for: compiler/rustc_session/src/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@
88
#![feature(map_many_mut)]
99
#![recursion_limit = "256"]
1010
#![allow(rustc::potential_query_instability)]
11+
#![deny(rustc::untranslatable_diagnostic)]
12+
#![deny(rustc::diagnostic_outside_of_impl)]
1113

1214
#[macro_use]
1315
extern crate rustc_macros;
16+
pub mod errors;
1417

1518
pub mod cgu_reuse_tracker;
1619
pub mod utils;

0 commit comments

Comments
 (0)