Skip to content

Commit de06ce8

Browse files
committed
Address unused tuple struct fields in clippy
1 parent a4c2cf1 commit de06ce8

File tree

4 files changed

+18
-19
lines changed

4 files changed

+18
-19
lines changed

clippy_lints/src/methods/iter_overeager_cloned.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub(super) enum Op<'a> {
2222

2323
// rm `.cloned()`
2424
// e.g. `map` `for_each` `all` `any`
25-
NeedlessMove(&'a str, &'a Expr<'a>),
25+
NeedlessMove(&'a Expr<'a>),
2626

2727
// later `.cloned()`
2828
// and add `&` to the parameter of closure parameter
@@ -59,7 +59,7 @@ pub(super) fn check<'tcx>(
5959
return;
6060
}
6161

62-
if let Op::NeedlessMove(_, expr) = op {
62+
if let Op::NeedlessMove(expr) = op {
6363
let rustc_hir::ExprKind::Closure(closure) = expr.kind else {
6464
return;
6565
};
@@ -104,7 +104,7 @@ pub(super) fn check<'tcx>(
104104
}
105105

106106
let (lint, msg, trailing_clone) = match op {
107-
Op::RmCloned | Op::NeedlessMove(_, _) => (REDUNDANT_CLONE, "unneeded cloning of iterator items", ""),
107+
Op::RmCloned | Op::NeedlessMove(_) => (REDUNDANT_CLONE, "unneeded cloning of iterator items", ""),
108108
Op::LaterCloned | Op::FixClosure(_, _) => (
109109
ITER_OVEREAGER_CLONED,
110110
"unnecessarily eager cloning of iterator items",
@@ -133,7 +133,7 @@ pub(super) fn check<'tcx>(
133133
diag.span_suggestion(replace_span, "try", snip, Applicability::MachineApplicable);
134134
}
135135
},
136-
Op::NeedlessMove(_, _) => {
136+
Op::NeedlessMove(_) => {
137137
let method_span = expr.span.with_lo(cloned_call.span.hi());
138138
if let Some(snip) = snippet_opt(cx, method_span) {
139139
let replace_span = expr.span.with_lo(cloned_recv.span.hi());

clippy_lints/src/methods/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4186,7 +4186,7 @@ impl Methods {
41864186
expr,
41874187
recv,
41884188
recv2,
4189-
iter_overeager_cloned::Op::NeedlessMove(name, arg),
4189+
iter_overeager_cloned::Op::NeedlessMove(arg),
41904190
false,
41914191
);
41924192
}
@@ -4204,7 +4204,7 @@ impl Methods {
42044204
expr,
42054205
recv,
42064206
recv2,
4207-
iter_overeager_cloned::Op::NeedlessMove(name, arg),
4207+
iter_overeager_cloned::Op::NeedlessMove(arg),
42084208
false,
42094209
),
42104210
Some(("chars", recv, _, _, _))
@@ -4379,7 +4379,7 @@ impl Methods {
43794379
expr,
43804380
recv,
43814381
recv2,
4382-
iter_overeager_cloned::Op::NeedlessMove(name, arg),
4382+
iter_overeager_cloned::Op::NeedlessMove(arg),
43834383
false,
43844384
),
43854385
_ => {},
@@ -4433,7 +4433,7 @@ impl Methods {
44334433
expr,
44344434
recv,
44354435
recv2,
4436-
iter_overeager_cloned::Op::NeedlessMove(name, m_arg),
4436+
iter_overeager_cloned::Op::NeedlessMove(m_arg),
44374437
false,
44384438
),
44394439
_ => {},

clippy_lints/src/question_mark.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ enum IfBlockType<'hir> {
8080
Ty<'hir>,
8181
Symbol,
8282
&'hir Expr<'hir>,
83-
Option<&'hir Expr<'hir>>,
8483
),
8584
/// An `if let Xxx(a) = b { c } else { d }` expression.
8685
///
@@ -143,7 +142,7 @@ fn check_let_some_else_return_none(cx: &LateContext<'_>, stmt: &Stmt<'_>) {
143142

144143
fn is_early_return(smbl: Symbol, cx: &LateContext<'_>, if_block: &IfBlockType<'_>) -> bool {
145144
match *if_block {
146-
IfBlockType::IfIs(caller, caller_ty, call_sym, if_then, _) => {
145+
IfBlockType::IfIs(caller, caller_ty, call_sym, if_then) => {
147146
// If the block could be identified as `if x.is_none()/is_err()`,
148147
// we then only need to check the if_then return to see if it is none/err.
149148
is_type_diagnostic_item(cx, caller_ty, smbl)
@@ -235,7 +234,7 @@ impl QuestionMark {
235234
&& !is_else_clause(cx.tcx, expr)
236235
&& let ExprKind::MethodCall(segment, caller, ..) = &cond.kind
237236
&& let caller_ty = cx.typeck_results().expr_ty(caller)
238-
&& let if_block = IfBlockType::IfIs(caller, caller_ty, segment.ident.name, then, r#else)
237+
&& let if_block = IfBlockType::IfIs(caller, caller_ty, segment.ident.name, then)
239238
&& (is_early_return(sym::Option, cx, &if_block) || is_early_return(sym::Result, cx, &if_block))
240239
{
241240
let mut applicability = Applicability::MachineApplicable;

clippy_lints/src/transmute/transmute_undefined_repr.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,18 @@ pub(super) fn check<'tcx>(
2626

2727
// `Repr(C)` <-> unordered type.
2828
// If the first field of the `Repr(C)` type matches then the transmute is ok
29-
(ReducedTy::OrderedFields(_, Some(from_sub_ty)), ReducedTy::UnorderedFields(to_sub_ty))
30-
| (ReducedTy::UnorderedFields(from_sub_ty), ReducedTy::OrderedFields(_, Some(to_sub_ty))) => {
29+
(ReducedTy::OrderedFields(Some(from_sub_ty)), ReducedTy::UnorderedFields(to_sub_ty))
30+
| (ReducedTy::UnorderedFields(from_sub_ty), ReducedTy::OrderedFields(Some(to_sub_ty))) => {
3131
from_ty = from_sub_ty;
3232
to_ty = to_sub_ty;
3333
continue;
3434
},
35-
(ReducedTy::OrderedFields(_, Some(from_sub_ty)), ReducedTy::Other(to_sub_ty)) if reduced_tys.to_fat_ptr => {
35+
(ReducedTy::OrderedFields(Some(from_sub_ty)), ReducedTy::Other(to_sub_ty)) if reduced_tys.to_fat_ptr => {
3636
from_ty = from_sub_ty;
3737
to_ty = to_sub_ty;
3838
continue;
3939
},
40-
(ReducedTy::Other(from_sub_ty), ReducedTy::OrderedFields(_, Some(to_sub_ty)))
40+
(ReducedTy::Other(from_sub_ty), ReducedTy::OrderedFields(Some(to_sub_ty)))
4141
if reduced_tys.from_fat_ptr =>
4242
{
4343
from_ty = from_sub_ty;
@@ -235,8 +235,8 @@ enum ReducedTy<'tcx> {
235235
TypeErasure { raw_ptr_only: bool },
236236
/// The type is a struct containing either zero non-zero sized fields, or multiple non-zero
237237
/// sized fields with a defined order.
238-
/// The second value is the first non-zero sized type.
239-
OrderedFields(Ty<'tcx>, Option<Ty<'tcx>>),
238+
/// The value is the first non-zero sized type.
239+
OrderedFields(Option<Ty<'tcx>>),
240240
/// The type is a struct containing multiple non-zero sized fields with no defined order.
241241
UnorderedFields(Ty<'tcx>),
242242
/// Any other type.
@@ -259,7 +259,7 @@ fn reduce_ty<'tcx>(cx: &LateContext<'tcx>, mut ty: Ty<'tcx>) -> ReducedTy<'tcx>
259259
ty::Tuple(args) => {
260260
let mut iter = args.iter();
261261
let Some(sized_ty) = iter.find(|&ty| !is_zero_sized_ty(cx, ty)) else {
262-
return ReducedTy::OrderedFields(ty, None);
262+
return ReducedTy::OrderedFields(None);
263263
};
264264
if iter.all(|ty| is_zero_sized_ty(cx, ty)) {
265265
ty = sized_ty;
@@ -281,7 +281,7 @@ fn reduce_ty<'tcx>(cx: &LateContext<'tcx>, mut ty: Ty<'tcx>) -> ReducedTy<'tcx>
281281
continue;
282282
}
283283
if def.repr().inhibit_struct_field_reordering_opt() {
284-
ReducedTy::OrderedFields(ty, Some(sized_ty))
284+
ReducedTy::OrderedFields(Some(sized_ty))
285285
} else {
286286
ReducedTy::UnorderedFields(ty)
287287
}

0 commit comments

Comments
 (0)