Merge remote-tracking branch 'upstream/master' into rustup

This commit is contained in:
flip1995 2021-12-30 14:04:13 +01:00
commit e45842e360
No known key found for this signature in database
GPG key ID: 1CA0DF2AF59D68A5
83 changed files with 1598 additions and 531 deletions

View file

@ -7,7 +7,7 @@ LL | unsafe { 0 };
= note: `-D clippy::undocumented-unsafe-blocks` implied by `-D warnings`
help: consider adding a safety comment
|
LL ~ // Safety: ...
LL ~ // SAFETY: ...
LL ~ unsafe { 0 };
|

View file

@ -145,4 +145,10 @@ enum HIDataRequest {
DeleteUnpubHIData(String),
}
enum North {
Normal,
NoLeft,
NoRight,
}
fn main() {}

View file

@ -6,6 +6,18 @@ LL | cFoo,
|
= note: `-D clippy::enum-variant-names` implied by `-D warnings`
error: all variants have the same prefix: `c`
--> $DIR/enum_variants.rs:14:1
|
LL | / enum Foo {
LL | | cFoo,
LL | | cBar,
LL | | cBaz,
LL | | }
| |_^
|
= help: remove the prefixes and use full paths to the variants instead of glob imports
error: variant name starts with the enum's name
--> $DIR/enum_variants.rs:26:5
|
@ -60,6 +72,18 @@ LL | | }
|
= help: remove the prefixes and use full paths to the variants instead of glob imports
error: all variants have the same prefix: `C`
--> $DIR/enum_variants.rs:59:1
|
LL | / enum Something {
LL | | CCall,
LL | | CCreate,
LL | | CCryogenize,
LL | | }
| |_^
|
= help: remove the prefixes and use full paths to the variants instead of glob imports
error: all variants have the same prefix: `WithOut`
--> $DIR/enum_variants.rs:81:1
|
@ -72,18 +96,6 @@ LL | | }
|
= help: remove the prefixes and use full paths to the variants instead of glob imports
error: all variants have the same prefix: `Prefix`
--> $DIR/enum_variants.rs:87:1
|
LL | / enum NonCaps {
LL | | Prefix的,
LL | | PrefixTea,
LL | | PrefixCake,
LL | | }
| |_^
|
= help: remove the prefixes and use full paths to the variants instead of glob imports
error: all variants have the same postfix: `IData`
--> $DIR/enum_variants.rs:136:1
|
@ -108,5 +120,5 @@ LL | | }
|
= help: remove the postfixes and use full paths to the variants instead of glob imports
error: aborting due to 11 previous errors
error: aborting due to 12 previous errors

View file

