Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit f232402

Browse files
committed
Warn about dead tuple struct fields
1 parent 7aaeee7 commit f232402

17 files changed

+60
-51
lines changed

tests/ui/borrow_interior_mutable_const/auxiliary/helper.rs

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

44
#![allow(clippy::declare_interior_mutable_const)]
5+
#![allow(unused_tuple_struct_fields)]
56

67
use std::sync::atomic::AtomicUsize;
78

tests/ui/format.fixed

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// run-rustfix
22

33
#![allow(
4+
unused_tuple_struct_fields,
45
clippy::print_literal,
56
clippy::redundant_clone,
67
clippy::to_string_in_format_args,

tests/ui/format.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// run-rustfix
22

33
#![allow(
4+
unused_tuple_struct_fields,
45
clippy::print_literal,
56
clippy::redundant_clone,
67
clippy::to_string_in_format_args,

tests/ui/format.stderr

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
error: useless use of `format!`
2-
--> $DIR/format.rs:18:5
2+
--> $DIR/format.rs:19:5
33
|
44
LL | format!("foo");
55
| ^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"foo".to_string()`
66
|
77
= note: `-D clippy::useless-format` implied by `-D warnings`
88

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

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

2121
error: useless use of `format!`
22-
--> $DIR/format.rs:21:5
22+
--> $DIR/format.rs:22:5
2323
|
2424
LL | / format!(
2525
LL | | r##"foo {{}}
@@ -34,91 +34,91 @@ LL ~ " bar"##.to_string();
3434
|
3535

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

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

4848
error: useless use of `format!`
49-
--> $DIR/format.rs:32:5
49+
--> $DIR/format.rs:33:5
5050
|
5151
LL | format!("{:+}", "foo"); // Warn when the format makes no difference.
5252
| ^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"foo".to_string()`
5353

