mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-13 12:36:47 +00:00
Warn about dead tuple struct fields
This commit is contained in:
parent
7aaeee734f
commit
f232402057
@ -2,6 +2,7 @@
|
||||
// As the most common case is the `http` crate, it replicates `http::HeadewrName`'s structure.
|
||||
|
||||
#![allow(clippy::declare_interior_mutable_const)]
|
||||
#![allow(unused_tuple_struct_fields)]
|
||||
|
||||
use std::sync::atomic::AtomicUsize;
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
// run-rustfix
|
||||
|
||||
#![allow(
|
||||
unused_tuple_struct_fields,
|
||||
clippy::print_literal,
|
||||
clippy::redundant_clone,
|
||||
clippy::to_string_in_format_args,
|
||||
|
@ -1,6 +1,7 @@
|
||||
// run-rustfix
|
||||
|
||||
#![allow(
|
||||
unused_tuple_struct_fields,
|
||||
clippy::print_literal,
|
||||
clippy::redundant_clone,
|
||||
clippy::to_string_in_format_args,
|
||||
|
@ -1,5 +1,5 @@
|
||||
error: useless use of `format!`
|
||||
--> $DIR/format.rs:18:5
|
||||
--> $DIR/format.rs:19:5
|
||||
|
|
||||
LL | format!("foo");
|
||||
| ^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"foo".to_string()`
|
||||
@ -7,19 +7,19 @@ LL | format!("foo");
|
||||
= note: `-D clippy::useless-format` implied by `-D warnings`
|
||||
|
||||
error: useless use of `format!`
|
||||
--> $DIR/format.rs:19:5
|
||||
--> $DIR/format.rs:20:5
|
||||
|
|
||||
LL | format!("{{}}");
|
||||
| ^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"{}".to_string()`
|
||||
|
||||
error: useless use of `format!`
|
||||
--> $DIR/format.rs:20:5
|
||||
--> $DIR/format.rs:21:5
|
||||
|
|
||||
LL | format!("{{}} abc {{}}");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"{} abc {}".to_string()`
|
||||
|
||||
error: useless use of `format!`
|
||||
--> $DIR/format.rs:21:5
|
||||
--> $DIR/format.rs:22:5
|
||||
|
|
||||
LL | / format!(
|
||||
LL | | r##"foo {{}}
|
||||
@ -34,91 +34,91 @@ LL ~ " bar"##.to_string();
|
||||
|
|
||||
|
||||
error: useless use of `format!`
|
||||
--> $DIR/format.rs:26:13
|
||||
--> $DIR/format.rs:27:13
|
||||
|
|
||||
LL | let _ = format!("");
|
||||
| ^^^^^^^^^^^ help: consider using `String::new()`: `String::new()`
|
||||
|
||||
error: useless use of `format!`
|
||||
--> $DIR/format.rs:28:5
|
||||
--> $DIR/format.rs:29:5
|
||||
|
|
||||
LL | format!("{}", "foo");
|
||||
| ^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"foo".to_string()`
|
||||
|
||||
error: useless use of `format!`
|
||||
--> $DIR/format.rs:32:5
|
||||
--> $DIR/format.rs:33:5
|
||||
|
|
||||
LL | format!("{:+}", "foo"); // Warn when the format makes no difference.
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"foo".to_string()`
|
||||
|
||||
error: useless use of `format!`
|
||||
--> $DIR/format.rs:33:5
|
||||
--> $DIR/format.rs:34:5
|
||||
|
|
||||
LL | format!("{:<}", "foo"); // Warn when the format makes no difference.
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"foo".to_string()`
|
||||
|
||||
error: useless use of `format!`
|
||||
--> $DIR/format.rs:38:5
|
||||
--> $DIR/format.rs:39:5
|
||||
|
|
||||
LL | format!("{}", arg);
|
||||
| ^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `arg.to_string()`
|
||||
|
||||
error: useless use of `format!`
|
||||
--> $DIR/format.rs:42:5
|
||||
--> $DIR/format.rs:43:5
|
||||
|
|
||||
LL | format!("{:+}", arg); // Warn when the format makes no difference.
|
||||
| ^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `arg.to_string()`
|
||||
|
||||
error: useless use of `format!`
|
||||
--> $DIR/format.rs:43:5
|
||||
--> $DIR/format.rs:44:5
|
||||
|
|
||||
LL | format!("{:<}", arg); // Warn when the format makes no difference.
|
||||
| ^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `arg.to_string()`
|
||||
|
||||
error: useless use of `format!`
|
||||
--> $DIR/format.rs:70:5
|
||||
--> $DIR/format.rs:71:5
|
||||
|
|
||||
LL | format!("{}", 42.to_string());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `42.to_string()`
|
||||
|
||||
error: useless use of `format!`
|
||||
--> $DIR/format.rs:72:5
|
||||
--> $DIR/format.rs:73:5
|
||||
|
|
||||
LL | format!("{}", x.display().to_string());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `x.display().to_string()`
|
||||
|
||||
error: useless use of `format!`
|
||||
--> $DIR/format.rs:76:18
|
||||
--> $DIR/format.rs:77:18
|
||||
|
|
||||
LL | let _ = Some(format!("{}", a + "bar"));
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `a + "bar"`
|
||||
|
||||
error: useless use of `format!`
|
||||
--> $DIR/format.rs:80:22
|
||||
--> $DIR/format.rs:81:22
|
||||
|
|
||||
LL | let _s: String = format!("{}", &*v.join("/n"));
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `(&*v.join("/n")).to_string()`
|
||||
|
||||
error: useless use of `format!`
|
||||
--> $DIR/format.rs:86:13
|
||||
--> $DIR/format.rs:87:13
|
||||
|
|
||||
LL | let _ = format!("{x}");
|
||||
| ^^^^^^^^^^^^^^ help: consider using `.to_string()`: `x.to_string()`
|
||||
|
||||
error: useless use of `format!`
|
||||
--> $DIR/format.rs:88:13
|
||||
--> $DIR/format.rs:89:13
|
||||
|
|
||||
LL | let _ = format!("{y}", y = x);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `x.to_string()`
|
||||
|
||||
error: useless use of `format!`
|
||||
--> $DIR/format.rs:92:13
|
||||
--> $DIR/format.rs:93:13
|
||||
|
|
||||
LL | let _ = format!("{abc}");
|
||||
| ^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `abc.to_string()`
|
||||
|
||||
error: useless use of `format!`
|
||||
--> $DIR/format.rs:94:13
|
||||
--> $DIR/format.rs:95:13
|
||||
|
|
||||
LL | let _ = format!("{xx}");
|
||||
| ^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `xx.to_string()`
|
||||
|
@ -1,7 +1,7 @@
|
||||
// run-rustfix
|
||||
|
||||
#![warn(clippy::from_iter_instead_of_collect)]
|
||||
#![allow(unused_imports)]
|
||||
#![allow(unused_imports, unused_tuple_struct_fields)]
|
||||
|
||||
use std::collections::{BTreeMap, BTreeSet, HashMap, VecDeque};
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
// run-rustfix
|
||||
|
||||
#![warn(clippy::from_iter_instead_of_collect)]
|
||||
#![allow(unused_imports)]
|
||||
#![allow(unused_imports, unused_tuple_struct_fields)]
|
||||
|
||||
use std::collections::{BTreeMap, BTreeSet, HashMap, VecDeque};
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
// run-rustfix
|
||||
#![feature(never_type)]
|
||||
#![allow(unused_mut, clippy::redundant_allocation)]
|
||||
#![allow(unused_mut, unused_tuple_struct_fields, clippy::redundant_allocation)]
|
||||
#![warn(clippy::must_use_candidate)]
|
||||
use std::rc::Rc;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
|
@ -1,6 +1,6 @@
|
||||
// run-rustfix
|
||||
#![feature(never_type)]
|
||||
#![allow(unused_mut, clippy::redundant_allocation)]
|
||||
#![allow(unused_mut, unused_tuple_struct_fields, clippy::redundant_allocation)]
|
||||
#![warn(clippy::must_use_candidate)]
|
||||
use std::rc::Rc;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
|
@ -1,5 +1,6 @@
|
||||
//run-rustfix
|
||||
#![warn(clippy::init_numbered_fields)]
|
||||
#![allow(unused_tuple_struct_fields)]
|
||||
|
||||
#[derive(Default)]
|
||||
struct TupleStruct(u32, u32, u8);
|
||||
|
@ -1,5 +1,6 @@
|
||||
//run-rustfix
|
||||
#![warn(clippy::init_numbered_fields)]
|
||||
#![allow(unused_tuple_struct_fields)]
|
||||
|
||||
#[derive(Default)]
|
||||
struct TupleStruct(u32, u32, u8);
|
||||
|
@ -1,5 +1,5 @@
|
||||
error: used a field initializer for a tuple struct
|
||||
--> $DIR/numbered_fields.rs:18:13
|
||||
--> $DIR/numbered_fields.rs:19:13
|
||||
|
|
||||
LL | let _ = TupleStruct {
|
||||
| _____________^
|
||||
@ -12,7 +12,7 @@ LL | | };
|
||||
= note: `-D clippy::init-numbered-fields` implied by `-D warnings`
|
||||
|
||||
error: used a field initializer for a tuple struct
|
||||
--> $DIR/numbered_fields.rs:25:13
|
||||
--> $DIR/numbered_fields.rs:26:13
|
||||
|
|
||||
LL | let _ = TupleStruct {
|
||||
| _____________^
|
||||
|
@ -1,6 +1,7 @@
|
||||
// run-rustfix
|
||||
#![warn(clippy::option_if_let_else)]
|
||||
#![allow(
|
||||
unused_tuple_struct_fields,
|
||||
clippy::redundant_closure,
|
||||
clippy::ref_option_ref,
|
||||
clippy::equatable_if_let,
|
||||
|
@ -1,6 +1,7 @@
|
||||
// run-rustfix
|
||||
#![warn(clippy::option_if_let_else)]
|
||||
#![allow(
|
||||
unused_tuple_struct_fields,
|
||||
clippy::redundant_closure,
|
||||
clippy::ref_option_ref,
|
||||
clippy::equatable_if_let,
|
||||
|
@ -1,5 +1,5 @@
|
||||
error: use Option::map_or instead of an if let/else
|
||||
--> $DIR/option_if_let_else.rs:11:5
|
||||
--> $DIR/option_if_let_else.rs:12:5
|
||||
|
|
||||
LL | / if let Some(x) = string {
|
||||
LL | | (true, x)
|
||||
@ -11,19 +11,19 @@ LL | | }
|
||||
= note: `-D clippy::option-if-let-else` implied by `-D warnings`
|
||||
|
||||
error: use Option::map_or instead of an if let/else
|
||||
--> $DIR/option_if_let_else.rs:29:13
|
||||
--> $DIR/option_if_let_else.rs:30:13
|
||||
|
|
||||
LL | let _ = if let Some(s) = *string { s.len() } else { 0 };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `string.map_or(0, |s| s.len())`
|
||||
|
||||
error: use Option::map_or instead of an if let/else
|
||||
--> $DIR/option_if_let_else.rs:30:13
|
||||
--> $DIR/option_if_let_else.rs:31:13
|
||||
|
|
||||
LL | let _ = if let Some(s) = &num { s } else { &0 };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `num.as_ref().map_or(&0, |s| s)`
|
||||
|
||||
error: use Option::map_or instead of an if let/else
|
||||
--> $DIR/option_if_let_else.rs:31:13
|
||||
--> $DIR/option_if_let_else.rs:32:13
|
||||
|
|
||||
LL | let _ = if let Some(s) = &mut num {
|
||||
| _____________^
|
||||
@ -43,13 +43,13 @@ LL ~ });
|
||||
|
|
||||
|
||||
error: use Option::map_or instead of an if let/else
|
||||
--> $DIR/option_if_let_else.rs:37:13
|
||||
--> $DIR/option_if_let_else.rs:38:13
|
||||
|
|
||||
LL | let _ = if let Some(ref s) = num { s } else { &0 };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `num.as_ref().map_or(&0, |s| s)`
|
||||
|
||||
error: use Option::map_or instead of an if let/else
|
||||
--> $DIR/option_if_let_else.rs:38:13
|
||||
--> $DIR/option_if_let_else.rs:39:13
|
||||
|
|
||||
LL | let _ = if let Some(mut s) = num {
|
||||
| _____________^
|
||||
@ -69,7 +69,7 @@ LL ~ });
|
||||
|
|
||||
|
||||
error: use Option::map_or instead of an if let/else
|
||||
--> $DIR/option_if_let_else.rs:44:13
|
||||
--> $DIR/option_if_let_else.rs:45:13
|
||||
|
|
||||
LL | let _ = if let Some(ref mut s) = num {
|
||||
| _____________^
|
||||
@ -89,7 +89,7 @@ LL ~ });
|
||||
|
|
||||
|
||||
error: use Option::map_or instead of an if let/else
|
||||
--> $DIR/option_if_let_else.rs:53:5
|
||||
--> $DIR/option_if_let_else.rs:54:5
|
||||
|
|
||||
LL | / if let Some(x) = arg {
|
||||
LL | | let y = x * x;
|
||||
@ -108,7 +108,7 @@ LL + })
|
||||
|
|
||||
|
||||
error: use Option::map_or_else instead of an if let/else
|
||||
--> $DIR/option_if_let_else.rs:66:13
|
||||
--> $DIR/option_if_let_else.rs:67:13
|
||||
|
|
||||
LL | let _ = if let Some(x) = arg {
|
||||
| _____________^
|
||||
@ -120,7 +120,7 @@ LL | | };
|
||||
| |_____^ help: try: `arg.map_or_else(|| side_effect(), |x| x)`
|
||||
|
||||
error: use Option::map_or_else instead of an if let/else
|
||||
--> $DIR/option_if_let_else.rs:75:13
|
||||
--> $DIR/option_if_let_else.rs:76:13
|
||||
|
|
||||
LL | let _ = if let Some(x) = arg {
|
||||
| _____________^
|
||||
@ -143,7 +143,7 @@ LL ~ }, |x| x * x * x * x);
|
||||
|
|
||||
|
||||
error: use Option::map_or_else instead of an if let/else
|
||||
--> $DIR/option_if_let_else.rs:108:13
|
||||
--> $DIR/option_if_let_else.rs:109:13
|
||||
|
|
||||
LL | / if let Some(idx) = s.find('.') {
|
||||
LL | | vec![s[..idx].to_string(), s[idx..].to_string()]
|
||||
@ -153,13 +153,13 @@ LL | | }
|
||||
| |_____________^ help: try: `s.find('.').map_or_else(|| vec![s.to_string()], |idx| vec![s[..idx].to_string(), s[idx..].to_string()])`
|
||||
|
||||
error: use Option::map_or instead of an if let/else
|
||||
--> $DIR/option_if_let_else.rs:132:13
|
||||
--> $DIR/option_if_let_else.rs:133:13
|
||||
|
|
||||
LL | let _ = if let Some(x) = optional { x + 2 } else { 5 };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `optional.map_or(5, |x| x + 2)`
|
||||
|
||||
error: use Option::map_or instead of an if let/else
|
||||
--> $DIR/option_if_let_else.rs:141:13
|
||||
--> $DIR/option_if_let_else.rs:142:13
|
||||
|
|
||||
LL | let _ = if let Some(x) = Some(0) {
|
||||
| _____________^
|
||||
@ -181,13 +181,13 @@ LL ~ });
|
||||
|
|
||||
|
||||
error: use Option::map_or instead of an if let/else
|
||||
--> $DIR/option_if_let_else.rs:169:13
|
||||
--> $DIR/option_if_let_else.rs:170:13
|
||||
|
|
||||
LL | let _ = if let Some(x) = Some(0) { s.len() + x } else { s.len() };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Some(0).map_or(s.len(), |x| s.len() + x)`
|
||||
|
||||
error: use Option::map_or instead of an if let/else
|
||||
--> $DIR/option_if_let_else.rs:173:13
|
||||
--> $DIR/option_if_let_else.rs:174:13
|
||||
|
|
||||
LL | let _ = if let Some(x) = Some(0) {
|
||||
| _____________^
|
||||
|
@ -1,6 +1,7 @@
|
||||
// run-rustfix
|
||||
|
||||
#![warn(clippy::unreadable_literal)]
|
||||
#![allow(unused_tuple_struct_fields)]
|
||||
|
||||
struct Foo(u64);
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
// run-rustfix
|
||||
|
||||
#![warn(clippy::unreadable_literal)]
|
||||
#![allow(unused_tuple_struct_fields)]
|
||||
|
||||
struct Foo(u64);
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
error: digits of hex or binary literal not grouped by four
|
||||
--> $DIR/unreadable_literal.rs:25:9
|
||||
--> $DIR/unreadable_literal.rs:26:9
|
||||
|
|
||||
LL | 0x1_234_567,
|
||||
| ^^^^^^^^^^^ help: consider: `0x0123_4567`
|
||||
@ -7,7 +7,7 @@ LL | 0x1_234_567,
|
||||
= note: `-D clippy::unusual-byte-groupings` implied by `-D warnings`
|
||||
|
||||
error: long literal lacking separators
|
||||
--> $DIR/unreadable_literal.rs:33:17
|
||||
--> $DIR/unreadable_literal.rs:34:17
|
||||
|
|
||||
LL | let _bad = (0b110110_i64, 0x12345678_usize, 123456_f32, 1.234567_f32);
|
||||
| ^^^^^^^^^^^^ help: consider: `0b11_0110_i64`
|
||||
@ -15,55 +15,55 @@ LL | let _bad = (0b110110_i64, 0x12345678_usize, 123456_f32, 1.234567_f32);
|
||||
= note: `-D clippy::unreadable-literal` implied by `-D warnings`
|
||||
|
||||
error: long literal lacking separators
|
||||
--> $DIR/unreadable_literal.rs:33:31
|
||||
--> $DIR/unreadable_literal.rs:34:31
|
||||
|
|
||||
LL | let _bad = (0b110110_i64, 0x12345678_usize, 123456_f32, 1.234567_f32);
|
||||
| ^^^^^^^^^^^^^^^^ help: consider: `0x1234_5678_usize`
|
||||
|
||||
error: long literal lacking separators
|
||||
--> $DIR/unreadable_literal.rs:33:49
|
||||
--> $DIR/unreadable_literal.rs:34:49
|
||||
|
|
||||
LL | let _bad = (0b110110_i64, 0x12345678_usize, 123456_f32, 1.234567_f32);
|
||||
| ^^^^^^^^^^ help: consider: `123_456_f32`
|
||||
|
||||
error: long literal lacking separators
|
||||
--> $DIR/unreadable_literal.rs:33:61
|
||||
--> $DIR/unreadable_literal.rs:34:61
|
||||
|
|
||||
LL | let _bad = (0b110110_i64, 0x12345678_usize, 123456_f32, 1.234567_f32);
|
||||
| ^^^^^^^^^^^^ help: consider: `1.234_567_f32`
|
||||
|
||||
error: long literal lacking separators
|
||||
--> $DIR/unreadable_literal.rs:35:20
|
||||
--> $DIR/unreadable_literal.rs:36:20
|
||||
|
|
||||
LL | let _bad_sci = 1.123456e1;
|
||||
| ^^^^^^^^^^ help: consider: `1.123_456e1`
|
||||
|
||||
error: long literal lacking separators
|
||||
--> $DIR/unreadable_literal.rs:37:18
|
||||
--> $DIR/unreadable_literal.rs:38:18
|
||||
|
|
||||
LL | let _fail1 = 0xabcdef;
|
||||
| ^^^^^^^^ help: consider: `0x00ab_cdef`
|
||||
|
||||
error: long literal lacking separators
|
||||
--> $DIR/unreadable_literal.rs:38:23
|
||||
--> $DIR/unreadable_literal.rs:39:23
|
||||
|
|
||||
LL | let _fail2: u32 = 0xBAFEBAFE;
|
||||
| ^^^^^^^^^^ help: consider: `0xBAFE_BAFE`
|
||||
|
||||
error: long literal lacking separators
|
||||
--> $DIR/unreadable_literal.rs:39:18
|
||||
--> $DIR/unreadable_literal.rs:40:18
|
||||
|
|
||||
LL | let _fail3 = 0xabcdeff;
|
||||
| ^^^^^^^^^ help: consider: `0x0abc_deff`
|
||||
|
||||
error: long literal lacking separators
|
||||
--> $DIR/unreadable_literal.rs:40:24
|
||||
--> $DIR/unreadable_literal.rs:41:24
|
||||
|
|
||||
LL | let _fail4: i128 = 0xabcabcabcabcabcabc;
|
||||
| ^^^^^^^^^^^^^^^^^^^^ help: consider: `0x00ab_cabc_abca_bcab_cabc`
|
||||
|
||||
error: long literal lacking separators
|
||||
--> $DIR/unreadable_literal.rs:41:18
|
||||
--> $DIR/unreadable_literal.rs:42:18
|
||||
|
|
||||
LL | let _fail5 = 1.100300400;
|
||||
| ^^^^^^^^^^^ help: consider: `1.100_300_400`
|
||||
|
Loading…
Reference in New Issue
Block a user