@ -11,7 +11,12 @@ pub const fn const_context() {
fn main() {
let x = 3f32;
let _ = x.to_degrees();
let _ = 90.0_f64.to_degrees();
let _ = 90.5_f64.to_degrees();
let _ = x.to_radians();
let _ = 90.0_f64.to_radians();
let _ = 90.5_f64.to_radians();
// let _ = 90.5 * 80. * std::f32::consts::PI / 180f32;
// Cases where the lint shouldn't be applied
let _ = x * 90f32 / std::f32::consts::PI;
let _ = x * std::f32::consts::PI / 90f32;

View file

@ -11,7 +11,12 @@ pub const fn const_context() {
fn main() {
let x = 3f32;
let _ = x * 180f32 / std::f32::consts::PI;
let _ = 90. * 180f64 / std::f64::consts::PI;
let _ = 90.5 * 180f64 / std::f64::consts::PI;
let _ = x * std::f32::consts::PI / 180f32;
let _ = 90. * std::f32::consts::PI / 180f32;
let _ = 90.5 * std::f32::consts::PI / 180f32;
// let _ = 90.5 * 80. * std::f32::consts::PI / 180f32;
// Cases where the lint shouldn't be applied
let _ = x * 90f32 / std::f32::consts::PI;
let _ = x * std::f32::consts::PI / 90f32;

View file

@ -6,11 +6,35 @@ LL | let _ = x * 180f32 / std::f32::consts::PI;
|
= note: `-D clippy::suboptimal-flops` implied by `-D warnings`
error: conversion to radians can be done more accurately
error: conversion to degrees can be done more accurately
--> $DIR/floating_point_rad.rs:14:13
|
LL | let _ = 90. * 180f64 / std::f64::consts::PI;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `90.0_f64.to_degrees()`
error: conversion to degrees can be done more accurately
--> $DIR/floating_point_rad.rs:15:13
|
LL | let _ = 90.5 * 180f64 / std::f64::consts::PI;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `90.5_f64.to_degrees()`
error: conversion to radians can be done more accurately
--> $DIR/floating_point_rad.rs:16:13
|
LL | let _ = x * std::f32::consts::PI / 180f32;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.to_radians()`
error: aborting due to 2 previous errors
error: conversion to radians can be done more accurately
--> $DIR/floating_point_rad.rs:17:13
|
LL | let _ = 90. * std::f32::consts::PI / 180f32;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `90.0_f64.to_radians()`
error: conversion to radians can be done more accurately
--> $DIR/floating_point_rad.rs:18:13
|
LL | let _ = 90.5 * std::f32::consts::PI / 180f32;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `90.5_f64.to_radians()`
error: aborting due to 6 previous errors

View file

@ -2,10 +2,20 @@ const ONE: i64 = 1;
const NEG_ONE: i64 = -1;
const ZERO: i64 = 0;
struct A(String);
impl std::ops::Shl<i32> for A {
type Output = A;
fn shl(mut self, other: i32) -> Self {
self.0.push_str(&format!("{}", other));
self
}
}
#[allow(
clippy::eq_op,
clippy::no_effect,
clippy::unnecessary_operation,
clippy::op_ref,
clippy::double_parens
)]
#[warn(clippy::identity_op)]
@ -38,4 +48,9 @@ fn main() {
42 << 0;
1 >> 0;
42 >> 0;
&x >> 0;
x >> &0;
let mut a = A("".into());
let b = a << 0; // no error: non-integer
}

View file

@ -1,5 +1,5 @@
error: the operation is ineffective. Consider reducing it to `x`
--> $DIR/identity_op.rs:16:5
--> $DIR/identity_op.rs:26:5
|
LL | x + 0;
| ^^^^^
@ -7,64 +7,76 @@ LL | x + 0;
= note: `-D clippy::identity-op` implied by `-D warnings`
error: the operation is ineffective. Consider reducing it to `x`
--> $DIR/identity_op.rs:17:5
--> $DIR/identity_op.rs:27:5
|
LL | x + (1 - 1);
| ^^^^^^^^^^^
error: the operation is ineffective. Consider reducing it to `x`
--> $DIR/identity_op.rs:19:5
--> $DIR/identity_op.rs:29:5
|
LL | 0 + x;
| ^^^^^
error: the operation is ineffective. Consider reducing it to `x`
--> $DIR/identity_op.rs:22:5
--> $DIR/identity_op.rs:32:5
|
LL | x | (0);
| ^^^^^^^
error: the operation is ineffective. Consider reducing it to `x`
--> $DIR/identity_op.rs:25:5
--> $DIR/identity_op.rs:35:5
|
LL | x * 1;
| ^^^^^
error: the operation is ineffective. Consider reducing it to `x`
--> $DIR/identity_op.rs:26:5
--> $DIR/identity_op.rs:36:5
|
LL | 1 * x;
| ^^^^^
error: the operation is ineffective. Consider reducing it to `x`
--> $DIR/identity_op.rs:32:5
--> $DIR/identity_op.rs:42:5
|
LL | -1 & x;
| ^^^^^^
error: the operation is ineffective. Consider reducing it to `u`
--> $DIR/identity_op.rs:35:5
--> $DIR/identity_op.rs:45:5
|
LL | u & 255;
| ^^^^^^^
error: the operation is ineffective. Consider reducing it to `42`
--> $DIR/identity_op.rs:38:5
--> $DIR/identity_op.rs:48:5
|
LL | 42 << 0;
| ^^^^^^^
error: the operation is ineffective. Consider reducing it to `1`
--> $DIR/identity_op.rs:39:5
--> $DIR/identity_op.rs:49:5
|
LL | 1 >> 0;
| ^^^^^^
error: the operation is ineffective. Consider reducing it to `42`
--> $DIR/identity_op.rs:40:5
--> $DIR/identity_op.rs:50:5
|
LL | 42 >> 0;
| ^^^^^^^
error: aborting due to 11 previous errors
error: the operation is ineffective. Consider reducing it to `&x`
--> $DIR/identity_op.rs:51:5
|
LL | &x >> 0;
| ^^^^^^^
error: the operation is ineffective. Consider reducing it to `x`
--> $DIR/identity_op.rs:52:5
|
LL | x >> &0;
| ^^^^^^^
error: aborting due to 13 previous errors

View file

@ -4,6 +4,7 @@
#![warn(clippy::iter_skip_next)]
#![allow(clippy::blacklisted_name)]
#![allow(clippy::iter_nth)]
#![allow(unused_mut, dead_code)]
extern crate option_helpers;
@ -19,4 +20,18 @@ fn main() {
let foo = IteratorFalsePositives { foo: 0 };
let _ = foo.skip(42).next();
let _ = foo.filter().skip(42).next();
// fix #8128
let test_string = "1|1 2";
let mut sp = test_string.split('|').map(|s| s.trim());
let _: Vec<&str> = sp.nth(1).unwrap().split(' ').collect();
if let Some(mut s) = Some(test_string.split('|').map(|s| s.trim())) {
let _: Vec<&str> = s.nth(1).unwrap().split(' ').collect();
};
fn check<T>(mut s: T)
where
T: Iterator<Item = String>,
{
let _: Vec<&str> = s.nth(1).unwrap().split(' ').collect();
}
}

View file

@ -4,6 +4,7 @@
#![warn(clippy::iter_skip_next)]
#![allow(clippy::blacklisted_name)]
#![allow(clippy::iter_nth)]
#![allow(unused_mut, dead_code)]
extern crate option_helpers;
@ -19,4 +20,18 @@ fn main() {
let foo = IteratorFalsePositives { foo: 0 };
let _ = foo.skip(42).next();
let _ = foo.filter().skip(42).next();
// fix #8128
let test_string = "1|1 2";
let mut sp = test_string.split('|').map(|s| s.trim());
let _: Vec<&str> = sp.skip(1).next().unwrap().split(' ').collect();
if let Some(mut s) = Some(test_string.split('|').map(|s| s.trim())) {
let _: Vec<&str> = s.skip(1).next().unwrap().split(' ').collect();
};
fn check<T>(mut s: T)
where
T: Iterator<Item = String>,
{
let _: Vec<&str> = s.skip(1).next().unwrap().split(' ').collect();
}
}

View file

@ -1,5 +1,5 @@
error: called `skip(..).next()` on an iterator
--> $DIR/iter_skip_next.rs:15:28
--> $DIR/iter_skip_next.rs:16:28
|
LL | let _ = some_vec.iter().skip(42).next();
| ^^^^^^^^^^^^^^^^ help: use `nth` instead: `.nth(42)`
@ -7,22 +7,40 @@ LL | let _ = some_vec.iter().skip(42).next();
= note: `-D clippy::iter-skip-next` implied by `-D warnings`
error: called `skip(..).next()` on an iterator
--> $DIR/iter_skip_next.rs:16:36
--> $DIR/iter_skip_next.rs:17:36
|
LL | let _ = some_vec.iter().cycle().skip(42).next();
| ^^^^^^^^^^^^^^^^ help: use `nth` instead: `.nth(42)`
error: called `skip(..).next()` on an iterator
--> $DIR/iter_skip_next.rs:17:20
--> $DIR/iter_skip_next.rs:18:20
|
LL | let _ = (1..10).skip(10).next();
| ^^^^^^^^^^^^^^^^ help: use `nth` instead: `.nth(10)`
error: called `skip(..).next()` on an iterator
--> $DIR/iter_skip_next.rs:18:33
--> $DIR/iter_skip_next.rs:19:33
|
LL | let _ = &some_vec[..].iter().skip(3).next();
| ^^^^^^^^^^^^^^^ help: use `nth` instead: `.nth(3)`
error: aborting due to 4 previous errors
error: called `skip(..).next()` on an iterator
--> $DIR/iter_skip_next.rs:27:26
|
LL | let _: Vec<&str> = sp.skip(1).next().unwrap().split(' ').collect();
| ^^^^^^^^^^^^^^^ help: use `nth` instead: `.nth(1)`
error: called `skip(..).next()` on an iterator
--> $DIR/iter_skip_next.rs:29:29
|
LL | let _: Vec<&str> = s.skip(1).next().unwrap().split(' ').collect();
| ^^^^^^^^^^^^^^^ help: use `nth` instead: `.nth(1)`
error: called `skip(..).next()` on an iterator
--> $DIR/iter_skip_next.rs:35:29
|
LL | let _: Vec<&str> = s.skip(1).next().unwrap().split(' ').collect();
| ^^^^^^^^^^^^^^^ help: use `nth` instead: `.nth(1)`
error: aborting due to 7 previous errors

View file

@ -0,0 +1,19 @@
#![warn(clippy::iter_skip_next)]
#![allow(dead_code)]
/// Checks implementation of `ITER_SKIP_NEXT` lint
fn main() {
// fix #8128
let test_string = "1|1 2";
let sp = test_string.split('|').map(|s| s.trim());
let _: Vec<&str> = sp.skip(1).next().unwrap().split(' ').collect();
if let Some(s) = Some(test_string.split('|').map(|s| s.trim())) {
let _: Vec<&str> = s.skip(1).next().unwrap().split(' ').collect();
};
fn check<T>(s: T)
where
T: Iterator<Item = String>,
{
let _: Vec<&str> = s.skip(1).next().unwrap().split(' ').collect();
}
}

View file

@ -0,0 +1,39 @@
error: called `skip(..).next()` on an iterator
--> $DIR/iter_skip_next_unfixable.rs:9:26
|
LL | let _: Vec<&str> = sp.skip(1).next().unwrap().split(' ').collect();
| ^^^^^^^^^^^^^^^ help: use `nth` instead: `.nth(1)`
|
= note: `-D clippy::iter-skip-next` implied by `-D warnings`
help: for this change `sp` has to be mutable
--> $DIR/iter_skip_next_unfixable.rs:8:9
|
LL | let sp = test_string.split('|').map(|s| s.trim());
| ^^
error: called `skip(..).next()` on an iterator
--> $DIR/iter_skip_next_unfixable.rs:11:29
|
LL | let _: Vec<&str> = s.skip(1).next().unwrap().split(' ').collect();
| ^^^^^^^^^^^^^^^ help: use `nth` instead: `.nth(1)`
|
help: for this change `s` has to be mutable
--> $DIR/iter_skip_next_unfixable.rs:10:17
|
LL | if let Some(s) = Some(test_string.split('|').map(|s| s.trim())) {
| ^
error: called `skip(..).next()` on an iterator
--> $DIR/iter_skip_next_unfixable.rs:17:29
|
LL | let _: Vec<&str> = s.skip(1).next().unwrap().split(' ').collect();
| ^^^^^^^^^^^^^^^ help: use `nth` instead: `.nth(1)`
|
help: for this change `s` has to be mutable
--> $DIR/iter_skip_next_unfixable.rs:13:17
|
LL | fn check<T>(s: T)
| ^
error: aborting due to 3 previous errors

View file

@ -43,7 +43,7 @@ LL | / for i in 3..(3 + src.len()) {
LL | | dst[i] = src[count];
LL | | count += 1;
LL | | }
| |_____^ help: try replacing the loop by: `dst[3..(3 + src.len())].clone_from_slice(&src[..((3 + src.len()) - 3)]);`
| |_____^ help: try replacing the loop by: `dst[3..(3 + src.len())].clone_from_slice(&src[..(3 + src.len() - 3)]);`
error: it looks like you're manually copying between slices
--> $DIR/with_loop_counters.rs:35:5

View file

@ -41,6 +41,15 @@ fn main() {
x;
!x;
!(x && y);
let a = 0;
let b = 1;
a != b;
a == b;
a >= b;
a > b;
a <= b;
a < b;
if x {
x
} else {

View file

@ -53,6 +53,39 @@ fn main() {
} else {
true
};
let a = 0;
let b = 1;
if a == b {
false
} else {
true
};
if a != b {
false
} else {
true
};
if a < b {
false
} else {
true
};
if a <= b {
false
} else {
true
};
if a > b {
false
} else {
true
};
if a >= b {
false
} else {
true
};
if x {
x
} else {

View file

@ -31,7 +31,67 @@ LL | | };
| |_____^ help: you can reduce it to: `!(x && y)`
error: this if-then-else expression returns a bool literal
--> $DIR/fixable.rs:72:5
--> $DIR/fixable.rs:59:5
|
LL | / if a == b {
LL | | false
LL | | } else {
LL | | true
LL | | };
| |_____^ help: you can reduce it to: `a != b`
error: this if-then-else expression returns a bool literal
--> $DIR/fixable.rs:64:5
|
LL | / if a != b {
LL | | false
LL | | } else {
LL | | true
LL | | };
| |_____^ help: you can reduce it to: `a == b`
error: this if-then-else expression returns a bool literal
--> $DIR/fixable.rs:69:5
|
LL | / if a < b {
LL | | false
LL | | } else {
LL | | true
LL | | };
| |_____^ help: you can reduce it to: `a >= b`
error: this if-then-else expression returns a bool literal
--> $DIR/fixable.rs:74:5
|
LL | / if a <= b {
LL | | false
LL | | } else {
LL | | true
LL | | };
| |_____^ help: you can reduce it to: `a > b`
error: this if-then-else expression returns a bool literal
--> $DIR/fixable.rs:79:5
|
LL | / if a > b {
LL | | false
LL | | } else {
LL | | true
LL | | };
| |_____^ help: you can reduce it to: `a <= b`
error: this if-then-else expression returns a bool literal
--> $DIR/fixable.rs:84:5
|
LL | / if a >= b {
LL | | false
LL | | } else {
LL | | true
LL | | };
| |_____^ help: you can reduce it to: `a < b`
error: this if-then-else expression returns a bool literal
--> $DIR/fixable.rs:105:5
|
LL | / if x {
LL | | return true;
@ -41,7 +101,7 @@ LL | | };
| |_____^ help: you can reduce it to: `return x`
error: this if-then-else expression returns a bool literal
--> $DIR/fixable.rs:80:5
--> $DIR/fixable.rs:113:5
|
LL | / if x {
LL | | return false;
@ -51,7 +111,7 @@ LL | | };
| |_____^ help: you can reduce it to: `return !x`
error: this if-then-else expression returns a bool literal
--> $DIR/fixable.rs:88:5
--> $DIR/fixable.rs:121:5
|
LL | / if x && y {
LL | | return true;
@ -61,7 +121,7 @@ LL | | };
| |_____^ help: you can reduce it to: `return x && y`
error: this if-then-else expression returns a bool literal
--> $DIR/fixable.rs:96:5
--> $DIR/fixable.rs:129:5
|
LL | / if x && y {
LL | | return false;
@ -71,7 +131,7 @@ LL | | };
| |_____^ help: you can reduce it to: `return !(x && y)`
error: equality checks against true are unnecessary
--> $DIR/fixable.rs:104:8
--> $DIR/fixable.rs:137:8
|
LL | if x == true {};
| ^^^^^^^^^ help: try simplifying it as shown: `x`
@ -79,25 +139,25 @@ LL | if x == true {};
= note: `-D clippy::bool-comparison` implied by `-D warnings`
error: equality checks against false can be replaced by a negation
--> $DIR/fixable.rs:108:8
--> $DIR/fixable.rs:141:8
|
LL | if x == false {};
| ^^^^^^^^^^ help: try simplifying it as shown: `!x`
error: equality checks against true are unnecessary
--> $DIR/fixable.rs:118:8
--> $DIR/fixable.rs:151:8
|
LL | if x == true {};
| ^^^^^^^^^ help: try simplifying it as shown: `x`
error: equality checks against false can be replaced by a negation
--> $DIR/fixable.rs:119:8
--> $DIR/fixable.rs:152:8
|
LL | if x == false {};
| ^^^^^^^^^^ help: try simplifying it as shown: `!x`
error: this if-then-else expression returns a bool literal
--> $DIR/fixable.rs:128:12
--> $DIR/fixable.rs:161:12
|
LL | } else if returns_bool() {
| ____________^
@ -108,7 +168,7 @@ LL | | };
| |_____^ help: you can reduce it to: `{ !returns_bool() }`
error: this if-then-else expression returns a bool literal
--> $DIR/fixable.rs:141:5
--> $DIR/fixable.rs:174:5
|
LL | / if unsafe { no(4) } & 1 != 0 {
LL | | true
@ -118,16 +178,16 @@ LL | | };
| |_____^ help: you can reduce it to: `(unsafe { no(4) } & 1 != 0)`
error: this if-then-else expression returns a bool literal
--> $DIR/fixable.rs:146:30
--> $DIR/fixable.rs:179:30
|
LL | let _brackets_unneeded = if unsafe { no(4) } & 1 != 0 { true } else { false };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can reduce it to: `unsafe { no(4) } & 1 != 0`
error: this if-then-else expression returns a bool literal
--> $DIR/fixable.rs:149:9
--> $DIR/fixable.rs:182:9
|
LL | if unsafe { no(4) } & 1 != 0 { true } else { false }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can reduce it to: `(unsafe { no(4) } & 1 != 0)`
error: aborting due to 15 previous errors
error: aborting due to 21 previous errors

View file

@ -71,7 +71,18 @@ fn test_void_if_fun(b: bool) {
fn test_void_match(x: u32) {
match x {
0 => (),
_ => {},
_ => (),
}
}
fn test_nested_match(x: u32) {
match x {
0 => (),
1 => {
let _ = 42;
},
_ => (),
}
}
@ -182,7 +193,7 @@ async fn async_test_void_if_fun(b: bool) {
async fn async_test_void_match(x: u32) {
match x {
0 => (),
_ => {},
_ => (),
}
}

View file

@ -75,6 +75,17 @@ fn test_void_match(x: u32) {
}
}
fn test_nested_match(x: u32) {
match x {
0 => (),
1 => {
let _ = 42;
return;
},
_ => return,
}
}
fn read_line() -> String {
use std::io::BufRead;
let stdin = ::std::io::stdin();

View file

@ -70,127 +70,139 @@ error: unneeded `return` statement
--> $DIR/needless_return.rs:74:14
|
LL | _ => return,
| ^^^^^^ help: replace `return` with an empty block: `{}`
| ^^^^^^ help: replace `return` with a unit value: `()`
error: unneeded `return` statement
--> $DIR/needless_return.rs:89:9
|
LL | return String::from("test");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove `return`: `String::from("test")`
error: unneeded `return` statement
--> $DIR/needless_return.rs:91:9
|
LL | return String::new();
| ^^^^^^^^^^^^^^^^^^^^^ help: remove `return`: `String::new()`
error: unneeded `return` statement
--> $DIR/needless_return.rs:113:32
|
LL | bar.unwrap_or_else(|_| return)
| ^^^^^^ help: replace `return` with an empty block: `{}`
error: unneeded `return` statement
--> $DIR/needless_return.rs:118:13
--> $DIR/needless_return.rs:83:13
|
LL | return;
| ^^^^^^^ help: remove `return`
error: unneeded `return` statement
--> $DIR/needless_return.rs:120:20
|
LL | let _ = || return;
| ^^^^^^ help: replace `return` with an empty block: `{}`
error: unneeded `return` statement
--> $DIR/needless_return.rs:126:32
|
LL | res.unwrap_or_else(|_| return Foo)
| ^^^^^^^^^^ help: remove `return`: `Foo`
error: unneeded `return` statement
--> $DIR/needless_return.rs:135:5
|
LL | return true;
| ^^^^^^^^^^^^ help: remove `return`: `true`
error: unneeded `return` statement
--> $DIR/needless_return.rs:139:5
|
LL | return true;
| ^^^^^^^^^^^^ help: remove `return`: `true`
error: unneeded `return` statement
--> $DIR/needless_return.rs:144:9
|
LL | return true;
| ^^^^^^^^^^^^ help: remove `return`: `true`
error: unneeded `return` statement
--> $DIR/needless_return.rs:146:9
|
LL | return false;
| ^^^^^^^^^^^^^ help: remove `return`: `false`
error: unneeded `return` statement
--> $DIR/needless_return.rs:152:17
|
LL | true => return false,
| ^^^^^^^^^^^^ help: remove `return`: `false`
error: unneeded `return` statement
--> $DIR/needless_return.rs:154:13
|
LL | return true;
| ^^^^^^^^^^^^ help: remove `return`: `true`
error: unneeded `return` statement
--> $DIR/needless_return.rs:161:9
|
LL | return true;
| ^^^^^^^^^^^^ help: remove `return`: `true`
error: unneeded `return` statement
--> $DIR/needless_return.rs:163:16
|
LL | let _ = || return true;
| ^^^^^^^^^^^ help: remove `return`: `true`
error: unneeded `return` statement
--> $DIR/needless_return.rs:171:5
|
LL | return;
| ^^^^^^^ help: remove `return`
error: unneeded `return` statement
--> $DIR/needless_return.rs:176:9
|
LL | return;
| ^^^^^^^ help: remove `return`
error: unneeded `return` statement
--> $DIR/needless_return.rs:178:9
|
LL | return;
| ^^^^^^^ help: remove `return`
error: unneeded `return` statement
--> $DIR/needless_return.rs:185:14
--> $DIR/needless_return.rs:85:14
|
LL | _ => return,
| ^^^^^^ help: replace `return` with an empty block: `{}`
| ^^^^^^ help: replace `return` with a unit value: `()`
error: unneeded `return` statement
--> $DIR/needless_return.rs:200:9
--> $DIR/needless_return.rs:100:9
|
LL | return String::from("test");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove `return`: `String::from("test")`
error: unneeded `return` statement
--> $DIR/needless_return.rs:202:9
--> $DIR/needless_return.rs:102:9
|
LL | return String::new();
| ^^^^^^^^^^^^^^^^^^^^^ help: remove `return`: `String::new()`
error: aborting due to 32 previous errors
error: unneeded `return` statement
--> $DIR/needless_return.rs:124:32
|
LL | bar.unwrap_or_else(|_| return)
| ^^^^^^ help: replace `return` with an empty block: `{}`
error: unneeded `return` statement
--> $DIR/needless_return.rs:129:13
|
LL | return;
| ^^^^^^^ help: remove `return`
error: unneeded `return` statement
--> $DIR/needless_return.rs:131:20
|
LL | let _ = || return;
| ^^^^^^ help: replace `return` with an empty block: `{}`
error: unneeded `return` statement
--> $DIR/needless_return.rs:137:32
|
LL | res.unwrap_or_else(|_| return Foo)
| ^^^^^^^^^^ help: remove `return`: `Foo`
error: unneeded `return` statement
--> $DIR/needless_return.rs:146:5
|
LL | return true;
| ^^^^^^^^^^^^ help: remove `return`: `true`
error: unneeded `return` statement
--> $DIR/needless_return.rs:150:5
|
LL | return true;
| ^^^^^^^^^^^^ help: remove `return`: `true`
error: unneeded `return` statement
--> $DIR/needless_return.rs:155:9
|
LL | return true;
| ^^^^^^^^^^^^ help: remove `return`: `true`
error: unneeded `return` statement
--> $DIR/needless_return.rs:157:9
|
LL | return false;
| ^^^^^^^^^^^^^ help: remove `return`: `false`
error: unneeded `return` statement
--> $DIR/needless_return.rs:163:17
|
LL | true => return false,
| ^^^^^^^^^^^^ help: remove `return`: `false`
error: unneeded `return` statement
--> $DIR/needless_return.rs:165:13
|
LL | return true;
| ^^^^^^^^^^^^ help: remove `return`: `true`
error: unneeded `return` statement
--> $DIR/needless_return.rs:172:9
|
LL | return true;
| ^^^^^^^^^^^^ help: remove `return`: `true`
error: unneeded `return` statement
--> $DIR/needless_return.rs:174:16
|
LL | let _ = || return true;
| ^^^^^^^^^^^ help: remove `return`: `true`
error: unneeded `return` statement
--> $DIR/needless_return.rs:182:5
|
LL | return;
| ^^^^^^^ help: remove `return`
error: unneeded `return` statement
--> $DIR/needless_return.rs:187:9
|
LL | return;
| ^^^^^^^ help: remove `return`
error: unneeded `return` statement
--> $DIR/needless_return.rs:189:9
|
LL | return;
| ^^^^^^^ help: remove `return`
error: unneeded `return` statement
--> $DIR/needless_return.rs:196:14
|
LL | _ => return,
| ^^^^^^ help: replace `return` with a unit value: `()`
error: unneeded `return` statement
--> $DIR/needless_return.rs:211:9
|
LL | return String::from("test");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove `return`: `String::from("test")`
error: unneeded `return` statement
--> $DIR/needless_return.rs:213:9
|
LL | return String::new();
| ^^^^^^^^^^^^^^^^^^^^^ help: remove `return`: `String::new()`
error: aborting due to 34 previous errors

View file

@ -0,0 +1,45 @@
// run-rustfix
#![warn(clippy::neg_multiply)]
#![allow(clippy::no_effect, clippy::unnecessary_operation, clippy::precedence)]
#![allow(unused)]
use std::ops::Mul;
struct X;
impl Mul<isize> for X {
type Output = X;
fn mul(self, _r: isize) -> Self {
self
}
}
impl Mul<X> for isize {
type Output = X;
fn mul(self, _r: X) -> X {
X
}
}
fn main() {
let x = 0;
-x;
-x;
100 + -x;
-(100 + x);
-17;
0xcafe | -0xff00;
-1 * -1; // should be ok
X * -1; // should be ok
-1 * X; // should also be ok
}

View file

@ -1,5 +1,7 @@
// run-rustfix
#![warn(clippy::neg_multiply)]
#![allow(clippy::no_effect, clippy::unnecessary_operation)]
#![allow(clippy::no_effect, clippy::unnecessary_operation, clippy::precedence)]
#![allow(unused)]
use std::ops::Mul;
@ -28,6 +30,14 @@ fn main() {
-1 * x;
100 + x * -1;
(100 + x) * -1;
-1 * 17;
0xcafe | 0xff00 * -1;
-1 * -1; // should be ok
X * -1; // should be ok

View file

@ -1,16 +1,40 @@
error: negation by multiplying with `-1`
--> $DIR/neg_multiply.rs:27:5
error: this multiplication by -1 can be written more succinctly
--> $DIR/neg_multiply.rs:29:5
|
LL | x * -1;
| ^^^^^^
| ^^^^^^ help: consider using: `-x`
|
= note: `-D clippy::neg-multiply` implied by `-D warnings`
error: negation by multiplying with `-1`
--> $DIR/neg_multiply.rs:29:5
error: this multiplication by -1 can be written more succinctly
--> $DIR/neg_multiply.rs:31:5
|
LL | -1 * x;
| ^^^^^^
| ^^^^^^ help: consider using: `-x`
error: aborting due to 2 previous errors
error: this multiplication by -1 can be written more succinctly
--> $DIR/neg_multiply.rs:33:11
|
LL | 100 + x * -1;
| ^^^^^^ help: consider using: `-x`
error: this multiplication by -1 can be written more succinctly
--> $DIR/neg_multiply.rs:35:5
|
LL | (100 + x) * -1;
| ^^^^^^^^^^^^^^ help: consider using: `-(100 + x)`
error: this multiplication by -1 can be written more succinctly
--> $DIR/neg_multiply.rs:37:5
|
LL | -1 * 17;
| ^^^^^^^ help: consider using: `-17`
error: this multiplication by -1 can be written more succinctly
--> $DIR/neg_multiply.rs:39:14
|
LL | 0xcafe | 0xff00 * -1;
| ^^^^^^^^^^^ help: consider using: `-0xff00`
error: aborting due to 6 previous errors

View file

@ -0,0 +1,33 @@
//run-rustfix
#![warn(clippy::init_numbered_fields)]
#[derive(Default)]
struct TupleStruct(u32, u32, u8);
// This shouldn't lint because it's in a macro
macro_rules! tuple_struct_init {
() => {
TupleStruct { 0: 0, 1: 1, 2: 2 }
};
}
fn main() {
let tuple_struct = TupleStruct::default();
// This should lint
let _ = TupleStruct(1u32, 42, 23u8);
// This should also lint and order the fields correctly
let _ = TupleStruct(1u32, 3u32, 2u8);
// Ok because of default initializer
let _ = TupleStruct { 0: 42, ..tuple_struct };
let _ = TupleStruct {
1: 23,
..TupleStruct::default()
};
// Ok because it's in macro
let _ = tuple_struct_init!();
}

View file

@ -0,0 +1,41 @@
//run-rustfix
#![warn(clippy::init_numbered_fields)]
#[derive(Default)]
struct TupleStruct(u32, u32, u8);
// This shouldn't lint because it's in a macro
macro_rules! tuple_struct_init {
() => {
TupleStruct { 0: 0, 1: 1, 2: 2 }
};
}
fn main() {
let tuple_struct = TupleStruct::default();
// This should lint
let _ = TupleStruct {
0: 1u32,
1: 42,
2: 23u8,
};
// This should also lint and order the fields correctly
let _ = TupleStruct {
0: 1u32,
2: 2u8,
1: 3u32,
};
// Ok because of default initializer
let _ = TupleStruct { 0: 42, ..tuple_struct };
let _ = TupleStruct {
1: 23,
..TupleStruct::default()
};
// Ok because it's in macro
let _ = tuple_struct_init!();
}

View file

@ -0,0 +1,26 @@
error: used a field initializer for a tuple struct
--> $DIR/numbered_fields.rs:18:13
|
LL | let _ = TupleStruct {
| _____________^
LL | | 0: 1u32,
LL | | 1: 42,
LL | | 2: 23u8,
LL | | };
| |_____^ help: try this instead: `TupleStruct(1u32, 42, 23u8)`
|
= 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
|
LL | let _ = TupleStruct {
| _____________^
LL | | 0: 1u32,
LL | | 2: 2u8,
LL | | 1: 3u32,
LL | | };
| |_____^ help: try this instead: `TupleStruct(1u32, 3u32, 2u8)`
error: aborting due to 2 previous errors

View file

@ -5,12 +5,12 @@ pub struct Bar;
pub trait Whatever {
fn what(&self) -> Self;
// There should be no warning here!
// There should be no warning here! (returns a reference)
fn what2(&self) -> &Self;
}
impl Bar {
// There should be no warning here!
// There should be no warning here! (note taking a self argument)
pub fn not_new() -> Self {
Self
}
@ -20,23 +20,38 @@ impl Bar {
pub fn bar(self) -> Self {
self
}
// There should be no warning here!
// There should be no warning here! (private method)
fn foo2(&self) -> Self {
Self
}
// There should be no warning here!
// There should be no warning here! (returns a reference)
pub fn foo3(&self) -> &Self {
self
}
// There should be no warning here! (already a `must_use` attribute)
#[must_use]
pub fn foo4(&self) -> Self {
Self
}
}
impl Whatever for Bar {
// There should be no warning here!
// There should be no warning here! (comes from the trait)
fn what(&self) -> Self {
self.foo2()
}
// There should be no warning here!
// There should be no warning here! (comes from the trait)
fn what2(&self) -> &Self {
self
}
}
#[must_use]
pub struct Foo;
impl Foo {
// There should be no warning here! (`Foo` already implements `#[must_use]`)
fn foo(&self) -> Self {
Self
}
}

View file

@ -47,6 +47,8 @@ fn syntax() {
let _ = |[x]: [u32; 1]| {
let x = 1;
};
let y = Some(1);
if let Some(y) = y {}
}
fn negative() {

View file

@ -241,17 +241,29 @@ note: previous binding is here
LL | let _ = |[x]: [u32; 1]| {
| ^
error: `y` is shadowed
--> $DIR/shadow.rs:51:17
|
LL | if let Some(y) = y {}
| ^
|
note: previous binding is here
--> $DIR/shadow.rs:50:9
|
LL | let y = Some(1);
| ^
error: `_b` shadows a previous, unrelated binding
--> $DIR/shadow.rs:85:9
--> $DIR/shadow.rs:87:9
|
LL | let _b = _a;
| ^^
|
note: previous binding is here
--> $DIR/shadow.rs:84:28
--> $DIR/shadow.rs:86:28
|
LL | pub async fn foo2(_a: i32, _b: i64) {
| ^^
error: aborting due to 21 previous errors
error: aborting due to 22 previous errors

View file

@ -6,7 +6,7 @@
fn main() {
if f() { g(); }
if !f() { g(); }
if !(1 == 2) { g(); }
if 1 != 2 { g(); }
}
fn f() -> bool {

View file

@ -16,7 +16,7 @@ error: boolean short circuit operator in statement may be clearer using an expli
--> $DIR/short_circuit_statement.rs:9:5
|
LL | 1 == 2 || g();
| ^^^^^^^^^^^^^^ help: replace it with: `if !(1 == 2) { g(); }`
| ^^^^^^^^^^^^^^ help: replace it with: `if 1 != 2 { g(); }`
error: aborting due to 3 previous errors

View file

@ -1,5 +1,4 @@
#![warn(clippy::temporary_assignment)]
#![allow(const_item_mutation)]
use std::ops::{Deref, DerefMut};

View file

@ -1,5 +1,5 @@
error: assignment to temporary
--> $DIR/temporary_assignment.rs:48:5
--> $DIR/temporary_assignment.rs:47:5
|
LL | Struct { field: 0 }.field = 1;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -7,7 +7,7 @@ LL | Struct { field: 0 }.field = 1;
= note: `-D clippy::temporary-assignment` implied by `-D warnings`
error: assignment to temporary
--> $DIR/temporary_assignment.rs:49:5
--> $DIR/temporary_assignment.rs:48:5
|
LL | / MultiStruct {
LL | | structure: Struct { field: 0 },
@ -17,13 +17,13 @@ LL | | .field = 1;
| |______________^
error: assignment to temporary
--> $DIR/temporary_assignment.rs:54:5
--> $DIR/temporary_assignment.rs:53:5
|
LL | ArrayStruct { array: [0] }.array[0] = 1;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: assignment to temporary
--> $DIR/temporary_assignment.rs:55:5
--> $DIR/temporary_assignment.rs:54:5
|
LL | (0, 0).0 = 1;
| ^^^^^^^^^^^^

View file

@ -5,7 +5,7 @@
fn nested_local() {
let _ = {
let _ = {
// Safety:
// SAFETY:
let _ = unsafe {};
};
};
@ -14,7 +14,7 @@ fn nested_local() {
fn deep_nest() {
let _ = {
let _ = {
// Safety:
// SAFETY:
let _ = unsafe {};
// Safety:
@ -28,7 +28,7 @@ fn deep_nest() {
// Safety:
let _ = unsafe {};
// Safety:
// SAFETY:
unsafe {};
};
};
@ -44,7 +44,7 @@ fn deep_nest() {
unsafe {};
};
// Safety:
// SAFETY:
unsafe {};
}
@ -59,7 +59,7 @@ fn line_comment() {
}
fn line_comment_newlines() {
// Safety:
// SAFETY:
unsafe {}
}
@ -84,7 +84,7 @@ fn block_comment() {
}
fn block_comment_newlines() {
/* Safety: */
/* SAFETY: */
unsafe {}
}
@ -96,7 +96,7 @@ fn inline_block_comment() {
fn block_comment_with_extras() {
/* This is a description
* Safety:
* SAFETY:
*/
unsafe {}
}
@ -122,7 +122,7 @@ fn buried_safety() {
}
fn safety_with_prepended_text() {
// This is a test. Safety:
// This is a test. safety:
unsafe {}
}
@ -132,7 +132,7 @@ fn local_line_comment() {
}
fn local_block_comment() {
/* Safety: */
/* SAFETY: */
let _ = unsafe {};
}
@ -142,18 +142,18 @@ fn comment_array() {
}
fn comment_tuple() {
// Safety:
// sAFETY:
let _ = (42, unsafe {}, "test", unsafe {});
}
fn comment_unary() {
// Safety:
// SAFETY:
let _ = *unsafe { &42 };
}
#[allow(clippy::match_single_binding)]
fn comment_match() {
// Safety:
// SAFETY:
let _ = match unsafe {} {
_ => {},
};
@ -177,7 +177,7 @@ fn comment_macro_call() {
}
t!(
// Safety:
// SAFETY:
unsafe {}
);
}
@ -194,18 +194,18 @@ fn comment_macro_def() {
}
fn non_ascii_comment() {
// ॐ᧻໒ Safety: ௵∰
// ॐ᧻໒ SaFeTy: ௵∰
unsafe {};
}
fn local_commented_block() {
let _ =
// Safety:
// safety:
unsafe {};
}
fn local_nest() {
// Safety:
// safety:
let _ = [(42, unsafe {}, unsafe {}), (52, unsafe {}, unsafe {})];
}
@ -267,17 +267,17 @@ fn no_comment_macro_def() {
}
fn trailing_comment() {
unsafe {} // Safety:
unsafe {} // SAFETY:
}
fn internal_comment() {
unsafe {
// Safety:
// SAFETY:
}
}
fn interference() {
// Safety
// SAFETY
let _ = 42;

View file

@ -7,7 +7,7 @@ LL | unsafe {}
= note: `-D clippy::undocumented-unsafe-blocks` implied by `-D warnings`
help: consider adding a safety comment
|
LL ~ // Safety: ...
LL ~ // SAFETY: ...
LL + unsafe {}
|
@ -19,7 +19,7 @@ LL | let _ = [unsafe { 14 }, unsafe { 15 }, 42, unsafe { 16 }];
|
help: consider adding a safety comment
|
LL ~ // Safety: ...
LL ~ // SAFETY: ...
LL + let _ = [unsafe { 14 }, unsafe { 15 }, 42, unsafe { 16 }];
|
@ -31,7 +31,7 @@ LL | let _ = (42, unsafe {}, "test", unsafe {});
|
help: consider adding a safety comment
|
LL ~ // Safety: ...
LL ~ // SAFETY: ...
LL + let _ = (42, unsafe {}, "test", unsafe {});
|
@ -43,7 +43,7 @@ LL | let _ = *unsafe { &42 };
|
help: consider adding a safety comment
|
LL ~ // Safety: ...
LL ~ // SAFETY: ...
LL + let _ = *unsafe { &42 };
|
@ -55,7 +55,7 @@ LL | let _ = match unsafe {} {
|
help: consider adding a safety comment
|
LL ~ // Safety: ...
LL ~ // SAFETY: ...
LL + let _ = match unsafe {} {
|
@ -67,7 +67,7 @@ LL | let _ = &unsafe {};
|
help: consider adding a safety comment
|
LL ~ // Safety: ...
LL ~ // SAFETY: ...
LL + let _ = &unsafe {};
|
@ -79,7 +79,7 @@ LL | let _ = [unsafe {}; 5];
|
help: consider adding a safety comment
|
LL ~ // Safety: ...
LL ~ // SAFETY: ...
LL + let _ = [unsafe {}; 5];
|
@ -91,7 +91,7 @@ LL | let _ = unsafe {};
|
help: consider adding a safety comment
|
LL ~ // Safety: ...
LL ~ // SAFETY: ...
LL + let _ = unsafe {};
|
@ -103,7 +103,7 @@ LL | t!(unsafe {});
|
help: consider adding a safety comment
|
LL ~ t!(// Safety: ...
LL ~ t!(// SAFETY: ...
LL ~ unsafe {});
|
@ -122,13 +122,13 @@ LL | t!();
error: unsafe block missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:270:5
|
LL | unsafe {} // Safety:
LL | unsafe {} // SAFETY:
| ^^^^^^^^^
|
help: consider adding a safety comment
|
LL ~ // Safety: ...
LL ~ unsafe {} // Safety:
LL ~ // SAFETY: ...
LL ~ unsafe {} // SAFETY:
|
error: unsafe block missing a safety comment
@ -139,7 +139,7 @@ LL | unsafe {
|
help: consider adding a safety comment
|
LL ~ // Safety: ...
LL ~ // SAFETY: ...
LL + unsafe {
|
@ -151,7 +151,7 @@ LL | unsafe {};
|
help: consider adding a safety comment
|
LL ~ // Safety: ...
LL ~ // SAFETY: ...
LL ~ unsafe {};
|
@ -163,7 +163,7 @@ LL | println!("{}", unsafe { String::from_utf8_unchecked(vec![]) });
|
help: consider adding a safety comment
|
LL ~ println!("{}", // Safety: ...
LL ~ println!("{}", // SAFETY: ...
LL ~ unsafe { String::from_utf8_unchecked(vec![]) });
|

View file

@ -45,7 +45,7 @@ fn unwrap_or_else_default() {
with_enum.unwrap_or_else(Enum::A);
let with_new = Some(vec![1]);
with_new.unwrap_or_else(Vec::new);
with_new.unwrap_or_default();
let with_err: Result<_, ()> = Ok(vec![1]);
with_err.unwrap_or_else(make);
@ -66,6 +66,9 @@ fn unwrap_or_else_default() {
let with_default_type = Some(1);
with_default_type.unwrap_or_default();
let with_default_type: Option<Vec<u64>> = None;
with_default_type.unwrap_or_default();
}
fn main() {}

View file

@ -66,6 +66,9 @@ fn unwrap_or_else_default() {
let with_default_type = Some(1);
with_default_type.unwrap_or_else(u64::default);
let with_default_type: Option<Vec<u64>> = None;
with_default_type.unwrap_or_else(Vec::new);
}
fn main() {}

View file

@ -1,10 +1,16 @@
error: use of `.unwrap_or_else(..)` to construct default value
--> $DIR/unwrap_or_else_default.rs:48:5
|
LL | with_new.unwrap_or_else(Vec::new);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `with_new.unwrap_or_default()`
|
= note: `-D clippy::unwrap-or-else-default` implied by `-D warnings`
error: use of `.unwrap_or_else(..)` to construct default value
--> $DIR/unwrap_or_else_default.rs:62:5
|
LL | with_real_default.unwrap_or_else(<HasDefaultAndDuplicate as Default>::default);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `with_real_default.unwrap_or_default()`
|
= note: `-D clippy::unwrap-or-else-default` implied by `-D warnings`
error: use of `.unwrap_or_else(..)` to construct default value
--> $DIR/unwrap_or_else_default.rs:65:5
@ -18,5 +24,11 @@ error: use of `.unwrap_or_else(..)` to construct default value
LL | with_default_type.unwrap_or_else(u64::default);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `with_default_type.unwrap_or_default()`
error: aborting due to 3 previous errors
error: use of `.unwrap_or_else(..)` to construct default value
--> $DIR/unwrap_or_else_default.rs:71:5
|
LL | with_default_type.unwrap_or_else(Vec::new);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `with_default_type.unwrap_or_default()`
error: aborting due to 5 previous errors