5454
error: useless use of `format!`
55-
--> $DIR/format.rs:33:5
55+
--> $DIR/format.rs:34:5
5656
|
5757
LL | format!("{:<}", "foo"); // Warn when the format makes no difference.
5858
| ^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"foo".to_string()`
5959

6060
error: useless use of `format!`
61-
--> $DIR/format.rs:38:5
61+
--> $DIR/format.rs:39:5
6262
|
6363
LL | format!("{}", arg);
6464
| ^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `arg.to_string()`
6565

6666
error: useless use of `format!`
67-
--> $DIR/format.rs:42:5
67+
--> $DIR/format.rs:43:5
6868
|
6969
LL | format!("{:+}", arg); // Warn when the format makes no difference.
7070
| ^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `arg.to_string()`
7171

7272
error: useless use of `format!`
73-
--> $DIR/format.rs:43:5
73+
--> $DIR/format.rs:44:5
7474
|
7575
LL | format!("{:<}", arg); // Warn when the format makes no difference.
7676
| ^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `arg.to_string()`
7777

7878
error: useless use of `format!`
79-
--> $DIR/format.rs:70:5
79+
--> $DIR/format.rs:71:5
8080
|
8181
LL | format!("{}", 42.to_string());
8282
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `42.to_string()`
8383

8484
error: useless use of `format!`
85-
--> $DIR/format.rs:72:5
85+
--> $DIR/format.rs:73:5
8686
|
8787
LL | format!("{}", x.display().to_string());
8888
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `x.display().to_string()`
8989

9090
error: useless use of `format!`
91-
--> $DIR/format.rs:76:18
91+
--> $DIR/format.rs:77:18
9292
|
9393
LL | let _ = Some(format!("{}", a + "bar"));
9494
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `a + "bar"`
9595

9696
error: useless use of `format!`
97-
--> $DIR/format.rs:80:22
97+
--> $DIR/format.rs:81:22
9898
|
9999
LL | let _s: String = format!("{}", &*v.join("/n"));
100100
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `(&*v.join("/n")).to_string()`
101101

102102
error: useless use of `format!`
103-
--> $DIR/format.rs:86:13
103+
--> $DIR/format.rs:87:13
104104
|
105105
LL | let _ = format!("{x}");
106106
| ^^^^^^^^^^^^^^ help: consider using `.to_string()`: `x.to_string()`
107107

108108
error: useless use of `format!`
109-
--> $DIR/format.rs:88:13
109+
--> $DIR/format.rs:89:13
110110
|
111111
LL | let _ = format!("{y}", y = x);
112112
| ^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `x.to_string()`
113113

114114
error: useless use of `format!`
115-
--> $DIR/format.rs:92:13
115+
--> $DIR/format.rs:93:13
116116
|
117117
LL | let _ = format!("{abc}");
118118
| ^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `abc.to_string()`
119119

120120
error: useless use of `format!`
121-
--> $DIR/format.rs:94:13
121+
--> $DIR/format.rs:95:13
122122
|
123123
LL | let _ = format!("{xx}");
124124
| ^^^^^^^^^^^^^^^ 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,7 +1,7 @@
11
// run-rustfix
22

33
#![warn(clippy::from_iter_instead_of_collect)]
4-
#![allow(unused_imports)]
4+
#![allow(unused_imports, unused_tuple_struct_fields)]
55

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

tests/ui/from_iter_instead_of_collect.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// run-rustfix
22

33
#![warn(clippy::from_iter_instead_of_collect)]
4-
#![allow(unused_imports)]
4+
#![allow(unused_imports, unused_tuple_struct_fields)]
55

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

tests/ui/must_use_candidates.fixed

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// run-rustfix
22
#![feature(never_type)]
3-
#![allow(unused_mut, clippy::redundant_allocation)]
3+
#![allow(unused_mut, unused_tuple_struct_fields, clippy::redundant_allocation)]
44
#![warn(clippy::must_use_candidate)]
55
use std::rc::Rc;
66
use std::sync::atomic::{AtomicBool, Ordering};

tests/ui/must_use_candidates.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// run-rustfix
22
#![feature(never_type)]
3-
#![allow(unused_mut, clippy::redundant_allocation)]
3+
#![allow(unused_mut, unused_tuple_struct_fields, clippy::redundant_allocation)]
44
#![warn(clippy::must_use_candidate)]
55
use std::rc::Rc;
66
use std::sync::atomic::{AtomicBool, Ordering};

tests/ui/numbered_fields.fixed

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//run-rustfix
22
#![warn(clippy::init_numbered_fields)]
3+
#![allow(unused_tuple_struct_fields)]
34

45
#[derive(Default)]
56
struct TupleStruct(u32, u32, u8);

tests/ui/numbered_fields.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//run-rustfix
22
#![warn(clippy::init_numbered_fields)]
3+
#![allow(unused_tuple_struct_fields)]
34

45
#[derive(Default)]
56
struct TupleStruct(u32, u32, u8);

tests/ui/numbered_fields.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: used a field initializer for a tuple struct
2-
--> $DIR/numbered_fields.rs:18:13
2+
--> $DIR/numbered_fields.rs:19:13
33
|
44
LL | let _ = TupleStruct {
55
| _____________^
@@ -12,7 +12,7 @@ LL | | };
1212
= note: `-D clippy::init-numbered-fields` implied by `-D warnings`
1313

1414
error: used a field initializer for a tuple struct
15-
--> $DIR/numbered_fields.rs:25:13
15+
--> $DIR/numbered_fields.rs:26:13
1616
|
1717
LL | let _ = TupleStruct {
1818
| _____________^

tests/ui/option_if_let_else.fixed

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// run-rustfix
22
#![warn(clippy::option_if_let_else)]
33
#![allow(
4+
unused_tuple_struct_fields,
45
clippy::redundant_closure,
56
clippy::ref_option_ref,
67
clippy::equatable_if_let,

tests/ui/option_if_let_else.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// run-rustfix
22
#![warn(clippy::option_if_let_else)]
33
#![allow(
4+
unused_tuple_struct_fields,
45
clippy::redundant_closure,
56
clippy::ref_option_ref,
67
clippy::equatable_if_let,

tests/ui/option_if_let_else.stderr

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: use Option::map_or instead of an if let/else
2-
--> $DIR/option_if_let_else.rs:11:5
2+
--> $DIR/option_if_let_else.rs:12:5
33
|
44
LL | / if let Some(x) = string {
55
LL | | (true, x)
@@ -11,19 +11,19 @@ LL | | }
1111
= note: `-D clippy::option-if-let-else` implied by `-D warnings`
1212

1313
error: use Option::map_or instead of an if let/else
14-
--> $DIR/option_if_let_else.rs:29:13
14+
--> $DIR/option_if_let_else.rs:30:13
1515
|
1616
LL | let _ = if let Some(s) = *string { s.len() } else { 0 };
1717
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `string.map_or(0, |s| s.len())`
1818

1919
error: use Option::map_or instead of an if let/else
20-
--> $DIR/option_if_let_else.rs:30:13
20+
--> $DIR/option_if_let_else.rs:31:13
2121
|
2222
LL | let _ = if let Some(s) = &num { s } else { &0 };
2323
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `num.as_ref().map_or(&0, |s| s)`
2424

2525
error: use Option::map_or instead of an if let/else
26-
--> $DIR/option_if_let_else.rs:31:13
26+
--> $DIR/option_if_let_else.rs:32:13
2727
|
2828
LL | let _ = if let Some(s) = &mut num {
2929
| _____________^
@@ -43,13 +43,13 @@ LL ~ });
4343
|
4444

4545
error: use Option::map_or instead of an if let/else
46-
--> $DIR/option_if_let_else.rs:37:13
46+
--> $DIR/option_if_let_else.rs:38:13
4747
|
4848
LL | let _ = if let Some(ref s) = num { s } else { &0 };
4949
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `num.as_ref().map_or(&0, |s| s)`
5050

5151
error: use Option::map_or instead of an if let/else
52-
--> $DIR/option_if_let_else.rs:38:13
52+
--> $DIR/option_if_let_else.rs:39:13
5353
|
5454
LL | let _ = if let Some(mut s) = num {
5555
| _____________^
@@ -69,7 +69,7 @@ LL ~ });
6969
|
7070

7171
error: use Option::map_or instead of an if let/else
72-
--> $DIR/option_if_let_else.rs:44:13
72+
--> $DIR/option_if_let_else.rs:45:13
7373
|
7474
LL | let _ = if let Some(ref mut s) = num {
7575
| _____________^
@@ -89,7 +89,7 @@ LL ~ });
8989
|
9090

9191
error: use Option::map_or instead of an if let/else
92-
--> $DIR/option_if_let_else.rs:53:5
92+
--> $DIR/option_if_let_else.rs:54:5
9393
|
9494
LL | / if let Some(x) = arg {
9595
LL | | let y = x * x;
@@ -108,7 +108,7 @@ LL + })
108108
|
109109

110110
error: use Option::map_or_else instead of an if let/else
111-
--> $DIR/option_if_let_else.rs:66:13
111+
--> $DIR/option_if_let_else.rs:67:13
112112
|
113113
LL | let _ = if let Some(x) = arg {
114114
| _____________^
@@ -120,7 +120,7 @@ LL | | };
120120
| |_____^ help: try: `arg.map_or_else(|| side_effect(), |x| x)`
121121

122122
error: use Option::map_or_else instead of an if let/else
123-
--> $DIR/option_if_let_else.rs:75:13
123+
--> $DIR/option_if_let_else.rs:76:13
124124
|
125125
LL | let _ = if let Some(x) = arg {
126126
| _____________^
@@ -143,7 +143,7 @@ LL ~ }, |x| x * x * x * x);
143143
|
144144

145145
error: use Option::map_or_else instead of an if let/else
146-
--> $DIR/option_if_let_else.rs:108:13
146+
--> $DIR/option_if_let_else.rs:109:13
147147
|
148148
LL | / if let Some(idx) = s.find('.') {
149149
LL | | vec![s[..idx].to_string(), s[idx..].to_string()]
@@ -153,13 +153,13 @@ LL | | }
153153
| |_____________^ help: try: `s.find('.').map_or_else(|| vec![s.to_string()], |idx| vec![s[..idx].to_string(), s[idx..].to_string()])`
154154

155155
error: use Option::map_or instead of an if let/else
156-
--> $DIR/option_if_let_else.rs:132:13
156+
--> $DIR/option_if_let_else.rs:133:13
157157
|
158158
LL | let _ = if let Some(x) = optional { x + 2 } else { 5 };
159159
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `optional.map_or(5, |x| x + 2)`
160160

161161
error: use Option::map_or instead of an if let/else
162-
--> $DIR/option_if_let_else.rs:141:13
162+
--> $DIR/option_if_let_else.rs:142:13
163163
|
164164
LL | let _ = if let Some(x) = Some(0) {
165165
| _____________^
@@ -181,13 +181,13 @@ LL ~ });
181181
|
182182

183183
error: use Option::map_or instead of an if let/else
184-
--> $DIR/option_if_let_else.rs:169:13
184+
--> $DIR/option_if_let_else.rs:170:13
185185
|
186186
LL | let _ = if let Some(x) = Some(0) { s.len() + x } else { s.len() };
187187
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Some(0).map_or(s.len(), |x| s.len() + x)`
188188

189189
error: use Option::map_or instead of an if let/else
190-
--> $DIR/option_if_let_else.rs:173:13
190+
--> $DIR/option_if_let_else.rs:174:13
191191
|
192192
LL | let _ = if let Some(x) = Some(0) {
193193
| _____________^

tests/ui/unreadable_literal.fixed

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// run-rustfix
22

33
#![warn(clippy::unreadable_literal)]
4+
#![allow(unused_tuple_struct_fields)]
45

56
struct Foo(u64);
67

tests/ui/unreadable_literal.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// run-rustfix
22

33
#![warn(clippy::unreadable_literal)]
4+
#![allow(unused_tuple_struct_fields)]
45

56
struct Foo(u64);
67

0 commit comments

Comments
 (0)