Skip to content

Commit 1755c85

Browse files
committed
Auto merge of #102684 - JhonnyBillM:delete-target-data-layout-errors-wrapper, r=davidtwco
Move `IntoDiagnostic` conformance for `TargetDataLayoutErrors` into `rustc_errors` Addressed this suggestion #101558 (comment). This way we comply with the Coherence rule given that `IntoDiagnostic` trait is defined in `rustc_errors`, and almost all other crates depend on it.
2 parents edabf59 + be22157 commit 1755c85

File tree

9 files changed

+229
-223
lines changed

9 files changed

+229
-223
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
errors_target_invalid_address_space = invalid address space `{$addr_space}` for `{$cause}` in "data-layout": {$err}
2+
3+
errors_target_invalid_bits = invalid {$kind} `{$bit}` for `{$cause}` in "data-layout": {$err}
4+
5+
errors_target_missing_alignment = missing alignment for `{$cause}` in "data-layout"
6+
7+
errors_target_invalid_alignment = invalid alignment for `{$cause}` in "data-layout": {$err}
8+
9+
errors_target_inconsistent_architecture = inconsistent target specification: "data-layout" claims architecture is {$dl}-endian, while "target-endian" is `{$target}`
10+
11+
errors_target_inconsistent_pointer_width = inconsistent target specification: "data-layout" claims pointers are {$pointer_size}-bit, while "target-pointer-width" is `{$target}`
12+
13+
errors_target_invalid_bits_size = {$err}

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

-14
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,6 @@ session_unstable_virtual_function_elimination = `-Zvirtual-function-elimination`
3939
4040
session_unsupported_dwarf_version = requested DWARF version {$dwarf_version} is greater than 5
4141
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-
5642
session_target_stack_protector_not_supported = `-Z stack-protector={$stack_protector}` is not supported for target {$target_triple} and will be ignored
5743
5844
session_split_debuginfo_unstable_platform = `-Csplit-debuginfo={$debuginfo}` is unstable on this platform

