Skip to content

Commit 200953d

Browse files
committed
Auto merge of #118297 - shepmaster:warn-dead-tuple-fields, r=WaffleLapkin
Merge `unused_tuple_struct_fields` into `dead_code` This implicitly upgrades the lint from `allow` to `warn` and places it into the `unused` lint group. [Discussion on Zulip](https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/Moving.20.60unused_tuple_struct_fields.60.20from.20allow.20to.20warn)
2 parents bd8e662 + e6580da commit 200953d

22 files changed

+77
-89
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
}

tests/ui/borrow_interior_mutable_const/auxiliary/helper.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// As the most common case is the `http` crate, it replicates `http::HeaderName`'s structure.
33

44
#![allow(clippy::declare_interior_mutable_const)]
5-
#![allow(unused_tuple_struct_fields)]
65

76
use std::sync::atomic::AtomicUsize;
87

tests/ui/format.fixed

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#![warn(clippy::useless_format)]
22
#![allow(
3-
unused_tuple_struct_fields,
43
clippy::print_literal,
54
clippy::redundant_clone,
65
clippy::to_string_in_format_args,

tests/ui/format.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#![warn(clippy::useless_format)]
22
#![allow(
3-
unused_tuple_struct_fields,
43
clippy::print_literal,
54
clippy::redundant_clone,
65
clippy::to_string_in_format_args,

tests/ui/format.stderr

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: useless use of `format!`
2-
--> $DIR/format.rs:20:5
2+
--> $DIR/format.rs:19:5
33
|
44
LL | format!("foo");
55
| ^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"foo".to_string()`
@@ -8,19 +8,19 @@ LL | format!("foo");
88
= help: to override `-D warnings` add `#[allow(clippy::useless_format)]`
99

1010
error: useless use of `format!`
11-
--> $DIR/format.rs:21:5
11+
--> $DIR/format.rs:20:5
1212
|
1313
LL | format!("{{}}");
1414
| ^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"{}".to_string()`
1515

1616
error: useless use of `format!`
17-
--> $DIR/format.rs:22:5
17+
--> $DIR/format.rs:21:5
1818
|
1919
LL | format!("{{}} abc {{}}");
2020
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"{} abc {}".to_string()`
2121

2222
error: useless use of `format!`
23-
--> $DIR/format.rs:23:5
23+
--> $DIR/format.rs:22:5
2424
|
2525
LL | / format!(
2626
LL | | r##"foo {{}}
@@ -35,67 +35,67 @@ LL ~ " bar"##.to_string();
3535
|
3636

3737
error: useless use of `format!`
38-
--> $DIR/format.rs:28:13
38+
--> $DIR/format.rs:27:13
3939
|
4040
LL | let _ = format!("");
4141
| ^^^^^^^^^^^ help: consider using `String::new()`: `String::new()`
4242

4343
error: useless use of `format!`
44-
--> $DIR/format.rs:30:5
44+
--> $DIR/format.rs:29:5
4545
|
4646
LL | format!("{}", "foo");
4747
| ^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"foo".to_string()`
4848

4949
error: useless use of `format!`
50-
--> $DIR/format.rs:38:5
50+
--> $DIR/format.rs:37:5
5151
|
5252
LL | format!("{}", arg);
5353
| ^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `arg.to_string()`
5454

5555
error: useless use of `format!`
56-
--> $DIR/format.rs:68:5
56+
--> $DIR/format.rs:67:5
5757
|
5858
LL | format!("{}", 42.to_string());
5959
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `42.to_string()`
6060

6161
error: useless use of `format!`
62-
--> $DIR/format.rs:70:5
62+
--> $DIR/format.rs:69:5
6363
|
6464
LL | format!("{}", x.display().to_string());
6565
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `x.display().to_string()`
6666

6767
error: useless use of `format!`
68-
--> $DIR/format.rs:74:18
68+
--> $DIR/format.rs:73:18
6969
|
7070
LL | let _ = Some(format!("{}", a + "bar"));
7171
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `a + "bar"`
7272

7373
error: useless use of `format!`
74-
--> $DIR/format.rs:78:22
74+
--> $DIR/format.rs:77:22
7575
|
7676
LL | let _s: String = format!("{}", &*v.join("\n"));
7777
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `(&*v.join("\n")).to_string()`
7878

7979
error: useless use of `format!`
80-
--> $DIR/format.rs:84:13
80+
--> $DIR/format.rs:83:13
8181
|
8282
LL | let _ = format!("{x}");
8383
| ^^^^^^^^^^^^^^ help: consider using `.to_string()`: `x.to_string()`
8484

8585
error: useless use of `format!`
86-
--> $DIR/format.rs:86:13
86+
--> $DIR/format.rs:85:13
8787
|
8888
LL | let _ = format!("{y}", y = x);
8989
| ^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `x.to_string()`
9090

9191
error: useless use of `format!`
92-
--> $DIR/format.rs:90:13
92+
--> $DIR/format.rs:89:13
9393
|
9494
LL | let _ = format!("{abc}");
9595
| ^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `abc.to_string()`
9696

9797
error: useless use of `format!`
98-
--> $DIR/format.rs:92:13
98+
--> $DIR/format.rs:91:13
9999
|
100100
LL | let _ = format!("{xx}");
101101
| ^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `xx.to_string()`

tests/ui/from_iter_instead_of_collect.fixed

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![warn(clippy::from_iter_instead_of_collect)]
2-
#![allow(unused_imports, unused_tuple_struct_fields)]
2+
#![allow(unused_imports)]
33
#![allow(clippy::useless_vec)]
44

55
use std::collections::{BTreeMap, BTreeSet, HashMap, VecDeque};

tests/ui/from_iter_instead_of_collect.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![warn(clippy::from_iter_instead_of_collect)]
2-
#![allow(unused_imports, unused_tuple_struct_fields)]
2+
#![allow(unused_imports)]
33
#![allow(clippy::useless_vec)]
44

55
use std::collections::{BTreeMap, BTreeSet, HashMap, VecDeque};

0 commit comments

Comments
 (0)