Skip to content

Commit 14c3016

Browse files
committed
lint: port variant size difference diagnostics
Signed-off-by: David Wood <david.wood@huawei.com>
1 parent e5f2e0e commit 14c3016

File tree

3 files changed

+54
-6
lines changed

3 files changed

+54
-6
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,3 +230,6 @@ lint-improper-ctypes-array-reason = passing raw arrays by value is not FFI-safe
230230
lint-improper-ctypes-array-help = consider passing a pointer to the array
231231
232232
lint-improper-ctypes-only-phantomdata = composed only of `PhantomData`
233+
234+
lint-variant-size-differences =
235+
enum variant is more than three times larger ({$largest} bytes) than the next largest

compiler/rustc_errors/src/diagnostic.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,54 @@ impl IntoDiagnosticArg for bool {
4949
}
5050
}
5151

52+
impl IntoDiagnosticArg for i8 {
53+
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
54+
DiagnosticArgValue::Str(Cow::Owned(self.to_string()))
55+
}
56+
}
57+
58+
impl IntoDiagnosticArg for u8 {
59+
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
60+
DiagnosticArgValue::Str(Cow::Owned(self.to_string()))
61+
}
62+
}
63+
64+
impl IntoDiagnosticArg for i16 {
65+
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
66+
DiagnosticArgValue::Str(Cow::Owned(self.to_string()))
67+
}
68+
}
69+
70+
impl IntoDiagnosticArg for u16 {
71+
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
72+
DiagnosticArgValue::Str(Cow::Owned(self.to_string()))
73+
}
74+
}
75+
76+
impl IntoDiagnosticArg for i32 {
77+
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
78+
DiagnosticArgValue::Str(Cow::Owned(self.to_string()))
79+
}
80+
}
81+
82+
impl IntoDiagnosticArg for u32 {
83+
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
84+
DiagnosticArgValue::Str(Cow::Owned(self.to_string()))
85+
}
86+
}
87+
88+
impl IntoDiagnosticArg for i64 {
89+
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
90+
DiagnosticArgValue::Str(Cow::Owned(self.to_string()))
91+
}
92+
}
93+
94+
impl IntoDiagnosticArg for u64 {
95+
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
96+
DiagnosticArgValue::Str(Cow::Owned(self.to_string()))
97+
}
98+
}
99+
52100
impl IntoDiagnosticArg for i128 {
53101
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
54102
DiagnosticArgValue::Str(Cow::Owned(self.to_string()))

compiler/rustc_lint/src/types.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,12 +1387,9 @@ impl<'tcx> LateLintPass<'tcx> for VariantSizeDifferences {
13871387
VARIANT_SIZE_DIFFERENCES,
13881388
enum_definition.variants[largest_index].span,
13891389
|lint| {
1390-
lint.build(&format!(
1391-
"enum variant is more than three times \
1392-
larger ({} bytes) than the next largest",
1393-
largest
1394-
))
1395-
.emit();
1390+
lint.build(fluent::lint::variant_size_differences)
1391+
.set_arg("largest", largest)
1392+
.emit();
13961393
},
13971394
);
13981395
}

0 commit comments

Comments
 (0)