mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-28 07:30:57 +00:00
Check for tuple structs
This commit is contained in:
parent
2a5a4f07cf
commit
9f402b370c
1 changed files with 10 additions and 17 deletions
|
@ -38,7 +38,6 @@ declare_lint_pass!(TrailingZeroSizedArrayWithoutReprC => [TRAILING_ZERO_SIZED_AR
|
||||||
|
|
||||||
impl<'tcx> LateLintPass<'tcx> for TrailingZeroSizedArrayWithoutReprC {
|
impl<'tcx> LateLintPass<'tcx> for TrailingZeroSizedArrayWithoutReprC {
|
||||||
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'tcx>) {
|
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'tcx>) {
|
||||||
dbg!(item.ident);
|
|
||||||
if is_struct_with_trailing_zero_sized_array(cx, item) {
|
if is_struct_with_trailing_zero_sized_array(cx, item) {
|
||||||
// NOTE: This is to include attributes on the definition when we print the lint. If the convention
|
// NOTE: This is to include attributes on the definition when we print the lint. If the convention
|
||||||
// is to not do that with struct definitions (I'm not sure), then this isn't necessary. (note: if
|
// is to not do that with struct definitions (I'm not sure), then this isn't necessary. (note: if
|
||||||
|
@ -66,9 +65,10 @@ impl<'tcx> LateLintPass<'tcx> for TrailingZeroSizedArrayWithoutReprC {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_struct_with_trailing_zero_sized_array(cx: &LateContext<'tcx>, item: &'tcx Item<'tcx>) -> bool {
|
fn is_struct_with_trailing_zero_sized_array(cx: &LateContext<'tcx>, item: &'tcx Item<'tcx>) -> bool {
|
||||||
|
// TODO: when finalized, replace with an `if_chain`. I have it like this because my rust-analyzer doesn't work when it's an `if_chain`
|
||||||
// First check if last field is an array
|
// First check if last field is an array
|
||||||
if let ItemKind::Struct(data, _) = &item.kind {
|
if let ItemKind::Struct(data, _) = &item.kind {
|
||||||
if let VariantData::Struct(field_defs, _) = data {
|
let field_defs = data.fields();
|
||||||
if let Some(last_field) = field_defs.last() {
|
if let Some(last_field) = field_defs.last() {
|
||||||
if let rustc_hir::TyKind::Array(_, length) = last_field.ty.kind {
|
if let rustc_hir::TyKind::Array(_, length) = last_field.ty.kind {
|
||||||
// Then check if that that array zero-sized
|
// Then check if that that array zero-sized
|
||||||
|
@ -76,14 +76,7 @@ fn is_struct_with_trailing_zero_sized_array(cx: &LateContext<'tcx>, item: &'tcx
|
||||||
let length = Const::from_anon_const(cx.tcx, length_ldid);
|
let length = Const::from_anon_const(cx.tcx, length_ldid);
|
||||||
let length = length.try_eval_usize(cx.tcx, cx.param_env);
|
let length = length.try_eval_usize(cx.tcx, cx.param_env);
|
||||||
// if let Some((Constant::Int(length), _)) = length {
|
// if let Some((Constant::Int(length), _)) = length {
|
||||||
if let Some(length) = length {
|
if let Some(length) = length { length == 0 } else { false }
|
||||||
length == 0
|
|
||||||
} else {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue