lint: port variant size difference diagnostics
Signed-off-by: David Wood <david.wood@huawei.com>
This commit is contained in:
parent
e5f2e0e16c
commit
14c3016583
3 changed files with 54 additions and 6 deletions
|
@ -230,3 +230,6 @@ lint-improper-ctypes-array-reason = passing raw arrays by value is not FFI-safe
|
||||||
lint-improper-ctypes-array-help = consider passing a pointer to the array
|
lint-improper-ctypes-array-help = consider passing a pointer to the array
|
||||||
|
|
||||||
lint-improper-ctypes-only-phantomdata = composed only of `PhantomData`
|
lint-improper-ctypes-only-phantomdata = composed only of `PhantomData`
|
||||||
|
|
||||||
|
lint-variant-size-differences =
|
||||||
|
enum variant is more than three times larger ({$largest} bytes) than the next largest
|
||||||
|
|
|
@ -49,6 +49,54 @@ impl IntoDiagnosticArg for bool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl IntoDiagnosticArg for i8 {
|
||||||
|
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
|
||||||
|
DiagnosticArgValue::Str(Cow::Owned(self.to_string()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl IntoDiagnosticArg for u8 {
|
||||||
|
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
|
||||||
|
DiagnosticArgValue::Str(Cow::Owned(self.to_string()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl IntoDiagnosticArg for i16 {
|
||||||
|
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
|
||||||
|
DiagnosticArgValue::Str(Cow::Owned(self.to_string()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl IntoDiagnosticArg for u16 {
|
||||||
|
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
|
||||||
|
DiagnosticArgValue::Str(Cow::Owned(self.to_string()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl IntoDiagnosticArg for i32 {
|
||||||
|
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
|
||||||
|
DiagnosticArgValue::Str(Cow::Owned(self.to_string()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl IntoDiagnosticArg for u32 {
|
||||||
|
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
|
||||||
|
DiagnosticArgValue::Str(Cow::Owned(self.to_string()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl IntoDiagnosticArg for i64 {
|
||||||
|
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
|
||||||
|
DiagnosticArgValue::Str(Cow::Owned(self.to_string()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl IntoDiagnosticArg for u64 {
|
||||||
|
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
|
||||||
|
DiagnosticArgValue::Str(Cow::Owned(self.to_string()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl IntoDiagnosticArg for i128 {
|
impl IntoDiagnosticArg for i128 {
|
||||||
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
|
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
|
||||||
DiagnosticArgValue::Str(Cow::Owned(self.to_string()))
|
DiagnosticArgValue::Str(Cow::Owned(self.to_string()))
|
||||||
|
|
|
@ -1387,11 +1387,8 @@ impl<'tcx> LateLintPass<'tcx> for VariantSizeDifferences {
|
||||||
VARIANT_SIZE_DIFFERENCES,
|
VARIANT_SIZE_DIFFERENCES,
|
||||||
enum_definition.variants[largest_index].span,
|
enum_definition.variants[largest_index].span,
|
||||||
|lint| {
|
|lint| {
|
||||||
lint.build(&format!(
|
lint.build(fluent::lint::variant_size_differences)
|
||||||
"enum variant is more than three times \
|
.set_arg("largest", largest)
|
||||||
larger ({} bytes) than the next largest",
|
|
||||||
largest
|
|
||||||
))
|
|
||||||
.emit();
|
.emit();
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue