Skip to content

Commit 8380a6b

Browse files
authored
Rollup merge of rust-lang#101041 - LuisCardosoOliveira:translation-rename-attr-warning-pt2, r=davidtwco
translations(rustc_session): migrates rustc_session to use SessionDiagnostic - Pt. 2 # Description This is the second part of the `rustc_session` [migration](rust-lang#100717 (comment)). **Please only review this [commit](rust-lang@5018581) that belongs to the part 2. The other ones are from the PR [rust-lang#100753](rust-lang#100753) that is not yet merged.** In this PR, we migrate the files `session.rs` and `config.rs`. Please not that we have to `allow` the lints rules in some functions from `session.rs` because they are (at least I believe) part of the diagnostic machinery.
2 parents db68742 + 0e497a7 commit 8380a6b

File tree

7 files changed

+258
-75
lines changed

7 files changed

+258
-75
lines changed

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

+42
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,45 @@ session_feature_diagnostic_for_issue =
1414
1515
session_feature_diagnostic_help =
1616
add `#![feature({$feature})]` to the crate attributes to enable
17+
18+
session_not_circumvent_feature = `-Zunleash-the-miri-inside-of-you` may not be used to circumvent feature gates, except when testing error paths in the CTFE engine
19+
20+
session_profile_use_file_does_not_exist = file `{$path}` passed to `-C profile-use` does not exist.
21+
22+
session_linker_plugin_lto_windows_not_supported = linker plugin based LTO is not supported together with `-C prefer-dynamic` when targeting Windows-like targets
23+
24+
session_profile_sample_use_file_does_not_exist = file `{$path}` passed to `-C profile-sample-use` does not exist.
25+
26+
session_target_requires_unwind_tables = target requires unwind tables, they cannot be disabled with `-C force-unwind-tables=no`
27+
28+
session_sanitizer_not_supported = {$us} sanitizer is not supported for this target
29+
30+
session_sanitizers_not_supported = {$us} sanitizers are not supported for this target
31+
32+
session_cannot_mix_and_match_sanitizers = `-Zsanitizer={$first}` is incompatible with `-Zsanitizer={$second}`
33+
34+
session_cannot_enable_crt_static_linux = sanitizer is incompatible with statically linked libc, disable it using `-C target-feature=-crt-static`
35+
36+
session_sanitizer_cfi_enabled = `-Zsanitizer=cfi` requires `-Clto`
37+
38+
session_unstable_virtual_function_elimination = `-Zvirtual-function-elimination` requires `-Clto`
39+
40+
session_unsupported_dwarf_version = requested DWARF version {$dwarf_version} is greater than 5
41+
42+
session_target_invalid_address_space = invalid address space `{$addr_space}` for `{$cause}` in "data-layout": {$err}
43+
44+
session_target_invalid_bits = invalid {$kind} `{$bit}` for `{$cause}` in "data-layout": {$err}
45+
46+
session_target_missing_alignment = missing alignment for `{$cause}` in "data-layout"
47+
48+
session_target_invalid_alignment = invalid alignment for `{$cause}` in "data-layout": {$err}
49+
50+
session_target_inconsistent_architecture = inconsistent target specification: "data-layout" claims architecture is {$dl}-endian, while "target-endian" is `{$target}`
51+
52+
session_target_inconsistent_pointer_width = inconsistent target specification: "data-layout" claims pointers are {$pointer_size}-bit, while "target-pointer-width" is `{$target}`
53+
54+
session_target_invalid_bits_size = {$err}
55+
56+
session_target_stack_protector_not_supported = `-Z stack-protector={$stack_protector}` is not supported for target {$target_triple} and will be ignored
57+
58+
session_split_debuginfo_unstable_platform = `-Csplit-debuginfo={$debuginfo}` is unstable on this platform

compiler/rustc_errors/src/diagnostic.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ use rustc_lint_defs::{Applicability, LintExpectationId};
1010
use rustc_span::edition::LATEST_STABLE_EDITION;
1111
use rustc_span::symbol::{Ident, MacroRulesNormalizedIdent, Symbol};
1212
use rustc_span::{edition::Edition, Span, DUMMY_SP};
13-
use rustc_target::spec::PanicStrategy;
13+
use rustc_target::spec::{PanicStrategy, SplitDebuginfo, StackProtector, TargetTriple};
1414
use std::borrow::Cow;
1515
use std::fmt;
1616
use std::hash::{Hash, Hasher};
17+
use std::num::ParseIntError;
1718
use std::path::{Path, PathBuf};
1819

1920
/// Error type for `Diagnostic`'s `suggestions` field, indicating that
@@ -91,6 +92,10 @@ into_diagnostic_arg_using_display!(
9192
Edition,
9293
Ident,
9394
MacroRulesNormalizedIdent,
95+
ParseIntError,
96+
StackProtector,
97+
&TargetTriple,
98+
SplitDebuginfo
9499
);
95100

96101
impl IntoDiagnosticArg for bool {

compiler/rustc_middle/src/ty/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1252,7 +1252,7 @@ impl<'tcx> TyCtxt<'tcx> {
12521252
output_filenames: OutputFilenames,
12531253
) -> GlobalCtxt<'tcx> {
12541254
let data_layout = TargetDataLayout::parse(&s.target).unwrap_or_else(|err| {
1255-
s.fatal(&err);
1255+
s.emit_fatal(err);
12561256
});
12571257
let interners = CtxtInterners::new(arena);
12581258
let common_types = CommonTypes::new(

compiler/rustc_session/src/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,7 @@ fn default_configuration(sess: &Session) -> CrateConfig {
898898
let max_atomic_width = sess.target.max_atomic_width();
899899
let atomic_cas = sess.target.atomic_cas;
900900
let layout = TargetDataLayout::parse(&sess.target).unwrap_or_else(|err| {
901-
sess.fatal(&err);
901+
sess.emit_fatal(err);
902902
});
903903

904904
let mut ret = CrateConfig::default();

compiler/rustc_session/src/errors.rs

+129-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
use std::num::NonZeroU32;
22

3-
use crate as rustc_session;
43
use crate::cgu_reuse_tracker::CguReuse;
5-
use rustc_errors::MultiSpan;
4+
use crate::{self as rustc_session, SessionDiagnostic};
5+
use rustc_errors::{fluent, DiagnosticBuilder, Handler, MultiSpan};
66
use rustc_macros::SessionDiagnostic;
77
use rustc_span::{Span, Symbol};
8+
use rustc_target::abi::TargetDataLayoutErrors;
9+
use rustc_target::spec::{SplitDebuginfo, StackProtector, TargetTriple};
810

911
#[derive(SessionDiagnostic)]
1012
#[diag(session::incorrect_cgu_reuse_type)]
@@ -43,3 +45,128 @@ pub struct FeatureDiagnosticForIssue {
4345
pub struct FeatureDiagnosticHelp {
4446
pub feature: Symbol,
4547
}
48+
49+
impl SessionDiagnostic<'_, !> for TargetDataLayoutErrors<'_> {
50+
fn into_diagnostic(self, sess: &Handler) -> DiagnosticBuilder<'_, !> {
51+
let mut diag;
52+
match self {
53+
TargetDataLayoutErrors::InvalidAddressSpace { addr_space, err, cause } => {
54+
diag = sess.struct_fatal(fluent::session::target_invalid_address_space);
55+
diag.set_arg("addr_space", addr_space);
56+
diag.set_arg("cause", cause);
57+
diag.set_arg("err", err);
58+
diag
59+
}
60+
TargetDataLayoutErrors::InvalidBits { kind, bit, cause, err } => {
61+
diag = sess.struct_fatal(fluent::session::target_invalid_bits);
62+
diag.set_arg("kind", kind);
63+
diag.set_arg("bit", bit);
64+
diag.set_arg("cause", cause);
65+
diag.set_arg("err", err);
66+
diag
67+
}
68+
TargetDataLayoutErrors::MissingAlignment { cause } => {
69+
diag = sess.struct_fatal(fluent::session::target_missing_alignment);
70+
diag.set_arg("cause", cause);
71+
diag
72+
}
73+
TargetDataLayoutErrors::InvalidAlignment { cause, err } => {
74+
diag = sess.struct_fatal(fluent::session::target_invalid_alignment);
75+
diag.set_arg("cause", cause);
76+
diag.set_arg("err", err);
77+
diag
78+
}
79+
TargetDataLayoutErrors::InconsistentTargetArchitecture { dl, target } => {
80+
diag = sess.struct_fatal(fluent::session::target_inconsistent_architecture);
81+
diag.set_arg("dl", dl);
82+
diag.set_arg("target", target);
83+
diag
84+
}
85+
TargetDataLayoutErrors::InconsistentTargetPointerWidth { pointer_size, target } => {
86+
diag = sess.struct_fatal(fluent::session::target_inconsistent_pointer_width);
87+
diag.set_arg("pointer_size", pointer_size);
88+
diag.set_arg("target", target);
89+
diag
90+
}
91+
TargetDataLayoutErrors::InvalidBitsSize { err } => {
92+
diag = sess.struct_fatal(fluent::session::target_invalid_bits_size);
93+
diag.set_arg("err", err);
94+
diag
95+
}
96+
}
97+
}
98+
}
99+
100+
#[derive(SessionDiagnostic)]
101+
#[diag(session::not_circumvent_feature)]
102+
pub struct NotCircumventFeature;
103+
104+
#[derive(SessionDiagnostic)]
105+
#[diag(session::linker_plugin_lto_windows_not_supported)]
106+
pub struct LinkerPluginToWindowsNotSupported;
107+
108+
#[derive(SessionDiagnostic)]
109+
#[diag(session::profile_use_file_does_not_exist)]
110+
pub struct ProfileUseFileDoesNotExist<'a> {
111+
pub path: &'a std::path::Path,
112+
}
113+
114+
#[derive(SessionDiagnostic)]
115+
#[diag(session::profile_sample_use_file_does_not_exist)]
116+
pub struct ProfileSampleUseFileDoesNotExist<'a> {
117+
pub path: &'a std::path::Path,
118+
}
119+
120+
#[derive(SessionDiagnostic)]
121+
#[diag(session::target_requires_unwind_tables)]
122+
pub struct TargetRequiresUnwindTables;
123+
124+
#[derive(SessionDiagnostic)]
125+
#[diag(session::sanitizer_not_supported)]
126+
pub struct SanitizerNotSupported {
127+
pub us: String,
128+
}
129+
130+
#[derive(SessionDiagnostic)]
131+
#[diag(session::sanitizers_not_supported)]
132+
pub struct SanitizersNotSupported {
133+
pub us: String,
134+
}
135+
136+
#[derive(SessionDiagnostic)]
137+
#[diag(session::cannot_mix_and_match_sanitizers)]
138+
pub struct CannotMixAndMatchSanitizers {
139+
pub first: String,
140+
pub second: String,
141+
}
142+
143+
#[derive(SessionDiagnostic)]
144+
#[diag(session::cannot_enable_crt_static_linux)]
145+
pub struct CannotEnableCrtStaticLinux;
146+
147+
#[derive(SessionDiagnostic)]
148+
#[diag(session::sanitizer_cfi_enabled)]
149+
pub struct SanitizerCfiEnabled;
150+
151+
#[derive(SessionDiagnostic)]
152+
#[diag(session::unstable_virtual_function_elimination)]
153+
pub struct UnstableVirtualFunctionElimination;
154+
155+
#[derive(SessionDiagnostic)]
156+
#[diag(session::unsupported_dwarf_version)]
157+
pub struct UnsupportedDwarfVersion {
158+
pub dwarf_version: u32,
159+
}
160+
161+
#[derive(SessionDiagnostic)]
162+
#[diag(session::target_stack_protector_not_supported)]
163+
pub struct StackProtectorNotSupportedForTarget<'a> {
164+
pub stack_protector: StackProtector,
165+
pub target_triple: &'a TargetTriple,
166+
}
167+
168+
#[derive(SessionDiagnostic)]
169+
#[diag(session::split_debuginfo_unstable_platform)]
170+
pub struct SplitDebugInfoUnstablePlatform {
171+
pub debuginfo: SplitDebuginfo,
172+
}

0 commit comments

Comments
 (0)