Skip to content

Commit

Permalink
Address unused tuple struct fields in clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
shepmaster committed Jan 1, 2024
1 parent a4c2cf1 commit de06ce8
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 19 deletions.
8 changes: 4 additions & 4 deletions clippy_lints/src/methods/iter_overeager_cloned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 22,7 @@ pub(super) enum Op<'a> {

// rm `.cloned()`
// e.g. `map` `for_each` `all` `any`
NeedlessMove(&'a str, &'a Expr<'a>),
NeedlessMove(&'a Expr<'a>),

// later `.cloned()`
// and add `&` to the parameter of closure parameter
Expand Down Expand Up @@ -59,7 59,7 @@ pub(super) fn check<'tcx>(
return;
}

if let Op::NeedlessMove(_, expr) = op {
if let Op::NeedlessMove(expr) = op {
let rustc_hir::ExprKind::Closure(closure) = expr.kind else {
return;
};
Expand Down Expand Up @@ -104,7 104,7 @@ pub(super) fn check<'tcx>(
}

let (lint, msg, trailing_clone) = match op {
Op::RmCloned | Op::NeedlessMove(_, _) => (REDUNDANT_CLONE, "unneeded cloning of iterator items", ""),
Op::RmCloned | Op::NeedlessMove(_) => (REDUNDANT_CLONE, "unneeded cloning of iterator items", ""),
Op::LaterCloned | Op::FixClosure(_, _) => (
ITER_OVEREAGER_CLONED,
"unnecessarily eager cloning of iterator items",
Expand Down Expand Up @@ -133,7 133,7 @@ pub(super) fn check<'tcx>(
diag.span_suggestion(replace_span, "try", snip, Applicability::MachineApplicable);
}
},
Op::NeedlessMove(_, _) => {
Op::NeedlessMove(_) => {
let method_span = expr.span.with_lo(cloned_call.span.hi());
if let Some(snip) = snippet_opt(cx, method_span) {
let replace_span = expr.span.with_lo(cloned_recv.span.hi());
Expand Down
8 changes: 4 additions & 4 deletions clippy_lints/src/methods/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4186,7 4186,7 @@ impl Methods {
expr,
recv,
recv2,
iter_overeager_cloned::Op::NeedlessMove(name, arg),
iter_overeager_cloned::Op::NeedlessMove(arg),
false,
);
}
Expand All @@ -4204,7 4204,7 @@ impl Methods {
expr,
recv,
recv2,
iter_overeager_cloned::Op::NeedlessMove(name, arg),
iter_overeager_cloned::Op::NeedlessMove(arg),
false,
),
Some(("chars", recv, _, _, _))
Expand Down Expand Up @@ -4379,7 4379,7 @@ impl Methods {
expr,
recv,
recv2,
iter_overeager_cloned::Op::NeedlessMove(name, arg),
iter_overeager_cloned::Op::NeedlessMove(arg),
false,
),
_ => {},
Expand Down Expand Up @@ -4433,7 4433,7 @@ impl Methods {
expr,
recv,
recv2,
iter_overeager_cloned::Op::NeedlessMove(name, m_arg),
iter_overeager_cloned::Op::NeedlessMove(m_arg),
false,
),
_ => {},
Expand Down
5 changes: 2 additions & 3 deletions clippy_lints/src/question_mark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 80,6 @@ enum IfBlockType<'hir> {
Ty<'hir>,
Symbol,
&'hir Expr<'hir>,
Option<&'hir Expr<'hir>>,
),
/// An `if let Xxx(a) = b { c } else { d }` expression.
///
Expand Down Expand Up @@ -143,7 142,7 @@ fn check_let_some_else_return_none(cx: &LateContext<'_>, stmt: &Stmt<'_>) {

fn is_early_return(smbl: Symbol, cx: &LateContext<'_>, if_block: &IfBlockType<'_>) -> bool {
match *if_block {
IfBlockType::IfIs(caller, caller_ty, call_sym, if_then, _) => {
IfBlockType::IfIs(caller, caller_ty, call_sym, if_then) => {
// If the block could be identified as `if x.is_none()/is_err()`,
// we then only need to check the if_then return to see if it is none/err.
is_type_diagnostic_item(cx, caller_ty, smbl)
Expand Down Expand Up @@ -235,7 234,7 @@ impl QuestionMark {
&& !is_else_clause(cx.tcx, expr)
&& let ExprKind::MethodCall(segment, caller, ..) = &cond.kind
&& let caller_ty = cx.typeck_results().expr_ty(caller)
&& let if_block = IfBlockType::IfIs(caller, caller_ty, segment.ident.name, then, r#else)
&& let if_block = IfBlockType::IfIs(caller, caller_ty, segment.ident.name, then)
&& (is_early_return(sym::Option, cx, &if_block) || is_early_return(sym::Result, cx, &if_block))
{
let mut applicability = Applicability::MachineApplicable;
Expand Down
16 changes: 8 additions & 8 deletions clippy_lints/src/transmute/transmute_undefined_repr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 26,18 @@ pub(super) fn check<'tcx>(

// `Repr(C)` <-> unordered type.
// If the first field of the `Repr(C)` type matches then the transmute is ok
(ReducedTy::OrderedFields(_, Some(from_sub_ty)), ReducedTy::UnorderedFields(to_sub_ty))
| (ReducedTy::UnorderedFields(from_sub_ty), ReducedTy::OrderedFields(_, Some(to_sub_ty))) => {
(ReducedTy::OrderedFields(Some(from_sub_ty)), ReducedTy::UnorderedFields(to_sub_ty))
| (ReducedTy::UnorderedFields(from_sub_ty), ReducedTy::OrderedFields(Some(to_sub_ty))) => {
from_ty = from_sub_ty;
to_ty = to_sub_ty;
continue;
},
(ReducedTy::OrderedFields(_, Some(from_sub_ty)), ReducedTy::Other(to_sub_ty)) if reduced_tys.to_fat_ptr => {
(ReducedTy::OrderedFields(Some(from_sub_ty)), ReducedTy::Other(to_sub_ty)) if reduced_tys.to_fat_ptr => {
from_ty = from_sub_ty;
to_ty = to_sub_ty;
continue;
},
(ReducedTy::Other(from_sub_ty), ReducedTy::OrderedFields(_, Some(to_sub_ty)))
(ReducedTy::Other(from_sub_ty), ReducedTy::OrderedFields(Some(to_sub_ty)))
if reduced_tys.from_fat_ptr =>
{
from_ty = from_sub_ty;
Expand Down Expand Up @@ -235,8 235,8 @@ enum ReducedTy<'tcx> {
TypeErasure { raw_ptr_only: bool },
/// The type is a struct containing either zero non-zero sized fields, or multiple non-zero
/// sized fields with a defined order.
/// The second value is the first non-zero sized type.
OrderedFields(Ty<'tcx>, Option<Ty<'tcx>>),
/// The value is the first non-zero sized type.
OrderedFields(Option<Ty<'tcx>>),
/// The type is a struct containing multiple non-zero sized fields with no defined order.
UnorderedFields(Ty<'tcx>),
/// Any other type.
Expand All @@ -259,7 259,7 @@ fn reduce_ty<'tcx>(cx: &LateContext<'tcx>, mut ty: Ty<'tcx>) -> ReducedTy<'tcx>
ty::Tuple(args) => {
let mut iter = args.iter();
let Some(sized_ty) = iter.find(|&ty| !is_zero_sized_ty(cx, ty)) else {
return ReducedTy::OrderedFields(ty, None);
return ReducedTy::OrderedFields(None);
};
if iter.all(|ty| is_zero_sized_ty(cx, ty)) {
ty = sized_ty;
Expand All @@ -281,7 281,7 @@ fn reduce_ty<'tcx>(cx: &LateContext<'tcx>, mut ty: Ty<'tcx>) -> ReducedTy<'tcx>
continue;
}
if def.repr().inhibit_struct_field_reordering_opt() {
ReducedTy::OrderedFields(ty, Some(sized_ty))
ReducedTy::OrderedFields(Some(sized_ty))
} else {
ReducedTy::UnorderedFields(ty)
}
Expand Down

0 comments on commit de06ce8

Please sign in to comment.