compiler/rustc_error_messages/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ fluent_messages! {
4646
compiletest => "../locales/en-US/compiletest.ftl",
4747
const_eval => "../locales/en-US/const_eval.ftl",
4848
driver => "../locales/en-US/driver.ftl",
49+
errors => "../locales/en-US/errors.ftl",
4950
expand => "../locales/en-US/expand.ftl",
5051
hir_analysis => "../locales/en-US/hir_analysis.ftl",
5152
infer => "../locales/en-US/infer.ftl",

compiler/rustc_errors/src/diagnostic.rs

+2-149
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,15 @@ use crate::{
33
CodeSuggestion, DiagnosticBuilder, DiagnosticMessage, EmissionGuarantee, Level, MultiSpan,
44
SubdiagnosticMessage, Substitution, SubstitutionPart, SuggestionStyle,
55
};
6-
use rustc_ast as ast;
7-
use rustc_ast_pretty::pprust;
86
use rustc_data_structures::fx::FxHashMap;
97
use rustc_error_messages::FluentValue;
10-
use rustc_hir as hir;
118
use rustc_lint_defs::{Applicability, LintExpectationId};
129
use rustc_span::edition::LATEST_STABLE_EDITION;
13-
use rustc_span::symbol::{Ident, MacroRulesNormalizedIdent, Symbol};
14-
use rustc_span::{edition::Edition, Span, DUMMY_SP};
15-
use rustc_target::spec::{PanicStrategy, SplitDebuginfo, StackProtector, TargetTriple};
10+
use rustc_span::symbol::Symbol;
11+
use rustc_span::{Span, DUMMY_SP};
1612
use std::borrow::Cow;
1713
use std::fmt;
1814
use std::hash::{Hash, Hasher};
19-
use std::num::ParseIntError;
20-
use std::path::{Path, PathBuf};
2115

2216
/// Error type for `Diagnostic`'s `suggestions` field, indicating that
2317
/// `.disable_suggestions()` was called on the `Diagnostic`.
@@ -49,119 +43,6 @@ pub trait IntoDiagnosticArg {
4943
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static>;
5044
}
5145

52-
pub struct DiagnosticArgFromDisplay<'a>(pub &'a dyn fmt::Display);
53-
54-
impl IntoDiagnosticArg for DiagnosticArgFromDisplay<'_> {
55-
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
56-
self.0.to_string().into_diagnostic_arg()
57-
}
58-
}
59-
60-
impl<'a> From<&'a dyn fmt::Display> for DiagnosticArgFromDisplay<'a> {
61-
fn from(t: &'a dyn fmt::Display) -> Self {
62-
DiagnosticArgFromDisplay(t)
63-
}
64-
}
65-
66-
impl<'a, T: fmt::Display> From<&'a T> for DiagnosticArgFromDisplay<'a> {
67-
fn from(t: &'a T) -> Self {
68-
DiagnosticArgFromDisplay(t)
69-
}
70-
}
71-
72-
macro_rules! into_diagnostic_arg_using_display {
73-
($( $ty:ty ),+ $(,)?) => {
74-
$(
75-
impl IntoDiagnosticArg for $ty {
76-
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
77-
self.to_string().into_diagnostic_arg()
78-
}
79-
}
80-
)+
81-
}
82-
}
83-
84-
into_diagnostic_arg_using_display!(
85-
i8,
86-
u8,
87-
i16,
88-
u16,
89-
i32,
90-
u32,
91-
i64,
92-
u64,
93-
i128,
94-
u128,
95-
std::io::Error,
96-
std::num::NonZeroU32,
97-
hir::Target,
98-
Edition,
99-
Ident,
100-
MacroRulesNormalizedIdent,
101-
ParseIntError,
102-
StackProtector,
103-
&TargetTriple,
104-
SplitDebuginfo
105-
);
106-
107-
impl IntoDiagnosticArg for bool {
108-
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
109-
if self {
110-
DiagnosticArgValue::Str(Cow::Borrowed("true"))
111-
} else {
112-
DiagnosticArgValue::Str(Cow::Borrowed("false"))
113-
}
114-
}
115-
}
116-
117-
impl IntoDiagnosticArg for char {
118-
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
119-
DiagnosticArgValue::Str(Cow::Owned(format!("{:?}", self)))
120-
}
121-
}
122-
123-
impl IntoDiagnosticArg for Symbol {
124-
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
125-
self.to_ident_string().into_diagnostic_arg()
126-
}
127-
}
128-
129-
impl<'a> IntoDiagnosticArg for &'a str {
130-
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
131-
self.to_string().into_diagnostic_arg()
132-
}
133-
}
134-
135-
impl IntoDiagnosticArg for String {
136-
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
137-
DiagnosticArgValue::Str(Cow::Owned(self))
138-
}
139-
}
140-
141-
impl<'a> IntoDiagnosticArg for &'a Path {
142-
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
143-
DiagnosticArgValue::Str(Cow::Owned(self.display().to_string()))
144-
}
145-
}
146-
147-
impl IntoDiagnosticArg for PathBuf {
148-
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
149-
DiagnosticArgValue::Str(Cow::Owned(self.display().to_string()))
150-
}
151-
}
152-
153-
impl IntoDiagnosticArg for usize {
154-
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
155-
DiagnosticArgValue::Number(self)
156-
}
157-
}
158-
159-
impl IntoDiagnosticArg for PanicStrategy {
160-
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
161-
DiagnosticArgValue::Str(Cow::Owned(self.desc().to_string()))
162-
}
163-
}
164-
16546
impl<'source> Into<FluentValue<'source>> for DiagnosticArgValue<'source> {
16647
fn into(self) -> FluentValue<'source> {
16748
match self {
@@ -171,34 +52,6 @@ impl<'source> Into<FluentValue<'source>> for DiagnosticArgValue<'source> {
17152
}
17253
}
17354

174-
impl IntoDiagnosticArg for hir::ConstContext {
175-
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
176-
DiagnosticArgValue::Str(Cow::Borrowed(match self {
177-
hir::ConstContext::ConstFn => "constant function",
178-
hir::ConstContext::Static(_) => "static",
179-
hir::ConstContext::Const => "constant",
180-
}))
181-
}
182-
}
183-
184-
impl IntoDiagnosticArg for ast::Path {
185-
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
186-
DiagnosticArgValue::Str(Cow::Owned(pprust::path_to_string(&self)))
187-
}
188-
}
189-
190-
impl IntoDiagnosticArg for ast::token::Token {
191-
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
192-
DiagnosticArgValue::Str(pprust::token_to_string(&self))
193-
}
194-
}
195-
196-
impl IntoDiagnosticArg for ast::token::TokenKind {
197-
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
198-
DiagnosticArgValue::Str(pprust::token_kind_to_string(&self))
199-
}
200-
}
201-
20255
/// Trait implemented by error types. This should not be implemented manually. Instead, use
20356
/// `#[derive(Subdiagnostic)]` -- see [rustc_macros::Subdiagnostic].
20457
#[cfg_attr(bootstrap, rustc_diagnostic_item = "AddSubdiagnostic")]

0 commit comments

Comments
 (0)