Merge commit '6ed6f1e6a1' into clippyup
This commit is contained in:
parent
36a27ecaac
commit
f2f2a005b4
297 changed files with 15401 additions and 12253 deletions
|
|
@ -5,7 +5,7 @@ LL | a += a + 1;
|
|||
| ^^^^^^^^^^
|
||||
|
|
||||
= note: `-D clippy::misrefactored-assign-op` implied by `-D warnings`
|
||||
help: Did you mean `a = a + 1` or `a = a + a + 1`? Consider replacing it with
|
||||
help: did you mean `a = a + 1` or `a = a + a + 1`? Consider replacing it with
|
||||
|
|
||||
LL | a += 1;
|
||||
| ^^^^^^
|
||||
|
|
@ -20,7 +20,7 @@ error: variable appears on both sides of an assignment operation
|
|||
LL | a += 1 + a;
|
||||
| ^^^^^^^^^^
|
||||
|
|
||||
help: Did you mean `a = a + 1` or `a = a + 1 + a`? Consider replacing it with
|
||||
help: did you mean `a = a + 1` or `a = a + 1 + a`? Consider replacing it with
|
||||
|
|
||||
LL | a += 1;
|
||||
| ^^^^^^
|
||||
|
|
@ -35,7 +35,7 @@ error: variable appears on both sides of an assignment operation
|
|||
LL | a -= a - 1;
|
||||
| ^^^^^^^^^^
|
||||
|
|
||||
help: Did you mean `a = a - 1` or `a = a - (a - 1)`? Consider replacing it with
|
||||
help: did you mean `a = a - 1` or `a = a - (a - 1)`? Consider replacing it with
|
||||
|
|
||||
LL | a -= 1;
|
||||
| ^^^^^^
|
||||
|
|
@ -50,7 +50,7 @@ error: variable appears on both sides of an assignment operation
|
|||
LL | a *= a * 99;
|
||||
| ^^^^^^^^^^^
|
||||
|
|
||||
help: Did you mean `a = a * 99` or `a = a * a * 99`? Consider replacing it with
|
||||
help: did you mean `a = a * 99` or `a = a * a * 99`? Consider replacing it with
|
||||
|
|
||||
LL | a *= 99;
|
||||
| ^^^^^^^
|
||||
|
|
@ -65,7 +65,7 @@ error: variable appears on both sides of an assignment operation
|
|||
LL | a *= 42 * a;
|
||||
| ^^^^^^^^^^^
|
||||
|
|
||||
help: Did you mean `a = a * 42` or `a = a * 42 * a`? Consider replacing it with
|
||||
help: did you mean `a = a * 42` or `a = a * 42 * a`? Consider replacing it with
|
||||
|
|
||||
LL | a *= 42;
|
||||
| ^^^^^^^
|
||||
|
|
@ -80,7 +80,7 @@ error: variable appears on both sides of an assignment operation
|
|||
LL | a /= a / 2;
|
||||
| ^^^^^^^^^^
|
||||
|
|
||||
help: Did you mean `a = a / 2` or `a = a / (a / 2)`? Consider replacing it with
|
||||
help: did you mean `a = a / 2` or `a = a / (a / 2)`? Consider replacing it with
|
||||
|
|
||||
LL | a /= 2;
|
||||
| ^^^^^^
|
||||
|
|
@ -95,7 +95,7 @@ error: variable appears on both sides of an assignment operation
|
|||
LL | a %= a % 5;
|
||||
| ^^^^^^^^^^
|
||||
|
|
||||
help: Did you mean `a = a % 5` or `a = a % (a % 5)`? Consider replacing it with
|
||||
help: did you mean `a = a % 5` or `a = a % (a % 5)`? Consider replacing it with
|
||||
|
|
||||
LL | a %= 5;
|
||||
| ^^^^^^
|
||||
|
|
@ -110,7 +110,7 @@ error: variable appears on both sides of an assignment operation
|
|||
LL | a &= a & 1;
|
||||
| ^^^^^^^^^^
|
||||
|
|
||||
help: Did you mean `a = a & 1` or `a = a & a & 1`? Consider replacing it with
|
||||
help: did you mean `a = a & 1` or `a = a & a & 1`? Consider replacing it with
|
||||
|
|
||||
LL | a &= 1;
|
||||
| ^^^^^^
|
||||
|
|
@ -125,7 +125,7 @@ error: variable appears on both sides of an assignment operation
|
|||
LL | a *= a * a;
|
||||
| ^^^^^^^^^^
|
||||
|
|
||||
help: Did you mean `a = a * a` or `a = a * a * a`? Consider replacing it with
|
||||
help: did you mean `a = a * a` or `a = a * a * a`? Consider replacing it with
|
||||
|
|
||||
LL | a *= a;
|
||||
| ^^^^^^
|
||||
|
|
|
|||
|
|
@ -23,11 +23,7 @@ macro_rules! try_err {
|
|||
pub fn try_err_fn() -> Result<i32, i32> {
|
||||
let err: i32 = 1;
|
||||
// To avoid warnings during rustfix
|
||||
if true {
|
||||
Err(err)?
|
||||
} else {
|
||||
Ok(2)
|
||||
}
|
||||
if true { Err(err)? } else { Ok(2) }
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,4 +48,8 @@ impl IteratorFalsePositives {
|
|||
pub fn skip_while(self) -> IteratorFalsePositives {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn count(self) -> usize {
|
||||
self.foo as usize
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
error: this MutexGuard is held across an 'await' point. Consider using an async-aware Mutex type or ensuring the MutexGuard is dropped before calling await.
|
||||
error: this MutexGuard is held across an 'await' point. Consider using an async-aware Mutex type or ensuring the MutexGuard is dropped before calling await
|
||||
--> $DIR/await_holding_lock.rs:7:9
|
||||
|
|
||||
LL | let guard = x.lock().unwrap();
|
||||
|
|
@ -13,7 +13,7 @@ LL | | baz().await
|
|||
LL | | }
|
||||
| |_^
|
||||
|
||||
error: this MutexGuard is held across an 'await' point. Consider using an async-aware Mutex type or ensuring the MutexGuard is dropped before calling await.
|
||||
error: this MutexGuard is held across an 'await' point. Consider using an async-aware Mutex type or ensuring the MutexGuard is dropped before calling await
|
||||
--> $DIR/await_holding_lock.rs:28:9
|
||||
|
|
||||
LL | let guard = x.lock().unwrap();
|
||||
|
|
@ -31,7 +31,7 @@ LL | | first + second + third
|
|||
LL | | }
|
||||
| |_^
|
||||
|
||||
error: this MutexGuard is held across an 'await' point. Consider using an async-aware Mutex type or ensuring the MutexGuard is dropped before calling await.
|
||||
error: this MutexGuard is held across an 'await' point. Consider using an async-aware Mutex type or ensuring the MutexGuard is dropped before calling await
|
||||
--> $DIR/await_holding_lock.rs:41:13
|
||||
|
|
||||
LL | let guard = x.lock().unwrap();
|
||||
|
|
@ -45,7 +45,7 @@ LL | | baz().await
|
|||
LL | | };
|
||||
| |_____^
|
||||
|
||||
error: this MutexGuard is held across an 'await' point. Consider using an async-aware Mutex type or ensuring the MutexGuard is dropped before calling await.
|
||||
error: this MutexGuard is held across an 'await' point. Consider using an async-aware Mutex type or ensuring the MutexGuard is dropped before calling await
|
||||
--> $DIR/await_holding_lock.rs:53:13
|
||||
|
|
||||
LL | let guard = x.lock().unwrap();
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
error: this RefCell Ref is held across an 'await' point. Consider ensuring the Ref is dropped before calling await.
|
||||
error: this RefCell Ref is held across an 'await' point. Consider ensuring the Ref is dropped before calling await
|
||||
--> $DIR/await_holding_refcell_ref.rs:7:9
|
||||
|
|
||||
LL | let b = x.borrow();
|
||||
|
|
@ -13,7 +13,7 @@ LL | | baz().await
|
|||
LL | | }
|
||||
| |_^
|
||||
|
||||
error: this RefCell Ref is held across an 'await' point. Consider ensuring the Ref is dropped before calling await.
|
||||
error: this RefCell Ref is held across an 'await' point. Consider ensuring the Ref is dropped before calling await
|
||||
--> $DIR/await_holding_refcell_ref.rs:12:9
|
||||
|
|
||||
LL | let b = x.borrow_mut();
|
||||
|
|
@ -27,7 +27,7 @@ LL | | baz().await
|
|||
LL | | }
|
||||
| |_^
|
||||
|
||||
error: this RefCell Ref is held across an 'await' point. Consider ensuring the Ref is dropped before calling await.
|
||||
error: this RefCell Ref is held across an 'await' point. Consider ensuring the Ref is dropped before calling await
|
||||
--> $DIR/await_holding_refcell_ref.rs:33:9
|
||||
|
|
||||
LL | let b = x.borrow_mut();
|
||||
|
|
@ -45,7 +45,7 @@ LL | | first + second + third
|
|||
LL | | }
|
||||
| |_^
|
||||
|
||||
error: this RefCell Ref is held across an 'await' point. Consider ensuring the Ref is dropped before calling await.
|
||||
error: this RefCell Ref is held across an 'await' point. Consider ensuring the Ref is dropped before calling await
|
||||
--> $DIR/await_holding_refcell_ref.rs:45:9
|
||||
|
|
||||
LL | let b = x.borrow_mut();
|
||||
|
|
@ -63,7 +63,7 @@ LL | | first + second + third
|
|||
LL | | }
|
||||
| |_^
|
||||
|
||||
error: this RefCell Ref is held across an 'await' point. Consider ensuring the Ref is dropped before calling await.
|
||||
error: this RefCell Ref is held across an 'await' point. Consider ensuring the Ref is dropped before calling await
|
||||
--> $DIR/await_holding_refcell_ref.rs:60:13
|
||||
|
|
||||
LL | let b = x.borrow_mut();
|
||||
|
|
@ -77,7 +77,7 @@ LL | | baz().await
|
|||
LL | | };
|
||||
| |_____^
|
||||
|
||||
error: this RefCell Ref is held across an 'await' point. Consider ensuring the Ref is dropped before calling await.
|
||||
error: this RefCell Ref is held across an 'await' point. Consider ensuring the Ref is dropped before calling await
|
||||
--> $DIR/await_holding_refcell_ref.rs:72:13
|
||||
|
|
||||
LL | let b = x.borrow_mut();
|
||||
|
|
|
|||
|
|
@ -4,9 +4,7 @@
|
|||
#![warn(clippy::nonminimal_bool)]
|
||||
|
||||
macro_rules! blocky {
|
||||
() => {{
|
||||
true
|
||||
}};
|
||||
() => {{ true }};
|
||||
}
|
||||
|
||||
macro_rules! blocky_too {
|
||||
|
|
@ -34,20 +32,12 @@ fn condition_has_block() -> i32 {
|
|||
}
|
||||
|
||||
fn condition_has_block_with_single_expression() -> i32 {
|
||||
if true {
|
||||
6
|
||||
} else {
|
||||
10
|
||||
}
|
||||
if true { 6 } else { 10 }
|
||||
}
|
||||
|
||||
fn condition_is_normal() -> i32 {
|
||||
let x = 3;
|
||||
if x == 3 {
|
||||
6
|
||||
} else {
|
||||
10
|
||||
}
|
||||
if x == 3 { 6 } else { 10 }
|
||||
}
|
||||
|
||||
fn condition_is_unsafe_block() {
|
||||
|
|
@ -61,14 +51,15 @@ fn condition_is_unsafe_block() {
|
|||
|
||||
fn block_in_assert() {
|
||||
let opt = Some(42);
|
||||
assert!(opt
|
||||
.as_ref()
|
||||
.map(|val| {
|
||||
let mut v = val * 2;
|
||||
v -= 1;
|
||||
v * 3
|
||||
})
|
||||
.is_some());
|
||||
assert!(
|
||||
opt.as_ref()
|
||||
.map(|val| {
|
||||
let mut v = val * 2;
|
||||
v -= 1;
|
||||
v * 3
|
||||
})
|
||||
.is_some()
|
||||
);
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -4,9 +4,7 @@
|
|||
#![warn(clippy::nonminimal_bool)]
|
||||
|
||||
macro_rules! blocky {
|
||||
() => {{
|
||||
true
|
||||
}};
|
||||
() => {{ true }};
|
||||
}
|
||||
|
||||
macro_rules! blocky_too {
|
||||
|
|
@ -34,20 +32,12 @@ fn condition_has_block() -> i32 {
|
|||
}
|
||||
|
||||
fn condition_has_block_with_single_expression() -> i32 {
|
||||
if { true } {
|
||||
6
|
||||
} else {
|
||||
10
|
||||
}
|
||||
if { true } { 6 } else { 10 }
|
||||
}
|
||||
|
||||
fn condition_is_normal() -> i32 {
|
||||
let x = 3;
|
||||
if true && x == 3 {
|
||||
6
|
||||
} else {
|
||||
10
|
||||
}
|
||||
if true && x == 3 { 6 } else { 10 }
|
||||
}
|
||||
|
||||
fn condition_is_unsafe_block() {
|
||||
|
|
@ -61,14 +51,15 @@ fn condition_is_unsafe_block() {
|
|||
|
||||
fn block_in_assert() {
|
||||
let opt = Some(42);
|
||||
assert!(opt
|
||||
.as_ref()
|
||||
.map(|val| {
|
||||
let mut v = val * 2;
|
||||
v -= 1;
|
||||
v * 3
|
||||
})
|
||||
.is_some());
|
||||
assert!(
|
||||
opt.as_ref()
|
||||
.map(|val| {
|
||||
let mut v = val * 2;
|
||||
v -= 1;
|
||||
v * 3
|
||||
})
|
||||
.is_some()
|
||||
);
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
error: in an `if` condition, avoid complex blocks or closures with blocks; instead, move the block or closure higher and bind it with a `let`
|
||||
--> $DIR/blocks_in_if_conditions.rs:26:5
|
||||
--> $DIR/blocks_in_if_conditions.rs:24:5
|
||||
|
|
||||
LL | / if {
|
||||
LL | | let x = 3;
|
||||
|
|
@ -17,15 +17,15 @@ LL | }; if res {
|
|||
|
|
||||
|
||||
error: omit braces around single expression condition
|
||||
--> $DIR/blocks_in_if_conditions.rs:37:8
|
||||
--> $DIR/blocks_in_if_conditions.rs:35:8
|
||||
|
|
||||
LL | if { true } {
|
||||
LL | if { true } { 6 } else { 10 }
|
||||
| ^^^^^^^^ help: try: `true`
|
||||
|
||||
error: this boolean expression can be simplified
|
||||
--> $DIR/blocks_in_if_conditions.rs:46:8
|
||||
--> $DIR/blocks_in_if_conditions.rs:40:8
|
||||
|
|
||||
LL | if true && x == 3 {
|
||||
LL | if true && x == 3 { 6 } else { 10 }
|
||||
| ^^^^^^^^^^^^^^ help: try: `x == 3`
|
||||
|
|
||||
= note: `-D clippy::nonminimal-bool` implied by `-D warnings`
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ LL | pub fn test(foo: Box<Vec<bool>>) {
|
|||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `-D clippy::box-vec` implied by `-D warnings`
|
||||
= help: `Vec<T>` is already on the heap, `Box<Vec<T>>` makes an extra allocation.
|
||||
= help: `Vec<T>` is already on the heap, `Box<Vec<T>>` makes an extra allocation
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
|||
|
|
@ -66,14 +66,16 @@ fn main() {
|
|||
}
|
||||
if x.is_ok() {
|
||||
x = Err(());
|
||||
x.unwrap(); // not unnecessary because of mutation of x
|
||||
// it will always panic but the lint is not smart enough to see this (it only
|
||||
// checks if conditions).
|
||||
// not unnecessary because of mutation of x
|
||||
// it will always panic but the lint is not smart enough to see this (it only
|
||||
// checks if conditions).
|
||||
x.unwrap();
|
||||
} else {
|
||||
x = Ok(());
|
||||
x.unwrap_err(); // not unnecessary because of mutation of x
|
||||
// it will always panic but the lint is not smart enough to see this (it
|
||||
// only checks if conditions).
|
||||
// not unnecessary because of mutation of x
|
||||
// it will always panic but the lint is not smart enough to see this (it
|
||||
// only checks if conditions).
|
||||
x.unwrap_err();
|
||||
}
|
||||
|
||||
assert!(x.is_ok(), "{:?}", x.unwrap_err()); // ok, it's a common test pattern
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
#[allow(clippy::unnecessary_operation)]
|
||||
#[allow(clippy::implicit_clone)]
|
||||
|
||||
fn main() {
|
||||
let x = &Baz;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
error: this creates an owned instance just for comparison
|
||||
--> $DIR/without_suggestion.rs:6:5
|
||||
--> $DIR/without_suggestion.rs:7:5
|
||||
|
|
||||
LL | y.to_owned() == *x;
|
||||
| ^^^^^^^^^^^^^^^^^^ try implementing the comparison without allocating
|
||||
|
|
@ -7,13 +7,13 @@ LL | y.to_owned() == *x;
|
|||
= note: `-D clippy::cmp-owned` implied by `-D warnings`
|
||||
|
||||
error: this creates an owned instance just for comparison
|
||||
--> $DIR/without_suggestion.rs:10:5
|
||||
--> $DIR/without_suggestion.rs:11:5
|
||||
|
|
||||
LL | y.to_owned() == **x;
|
||||
| ^^^^^^^^^^^^^^^^^^^ try implementing the comparison without allocating
|
||||
|
||||
error: this creates an owned instance just for comparison
|
||||
--> $DIR/without_suggestion.rs:17:9
|
||||
--> $DIR/without_suggestion.rs:18:9
|
||||
|
|
||||
LL | self.to_owned() == *other
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ try implementing the comparison without allocating
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ LL | | }
|
|||
| |_____^
|
||||
|
|
||||
= note: `-D clippy::comparison-chain` implied by `-D warnings`
|
||||
= help: Consider rewriting the `if` chain to use `cmp` and `match`.
|
||||
= help: consider rewriting the `if` chain to use `cmp` and `match`
|
||||
|
||||
error: `if` chain can be rewritten with `match`
|
||||
--> $DIR/comparison_chain.rs:27:5
|
||||
|
|
@ -23,7 +23,7 @@ LL | | c()
|
|||
LL | | }
|
||||
| |_____^
|
||||
|
|
||||
= help: Consider rewriting the `if` chain to use `cmp` and `match`.
|
||||
= help: consider rewriting the `if` chain to use `cmp` and `match`
|
||||
|
||||
error: `if` chain can be rewritten with `match`
|
||||
--> $DIR/comparison_chain.rs:35:5
|
||||
|
|
@ -37,7 +37,7 @@ LL | | c()
|
|||
LL | | }
|
||||
| |_____^
|
||||
|
|
||||
= help: Consider rewriting the `if` chain to use `cmp` and `match`.
|
||||
= help: consider rewriting the `if` chain to use `cmp` and `match`
|
||||
|
||||
error: `if` chain can be rewritten with `match`
|
||||
--> $DIR/comparison_chain.rs:43:5
|
||||
|
|
@ -51,7 +51,7 @@ LL | | c()
|
|||
LL | | }
|
||||
| |_____^
|
||||
|
|
||||
= help: Consider rewriting the `if` chain to use `cmp` and `match`.
|
||||
= help: consider rewriting the `if` chain to use `cmp` and `match`
|
||||
|
||||
error: `if` chain can be rewritten with `match`
|
||||
--> $DIR/comparison_chain.rs:117:5
|
||||
|
|
@ -63,7 +63,7 @@ LL | | b()
|
|||
LL | | }
|
||||
| |_____^
|
||||
|
|
||||
= help: Consider rewriting the `if` chain to use `cmp` and `match`.
|
||||
= help: consider rewriting the `if` chain to use `cmp` and `match`
|
||||
|
||||
error: `if` chain can be rewritten with `match`
|
||||
--> $DIR/comparison_chain.rs:123:5
|
||||
|
|
@ -77,7 +77,7 @@ LL | | c()
|
|||
LL | | }
|
||||
| |_____^
|
||||
|
|
||||
= help: Consider rewriting the `if` chain to use `cmp` and `match`.
|
||||
= help: consider rewriting the `if` chain to use `cmp` and `match`
|
||||
|
||||
error: `if` chain can be rewritten with `match`
|
||||
--> $DIR/comparison_chain.rs:131:5
|
||||
|
|
@ -91,7 +91,7 @@ LL | | c()
|
|||
LL | | }
|
||||
| |_____^
|
||||
|
|
||||
= help: Consider rewriting the `if` chain to use `cmp` and `match`.
|
||||
= help: consider rewriting the `if` chain to use `cmp` and `match`
|
||||
|
||||
error: aborting due to 7 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ impl dyn TT {
|
|||
fn func(&self) {}
|
||||
}
|
||||
|
||||
#[rustfmt::skip]
|
||||
fn main() {
|
||||
let f = |x: &dyn TT| x.func(); //[default]~ ERROR: mismatched types
|
||||
//[nll]~^ ERROR: borrowed data escapes outside of closure
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
error[E0308]: mismatched types
|
||||
--> $DIR/ice-6256.rs:12:28
|
||||
--> $DIR/ice-6256.rs:13:28
|
||||
|
|
||||
LL | let f = |x: &dyn TT| x.func(); //[default]~ ERROR: mismatched types
|
||||
| ^^^^ lifetime mismatch
|
||||
|
|
||||
= note: expected reference `&(dyn TT + 'static)`
|
||||
found reference `&dyn TT`
|
||||
note: the anonymous lifetime #1 defined on the body at 12:13...
|
||||
--> $DIR/ice-6256.rs:12:13
|
||||
note: the anonymous lifetime #1 defined on the body at 13:13...
|
||||
--> $DIR/ice-6256.rs:13:13
|
||||
|
|
||||
LL | let f = |x: &dyn TT| x.func(); //[default]~ ERROR: mismatched types
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
|
|||
20
tests/ui/crashes/ice-6792.rs
Normal file
20
tests/ui/crashes/ice-6792.rs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
//! This is a reproducer for the ICE 6792: https://github.com/rust-lang/rust-clippy/issues/6792.
|
||||
//! The ICE is caused by using `TyCtxt::type_of(assoc_type_id)`.
|
||||
|
||||
trait Trait {
|
||||
type Ty;
|
||||
|
||||
fn broken() -> Self::Ty;
|
||||
}
|
||||
|
||||
struct Foo {}
|
||||
|
||||
impl Trait for Foo {
|
||||
type Ty = Foo;
|
||||
|
||||
fn broken() -> Self::Ty {
|
||||
Self::Ty {}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
23
tests/ui/crashes/ice-6793.rs
Normal file
23
tests/ui/crashes/ice-6793.rs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
//! This is a reproducer for the ICE 6793: https://github.com/rust-lang/rust-clippy/issues/6793.
|
||||
//! The ICE is caused by using `TyCtxt::type_of(assoc_type_id)`, which is the same as the ICE 6792.
|
||||
|
||||
trait Trait {
|
||||
type Ty: 'static + Clone;
|
||||
|
||||
fn broken() -> Self::Ty;
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
struct MyType {
|
||||
x: i32,
|
||||
}
|
||||
|
||||
impl Trait for MyType {
|
||||
type Ty = MyType;
|
||||
|
||||
fn broken() -> Self::Ty {
|
||||
Self::Ty { x: 1 }
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
31
tests/ui/crashes/ice-6840.rs
Normal file
31
tests/ui/crashes/ice-6840.rs
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
//! This is a reproducer for the ICE 6840: https://github.com/rust-lang/rust-clippy/issues/6840.
|
||||
//! The ICE is caused by `TyCtxt::layout_of` and `is_normalizable` not being strict enough
|
||||
#![allow(dead_code)]
|
||||
use std::collections::HashMap;
|
||||
|
||||
pub trait Rule {
|
||||
type DependencyKey;
|
||||
}
|
||||
|
||||
pub struct RuleEdges<R: Rule> {
|
||||
dependencies: R::DependencyKey,
|
||||
}
|
||||
|
||||
type RuleDependencyEdges<R> = HashMap<u32, RuleEdges<R>>;
|
||||
|
||||
// reproducer from the GitHub issue ends here
|
||||
// but check some additional variants
|
||||
type RuleDependencyEdgesArray<R> = HashMap<u32, [RuleEdges<R>; 8]>;
|
||||
type RuleDependencyEdgesSlice<R> = HashMap<u32, &'static [RuleEdges<R>]>;
|
||||
type RuleDependencyEdgesRef<R> = HashMap<u32, &'static RuleEdges<R>>;
|
||||
type RuleDependencyEdgesRaw<R> = HashMap<u32, *const RuleEdges<R>>;
|
||||
type RuleDependencyEdgesTuple<R> = HashMap<u32, (RuleEdges<R>, RuleEdges<R>)>;
|
||||
|
||||
// and an additional checks to make sure fix doesn't have stack-overflow issue
|
||||
// on self-containing types
|
||||
pub struct SelfContaining {
|
||||
inner: Box<SelfContaining>,
|
||||
}
|
||||
type SelfContainingEdges = HashMap<u32, SelfContaining>;
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -1,11 +1,7 @@
|
|||
#![warn(clippy::dbg_macro)]
|
||||
|
||||
fn foo(n: u32) -> u32 {
|
||||
if let Some(n) = dbg!(n.checked_sub(4)) {
|
||||
n
|
||||
} else {
|
||||
n
|
||||
}
|
||||
if let Some(n) = dbg!(n.checked_sub(4)) { n } else { n }
|
||||
}
|
||||
|
||||
fn factorial(n: u32) -> u32 {
|
||||
|
|
|
|||
|
|
@ -1,17 +1,17 @@
|
|||
error: `dbg!` macro is intended as a debugging tool
|
||||
--> $DIR/dbg_macro.rs:4:22
|
||||
|
|
||||
LL | if let Some(n) = dbg!(n.checked_sub(4)) {
|
||||
LL | if let Some(n) = dbg!(n.checked_sub(4)) { n } else { n }
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `-D clippy::dbg-macro` implied by `-D warnings`
|
||||
help: ensure to avoid having uses of it in version control
|
||||
|
|
||||
LL | if let Some(n) = n.checked_sub(4) {
|
||||
LL | if let Some(n) = n.checked_sub(4) { n } else { n }
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
||||
error: `dbg!` macro is intended as a debugging tool
|
||||
--> $DIR/dbg_macro.rs:12:8
|
||||
--> $DIR/dbg_macro.rs:8:8
|
||||
|
|
||||
LL | if dbg!(n <= 1) {
|
||||
| ^^^^^^^^^^^^
|
||||
|
|
@ -22,7 +22,7 @@ LL | if n <= 1 {
|
|||
| ^^^^^^
|
||||
|
||||
error: `dbg!` macro is intended as a debugging tool
|
||||
--> $DIR/dbg_macro.rs:13:9
|
||||
--> $DIR/dbg_macro.rs:9:9
|
||||
|
|
||||
LL | dbg!(1)
|
||||
| ^^^^^^^
|
||||
|
|
@ -33,7 +33,7 @@ LL | 1
|
|||
|
|
||||
|
||||
error: `dbg!` macro is intended as a debugging tool
|
||||
--> $DIR/dbg_macro.rs:15:9
|
||||
--> $DIR/dbg_macro.rs:11:9
|
||||
|
|
||||
LL | dbg!(n * factorial(n - 1))
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
@ -44,7 +44,7 @@ LL | n * factorial(n - 1)
|
|||
|
|
||||
|
||||
error: `dbg!` macro is intended as a debugging tool
|
||||
--> $DIR/dbg_macro.rs:20:5
|
||||
--> $DIR/dbg_macro.rs:16:5
|
||||
|
|
||||
LL | dbg!(42);
|
||||
| ^^^^^^^^
|
||||
|
|
@ -55,7 +55,7 @@ LL | 42;
|
|||
| ^^
|
||||
|
||||
error: `dbg!` macro is intended as a debugging tool
|
||||
--> $DIR/dbg_macro.rs:21:5
|
||||
--> $DIR/dbg_macro.rs:17:5
|
||||
|
|
||||
LL | dbg!(dbg!(dbg!(42)));
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
@ -66,7 +66,7 @@ LL | dbg!(dbg!(42));
|
|||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error: `dbg!` macro is intended as a debugging tool
|
||||
--> $DIR/dbg_macro.rs:22:14
|
||||
--> $DIR/dbg_macro.rs:18:14
|
||||
|
|
||||
LL | foo(3) + dbg!(factorial(4));
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
|
|
|||
|
|
@ -48,25 +48,7 @@ fn main() {
|
|||
|
||||
println!(
|
||||
"[{}] [{}] [{}] [{}] [{}] [{}] [{}] [{}] [{}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}], [{:?}]",
|
||||
s1,
|
||||
s2,
|
||||
s3,
|
||||
s4,
|
||||
s5,
|
||||
s6,
|
||||
s7,
|
||||
s8,
|
||||
s9,
|
||||
s10,
|
||||
s11,
|
||||
s12,
|
||||
s13,
|
||||
s14,
|
||||
s15,
|
||||
s16,
|
||||
s17,
|
||||
s18,
|
||||
s19,
|
||||
s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s15, s16, s17, s18, s19,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -48,25 +48,7 @@ fn main() {
|
|||
|
||||
println!(
|
||||
"[{}] [{}] [{}] [{}] [{}] [{}] [{}] [{}] [{}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}], [{:?}]",
|
||||
s1,
|
||||
s2,
|
||||
s3,
|
||||
s4,
|
||||
s5,
|
||||
s6,
|
||||
s7,
|
||||
s8,
|
||||
s9,
|
||||
s10,
|
||||
s11,
|
||||
s12,
|
||||
s13,
|
||||
s14,
|
||||
s15,
|
||||
s16,
|
||||
s17,
|
||||
s18,
|
||||
s19,
|
||||
s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s15, s16, s17, s18, s19,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
error: I see you're using a LinkedList! Perhaps you meant some other data structure?
|
||||
error: you seem to be using a `LinkedList`! Perhaps you meant some other data structure?
|
||||
--> $DIR/dlist.rs:9:16
|
||||
|
|
||||
LL | type Baz = LinkedList<u8>;
|
||||
|
|
@ -7,7 +7,7 @@ LL | type Baz = LinkedList<u8>;
|
|||
= note: `-D clippy::linkedlist` implied by `-D warnings`
|
||||
= help: a `VecDeque` might work
|
||||
|
||||
error: I see you're using a LinkedList! Perhaps you meant some other data structure?
|
||||
error: you seem to be using a `LinkedList`! Perhaps you meant some other data structure?
|
||||
--> $DIR/dlist.rs:10:15
|
||||
|
|
||||
LL | fn foo(_: LinkedList<u8>);
|
||||
|
|
@ -15,7 +15,7 @@ LL | fn foo(_: LinkedList<u8>);
|
|||
|
|
||||
= help: a `VecDeque` might work
|
||||
|
||||
error: I see you're using a LinkedList! Perhaps you meant some other data structure?
|
||||
error: you seem to be using a `LinkedList`! Perhaps you meant some other data structure?
|
||||
--> $DIR/dlist.rs:11:23
|
||||
|
|
||||
LL | const BAR: Option<LinkedList<u8>>;
|
||||
|
|
@ -23,7 +23,7 @@ LL | const BAR: Option<LinkedList<u8>>;
|
|||
|
|
||||
= help: a `VecDeque` might work
|
||||
|
||||
error: I see you're using a LinkedList! Perhaps you meant some other data structure?
|
||||
error: you seem to be using a `LinkedList`! Perhaps you meant some other data structure?
|
||||
--> $DIR/dlist.rs:22:15
|
||||
|
|
||||
LL | fn foo(_: LinkedList<u8>) {}
|
||||
|
|
@ -31,7 +31,7 @@ LL | fn foo(_: LinkedList<u8>) {}
|
|||
|
|
||||
= help: a `VecDeque` might work
|
||||
|
||||
error: I see you're using a LinkedList! Perhaps you meant some other data structure?
|
||||
error: you seem to be using a `LinkedList`! Perhaps you meant some other data structure?
|
||||
--> $DIR/dlist.rs:25:39
|
||||
|
|
||||
LL | pub fn test(my_favourite_linked_list: LinkedList<u8>) {
|
||||
|
|
@ -39,7 +39,7 @@ LL | pub fn test(my_favourite_linked_list: LinkedList<u8>) {
|
|||
|
|
||||
= help: a `VecDeque` might work
|
||||
|
||||
error: I see you're using a LinkedList! Perhaps you meant some other data structure?
|
||||
error: you seem to be using a `LinkedList`! Perhaps you meant some other data structure?
|
||||
--> $DIR/dlist.rs:29:29
|
||||
|
|
||||
LL | pub fn test_ret() -> Option<LinkedList<u8>> {
|
||||
|
|
|
|||
|
|
@ -30,11 +30,7 @@ pub fn inner_body(opt: Option<u32>) {
|
|||
|
||||
/// This needs to be documented
|
||||
pub fn unreachable_and_panic() {
|
||||
if true {
|
||||
unreachable!()
|
||||
} else {
|
||||
panic!()
|
||||
}
|
||||
if true { unreachable!() } else { panic!() }
|
||||
}
|
||||
|
||||
/// This is documented
|
||||
|
|
@ -84,11 +80,7 @@ pub fn todo_documented() {
|
|||
///
|
||||
/// We still need to do this part
|
||||
pub fn unreachable_amd_panic_documented() {
|
||||
if true {
|
||||
unreachable!()
|
||||
} else {
|
||||
panic!()
|
||||
}
|
||||
if true { unreachable!() } else { panic!() }
|
||||
}
|
||||
|
||||
/// This is okay because it is private
|
||||
|
|
|
|||
|
|
@ -67,19 +67,15 @@ error: docs for function which may panic missing `# Panics` section
|
|||
--> $DIR/doc_panics.rs:32:1
|
||||
|
|
||||
LL | / pub fn unreachable_and_panic() {
|
||||
LL | | if true {
|
||||
LL | | unreachable!()
|
||||
LL | | } else {
|
||||
LL | | panic!()
|
||||
LL | | }
|
||||
LL | | if true { unreachable!() } else { panic!() }
|
||||
LL | | }
|
||||
| |_^
|
||||
|
|
||||
note: first possible panic found here
|
||||
--> $DIR/doc_panics.rs:36:9
|
||||
--> $DIR/doc_panics.rs:33:39
|
||||
|
|
||||
LL | panic!()
|
||||
| ^^^^^^^^
|
||||
LL | if true { unreachable!() } else { panic!() }
|
||||
| ^^^^^^^^
|
||||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error: aborting due to 5 previous errors
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
error: calls to `std::mem::drop` with a value that implements `Copy`. Dropping a copy leaves the original intact.
|
||||
error: calls to `std::mem::drop` with a value that implements `Copy`. Dropping a copy leaves the original intact
|
||||
--> $DIR/drop_forget_copy.rs:33:5
|
||||
|
|
||||
LL | drop(s1);
|
||||
|
|
@ -11,7 +11,7 @@ note: argument has type SomeStruct
|
|||
LL | drop(s1);
|
||||
| ^^
|
||||
|
||||
error: calls to `std::mem::drop` with a value that implements `Copy`. Dropping a copy leaves the original intact.
|
||||
error: calls to `std::mem::drop` with a value that implements `Copy`. Dropping a copy leaves the original intact
|
||||
--> $DIR/drop_forget_copy.rs:34:5
|
||||
|
|
||||
LL | drop(s2);
|
||||
|
|
@ -23,7 +23,7 @@ note: argument has type SomeStruct
|
|||
LL | drop(s2);
|
||||
| ^^
|
||||
|
||||
error: calls to `std::mem::drop` with a value that implements `Copy`. Dropping a copy leaves the original intact.
|
||||
error: calls to `std::mem::drop` with a value that implements `Copy`. Dropping a copy leaves the original intact
|
||||
--> $DIR/drop_forget_copy.rs:36:5
|
||||
|
|
||||
LL | drop(s4);
|
||||
|
|
@ -35,7 +35,7 @@ note: argument has type SomeStruct
|
|||
LL | drop(s4);
|
||||
| ^^
|
||||
|
||||
error: calls to `std::mem::forget` with a value that implements `Copy`. Forgetting a copy leaves the original intact.
|
||||
error: calls to `std::mem::forget` with a value that implements `Copy`. Forgetting a copy leaves the original intact
|
||||
--> $DIR/drop_forget_copy.rs:39:5
|
||||
|
|
||||
LL | forget(s1);
|
||||
|
|
@ -48,7 +48,7 @@ note: argument has type SomeStruct
|
|||
LL | forget(s1);
|
||||
| ^^
|
||||
|
||||
error: calls to `std::mem::forget` with a value that implements `Copy`. Forgetting a copy leaves the original intact.
|
||||
error: calls to `std::mem::forget` with a value that implements `Copy`. Forgetting a copy leaves the original intact
|
||||
--> $DIR/drop_forget_copy.rs:40:5
|
||||
|
|
||||
LL | forget(s2);
|
||||
|
|
@ -60,7 +60,7 @@ note: argument has type SomeStruct
|
|||
LL | forget(s2);
|
||||
| ^^
|
||||
|
||||
error: calls to `std::mem::forget` with a value that implements `Copy`. Forgetting a copy leaves the original intact.
|
||||
error: calls to `std::mem::forget` with a value that implements `Copy`. Forgetting a copy leaves the original intact
|
||||
--> $DIR/drop_forget_copy.rs:42:5
|
||||
|
|
||||
LL | forget(s4);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing.
|
||||
error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing
|
||||
--> $DIR/drop_ref.rs:11:5
|
||||
|
|
||||
LL | drop(&SomeStruct);
|
||||
|
|
@ -11,7 +11,7 @@ note: argument has type `&SomeStruct`
|
|||
LL | drop(&SomeStruct);
|
||||
| ^^^^^^^^^^^
|
||||
|
||||
error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing.
|
||||
error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing
|
||||
--> $DIR/drop_ref.rs:14:5
|
||||
|
|
||||
LL | drop(&owned1);
|
||||
|
|
@ -23,7 +23,7 @@ note: argument has type `&SomeStruct`
|
|||
LL | drop(&owned1);
|
||||
| ^^^^^^^
|
||||
|
||||
error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing.
|
||||
error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing
|
||||
--> $DIR/drop_ref.rs:15:5
|
||||
|
|
||||
LL | drop(&&owned1);
|
||||
|
|
@ -35,7 +35,7 @@ note: argument has type `&&SomeStruct`
|
|||
LL | drop(&&owned1);
|
||||
| ^^^^^^^^
|
||||
|
||||
error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing.
|
||||
error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing
|
||||
--> $DIR/drop_ref.rs:16:5
|
||||
|
|
||||
LL | drop(&mut owned1);
|
||||
|
|
@ -47,7 +47,7 @@ note: argument has type `&mut SomeStruct`
|
|||
LL | drop(&mut owned1);
|
||||
| ^^^^^^^^^^^
|
||||
|
||||
error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing.
|
||||
error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing
|
||||
--> $DIR/drop_ref.rs:20:5
|
||||
|
|
||||
LL | drop(reference1);
|
||||
|
|
@ -59,7 +59,7 @@ note: argument has type `&SomeStruct`
|
|||
LL | drop(reference1);
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing.
|
||||
error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing
|
||||
--> $DIR/drop_ref.rs:23:5
|
||||
|
|
||||
LL | drop(reference2);
|
||||
|
|
@ -71,7 +71,7 @@ note: argument has type `&mut SomeStruct`
|
|||
LL | drop(reference2);
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing.
|
||||
error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing
|
||||
--> $DIR/drop_ref.rs:26:5
|
||||
|
|
||||
LL | drop(reference3);
|
||||
|
|
@ -83,7 +83,7 @@ note: argument has type `&SomeStruct`
|
|||
LL | drop(reference3);
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing.
|
||||
error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing
|
||||
--> $DIR/drop_ref.rs:31:5
|
||||
|
|
||||
LL | drop(&val);
|
||||
|
|
@ -95,7 +95,7 @@ note: argument has type `&T`
|
|||
LL | drop(&val);
|
||||
| ^^^^
|
||||
|
||||
error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing.
|
||||
error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing
|
||||
--> $DIR/drop_ref.rs:39:5
|
||||
|
|
||||
LL | std::mem::drop(&SomeStruct);
|
||||
|
|
|
|||
|
|
@ -16,10 +16,25 @@
|
|||
|
||||
use std::path::PathBuf;
|
||||
|
||||
macro_rules! mac {
|
||||
() => {
|
||||
foobar()
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! closure_mac {
|
||||
() => {
|
||||
|n| foo(n)
|
||||
};
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let a = Some(1u8).map(foo);
|
||||
meta(foo);
|
||||
let c = Some(1u8).map(|a| {1+2; foo}(a));
|
||||
true.then(|| mac!()); // don't lint function in macro expansion
|
||||
Some(1).map(closure_mac!()); // don't lint closure in macro expansion
|
||||
let _: Option<Vec<u8>> = true.then(std::vec::Vec::new); // special case vec!
|
||||
let d = Some(1u8).map(|a| foo((|b| foo2(b))(a))); //is adjusted?
|
||||
all(&[1, 2, 3], &2, |x, y| below(x, y)); //is adjusted
|
||||
unsafe {
|
||||
|
|
|
|||
|
|
@ -16,10 +16,25 @@
|
|||
|
||||
use std::path::PathBuf;
|
||||
|
||||
macro_rules! mac {
|
||||
() => {
|
||||
foobar()
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! closure_mac {
|
||||
() => {
|
||||
|n| foo(n)
|
||||
};
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let a = Some(1u8).map(|a| foo(a));
|
||||
meta(|a| foo(a));
|
||||
let c = Some(1u8).map(|a| {1+2; foo}(a));
|
||||
true.then(|| mac!()); // don't lint function in macro expansion
|
||||
Some(1).map(closure_mac!()); // don't lint closure in macro expansion
|
||||
let _: Option<Vec<u8>> = true.then(|| vec![]); // special case vec!
|
||||
let d = Some(1u8).map(|a| foo((|b| foo2(b))(a))); //is adjusted?
|
||||
all(&[1, 2, 3], &&2, |x, y| below(x, y)); //is adjusted
|
||||
unsafe {
|
||||
|
|
|
|||
|
|
@ -1,80 +1,86 @@
|
|||
error: redundant closure found
|
||||
--> $DIR/eta.rs:20:27
|
||||
error: redundant closure
|
||||
--> $DIR/eta.rs:32:27
|
||||
|
|
||||
LL | let a = Some(1u8).map(|a| foo(a));
|
||||
| ^^^^^^^^^^ help: remove closure as shown: `foo`
|
||||
| ^^^^^^^^^^ help: replace the closure with the function itself: `foo`
|
||||
|
|
||||
= note: `-D clippy::redundant-closure` implied by `-D warnings`
|
||||
|
||||
error: redundant closure found
|
||||
--> $DIR/eta.rs:21:10
|
||||
error: redundant closure
|
||||
--> $DIR/eta.rs:33:10
|
||||
|
|
||||
LL | meta(|a| foo(a));
|
||||
| ^^^^^^^^^^ help: remove closure as shown: `foo`
|
||||
| ^^^^^^^^^^ help: replace the closure with the function itself: `foo`
|
||||
|
||||
error: redundant closure
|
||||
--> $DIR/eta.rs:37:40
|
||||
|
|
||||
LL | let _: Option<Vec<u8>> = true.then(|| vec![]); // special case vec!
|
||||
| ^^^^^^^^^ help: replace the closure with `Vec::new`: `std::vec::Vec::new`
|
||||
|
||||
error: this expression borrows a reference (`&u8`) that is immediately dereferenced by the compiler
|
||||
--> $DIR/eta.rs:24:21
|
||||
--> $DIR/eta.rs:39:21
|
||||
|
|
||||
LL | all(&[1, 2, 3], &&2, |x, y| below(x, y)); //is adjusted
|
||||
| ^^^ help: change this to: `&2`
|
||||
|
|
||||
= note: `-D clippy::needless-borrow` implied by `-D warnings`
|
||||
|
||||
error: redundant closure found
|
||||
--> $DIR/eta.rs:31:27
|
||||
error: redundant closure
|
||||
--> $DIR/eta.rs:46:27
|
||||
|
|
||||
LL | let e = Some(1u8).map(|a| generic(a));
|
||||
| ^^^^^^^^^^^^^^ help: remove closure as shown: `generic`
|
||||
| ^^^^^^^^^^^^^^ help: replace the closure with the function itself: `generic`
|
||||
|
||||
error: redundant closure found
|
||||
--> $DIR/eta.rs:74:51
|
||||
error: redundant closure
|
||||
--> $DIR/eta.rs:89:51
|
||||
|
|
||||
LL | let e = Some(TestStruct { some_ref: &i }).map(|a| a.foo());
|
||||
| ^^^^^^^^^^^ help: remove closure as shown: `TestStruct::foo`
|
||||
| ^^^^^^^^^^^ help: replace the closure with the method itself: `TestStruct::foo`
|
||||
|
|
||||
= note: `-D clippy::redundant-closure-for-method-calls` implied by `-D warnings`
|
||||
|
||||
error: redundant closure found
|
||||
--> $DIR/eta.rs:76:51
|
||||
error: redundant closure
|
||||
--> $DIR/eta.rs:91:51
|
||||
|
|
||||
LL | let e = Some(TestStruct { some_ref: &i }).map(|a| a.trait_foo());
|
||||
| ^^^^^^^^^^^^^^^^^ help: remove closure as shown: `TestTrait::trait_foo`
|
||||
| ^^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `TestTrait::trait_foo`
|
||||
|
||||
error: redundant closure found
|
||||
--> $DIR/eta.rs:79:42
|
||||
error: redundant closure
|
||||
--> $DIR/eta.rs:94:42
|
||||
|
|
||||
LL | let e = Some(&mut vec![1, 2, 3]).map(|v| v.clear());
|
||||
| ^^^^^^^^^^^^^ help: remove closure as shown: `std::vec::Vec::clear`
|
||||
| ^^^^^^^^^^^^^ help: replace the closure with the method itself: `std::vec::Vec::clear`
|
||||
|
||||
error: redundant closure found
|
||||
--> $DIR/eta.rs:84:29
|
||||
error: redundant closure
|
||||
--> $DIR/eta.rs:99:29
|
||||
|
|
||||
LL | let e = Some("str").map(|s| s.to_string());
|
||||
| ^^^^^^^^^^^^^^^^^ help: remove closure as shown: `std::string::ToString::to_string`
|
||||
| ^^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `std::string::ToString::to_string`
|
||||
|
||||
error: redundant closure found
|
||||
--> $DIR/eta.rs:86:27
|
||||
error: redundant closure
|
||||
--> $DIR/eta.rs:101:27
|
||||
|
|
||||
LL | let e = Some('a').map(|s| s.to_uppercase());
|
||||
| ^^^^^^^^^^^^^^^^^^^^ help: remove closure as shown: `char::to_uppercase`
|
||||
| ^^^^^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `char::to_uppercase`
|
||||
|
||||
error: redundant closure found
|
||||
--> $DIR/eta.rs:89:65
|
||||
error: redundant closure
|
||||
--> $DIR/eta.rs:104:65
|
||||
|
|
||||
LL | let e: std::vec::Vec<char> = vec!['a', 'b', 'c'].iter().map(|c| c.to_ascii_uppercase()).collect();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove closure as shown: `char::to_ascii_uppercase`
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `char::to_ascii_uppercase`
|
||||
|
||||
error: redundant closure found
|
||||
--> $DIR/eta.rs:172:27
|
||||
error: redundant closure
|
||||
--> $DIR/eta.rs:187:27
|
||||
|
|
||||
LL | let a = Some(1u8).map(|a| foo_ptr(a));
|
||||
| ^^^^^^^^^^^^^^ help: remove closure as shown: `foo_ptr`
|
||||
| ^^^^^^^^^^^^^^ help: replace the closure with the function itself: `foo_ptr`
|
||||
|
||||
error: redundant closure found
|
||||
--> $DIR/eta.rs:177:27
|
||||
error: redundant closure
|
||||
--> $DIR/eta.rs:192:27
|
||||
|
|
||||
LL | let a = Some(1u8).map(|a| closure(a));
|
||||
| ^^^^^^^^^^^^^^ help: remove closure as shown: `closure`
|
||||
| ^^^^^^^^^^^^^^ help: replace the closure with the function itself: `closure`
|
||||
|
||||
error: aborting due to 12 previous errors
|
||||
error: aborting due to 13 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
error: the variable `_index` is used as a loop counter.
|
||||
error: the variable `_index` is used as a loop counter
|
||||
--> $DIR/explicit_counter_loop.rs:6:5
|
||||
|
|
||||
LL | for _v in &vec {
|
||||
|
|
@ -6,37 +6,37 @@ LL | for _v in &vec {
|
|||
|
|
||||
= note: `-D clippy::explicit-counter-loop` implied by `-D warnings`
|
||||
|
||||
error: the variable `_index` is used as a loop counter.
|
||||
error: the variable `_index` is used as a loop counter
|
||||
--> $DIR/explicit_counter_loop.rs:12:5
|
||||
|
|
||||
LL | for _v in &vec {
|
||||
| ^^^^^^^^^^^^^^ help: consider using: `for (_index, _v) in vec.iter().enumerate()`
|
||||
|
||||
error: the variable `_index` is used as a loop counter.
|
||||
error: the variable `_index` is used as a loop counter
|
||||
--> $DIR/explicit_counter_loop.rs:17:5
|
||||
|
|
||||
LL | for _v in &mut vec {
|
||||
| ^^^^^^^^^^^^^^^^^^ help: consider using: `for (_index, _v) in vec.iter_mut().enumerate()`
|
||||
|
||||
error: the variable `_index` is used as a loop counter.
|
||||
error: the variable `_index` is used as a loop counter
|
||||
--> $DIR/explicit_counter_loop.rs:22:5
|
||||
|
|
||||
LL | for _v in vec {
|
||||
| ^^^^^^^^^^^^^ help: consider using: `for (_index, _v) in vec.into_iter().enumerate()`
|
||||
|
||||
error: the variable `count` is used as a loop counter.
|
||||
error: the variable `count` is used as a loop counter
|
||||
--> $DIR/explicit_counter_loop.rs:61:9
|
||||
|
|
||||
LL | for ch in text.chars() {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `for (count, ch) in text.chars().enumerate()`
|
||||
|
||||
error: the variable `count` is used as a loop counter.
|
||||
error: the variable `count` is used as a loop counter
|
||||
--> $DIR/explicit_counter_loop.rs:72:9
|
||||
|
|
||||
LL | for ch in text.chars() {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `for (count, ch) in text.chars().enumerate()`
|
||||
|
||||
error: the variable `count` is used as a loop counter.
|
||||
error: the variable `count` is used as a loop counter
|
||||
--> $DIR/explicit_counter_loop.rs:130:9
|
||||
|
|
||||
LL | for _i in 3..10 {
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ note: the lint level is defined here
|
|||
|
|
||||
LL | #![deny(clippy::fallible_impl_from)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
= help: `From` is intended for infallible conversions only. Use `TryFrom` if there's a possibility for the conversion to fail.
|
||||
= help: `From` is intended for infallible conversions only. Use `TryFrom` if there's a possibility for the conversion to fail
|
||||
note: potential failure(s)
|
||||
--> $DIR/fallible_impl_from.rs:7:13
|
||||
|
|
||||
|
|
@ -32,7 +32,7 @@ LL | | }
|
|||
LL | | }
|
||||
| |_^
|
||||
|
|
||||
= help: `From` is intended for infallible conversions only. Use `TryFrom` if there's a possibility for the conversion to fail.
|
||||
= help: `From` is intended for infallible conversions only. Use `TryFrom` if there's a possibility for the conversion to fail
|
||||
note: potential failure(s)
|
||||
--> $DIR/fallible_impl_from.rs:29:13
|
||||
|
|
||||
|
|
@ -52,7 +52,7 @@ LL | | }
|
|||
LL | | }
|
||||
| |_^
|
||||
|
|
||||
= help: `From` is intended for infallible conversions only. Use `TryFrom` if there's a possibility for the conversion to fail.
|
||||
= help: `From` is intended for infallible conversions only. Use `TryFrom` if there's a possibility for the conversion to fail
|
||||
note: potential failure(s)
|
||||
--> $DIR/fallible_impl_from.rs:37:17
|
||||
|
|
||||
|
|
@ -79,7 +79,7 @@ LL | | }
|
|||
LL | | }
|
||||
| |_^
|
||||
|
|
||||
= help: `From` is intended for infallible conversions only. Use `TryFrom` if there's a possibility for the conversion to fail.
|
||||
= help: `From` is intended for infallible conversions only. Use `TryFrom` if there's a possibility for the conversion to fail
|
||||
note: potential failure(s)
|
||||
--> $DIR/fallible_impl_from.rs:55:12
|
||||
|
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
error: called `filter_map(..).next()` on an `Iterator`. This is more succinctly expressed by calling `.find_map(..)` instead.
|
||||
error: called `filter_map(..).next()` on an `Iterator`. This is more succinctly expressed by calling `.find_map(..)` instead
|
||||
--> $DIR/filter_map_next.rs:7:26
|
||||
|
|
||||
LL | let _: Option<u32> = vec![1, 2, 3, 4, 5, 6]
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
error: called `filter_map(..).next()` on an `Iterator`. This is more succinctly expressed by calling `.find_map(..)` instead.
|
||||
error: called `filter_map(..).next()` on an `Iterator`. This is more succinctly expressed by calling `.find_map(..)` instead
|
||||
--> $DIR/filter_map_next_fixable.rs:8:32
|
||||
|
|
||||
LL | let element: Option<i32> = a.iter().filter_map(|s| s.parse().ok()).next();
|
||||
|
|
|
|||
|
|
@ -21,19 +21,11 @@ where
|
|||
}
|
||||
|
||||
fn eq_fl(x: f32, y: f32) -> bool {
|
||||
if x.is_nan() {
|
||||
y.is_nan()
|
||||
} else {
|
||||
x == y
|
||||
} // no error, inside "eq" fn
|
||||
if x.is_nan() { y.is_nan() } else { x == y } // no error, inside "eq" fn
|
||||
}
|
||||
|
||||
fn fl_eq(x: f32, y: f32) -> bool {
|
||||
if x.is_nan() {
|
||||
y.is_nan()
|
||||
} else {
|
||||
x == y
|
||||
} // no error, inside "eq" fn
|
||||
if x.is_nan() { y.is_nan() } else { x == y } // no error, inside "eq" fn
|
||||
}
|
||||
|
||||
struct X {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
error: strict comparison of `f32` or `f64`
|
||||
--> $DIR/float_cmp.rs:66:5
|
||||
--> $DIR/float_cmp.rs:58:5
|
||||
|
|
||||
LL | ONE as f64 != 2.0;
|
||||
| ^^^^^^^^^^^^^^^^^ help: consider comparing them within some margin of error: `(ONE as f64 - 2.0).abs() > error_margin`
|
||||
|
|
@ -8,7 +8,7 @@ LL | ONE as f64 != 2.0;
|
|||
= note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin`
|
||||
|
||||
error: strict comparison of `f32` or `f64`
|
||||
--> $DIR/float_cmp.rs:71:5
|
||||
--> $DIR/float_cmp.rs:63:5
|
||||
|
|
||||
LL | x == 1.0;
|
||||
| ^^^^^^^^ help: consider comparing them within some margin of error: `(x - 1.0).abs() < error_margin`
|
||||
|
|
@ -16,7 +16,7 @@ LL | x == 1.0;
|
|||
= note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin`
|
||||
|
||||
error: strict comparison of `f32` or `f64`
|
||||
--> $DIR/float_cmp.rs:74:5
|
||||
--> $DIR/float_cmp.rs:66:5
|
||||
|
|
||||
LL | twice(x) != twice(ONE as f64);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider comparing them within some margin of error: `(twice(x) - twice(ONE as f64)).abs() > error_margin`
|
||||
|
|
@ -24,7 +24,7 @@ LL | twice(x) != twice(ONE as f64);
|
|||
= note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin`
|
||||
|
||||
error: strict comparison of `f32` or `f64`
|
||||
--> $DIR/float_cmp.rs:94:5
|
||||
--> $DIR/float_cmp.rs:86:5
|
||||
|
|
||||
LL | NON_ZERO_ARRAY[i] == NON_ZERO_ARRAY[j];
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider comparing them within some margin of error: `(NON_ZERO_ARRAY[i] - NON_ZERO_ARRAY[j]).abs() < error_margin`
|
||||
|
|
@ -32,7 +32,7 @@ LL | NON_ZERO_ARRAY[i] == NON_ZERO_ARRAY[j];
|
|||
= note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin`
|
||||
|
||||
error: strict comparison of `f32` or `f64` arrays
|
||||
--> $DIR/float_cmp.rs:99:5
|
||||
--> $DIR/float_cmp.rs:91:5
|
||||
|
|
||||
LL | a1 == a2;
|
||||
| ^^^^^^^^
|
||||
|
|
@ -40,7 +40,7 @@ LL | a1 == a2;
|
|||
= note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin`
|
||||
|
||||
error: strict comparison of `f32` or `f64`
|
||||
--> $DIR/float_cmp.rs:100:5
|
||||
--> $DIR/float_cmp.rs:92:5
|
||||
|
|
||||
LL | a1[0] == a2[0];
|
||||
| ^^^^^^^^^^^^^^ help: consider comparing them within some margin of error: `(a1[0] - a2[0]).abs() < error_margin`
|
||||
|
|
|
|||
|
|
@ -8,11 +8,7 @@ const ONE: f32 = 1.0;
|
|||
const TWO: f32 = 2.0;
|
||||
|
||||
fn eq_one(x: f32) -> bool {
|
||||
if x.is_nan() {
|
||||
false
|
||||
} else {
|
||||
x == ONE
|
||||
} // no error, inside "eq" fn
|
||||
if x.is_nan() { false } else { x == ONE } // no error, inside "eq" fn
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
error: strict comparison of `f32` or `f64` constant
|
||||
--> $DIR/float_cmp_const.rs:20:5
|
||||
--> $DIR/float_cmp_const.rs:16:5
|
||||
|
|
||||
LL | 1f32 == ONE;
|
||||
| ^^^^^^^^^^^ help: consider comparing them within some margin of error: `(1f32 - ONE).abs() < error_margin`
|
||||
|
|
@ -8,7 +8,7 @@ LL | 1f32 == ONE;
|
|||
= note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin`
|
||||
|
||||
error: strict comparison of `f32` or `f64` constant
|
||||
--> $DIR/float_cmp_const.rs:21:5
|
||||
--> $DIR/float_cmp_const.rs:17:5
|
||||
|
|
||||
LL | TWO == ONE;
|
||||
| ^^^^^^^^^^ help: consider comparing them within some margin of error: `(TWO - ONE).abs() < error_margin`
|
||||
|
|
@ -16,7 +16,7 @@ LL | TWO == ONE;
|
|||
= note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin`
|
||||
|
||||
error: strict comparison of `f32` or `f64` constant
|
||||
--> $DIR/float_cmp_const.rs:22:5
|
||||
--> $DIR/float_cmp_const.rs:18:5
|
||||
|
|
||||
LL | TWO != ONE;
|
||||
| ^^^^^^^^^^ help: consider comparing them within some margin of error: `(TWO - ONE).abs() > error_margin`
|
||||
|
|
@ -24,7 +24,7 @@ LL | TWO != ONE;
|
|||
= note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin`
|
||||
|
||||
error: strict comparison of `f32` or `f64` constant
|
||||
--> $DIR/float_cmp_const.rs:23:5
|
||||
--> $DIR/float_cmp_const.rs:19:5
|
||||
|
|
||||
LL | ONE + ONE == TWO;
|
||||
| ^^^^^^^^^^^^^^^^ help: consider comparing them within some margin of error: `(ONE + ONE - TWO).abs() < error_margin`
|
||||
|
|
@ -32,7 +32,7 @@ LL | ONE + ONE == TWO;
|
|||
= note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin`
|
||||
|
||||
error: strict comparison of `f32` or `f64` constant
|
||||
--> $DIR/float_cmp_const.rs:25:5
|
||||
--> $DIR/float_cmp_const.rs:21:5
|
||||
|
|
||||
LL | x as f32 == ONE;
|
||||
| ^^^^^^^^^^^^^^^ help: consider comparing them within some margin of error: `(x as f32 - ONE).abs() < error_margin`
|
||||
|
|
@ -40,7 +40,7 @@ LL | x as f32 == ONE;
|
|||
= note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin`
|
||||
|
||||
error: strict comparison of `f32` or `f64` constant
|
||||
--> $DIR/float_cmp_const.rs:28:5
|
||||
--> $DIR/float_cmp_const.rs:24:5
|
||||
|
|
||||
LL | v == ONE;
|
||||
| ^^^^^^^^ help: consider comparing them within some margin of error: `(v - ONE).abs() < error_margin`
|
||||
|
|
@ -48,7 +48,7 @@ LL | v == ONE;
|
|||
= note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin`
|
||||
|
||||
error: strict comparison of `f32` or `f64` constant
|
||||
--> $DIR/float_cmp_const.rs:29:5
|
||||
--> $DIR/float_cmp_const.rs:25:5
|
||||
|
|
||||
LL | v != ONE;
|
||||
| ^^^^^^^^ help: consider comparing them within some margin of error: `(v - ONE).abs() > error_margin`
|
||||
|
|
@ -56,7 +56,7 @@ LL | v != ONE;
|
|||
= note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin`
|
||||
|
||||
error: strict comparison of `f32` or `f64` constant arrays
|
||||
--> $DIR/float_cmp_const.rs:61:5
|
||||
--> $DIR/float_cmp_const.rs:57:5
|
||||
|
|
||||
LL | NON_ZERO_ARRAY == NON_ZERO_ARRAY2;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
|
|||
|
|
@ -42,43 +42,23 @@ fn fake_nabs3(a: A) -> A {
|
|||
}
|
||||
|
||||
fn not_fake_abs1(num: f64) -> f64 {
|
||||
if num > 0.0 {
|
||||
num
|
||||
} else {
|
||||
-num - 1f64
|
||||
}
|
||||
if num > 0.0 { num } else { -num - 1f64 }
|
||||
}
|
||||
|
||||
fn not_fake_abs2(num: f64) -> f64 {
|
||||
if num > 0.0 {
|
||||
num + 1.0
|
||||
} else {
|
||||
-(num + 1.0)
|
||||
}
|
||||
if num > 0.0 { num + 1.0 } else { -(num + 1.0) }
|
||||
}
|
||||
|
||||
fn not_fake_abs3(num1: f64, num2: f64) -> f64 {
|
||||
if num1 > 0.0 {
|
||||
num2
|
||||
} else {
|
||||
-num2
|
||||
}
|
||||
if num1 > 0.0 { num2 } else { -num2 }
|
||||
}
|
||||
|
||||
fn not_fake_abs4(a: A) -> f64 {
|
||||
if a.a > 0.0 {
|
||||
a.b
|
||||
} else {
|
||||
-a.b
|
||||
}
|
||||
if a.a > 0.0 { a.b } else { -a.b }
|
||||
}
|
||||
|
||||
fn not_fake_abs5(a: A) -> f64 {
|
||||
if a.a > 0.0 {
|
||||
a.a
|
||||
} else {
|
||||
-a.b
|
||||
}
|
||||
if a.a > 0.0 { a.a } else { -a.b }
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
|
|
|||
|
|
@ -7,59 +7,31 @@ struct A {
|
|||
}
|
||||
|
||||
fn fake_abs1(num: f64) -> f64 {
|
||||
if num >= 0.0 {
|
||||
num
|
||||
} else {
|
||||
-num
|
||||
}
|
||||
if num >= 0.0 { num } else { -num }
|
||||
}
|
||||
|
||||
fn fake_abs2(num: f64) -> f64 {
|
||||
if 0.0 < num {
|
||||
num
|
||||
} else {
|
||||
-num
|
||||
}
|
||||
if 0.0 < num { num } else { -num }
|
||||
}
|
||||
|
||||
fn fake_abs3(a: A) -> f64 {
|
||||
if a.a > 0.0 {
|
||||
a.a
|
||||
} else {
|
||||
-a.a
|
||||
}
|
||||
if a.a > 0.0 { a.a } else { -a.a }
|
||||
}
|
||||
|
||||
fn fake_abs4(num: f64) -> f64 {
|
||||
if 0.0 >= num {
|
||||
-num
|
||||
} else {
|
||||
num
|
||||
}
|
||||
if 0.0 >= num { -num } else { num }
|
||||
}
|
||||
|
||||
fn fake_abs5(a: A) -> f64 {
|
||||
if a.a < 0.0 {
|
||||
-a.a
|
||||
} else {
|
||||
a.a
|
||||
}
|
||||
if a.a < 0.0 { -a.a } else { a.a }
|
||||
}
|
||||
|
||||
fn fake_nabs1(num: f64) -> f64 {
|
||||
if num < 0.0 {
|
||||
num
|
||||
} else {
|
||||
-num
|
||||
}
|
||||
if num < 0.0 { num } else { -num }
|
||||
}
|
||||
|
||||
fn fake_nabs2(num: f64) -> f64 {
|
||||
if 0.0 >= num {
|
||||
num
|
||||
} else {
|
||||
-num
|
||||
}
|
||||
if 0.0 >= num { num } else { -num }
|
||||
}
|
||||
|
||||
fn fake_nabs3(a: A) -> A {
|
||||
|
|
@ -70,43 +42,23 @@ fn fake_nabs3(a: A) -> A {
|
|||
}
|
||||
|
||||
fn not_fake_abs1(num: f64) -> f64 {
|
||||
if num > 0.0 {
|
||||
num
|
||||
} else {
|
||||
-num - 1f64
|
||||
}
|
||||
if num > 0.0 { num } else { -num - 1f64 }
|
||||
}
|
||||
|
||||
fn not_fake_abs2(num: f64) -> f64 {
|
||||
if num > 0.0 {
|
||||
num + 1.0
|
||||
} else {
|
||||
-(num + 1.0)
|
||||
}
|
||||
if num > 0.0 { num + 1.0 } else { -(num + 1.0) }
|
||||
}
|
||||
|
||||
fn not_fake_abs3(num1: f64, num2: f64) -> f64 {
|
||||
if num1 > 0.0 {
|
||||
num2
|
||||
} else {
|
||||
-num2
|
||||
}
|
||||
if num1 > 0.0 { num2 } else { -num2 }
|
||||
}
|
||||
|
||||
fn not_fake_abs4(a: A) -> f64 {
|
||||
if a.a > 0.0 {
|
||||
a.b
|
||||
} else {
|
||||
-a.b
|
||||
}
|
||||
if a.a > 0.0 { a.b } else { -a.b }
|
||||
}
|
||||
|
||||
fn not_fake_abs5(a: A) -> f64 {
|
||||
if a.a > 0.0 {
|
||||
a.a
|
||||
} else {
|
||||
-a.b
|
||||
}
|
||||
if a.a > 0.0 { a.a } else { -a.b }
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
|
|
|||
|
|
@ -1,77 +1,49 @@
|
|||
error: manual implementation of `abs` method
|
||||
--> $DIR/floating_point_abs.rs:10:5
|
||||
|
|
||||
LL | / if num >= 0.0 {
|
||||
LL | | num
|
||||
LL | | } else {
|
||||
LL | | -num
|
||||
LL | | }
|
||||
| |_____^ help: try: `num.abs()`
|
||||
LL | if num >= 0.0 { num } else { -num }
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `num.abs()`
|
||||
|
|
||||
= note: `-D clippy::suboptimal-flops` implied by `-D warnings`
|
||||
|
||||
error: manual implementation of `abs` method
|
||||
--> $DIR/floating_point_abs.rs:14:5
|
||||
|
|
||||
LL | if 0.0 < num { num } else { -num }
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `num.abs()`
|
||||
|
||||
error: manual implementation of `abs` method
|
||||
--> $DIR/floating_point_abs.rs:18:5
|
||||
|
|
||||
LL | / if 0.0 < num {
|
||||
LL | | num
|
||||
LL | | } else {
|
||||
LL | | -num
|
||||
LL | | }
|
||||
| |_____^ help: try: `num.abs()`
|
||||
LL | if a.a > 0.0 { a.a } else { -a.a }
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `a.a.abs()`
|
||||
|
||||
error: manual implementation of `abs` method
|
||||
--> $DIR/floating_point_abs.rs:22:5
|
||||
|
|
||||
LL | if 0.0 >= num { -num } else { num }
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `num.abs()`
|
||||
|
||||
error: manual implementation of `abs` method
|
||||
--> $DIR/floating_point_abs.rs:26:5
|
||||
|
|
||||
LL | / if a.a > 0.0 {
|
||||
LL | | a.a
|
||||
LL | | } else {
|
||||
LL | | -a.a
|
||||
LL | | }
|
||||
| |_____^ help: try: `a.a.abs()`
|
||||
LL | if a.a < 0.0 { -a.a } else { a.a }
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `a.a.abs()`
|
||||
|
||||
error: manual implementation of `abs` method
|
||||
error: manual implementation of negation of `abs` method
|
||||
--> $DIR/floating_point_abs.rs:30:5
|
||||
|
|
||||
LL | if num < 0.0 { num } else { -num }
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `-num.abs()`
|
||||
|
||||
error: manual implementation of negation of `abs` method
|
||||
--> $DIR/floating_point_abs.rs:34:5
|
||||
|
|
||||
LL | / if 0.0 >= num {
|
||||
LL | | -num
|
||||
LL | | } else {
|
||||
LL | | num
|
||||
LL | | }
|
||||
| |_____^ help: try: `num.abs()`
|
||||
|
||||
error: manual implementation of `abs` method
|
||||
--> $DIR/floating_point_abs.rs:42:5
|
||||
|
|
||||
LL | / if a.a < 0.0 {
|
||||
LL | | -a.a
|
||||
LL | | } else {
|
||||
LL | | a.a
|
||||
LL | | }
|
||||
| |_____^ help: try: `a.a.abs()`
|
||||
LL | if 0.0 >= num { num } else { -num }
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `-num.abs()`
|
||||
|
||||
error: manual implementation of negation of `abs` method
|
||||
--> $DIR/floating_point_abs.rs:50:5
|
||||
|
|
||||
LL | / if num < 0.0 {
|
||||
LL | | num
|
||||
LL | | } else {
|
||||
LL | | -num
|
||||
LL | | }
|
||||
| |_____^ help: try: `-num.abs()`
|
||||
|
||||
error: manual implementation of negation of `abs` method
|
||||
--> $DIR/floating_point_abs.rs:58:5
|
||||
|
|
||||
LL | / if 0.0 >= num {
|
||||
LL | | num
|
||||
LL | | } else {
|
||||
LL | | -num
|
||||
LL | | }
|
||||
| |_____^ help: try: `-num.abs()`
|
||||
|
||||
error: manual implementation of negation of `abs` method
|
||||
--> $DIR/floating_point_abs.rs:67:12
|
||||
--> $DIR/floating_point_abs.rs:39:12
|
||||
|
|
||||
LL | a: if a.a >= 0.0 { -a.a } else { a.a },
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `-a.a.abs()`
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
error: for loop over `option`, which is an `Option`. This is more readably written as an `if let` statement.
|
||||
error: for loop over `option`, which is an `Option`. This is more readably written as an `if let` statement
|
||||
--> $DIR/for_loops_over_fallibles.rs:9:14
|
||||
|
|
||||
LL | for x in option {
|
||||
|
|
@ -7,7 +7,7 @@ LL | for x in option {
|
|||
= note: `-D clippy::for-loops-over-fallibles` implied by `-D warnings`
|
||||
= help: consider replacing `for x in option` with `if let Some(x) = option`
|
||||
|
||||
error: for loop over `result`, which is a `Result`. This is more readably written as an `if let` statement.
|
||||
error: for loop over `result`, which is a `Result`. This is more readably written as an `if let` statement
|
||||
--> $DIR/for_loops_over_fallibles.rs:14:14
|
||||
|
|
||||
LL | for x in result {
|
||||
|
|
@ -15,7 +15,7 @@ LL | for x in result {
|
|||
|
|
||||
= help: consider replacing `for x in result` with `if let Ok(x) = result`
|
||||
|
||||
error: for loop over `option.ok_or("x not found")`, which is a `Result`. This is more readably written as an `if let` statement.
|
||||
error: for loop over `option.ok_or("x not found")`, which is a `Result`. This is more readably written as an `if let` statement
|
||||
--> $DIR/for_loops_over_fallibles.rs:18:14
|
||||
|
|
||||
LL | for x in option.ok_or("x not found") {
|
||||
|
|
@ -31,7 +31,7 @@ LL | for x in v.iter().next() {
|
|||
|
|
||||
= note: `#[deny(clippy::iter_next_loop)]` on by default
|
||||
|
||||
error: for loop over `v.iter().next().and(Some(0))`, which is an `Option`. This is more readably written as an `if let` statement.
|
||||
error: for loop over `v.iter().next().and(Some(0))`, which is an `Option`. This is more readably written as an `if let` statement
|
||||
--> $DIR/for_loops_over_fallibles.rs:29:14
|
||||
|
|
||||
LL | for x in v.iter().next().and(Some(0)) {
|
||||
|
|
@ -39,7 +39,7 @@ LL | for x in v.iter().next().and(Some(0)) {
|
|||
|
|
||||
= help: consider replacing `for x in v.iter().next().and(Some(0))` with `if let Some(x) = v.iter().next().and(Some(0))`
|
||||
|
||||
error: for loop over `v.iter().next().ok_or("x not found")`, which is a `Result`. This is more readably written as an `if let` statement.
|
||||
error: for loop over `v.iter().next().ok_or("x not found")`, which is a `Result`. This is more readably written as an `if let` statement
|
||||
--> $DIR/for_loops_over_fallibles.rs:33:14
|
||||
|
|
||||
LL | for x in v.iter().next().ok_or("x not found") {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
error: calls to `std::mem::forget` with a reference instead of an owned value. Forgetting a reference does nothing.
|
||||
error: calls to `std::mem::forget` with a reference instead of an owned value. Forgetting a reference does nothing
|
||||
--> $DIR/forget_ref.rs:10:5
|
||||
|
|
||||
LL | forget(&SomeStruct);
|
||||
|
|
@ -11,7 +11,7 @@ note: argument has type `&SomeStruct`
|
|||
LL | forget(&SomeStruct);
|
||||
| ^^^^^^^^^^^
|
||||
|
||||
error: calls to `std::mem::forget` with a reference instead of an owned value. Forgetting a reference does nothing.
|
||||
error: calls to `std::mem::forget` with a reference instead of an owned value. Forgetting a reference does nothing
|
||||
--> $DIR/forget_ref.rs:13:5
|
||||
|
|
||||
LL | forget(&owned);
|
||||
|
|
@ -23,7 +23,7 @@ note: argument has type `&SomeStruct`
|
|||
LL | forget(&owned);
|
||||
| ^^^^^^
|
||||
|
||||
error: calls to `std::mem::forget` with a reference instead of an owned value. Forgetting a reference does nothing.
|
||||
error: calls to `std::mem::forget` with a reference instead of an owned value. Forgetting a reference does nothing
|
||||
--> $DIR/forget_ref.rs:14:5
|
||||
|
|
||||
LL | forget(&&owned);
|
||||
|
|
@ -35,7 +35,7 @@ note: argument has type `&&SomeStruct`
|
|||
LL | forget(&&owned);
|
||||
| ^^^^^^^
|
||||
|
||||
error: calls to `std::mem::forget` with a reference instead of an owned value. Forgetting a reference does nothing.
|
||||
error: calls to `std::mem::forget` with a reference instead of an owned value. Forgetting a reference does nothing
|
||||
--> $DIR/forget_ref.rs:15:5
|
||||
|
|
||||
LL | forget(&mut owned);
|
||||
|
|
@ -47,7 +47,7 @@ note: argument has type `&mut SomeStruct`
|
|||
LL | forget(&mut owned);
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: calls to `std::mem::forget` with a reference instead of an owned value. Forgetting a reference does nothing.
|
||||
error: calls to `std::mem::forget` with a reference instead of an owned value. Forgetting a reference does nothing
|
||||
--> $DIR/forget_ref.rs:19:5
|
||||
|
|
||||
LL | forget(&*reference1);
|
||||
|
|
@ -59,7 +59,7 @@ note: argument has type `&SomeStruct`
|
|||
LL | forget(&*reference1);
|
||||
| ^^^^^^^^^^^^
|
||||
|
||||
error: calls to `std::mem::forget` with a reference instead of an owned value. Forgetting a reference does nothing.
|
||||
error: calls to `std::mem::forget` with a reference instead of an owned value. Forgetting a reference does nothing
|
||||
--> $DIR/forget_ref.rs:22:5
|
||||
|
|
||||
LL | forget(reference2);
|
||||
|
|
@ -71,7 +71,7 @@ note: argument has type `&mut SomeStruct`
|
|||
LL | forget(reference2);
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: calls to `std::mem::forget` with a reference instead of an owned value. Forgetting a reference does nothing.
|
||||
error: calls to `std::mem::forget` with a reference instead of an owned value. Forgetting a reference does nothing
|
||||
--> $DIR/forget_ref.rs:25:5
|
||||
|
|
||||
LL | forget(reference3);
|
||||
|
|
@ -83,7 +83,7 @@ note: argument has type `&SomeStruct`
|
|||
LL | forget(reference3);
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: calls to `std::mem::forget` with a reference instead of an owned value. Forgetting a reference does nothing.
|
||||
error: calls to `std::mem::forget` with a reference instead of an owned value. Forgetting a reference does nothing
|
||||
--> $DIR/forget_ref.rs:30:5
|
||||
|
|
||||
LL | forget(&val);
|
||||
|
|
@ -95,7 +95,7 @@ note: argument has type `&T`
|
|||
LL | forget(&val);
|
||||
| ^^^^
|
||||
|
||||
error: calls to `std::mem::forget` with a reference instead of an owned value. Forgetting a reference does nothing.
|
||||
error: calls to `std::mem::forget` with a reference instead of an owned value. Forgetting a reference does nothing
|
||||
--> $DIR/forget_ref.rs:38:5
|
||||
|
|
||||
LL | std::mem::forget(&SomeStruct);
|
||||
|
|
|
|||
|
|
@ -3,19 +3,11 @@
|
|||
#![warn(clippy::if_let_some_result)]
|
||||
|
||||
fn str_to_int(x: &str) -> i32 {
|
||||
if let Ok(y) = x.parse() {
|
||||
y
|
||||
} else {
|
||||
0
|
||||
}
|
||||
if let Ok(y) = x.parse() { y } else { 0 }
|
||||
}
|
||||
|
||||
fn str_to_int_ok(x: &str) -> i32 {
|
||||
if let Ok(y) = x.parse() {
|
||||
y
|
||||
} else {
|
||||
0
|
||||
}
|
||||
if let Ok(y) = x.parse() { y } else { 0 }
|
||||
}
|
||||
|
||||
#[rustfmt::skip]
|
||||
|
|
|
|||
|
|
@ -3,19 +3,11 @@
|
|||
#![warn(clippy::if_let_some_result)]
|
||||
|
||||
fn str_to_int(x: &str) -> i32 {
|
||||
if let Some(y) = x.parse().ok() {
|
||||
y
|
||||
} else {
|
||||
0
|
||||
}
|
||||
if let Some(y) = x.parse().ok() { y } else { 0 }
|
||||
}
|
||||
|
||||
fn str_to_int_ok(x: &str) -> i32 {
|
||||
if let Ok(y) = x.parse() {
|
||||
y
|
||||
} else {
|
||||
0
|
||||
}
|
||||
if let Ok(y) = x.parse() { y } else { 0 }
|
||||
}
|
||||
|
||||
#[rustfmt::skip]
|
||||
|
|
|
|||
|
|
@ -1,17 +1,17 @@
|
|||
error: matching on `Some` with `ok()` is redundant
|
||||
--> $DIR/if_let_some_result.rs:6:5
|
||||
|
|
||||
LL | if let Some(y) = x.parse().ok() {
|
||||
LL | if let Some(y) = x.parse().ok() { y } else { 0 }
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `-D clippy::if-let-some-result` implied by `-D warnings`
|
||||
help: consider matching on `Ok(y)` and removing the call to `ok` instead
|
||||
|
|
||||
LL | if let Ok(y) = x.parse() {
|
||||
LL | if let Ok(y) = x.parse() { y } else { 0 }
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: matching on `Some` with `ok()` is redundant
|
||||
--> $DIR/if_let_some_result.rs:24:9
|
||||
--> $DIR/if_let_some_result.rs:16:9
|
||||
|
|
||||
LL | if let Some(y) = x . parse() . ok () {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
|
|||
108
tests/ui/implicit_clone.rs
Normal file
108
tests/ui/implicit_clone.rs
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
#![warn(clippy::implicit_clone)]
|
||||
#![allow(clippy::redundant_clone)]
|
||||
use std::borrow::Borrow;
|
||||
use std::ffi::{OsStr, OsString};
|
||||
use std::path::PathBuf;
|
||||
|
||||
fn return_owned_from_slice(slice: &[u32]) -> Vec<u32> {
|
||||
slice.to_owned()
|
||||
}
|
||||
|
||||
pub fn own_same<T>(v: T) -> T
|
||||
where
|
||||
T: ToOwned<Owned = T>,
|
||||
{
|
||||
v.to_owned()
|
||||
}
|
||||
|
||||
pub fn own_same_from_ref<T>(v: &T) -> T
|
||||
where
|
||||
T: ToOwned<Owned = T>,
|
||||
{
|
||||
v.to_owned()
|
||||
}
|
||||
|
||||
pub fn own_different<T, U>(v: T) -> U
|
||||
where
|
||||
T: ToOwned<Owned = U>,
|
||||
{
|
||||
v.to_owned()
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
struct Kitten {}
|
||||
impl Kitten {
|
||||
// badly named method
|
||||
fn to_vec(self) -> Kitten {
|
||||
Kitten {}
|
||||
}
|
||||
}
|
||||
impl Borrow<BorrowedKitten> for Kitten {
|
||||
fn borrow(&self) -> &BorrowedKitten {
|
||||
static VALUE: BorrowedKitten = BorrowedKitten {};
|
||||
&VALUE
|
||||
}
|
||||
}
|
||||
|
||||
struct BorrowedKitten {}
|
||||
impl ToOwned for BorrowedKitten {
|
||||
type Owned = Kitten;
|
||||
fn to_owned(&self) -> Kitten {
|
||||
Kitten {}
|
||||
}
|
||||
}
|
||||
|
||||
mod weird {
|
||||
#[allow(clippy::ptr_arg)]
|
||||
pub fn to_vec(v: &Vec<u32>) -> Vec<u32> {
|
||||
v.clone()
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let vec = vec![5];
|
||||
let _ = return_owned_from_slice(&vec);
|
||||
let _ = vec.to_owned();
|
||||
let _ = vec.to_vec();
|
||||
|
||||
let vec_ref = &vec;
|
||||
let _ = return_owned_from_slice(&vec_ref);
|
||||
let _ = vec_ref.to_owned();
|
||||
let _ = vec_ref.to_vec();
|
||||
|
||||
// we expect no lint for this
|
||||
let _ = weird::to_vec(&vec);
|
||||
|
||||
// we expect no lints for this
|
||||
let slice: &[u32] = &[1, 2, 3, 4, 5];
|
||||
let _ = return_owned_from_slice(slice);
|
||||
let _ = slice.to_owned();
|
||||
let _ = slice.to_vec();
|
||||
|
||||
let str = "hello world".to_string();
|
||||
let _ = str.to_owned();
|
||||
|
||||
// testing w/ an arbitrary type
|
||||
let kitten = Kitten {};
|
||||
let _ = kitten.to_owned();
|
||||
let _ = own_same_from_ref(&kitten);
|
||||
// this shouln't lint
|
||||
let _ = kitten.to_vec();
|
||||
|
||||
// we expect no lints for this
|
||||
let borrowed = BorrowedKitten {};
|
||||
let _ = borrowed.to_owned();
|
||||
|
||||
let pathbuf = PathBuf::new();
|
||||
let _ = pathbuf.to_owned();
|
||||
let _ = pathbuf.to_path_buf();
|
||||
|
||||
let os_string = OsString::from("foo");
|
||||
let _ = os_string.to_owned();
|
||||
let _ = os_string.to_os_string();
|
||||
|
||||
// we expect no lints for this
|
||||
let os_str = OsStr::new("foo");
|
||||
let _ = os_str.to_owned();
|
||||
let _ = os_str.to_os_string();
|
||||
}
|
||||
64
tests/ui/implicit_clone.stderr
Normal file
64
tests/ui/implicit_clone.stderr
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
error: implicitly cloning a `Vec` by calling `to_owned` on its dereferenced type
|
||||
--> $DIR/implicit_clone.rs:65:17
|
||||
|
|
||||
LL | let _ = vec.to_owned();
|
||||
| ^^^^^^^^ help: consider using: `clone`
|
||||
|
|
||||
= note: `-D clippy::implicit-clone` implied by `-D warnings`
|
||||
|
||||
error: implicitly cloning a `Vec` by calling `to_vec` on its dereferenced type
|
||||
--> $DIR/implicit_clone.rs:66:17
|
||||
|
|
||||
LL | let _ = vec.to_vec();
|
||||
| ^^^^^^ help: consider using: `clone`
|
||||
|
||||
error: implicitly cloning a `Vec` by calling `to_owned` on its dereferenced type
|
||||
--> $DIR/implicit_clone.rs:70:21
|
||||
|
|
||||
LL | let _ = vec_ref.to_owned();
|
||||
| ^^^^^^^^ help: consider using: `clone`
|
||||
|
||||
error: implicitly cloning a `Vec` by calling `to_vec` on its dereferenced type
|
||||
--> $DIR/implicit_clone.rs:71:21
|
||||
|
|
||||
LL | let _ = vec_ref.to_vec();
|
||||
| ^^^^^^ help: consider using: `clone`
|
||||
|
||||
error: implicitly cloning a `String` by calling `to_owned` on its dereferenced type
|
||||
--> $DIR/implicit_clone.rs:83:17
|
||||
|
|
||||
LL | let _ = str.to_owned();
|
||||
| ^^^^^^^^ help: consider using: `clone`
|
||||
|
||||
error: implicitly cloning a `Kitten` by calling `to_owned` on its dereferenced type
|
||||
--> $DIR/implicit_clone.rs:87:20
|
||||
|
|
||||
LL | let _ = kitten.to_owned();
|
||||
| ^^^^^^^^ help: consider using: `clone`
|
||||
|
||||
error: implicitly cloning a `PathBuf` by calling `to_owned` on its dereferenced type
|
||||
--> $DIR/implicit_clone.rs:97:21
|
||||
|
|
||||
LL | let _ = pathbuf.to_owned();
|
||||
| ^^^^^^^^ help: consider using: `clone`
|
||||
|
||||
error: implicitly cloning a `PathBuf` by calling `to_path_buf` on its dereferenced type
|
||||
--> $DIR/implicit_clone.rs:98:21
|
||||
|
|
||||
LL | let _ = pathbuf.to_path_buf();
|
||||
| ^^^^^^^^^^^ help: consider using: `clone`
|
||||
|
||||
error: implicitly cloning a `OsString` by calling `to_owned` on its dereferenced type
|
||||
--> $DIR/implicit_clone.rs:101:23
|
||||
|
|
||||
LL | let _ = os_string.to_owned();
|
||||
| ^^^^^^^^ help: consider using: `clone`
|
||||
|
||||
error: implicitly cloning a `OsString` by calling `to_os_string` on its dereferenced type
|
||||
--> $DIR/implicit_clone.rs:102:23
|
||||
|
|
||||
LL | let _ = os_string.to_os_string();
|
||||
| ^^^^^^^^^^^^ help: consider using: `clone`
|
||||
|
||||
error: aborting due to 10 previous errors
|
||||
|
||||
|
|
@ -14,11 +14,7 @@ fn test_end_of_fn() -> bool {
|
|||
|
||||
#[allow(clippy::needless_bool)]
|
||||
fn test_if_block() -> bool {
|
||||
if true {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
if true { return true } else { return false }
|
||||
}
|
||||
|
||||
#[rustfmt::skip]
|
||||
|
|
|
|||
|
|
@ -14,11 +14,7 @@ fn test_end_of_fn() -> bool {
|
|||
|
||||
#[allow(clippy::needless_bool)]
|
||||
fn test_if_block() -> bool {
|
||||
if true {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
if true { true } else { false }
|
||||
}
|
||||
|
||||
#[rustfmt::skip]
|
||||
|
|
|
|||
|
|
@ -7,61 +7,61 @@ LL | true
|
|||
= note: `-D clippy::implicit-return` implied by `-D warnings`
|
||||
|
||||
error: missing `return` statement
|
||||
--> $DIR/implicit_return.rs:18:9
|
||||
--> $DIR/implicit_return.rs:17:15
|
||||
|
|
||||
LL | true
|
||||
| ^^^^ help: add `return` as shown: `return true`
|
||||
LL | if true { true } else { false }
|
||||
| ^^^^ help: add `return` as shown: `return true`
|
||||
|
||||
error: missing `return` statement
|
||||
--> $DIR/implicit_return.rs:20:9
|
||||
--> $DIR/implicit_return.rs:17:29
|
||||
|
|
||||
LL | false
|
||||
| ^^^^^ help: add `return` as shown: `return false`
|
||||
LL | if true { true } else { false }
|
||||
| ^^^^^ help: add `return` as shown: `return false`
|
||||
|
||||
error: missing `return` statement
|
||||
--> $DIR/implicit_return.rs:27:17
|
||||
--> $DIR/implicit_return.rs:23:17
|
||||
|
|
||||
LL | true => false,
|
||||
| ^^^^^ help: add `return` as shown: `return false`
|
||||
|
||||
error: missing `return` statement
|
||||
--> $DIR/implicit_return.rs:28:20
|
||||
--> $DIR/implicit_return.rs:24:20
|
||||
|
|
||||
LL | false => { true },
|
||||
| ^^^^ help: add `return` as shown: `return true`
|
||||
|
||||
error: missing `return` statement
|
||||
--> $DIR/implicit_return.rs:43:9
|
||||
--> $DIR/implicit_return.rs:39:9
|
||||
|
|
||||
LL | break true;
|
||||
| ^^^^^^^^^^ help: change `break` to `return` as shown: `return true`
|
||||
|
||||
error: missing `return` statement
|
||||
--> $DIR/implicit_return.rs:51:13
|
||||
--> $DIR/implicit_return.rs:47:13
|
||||
|
|
||||
LL | break true;
|
||||
| ^^^^^^^^^^ help: change `break` to `return` as shown: `return true`
|
||||
|
||||
error: missing `return` statement
|
||||
--> $DIR/implicit_return.rs:60:13
|
||||
--> $DIR/implicit_return.rs:56:13
|
||||
|
|
||||
LL | break true;
|
||||
| ^^^^^^^^^^ help: change `break` to `return` as shown: `return true`
|
||||
|
||||
error: missing `return` statement
|
||||
--> $DIR/implicit_return.rs:78:18
|
||||
--> $DIR/implicit_return.rs:74:18
|
||||
|
|
||||
LL | let _ = || { true };
|
||||
| ^^^^ help: add `return` as shown: `return true`
|
||||
|
||||
error: missing `return` statement
|
||||
--> $DIR/implicit_return.rs:79:16
|
||||
--> $DIR/implicit_return.rs:75:16
|
||||
|
|
||||
LL | let _ = || true;
|
||||
| ^^^^ help: add `return` as shown: `return true`
|
||||
|
||||
error: missing `return` statement
|
||||
--> $DIR/implicit_return.rs:87:5
|
||||
--> $DIR/implicit_return.rs:83:5
|
||||
|
|
||||
LL | format!("test {}", "test")
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add `return` as shown: `return format!("test {}", "test")`
|
||||
|
|
|
|||
|
|
@ -1,51 +1,51 @@
|
|||
error: indexing may panic.
|
||||
error: indexing may panic
|
||||
--> $DIR/indexing_slicing_index.rs:10:5
|
||||
|
|
||||
LL | x[index];
|
||||
| ^^^^^^^^
|
||||
|
|
||||
= note: `-D clippy::indexing-slicing` implied by `-D warnings`
|
||||
= help: Consider using `.get(n)` or `.get_mut(n)` instead
|
||||
= help: consider using `.get(n)` or `.get_mut(n)` instead
|
||||
|
||||
error: indexing may panic.
|
||||
error: indexing may panic
|
||||
--> $DIR/indexing_slicing_index.rs:22:5
|
||||
|
|
||||
LL | v[0];
|
||||
| ^^^^
|
||||
|
|
||||
= help: Consider using `.get(n)` or `.get_mut(n)` instead
|
||||
= help: consider using `.get(n)` or `.get_mut(n)` instead
|
||||
|
||||
error: indexing may panic.
|
||||
error: indexing may panic
|
||||
--> $DIR/indexing_slicing_index.rs:23:5
|
||||
|
|
||||
LL | v[10];
|
||||
| ^^^^^
|
||||
|
|
||||
= help: Consider using `.get(n)` or `.get_mut(n)` instead
|
||||
= help: consider using `.get(n)` or `.get_mut(n)` instead
|
||||
|
||||
error: indexing may panic.
|
||||
error: indexing may panic
|
||||
--> $DIR/indexing_slicing_index.rs:24:5
|
||||
|
|
||||
LL | v[1 << 3];
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= help: Consider using `.get(n)` or `.get_mut(n)` instead
|
||||
= help: consider using `.get(n)` or `.get_mut(n)` instead
|
||||
|
||||
error: indexing may panic.
|
||||
error: indexing may panic
|
||||
--> $DIR/indexing_slicing_index.rs:30:5
|
||||
|
|
||||
LL | v[N];
|
||||
| ^^^^
|
||||
|
|
||||
= help: Consider using `.get(n)` or `.get_mut(n)` instead
|
||||
= help: consider using `.get(n)` or `.get_mut(n)` instead
|
||||
|
||||
error: indexing may panic.
|
||||
error: indexing may panic
|
||||
--> $DIR/indexing_slicing_index.rs:31:5
|
||||
|
|
||||
LL | v[M];
|
||||
| ^^^^
|
||||
|
|
||||
= help: Consider using `.get(n)` or `.get_mut(n)` instead
|
||||
= help: consider using `.get(n)` or `.get_mut(n)` instead
|
||||
|
||||
error: aborting due to 6 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -1,51 +1,51 @@
|
|||
error: slicing may panic.
|
||||
error: slicing may panic
|
||||
--> $DIR/indexing_slicing_slice.rs:12:6
|
||||
|
|
||||
LL | &x[index..];
|
||||
| ^^^^^^^^^^
|
||||
|
|
||||
= note: `-D clippy::indexing-slicing` implied by `-D warnings`
|
||||
= help: Consider using `.get(n..)` or .get_mut(n..)` instead
|
||||
= help: consider using `.get(n..)` or .get_mut(n..)` instead
|
||||
|
||||
error: slicing may panic.
|
||||
error: slicing may panic
|
||||
--> $DIR/indexing_slicing_slice.rs:13:6
|
||||
|
|
||||
LL | &x[..index];
|
||||
| ^^^^^^^^^^
|
||||
|
|
||||
= help: Consider using `.get(..n)`or `.get_mut(..n)` instead
|
||||
= help: consider using `.get(..n)`or `.get_mut(..n)` instead
|
||||
|
||||
error: slicing may panic.
|
||||
error: slicing may panic
|
||||
--> $DIR/indexing_slicing_slice.rs:14:6
|
||||
|
|
||||
LL | &x[index_from..index_to];
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: Consider using `.get(n..m)` or `.get_mut(n..m)` instead
|
||||
= help: consider using `.get(n..m)` or `.get_mut(n..m)` instead
|
||||
|
||||
error: slicing may panic.
|
||||
error: slicing may panic
|
||||
--> $DIR/indexing_slicing_slice.rs:15:6
|
||||
|
|
||||
LL | &x[index_from..][..index_to]; // Two lint reports, one for [index_from..] and another for [..index_to].
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: Consider using `.get(..n)`or `.get_mut(..n)` instead
|
||||
= help: consider using `.get(..n)`or `.get_mut(..n)` instead
|
||||
|
||||
error: slicing may panic.
|
||||
error: slicing may panic
|
||||
--> $DIR/indexing_slicing_slice.rs:15:6
|
||||
|
|
||||
LL | &x[index_from..][..index_to]; // Two lint reports, one for [index_from..] and another for [..index_to].
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: Consider using `.get(n..)` or .get_mut(n..)` instead
|
||||
= help: consider using `.get(n..)` or .get_mut(n..)` instead
|
||||
|
||||
error: slicing may panic.
|
||||
error: slicing may panic
|
||||
--> $DIR/indexing_slicing_slice.rs:16:6
|
||||
|
|
||||
LL | &x[5..][..10]; // Two lint reports, one for out of bounds [5..] and another for slicing [..10].
|
||||
| ^^^^^^^^^^^^
|
||||
|
|
||||
= help: Consider using `.get(..n)`or `.get_mut(..n)` instead
|
||||
= help: consider using `.get(..n)`or `.get_mut(..n)` instead
|
||||
|
||||
error: range is out of bounds
|
||||
--> $DIR/indexing_slicing_slice.rs:16:8
|
||||
|
|
@ -55,21 +55,21 @@ LL | &x[5..][..10]; // Two lint reports, one for out of bounds [5..] and ano
|
|||
|
|
||||
= note: `-D clippy::out-of-bounds-indexing` implied by `-D warnings`
|
||||
|
||||
error: slicing may panic.
|
||||
error: slicing may panic
|
||||
--> $DIR/indexing_slicing_slice.rs:17:6
|
||||
|
|
||||
LL | &x[0..][..3];
|
||||
| ^^^^^^^^^^^
|
||||
|
|
||||
= help: Consider using `.get(..n)`or `.get_mut(..n)` instead
|
||||
= help: consider using `.get(..n)`or `.get_mut(..n)` instead
|
||||
|
||||
error: slicing may panic.
|
||||
error: slicing may panic
|
||||
--> $DIR/indexing_slicing_slice.rs:18:6
|
||||
|
|
||||
LL | &x[1..][..5];
|
||||
| ^^^^^^^^^^^
|
||||
|
|
||||
= help: Consider using `.get(..n)`or `.get_mut(..n)` instead
|
||||
= help: consider using `.get(..n)`or `.get_mut(..n)` instead
|
||||
|
||||
error: range is out of bounds
|
||||
--> $DIR/indexing_slicing_slice.rs:25:12
|
||||
|
|
@ -83,21 +83,21 @@ error: range is out of bounds
|
|||
LL | &y[..=4];
|
||||
| ^
|
||||
|
||||
error: slicing may panic.
|
||||
error: slicing may panic
|
||||
--> $DIR/indexing_slicing_slice.rs:31:6
|
||||
|
|
||||
LL | &v[10..100];
|
||||
| ^^^^^^^^^^
|
||||
|
|
||||
= help: Consider using `.get(n..m)` or `.get_mut(n..m)` instead
|
||||
= help: consider using `.get(n..m)` or `.get_mut(n..m)` instead
|
||||
|
||||
error: slicing may panic.
|
||||
error: slicing may panic
|
||||
--> $DIR/indexing_slicing_slice.rs:32:6
|
||||
|
|
||||
LL | &x[10..][..100]; // Two lint reports, one for [10..] and another for [..100].
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: Consider using `.get(..n)`or `.get_mut(..n)` instead
|
||||
= help: consider using `.get(..n)`or `.get_mut(..n)` instead
|
||||
|
||||
error: range is out of bounds
|
||||
--> $DIR/indexing_slicing_slice.rs:32:8
|
||||
|
|
@ -105,21 +105,21 @@ error: range is out of bounds
|
|||
LL | &x[10..][..100]; // Two lint reports, one for [10..] and another for [..100].
|
||||
| ^^
|
||||
|
||||
error: slicing may panic.
|
||||
error: slicing may panic
|
||||
--> $DIR/indexing_slicing_slice.rs:33:6
|
||||
|
|
||||
LL | &v[10..];
|
||||
| ^^^^^^^
|
||||
|
|
||||
= help: Consider using `.get(n..)` or .get_mut(n..)` instead
|
||||
= help: consider using `.get(n..)` or .get_mut(n..)` instead
|
||||
|
||||
error: slicing may panic.
|
||||
error: slicing may panic
|
||||
--> $DIR/indexing_slicing_slice.rs:34:6
|
||||
|
|
||||
LL | &v[..100];
|
||||
| ^^^^^^^^
|
||||
|
|
||||
= help: Consider using `.get(..n)`or `.get_mut(..n)` instead
|
||||
= help: consider using `.get(..n)`or `.get_mut(..n)` instead
|
||||
|
||||
error: aborting due to 16 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ LL | let n = 1 / 2;
|
|||
| ^^^^^
|
||||
|
|
||||
= note: `-D clippy::integer-division` implied by `-D warnings`
|
||||
= help: division of integers may cause loss of precision. consider using floats.
|
||||
= help: division of integers may cause loss of precision. consider using floats
|
||||
|
||||
error: integer division
|
||||
--> $DIR/integer_division.rs:6:13
|
||||
|
|
@ -13,7 +13,7 @@ error: integer division
|
|||
LL | let o = 1 / two;
|
||||
| ^^^^^^^
|
||||
|
|
||||
= help: division of integers may cause loss of precision. consider using floats.
|
||||
= help: division of integers may cause loss of precision. consider using floats
|
||||
|
||||
error: integer division
|
||||
--> $DIR/integer_division.rs:7:13
|
||||
|
|
@ -21,7 +21,7 @@ error: integer division
|
|||
LL | let p = two / 4;
|
||||
| ^^^^^^^
|
||||
|
|
||||
= help: division of integers may cause loss of precision. consider using floats.
|
||||
= help: division of integers may cause loss of precision. consider using floats
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
|
|
|||
86
tests/ui/iter_count.fixed
Normal file
86
tests/ui/iter_count.fixed
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
// run-rustfix
|
||||
// aux-build:option_helpers.rs
|
||||
|
||||
#![warn(clippy::iter_count)]
|
||||
#![allow(
|
||||
unused_variables,
|
||||
array_into_iter,
|
||||
unused_mut,
|
||||
clippy::into_iter_on_ref,
|
||||
clippy::unnecessary_operation
|
||||
)]
|
||||
|
||||
extern crate option_helpers;
|
||||
|
||||
use option_helpers::IteratorFalsePositives;
|
||||
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, LinkedList, VecDeque};
|
||||
|
||||
/// Struct to generate false positives for things with `.iter()`.
|
||||
#[derive(Copy, Clone)]
|
||||
struct HasIter;
|
||||
|
||||
impl HasIter {
|
||||
fn iter(self) -> IteratorFalsePositives {
|
||||
IteratorFalsePositives { foo: 0 }
|
||||
}
|
||||
|
||||
fn iter_mut(self) -> IteratorFalsePositives {
|
||||
IteratorFalsePositives { foo: 0 }
|
||||
}
|
||||
|
||||
fn into_iter(self) -> IteratorFalsePositives {
|
||||
IteratorFalsePositives { foo: 0 }
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut vec = vec![0, 1, 2, 3];
|
||||
let mut boxed_slice: Box<[u8]> = Box::new([0, 1, 2, 3]);
|
||||
let mut vec_deque: VecDeque<_> = vec.iter().cloned().collect();
|
||||
let mut hash_set = HashSet::new();
|
||||
let mut hash_map = HashMap::new();
|
||||
let mut b_tree_map = BTreeMap::new();
|
||||
let mut b_tree_set = BTreeSet::new();
|
||||
let mut linked_list = LinkedList::new();
|
||||
let mut binary_heap = BinaryHeap::new();
|
||||
hash_set.insert(1);
|
||||
hash_map.insert(1, 2);
|
||||
b_tree_map.insert(1, 2);
|
||||
b_tree_set.insert(1);
|
||||
linked_list.push_back(1);
|
||||
binary_heap.push(1);
|
||||
|
||||
&vec[..].len();
|
||||
vec.len();
|
||||
boxed_slice.len();
|
||||
vec_deque.len();
|
||||
hash_set.len();
|
||||
hash_map.len();
|
||||
b_tree_map.len();
|
||||
b_tree_set.len();
|
||||
linked_list.len();
|
||||
binary_heap.len();
|
||||
|
||||
vec.len();
|
||||
&vec[..].len();
|
||||
vec_deque.len();
|
||||
hash_map.len();
|
||||
b_tree_map.len();
|
||||
linked_list.len();
|
||||
|
||||
&vec[..].len();
|
||||
vec.len();
|
||||
vec_deque.len();
|
||||
hash_set.len();
|
||||
hash_map.len();
|
||||
b_tree_map.len();
|
||||
b_tree_set.len();
|
||||
linked_list.len();
|
||||
binary_heap.len();
|
||||
|
||||
// Make sure we don't lint for non-relevant types.
|
||||
let false_positive = HasIter;
|
||||
false_positive.iter().count();
|
||||
false_positive.iter_mut().count();
|
||||
false_positive.into_iter().count();
|
||||
}
|
||||
86
tests/ui/iter_count.rs
Normal file
86
tests/ui/iter_count.rs
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
// run-rustfix
|
||||
// aux-build:option_helpers.rs
|
||||
|
||||
#![warn(clippy::iter_count)]
|
||||
#![allow(
|
||||
unused_variables,
|
||||
array_into_iter,
|
||||
unused_mut,
|
||||
clippy::into_iter_on_ref,
|
||||
clippy::unnecessary_operation
|
||||
)]
|
||||
|
||||
extern crate option_helpers;
|
||||
|
||||
use option_helpers::IteratorFalsePositives;
|
||||
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, LinkedList, VecDeque};
|
||||
|
||||
/// Struct to generate false positives for things with `.iter()`.
|
||||
#[derive(Copy, Clone)]
|
||||
struct HasIter;
|
||||
|
||||
impl HasIter {
|
||||
fn iter(self) -> IteratorFalsePositives {
|
||||
IteratorFalsePositives { foo: 0 }
|
||||
}
|
||||
|
||||
fn iter_mut(self) -> IteratorFalsePositives {
|
||||
IteratorFalsePositives { foo: 0 }
|
||||
}
|
||||
|
||||
fn into_iter(self) -> IteratorFalsePositives {
|
||||
IteratorFalsePositives { foo: 0 }
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut vec = vec![0, 1, 2, 3];
|
||||
let mut boxed_slice: Box<[u8]> = Box::new([0, 1, 2, 3]);
|
||||
let mut vec_deque: VecDeque<_> = vec.iter().cloned().collect();
|
||||
let mut hash_set = HashSet::new();
|
||||
let mut hash_map = HashMap::new();
|
||||
let mut b_tree_map = BTreeMap::new();
|
||||
let mut b_tree_set = BTreeSet::new();
|
||||
let mut linked_list = LinkedList::new();
|
||||
let mut binary_heap = BinaryHeap::new();
|
||||
hash_set.insert(1);
|
||||
hash_map.insert(1, 2);
|
||||
b_tree_map.insert(1, 2);
|
||||
b_tree_set.insert(1);
|
||||
linked_list.push_back(1);
|
||||
binary_heap.push(1);
|
||||
|
||||
&vec[..].iter().count();
|
||||
vec.iter().count();
|
||||
boxed_slice.iter().count();
|
||||
vec_deque.iter().count();
|
||||
hash_set.iter().count();
|
||||
hash_map.iter().count();
|
||||
b_tree_map.iter().count();
|
||||
b_tree_set.iter().count();
|
||||
linked_list.iter().count();
|
||||
binary_heap.iter().count();
|
||||
|
||||
vec.iter_mut().count();
|
||||
&vec[..].iter_mut().count();
|
||||
vec_deque.iter_mut().count();
|
||||
hash_map.iter_mut().count();
|
||||
b_tree_map.iter_mut().count();
|
||||
linked_list.iter_mut().count();
|
||||
|
||||
&vec[..].into_iter().count();
|
||||
vec.into_iter().count();
|
||||
vec_deque.into_iter().count();
|
||||
hash_set.into_iter().count();
|
||||
hash_map.into_iter().count();
|
||||
b_tree_map.into_iter().count();
|
||||
b_tree_set.into_iter().count();
|
||||
linked_list.into_iter().count();
|
||||
binary_heap.into_iter().count();
|
||||
|
||||
// Make sure we don't lint for non-relevant types.
|
||||
let false_positive = HasIter;
|
||||
false_positive.iter().count();
|
||||
false_positive.iter_mut().count();
|
||||
false_positive.into_iter().count();
|
||||
}
|
||||
154
tests/ui/iter_count.stderr
Normal file
154
tests/ui/iter_count.stderr
Normal file
|
|
@ -0,0 +1,154 @@
|
|||
error: called `.iter().count()` on a `slice`
|
||||
--> $DIR/iter_count.rs:53:6
|
||||
|
|
||||
LL | &vec[..].iter().count();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec[..].len()`
|
||||
|
|
||||
= note: `-D clippy::iter-count` implied by `-D warnings`
|
||||
|
||||
error: called `.iter().count()` on a `Vec`
|
||||
--> $DIR/iter_count.rs:54:5
|
||||
|
|
||||
LL | vec.iter().count();
|
||||
| ^^^^^^^^^^^^^^^^^^ help: try: `vec.len()`
|
||||
|
||||
error: called `.iter().count()` on a `slice`
|
||||
--> $DIR/iter_count.rs:55:5
|
||||
|
|
||||
LL | boxed_slice.iter().count();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `boxed_slice.len()`
|
||||
|
||||
error: called `.iter().count()` on a `VecDeque`
|
||||
--> $DIR/iter_count.rs:56:5
|
||||
|
|
||||
LL | vec_deque.iter().count();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec_deque.len()`
|
||||
|
||||
error: called `.iter().count()` on a `HashSet`
|
||||
--> $DIR/iter_count.rs:57:5
|
||||
|
|
||||
LL | hash_set.iter().count();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `hash_set.len()`
|
||||
|
||||
error: called `.iter().count()` on a `HashMap`
|
||||
--> $DIR/iter_count.rs:58:5
|
||||
|
|
||||
LL | hash_map.iter().count();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `hash_map.len()`
|
||||
|
||||
error: called `.iter().count()` on a `BTreeMap`
|
||||
--> $DIR/iter_count.rs:59:5
|
||||
|
|
||||
LL | b_tree_map.iter().count();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b_tree_map.len()`
|
||||
|
||||
error: called `.iter().count()` on a `BTreeSet`
|
||||
--> $DIR/iter_count.rs:60:5
|
||||
|
|
||||
LL | b_tree_set.iter().count();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b_tree_set.len()`
|
||||
|
||||
error: called `.iter().count()` on a `LinkedList`
|
||||
--> $DIR/iter_count.rs:61:5
|
||||
|
|
||||
LL | linked_list.iter().count();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `linked_list.len()`
|
||||
|
||||
error: called `.iter().count()` on a `BinaryHeap`
|
||||
--> $DIR/iter_count.rs:62:5
|
||||
|
|
||||
LL | binary_heap.iter().count();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `binary_heap.len()`
|
||||
|
||||
error: called `.iter_mut().count()` on a `Vec`
|
||||
--> $DIR/iter_count.rs:64:5
|
||||
|
|
||||
LL | vec.iter_mut().count();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec.len()`
|
||||
|
||||
error: called `.iter_mut().count()` on a `slice`
|
||||
--> $DIR/iter_count.rs:65:6
|
||||
|
|
||||
LL | &vec[..].iter_mut().count();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec[..].len()`
|
||||
|
||||
error: called `.iter_mut().count()` on a `VecDeque`
|
||||
--> $DIR/iter_count.rs:66:5
|
||||
|
|
||||
LL | vec_deque.iter_mut().count();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec_deque.len()`
|
||||
|
||||
error: called `.iter_mut().count()` on a `HashMap`
|
||||
--> $DIR/iter_count.rs:67:5
|
||||
|
|
||||
LL | hash_map.iter_mut().count();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `hash_map.len()`
|
||||
|
||||
error: called `.iter_mut().count()` on a `BTreeMap`
|
||||
--> $DIR/iter_count.rs:68:5
|
||||
|
|
||||
LL | b_tree_map.iter_mut().count();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b_tree_map.len()`
|
||||
|
||||
error: called `.iter_mut().count()` on a `LinkedList`
|
||||
--> $DIR/iter_count.rs:69:5
|
||||
|
|
||||
LL | linked_list.iter_mut().count();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `linked_list.len()`
|
||||
|
||||
error: called `.into_iter().count()` on a `slice`
|
||||
--> $DIR/iter_count.rs:71:6
|
||||
|
|
||||
LL | &vec[..].into_iter().count();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec[..].len()`
|
||||
|
||||
error: called `.into_iter().count()` on a `Vec`
|
||||
--> $DIR/iter_count.rs:72:5
|
||||
|
|
||||
LL | vec.into_iter().count();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec.len()`
|
||||
|
||||
error: called `.into_iter().count()` on a `VecDeque`
|
||||
--> $DIR/iter_count.rs:73:5
|
||||
|
|
||||
LL | vec_deque.into_iter().count();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec_deque.len()`
|
||||
|
||||
error: called `.into_iter().count()` on a `HashSet`
|
||||
--> $DIR/iter_count.rs:74:5
|
||||
|
|
||||
LL | hash_set.into_iter().count();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `hash_set.len()`
|
||||
|
||||
error: called `.into_iter().count()` on a `HashMap`
|
||||
--> $DIR/iter_count.rs:75:5
|
||||
|
|
||||
LL | hash_map.into_iter().count();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `hash_map.len()`
|
||||
|
||||
error: called `.into_iter().count()` on a `BTreeMap`
|
||||
--> $DIR/iter_count.rs:76:5
|
||||
|
|
||||
LL | b_tree_map.into_iter().count();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b_tree_map.len()`
|
||||
|
||||
error: called `.into_iter().count()` on a `BTreeSet`
|
||||
--> $DIR/iter_count.rs:77:5
|
||||
|
|
||||
LL | b_tree_set.into_iter().count();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b_tree_set.len()`
|
||||
|
||||
error: called `.into_iter().count()` on a `LinkedList`
|
||||
--> $DIR/iter_count.rs:78:5
|
||||
|
|
||||
LL | linked_list.into_iter().count();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `linked_list.len()`
|
||||
|
||||
error: called `.into_iter().count()` on a `BinaryHeap`
|
||||
--> $DIR/iter_count.rs:79:5
|
||||
|
|
||||
LL | binary_heap.into_iter().count();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `binary_heap.len()`
|
||||
|
||||
error: aborting due to 25 previous errors
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
error: Iterator::step_by(0) will panic at runtime
|
||||
error: `Iterator::step_by(0)` will panic at runtime
|
||||
--> $DIR/iterator_step_by_zero.rs:3:13
|
||||
|
|
||||
LL | let _ = vec!["A", "B", "B"].iter().step_by(0);
|
||||
|
|
@ -6,37 +6,37 @@ LL | let _ = vec!["A", "B", "B"].iter().step_by(0);
|
|||
|
|
||||
= note: `-D clippy::iterator-step-by-zero` implied by `-D warnings`
|
||||
|
||||
error: Iterator::step_by(0) will panic at runtime
|
||||
error: `Iterator::step_by(0)` will panic at runtime
|
||||
--> $DIR/iterator_step_by_zero.rs:4:13
|
||||
|
|
||||
LL | let _ = "XXX".chars().step_by(0);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: Iterator::step_by(0) will panic at runtime
|
||||
error: `Iterator::step_by(0)` will panic at runtime
|
||||
--> $DIR/iterator_step_by_zero.rs:5:13
|
||||
|
|
||||
LL | let _ = (0..1).step_by(0);
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: Iterator::step_by(0) will panic at runtime
|
||||
error: `Iterator::step_by(0)` will panic at runtime
|
||||
--> $DIR/iterator_step_by_zero.rs:14:13
|
||||
|
|
||||
LL | let _ = (1..).step_by(0);
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
||||
error: Iterator::step_by(0) will panic at runtime
|
||||
error: `Iterator::step_by(0)` will panic at runtime
|
||||
--> $DIR/iterator_step_by_zero.rs:15:13
|
||||
|
|
||||
LL | let _ = (1..=2).step_by(0);
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: Iterator::step_by(0) will panic at runtime
|
||||
error: `Iterator::step_by(0)` will panic at runtime
|
||||
--> $DIR/iterator_step_by_zero.rs:18:13
|
||||
|
|
||||
LL | let _ = x.step_by(0);
|
||||
| ^^^^^^^^^^^^
|
||||
|
||||
error: Iterator::step_by(0) will panic at runtime
|
||||
error: `Iterator::step_by(0)` will panic at runtime
|
||||
--> $DIR/iterator_step_by_zero.rs:22:13
|
||||
|
|
||||
LL | let _ = v1.iter().step_by(2 / 3);
|
||||
|
|
|
|||
|
|
@ -34,6 +34,24 @@ impl PubAllowed {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct PubAllowedFn;
|
||||
|
||||
impl PubAllowedFn {
|
||||
#[allow(clippy::len_without_is_empty)]
|
||||
pub fn len(&self) -> isize {
|
||||
1
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::len_without_is_empty)]
|
||||
pub struct PubAllowedStruct;
|
||||
|
||||
impl PubAllowedStruct {
|
||||
pub fn len(&self) -> isize {
|
||||
1
|
||||
}
|
||||
}
|
||||
|
||||
pub trait PubTraitsToo {
|
||||
fn len(&self) -> isize;
|
||||
}
|
||||
|
|
@ -68,6 +86,18 @@ impl HasWrongIsEmpty {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct MismatchedSelf;
|
||||
|
||||
impl MismatchedSelf {
|
||||
pub fn len(self) -> isize {
|
||||
1
|
||||
}
|
||||
|
||||
pub fn is_empty(&self) -> bool {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
struct NotPubOne;
|
||||
|
||||
impl NotPubOne {
|
||||
|
|
@ -142,4 +172,19 @@ pub trait DependsOnFoo: Foo {
|
|||
fn len(&mut self) -> usize;
|
||||
}
|
||||
|
||||
pub struct MultipleImpls;
|
||||
|
||||
// issue #1562
|
||||
impl MultipleImpls {
|
||||
pub fn len(&self) -> usize {
|
||||
1
|
||||
}
|
||||
}
|
||||
|
||||
impl MultipleImpls {
|
||||
pub fn is_empty(&self) -> bool {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -1,54 +1,64 @@
|
|||
error: item `PubOne` has a public `len` method but no corresponding `is_empty` method
|
||||
--> $DIR/len_without_is_empty.rs:6:1
|
||||
error: struct `PubOne` has a public `len` method, but no `is_empty` method
|
||||
--> $DIR/len_without_is_empty.rs:7:5
|
||||
|
|
||||
LL | / impl PubOne {
|
||||
LL | | pub fn len(&self) -> isize {
|
||||
LL | | 1
|
||||
LL | | }
|
||||
LL | | }
|
||||
| |_^
|
||||
LL | pub fn len(&self) -> isize {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `-D clippy::len-without-is-empty` implied by `-D warnings`
|
||||
|
||||
error: trait `PubTraitsToo` has a `len` method but no (possibly inherited) `is_empty` method
|
||||
--> $DIR/len_without_is_empty.rs:37:1
|
||||
--> $DIR/len_without_is_empty.rs:55:1
|
||||
|
|
||||
LL | / pub trait PubTraitsToo {
|
||||
LL | | fn len(&self) -> isize;
|
||||
LL | | }
|
||||
| |_^
|
||||
|
||||
error: item `HasIsEmpty` has a public `len` method but a private `is_empty` method
|
||||
--> $DIR/len_without_is_empty.rs:49:1
|
||||
error: struct `HasIsEmpty` has a public `len` method, but a private `is_empty` method
|
||||
--> $DIR/len_without_is_empty.rs:68:5
|
||||
|
|
||||
LL | / impl HasIsEmpty {
|
||||
LL | | pub fn len(&self) -> isize {
|
||||
LL | | 1
|
||||
LL | | }
|
||||
... |
|
||||
LL | | }
|
||||
LL | | }
|
||||
| |_^
|
||||
LL | pub fn len(&self) -> isize {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: `is_empty` defined here
|
||||
--> $DIR/len_without_is_empty.rs:72:5
|
||||
|
|
||||
LL | fn is_empty(&self) -> bool {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: item `HasWrongIsEmpty` has a public `len` method but no corresponding `is_empty` method
|
||||
--> $DIR/len_without_is_empty.rs:61:1
|
||||
error: struct `HasWrongIsEmpty` has a public `len` method, but the `is_empty` method has an unexpected signature
|
||||
--> $DIR/len_without_is_empty.rs:80:5
|
||||
|
|
||||
LL | / impl HasWrongIsEmpty {
|
||||
LL | | pub fn len(&self) -> isize {
|
||||
LL | | 1
|
||||
LL | | }
|
||||
... |
|
||||
LL | | }
|
||||
LL | | }
|
||||
| |_^
|
||||
LL | pub fn len(&self) -> isize {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: `is_empty` defined here
|
||||
--> $DIR/len_without_is_empty.rs:84:5
|
||||
|
|
||||
LL | pub fn is_empty(&self, x: u32) -> bool {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
= note: expected signature: `(&self) -> bool`
|
||||
|
||||
error: struct `MismatchedSelf` has a public `len` method, but the `is_empty` method has an unexpected signature
|
||||
--> $DIR/len_without_is_empty.rs:92:5
|
||||
|
|
||||
LL | pub fn len(self) -> isize {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: `is_empty` defined here
|
||||
--> $DIR/len_without_is_empty.rs:96:5
|
||||
|
|
||||
LL | pub fn is_empty(&self) -> bool {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
= note: expected signature: `(self) -> bool`
|
||||
|
||||
error: trait `DependsOnFoo` has a `len` method but no (possibly inherited) `is_empty` method
|
||||
--> $DIR/len_without_is_empty.rs:141:1
|
||||
--> $DIR/len_without_is_empty.rs:171:1
|
||||
|
|
||||
LL | / pub trait DependsOnFoo: Foo {
|
||||
LL | | fn len(&mut self) -> usize;
|
||||
LL | | }
|
||||
| |_^
|
||||
|
||||
error: aborting due to 5 previous errors
|
||||
error: aborting due to 6 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,14 @@
|
|||
// edition:2018
|
||||
// run-rustfix
|
||||
|
||||
#![warn(clippy::manual_map)]
|
||||
#![allow(clippy::no_effect, clippy::map_identity, clippy::unit_arg, clippy::match_ref_pats)]
|
||||
#![allow(
|
||||
clippy::no_effect,
|
||||
clippy::map_identity,
|
||||
clippy::unit_arg,
|
||||
clippy::match_ref_pats,
|
||||
dead_code
|
||||
)]
|
||||
|
||||
fn main() {
|
||||
Some(0).map(|_| 2);
|
||||
|
|
@ -67,4 +74,58 @@ fn main() {
|
|||
Some(Some((x, 1))) => Some(x),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
// #6795
|
||||
fn f1() -> Result<(), ()> {
|
||||
let _ = match Some(Ok(())) {
|
||||
Some(x) => Some(x?),
|
||||
None => None,
|
||||
};
|
||||
Ok(())
|
||||
}
|
||||
|
||||
for &x in Some(Some(true)).iter() {
|
||||
let _ = match x {
|
||||
Some(x) => Some(if x { continue } else { x }),
|
||||
None => None,
|
||||
};
|
||||
}
|
||||
|
||||
// #6797
|
||||
let x1 = (Some(String::new()), 0);
|
||||
let x2 = x1.0;
|
||||
match x2 {
|
||||
Some(x) => Some((x, x1.1)),
|
||||
None => None,
|
||||
};
|
||||
|
||||
struct S1 {
|
||||
x: Option<String>,
|
||||
y: u32,
|
||||
}
|
||||
impl S1 {
|
||||
fn f(self) -> Option<(String, u32)> {
|
||||
match self.x {
|
||||
Some(x) => Some((x, self.y)),
|
||||
None => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// #6811
|
||||
Some(0).map(|x| vec![x]);
|
||||
|
||||
option_env!("").map(String::from);
|
||||
|
||||
// #6819
|
||||
async fn f2(x: u32) -> u32 {
|
||||
x
|
||||
}
|
||||
|
||||
async fn f3() {
|
||||
match Some(0) {
|
||||
Some(x) => Some(f2(x).await),
|
||||
None => None,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,14 @@
|
|||
// edition:2018
|
||||
// run-rustfix
|
||||
|
||||
#![warn(clippy::manual_map)]
|
||||
#![allow(clippy::no_effect, clippy::map_identity, clippy::unit_arg, clippy::match_ref_pats)]
|
||||
#![allow(
|
||||
clippy::no_effect,
|
||||
clippy::map_identity,
|
||||
clippy::unit_arg,
|
||||
clippy::match_ref_pats,
|
||||
dead_code
|
||||
)]
|
||||
|
||||
fn main() {
|
||||
match Some(0) {
|
||||
|
|
@ -119,4 +126,64 @@ fn main() {
|
|||
Some(Some((x, 1))) => Some(x),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
// #6795
|
||||
fn f1() -> Result<(), ()> {
|
||||
let _ = match Some(Ok(())) {
|
||||
Some(x) => Some(x?),
|
||||
None => None,
|
||||
};
|
||||
Ok(())
|
||||
}
|
||||
|
||||
for &x in Some(Some(true)).iter() {
|
||||
let _ = match x {
|
||||
Some(x) => Some(if x { continue } else { x }),
|
||||
None => None,
|
||||
};
|
||||
}
|
||||
|
||||
// #6797
|
||||
let x1 = (Some(String::new()), 0);
|
||||
let x2 = x1.0;
|
||||
match x2 {
|
||||
Some(x) => Some((x, x1.1)),
|
||||
None => None,
|
||||
};
|
||||
|
||||
struct S1 {
|
||||
x: Option<String>,
|
||||
y: u32,
|
||||
}
|
||||
impl S1 {
|
||||
fn f(self) -> Option<(String, u32)> {
|
||||
match self.x {
|
||||
Some(x) => Some((x, self.y)),
|
||||
None => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// #6811
|
||||
match Some(0) {
|
||||
Some(x) => Some(vec![x]),
|
||||
None => None,
|
||||
};
|
||||
|
||||
match option_env!("") {
|
||||
Some(x) => Some(String::from(x)),
|
||||
None => None,
|
||||
};
|
||||
|
||||
// #6819
|
||||
async fn f2(x: u32) -> u32 {
|
||||
x
|
||||
}
|
||||
|
||||
async fn f3() {
|
||||
match Some(0) {
|
||||
Some(x) => Some(f2(x).await),
|
||||
None => None,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
error: manual implementation of `Option::map`
|
||||
--> $DIR/manual_map_option.rs:7:5
|
||||
--> $DIR/manual_map_option.rs:14:5
|
||||
|
|
||||
LL | / match Some(0) {
|
||||
LL | | Some(_) => Some(2),
|
||||
|
|
@ -10,7 +10,7 @@ LL | | };
|
|||
= note: `-D clippy::manual-map` implied by `-D warnings`
|
||||
|
||||
error: manual implementation of `Option::map`
|
||||
--> $DIR/manual_map_option.rs:12:5
|
||||
--> $DIR/manual_map_option.rs:19:5
|
||||
|
|
||||
LL | / match Some(0) {
|
||||
LL | | Some(x) => Some(x + 1),
|
||||
|
|
@ -19,7 +19,7 @@ LL | | };
|
|||
| |_____^ help: try this: `Some(0).map(|x| x + 1)`
|
||||
|
||||
error: manual implementation of `Option::map`
|
||||
--> $DIR/manual_map_option.rs:17:5
|
||||
--> $DIR/manual_map_option.rs:24:5
|
||||
|
|
||||
LL | / match Some("") {
|
||||
LL | | Some(x) => Some(x.is_empty()),
|
||||
|
|
@ -28,7 +28,7 @@ LL | | };
|
|||
| |_____^ help: try this: `Some("").map(|x| x.is_empty())`
|
||||
|
||||
error: manual implementation of `Option::map`
|
||||
--> $DIR/manual_map_option.rs:22:5
|
||||
--> $DIR/manual_map_option.rs:29:5
|
||||
|
|
||||
LL | / if let Some(x) = Some(0) {
|
||||
LL | | Some(!x)
|
||||
|
|
@ -38,7 +38,7 @@ LL | | };
|
|||
| |_____^ help: try this: `Some(0).map(|x| !x)`
|
||||
|
||||
error: manual implementation of `Option::map`
|
||||
--> $DIR/manual_map_option.rs:29:5
|
||||
--> $DIR/manual_map_option.rs:36:5
|
||||
|
|
||||
LL | / match Some(0) {
|
||||
LL | | Some(x) => { Some(std::convert::identity(x)) }
|
||||
|
|
@ -47,7 +47,7 @@ LL | | };
|
|||
| |_____^ help: try this: `Some(0).map(std::convert::identity)`
|
||||
|
||||
error: manual implementation of `Option::map`
|
||||
--> $DIR/manual_map_option.rs:34:5
|
||||
--> $DIR/manual_map_option.rs:41:5
|
||||
|
|
||||
LL | / match Some(&String::new()) {
|
||||
LL | | Some(x) => Some(str::len(x)),
|
||||
|
|
@ -56,7 +56,7 @@ LL | | };
|
|||
| |_____^ help: try this: `Some(&String::new()).map(|x| str::len(x))`
|
||||
|
||||
error: manual implementation of `Option::map`
|
||||
--> $DIR/manual_map_option.rs:44:5
|
||||
--> $DIR/manual_map_option.rs:51:5
|
||||
|
|
||||
LL | / match &Some([0, 1]) {
|
||||
LL | | Some(x) => Some(x[0]),
|
||||
|
|
@ -65,7 +65,7 @@ LL | | };
|
|||
| |_____^ help: try this: `Some([0, 1]).as_ref().map(|x| x[0])`
|
||||
|
||||
error: manual implementation of `Option::map`
|
||||
--> $DIR/manual_map_option.rs:49:5
|
||||
--> $DIR/manual_map_option.rs:56:5
|
||||
|
|
||||
LL | / match &Some(0) {
|
||||
LL | | &Some(x) => Some(x * 2),
|
||||
|
|
@ -74,7 +74,7 @@ LL | | };
|
|||
| |_____^ help: try this: `Some(0).map(|x| x * 2)`
|
||||
|
||||
error: manual implementation of `Option::map`
|
||||
--> $DIR/manual_map_option.rs:54:5
|
||||
--> $DIR/manual_map_option.rs:61:5
|
||||
|
|
||||
LL | / match Some(String::new()) {
|
||||
LL | | Some(ref x) => Some(x.is_empty()),
|
||||
|
|
@ -83,7 +83,7 @@ LL | | };
|
|||
| |_____^ help: try this: `Some(String::new()).as_ref().map(|x| x.is_empty())`
|
||||
|
||||
error: manual implementation of `Option::map`
|
||||
--> $DIR/manual_map_option.rs:59:5
|
||||
--> $DIR/manual_map_option.rs:66:5
|
||||
|
|
||||
LL | / match &&Some(String::new()) {
|
||||
LL | | Some(x) => Some(x.len()),
|
||||
|
|
@ -92,7 +92,7 @@ LL | | };
|
|||
| |_____^ help: try this: `Some(String::new()).as_ref().map(|x| x.len())`
|
||||
|
||||
error: manual implementation of `Option::map`
|
||||
--> $DIR/manual_map_option.rs:64:5
|
||||
--> $DIR/manual_map_option.rs:71:5
|
||||
|
|
||||
LL | / match &&Some(0) {
|
||||
LL | | &&Some(x) => Some(x + x),
|
||||
|
|
@ -101,7 +101,7 @@ LL | | };
|
|||
| |_____^ help: try this: `Some(0).map(|x| x + x)`
|
||||
|
||||
error: manual implementation of `Option::map`
|
||||
--> $DIR/manual_map_option.rs:77:9
|
||||
--> $DIR/manual_map_option.rs:84:9
|
||||
|
|
||||
LL | / match &mut Some(String::new()) {
|
||||
LL | | Some(x) => Some(x.push_str("")),
|
||||
|
|
@ -110,7 +110,7 @@ LL | | };
|
|||
| |_________^ help: try this: `Some(String::new()).as_mut().map(|x| x.push_str(""))`
|
||||
|
||||
error: manual implementation of `Option::map`
|
||||
--> $DIR/manual_map_option.rs:83:5
|
||||
--> $DIR/manual_map_option.rs:90:5
|
||||
|
|
||||
LL | / match &mut Some(String::new()) {
|
||||
LL | | Some(ref x) => Some(x.len()),
|
||||
|
|
@ -119,7 +119,7 @@ LL | | };
|
|||
| |_____^ help: try this: `Some(String::new()).as_ref().map(|x| x.len())`
|
||||
|
||||
error: manual implementation of `Option::map`
|
||||
--> $DIR/manual_map_option.rs:88:5
|
||||
--> $DIR/manual_map_option.rs:95:5
|
||||
|
|
||||
LL | / match &mut &Some(String::new()) {
|
||||
LL | | Some(x) => Some(x.is_empty()),
|
||||
|
|
@ -128,7 +128,7 @@ LL | | };
|
|||
| |_____^ help: try this: `Some(String::new()).as_ref().map(|x| x.is_empty())`
|
||||
|
||||
error: manual implementation of `Option::map`
|
||||
--> $DIR/manual_map_option.rs:93:5
|
||||
--> $DIR/manual_map_option.rs:100:5
|
||||
|
|
||||
LL | / match Some((0, 1, 2)) {
|
||||
LL | | Some((x, y, z)) => Some(x + y + z),
|
||||
|
|
@ -137,7 +137,7 @@ LL | | };
|
|||
| |_____^ help: try this: `Some((0, 1, 2)).map(|(x, y, z)| x + y + z)`
|
||||
|
||||
error: manual implementation of `Option::map`
|
||||
--> $DIR/manual_map_option.rs:98:5
|
||||
--> $DIR/manual_map_option.rs:105:5
|
||||
|
|
||||
LL | / match Some([1, 2, 3]) {
|
||||
LL | | Some([first, ..]) => Some(first),
|
||||
|
|
@ -146,7 +146,7 @@ LL | | };
|
|||
| |_____^ help: try this: `Some([1, 2, 3]).map(|[first, ..]| first)`
|
||||
|
||||
error: manual implementation of `Option::map`
|
||||
--> $DIR/manual_map_option.rs:103:5
|
||||
--> $DIR/manual_map_option.rs:110:5
|
||||
|
|
||||
LL | / match &Some((String::new(), "test")) {
|
||||
LL | | Some((x, y)) => Some((y, x)),
|
||||
|
|
@ -154,5 +154,23 @@ LL | | None => None,
|
|||
LL | | };
|
||||
| |_____^ help: try this: `Some((String::new(), "test")).as_ref().map(|(x, y)| (y, x))`
|
||||
|
||||
error: aborting due to 17 previous errors
|
||||
error: manual implementation of `Option::map`
|
||||
--> $DIR/manual_map_option.rs:168:5
|
||||
|
|
||||
LL | / match Some(0) {
|
||||
LL | | Some(x) => Some(vec![x]),
|
||||
LL | | None => None,
|
||||
LL | | };
|
||||
| |_____^ help: try this: `Some(0).map(|x| vec![x])`
|
||||
|
||||
error: manual implementation of `Option::map`
|
||||
--> $DIR/manual_map_option.rs:173:5
|
||||
|
|
||||
LL | / match option_env!("") {
|
||||
LL | | Some(x) => Some(String::from(x)),
|
||||
LL | | None => None,
|
||||
LL | | };
|
||||
| |_____^ help: try this: `option_env!("").map(String::from)`
|
||||
|
||||
error: aborting due to 19 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -120,6 +120,35 @@ fn match_same_arms() {
|
|||
},
|
||||
}
|
||||
|
||||
// False positive #1390
|
||||
macro_rules! empty {
|
||||
($e:expr) => {};
|
||||
}
|
||||
match 0 {
|
||||
0 => {
|
||||
empty!(0);
|
||||
},
|
||||
1 => {
|
||||
empty!(1);
|
||||
},
|
||||
x => {
|
||||
empty!(x);
|
||||
},
|
||||
};
|
||||
|
||||
// still lint if the tokens are the same
|
||||
match 0 {
|
||||
0 => {
|
||||
empty!(0);
|
||||
},
|
||||
1 => {
|
||||
empty!(0);
|
||||
},
|
||||
x => {
|
||||
empty!(x);
|
||||
},
|
||||
}
|
||||
|
||||
match_expr_like_matches_macro_priority();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -141,8 +141,31 @@ LL | Ok(3) => println!("ok"),
|
|||
| ^^^^^
|
||||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error: this `match` has identical arm bodies
|
||||
--> $DIR/match_same_arms2.rs:144:14
|
||||
|
|
||||
LL | 1 => {
|
||||
| ______________^
|
||||
LL | | empty!(0);
|
||||
LL | | },
|
||||
| |_________^
|
||||
|
|
||||
note: same as this
|
||||
--> $DIR/match_same_arms2.rs:141:14
|
||||
|
|
||||
LL | 0 => {
|
||||
| ______________^
|
||||
LL | | empty!(0);
|
||||
LL | | },
|
||||
| |_________^
|
||||
help: consider refactoring into `0 | 1`
|
||||
--> $DIR/match_same_arms2.rs:141:9
|
||||
|
|
||||
LL | 0 => {
|
||||
| ^
|
||||
|
||||
error: match expression looks like `matches!` macro
|
||||
--> $DIR/match_same_arms2.rs:133:16
|
||||
--> $DIR/match_same_arms2.rs:162:16
|
||||
|
|
||||
LL | let _ans = match x {
|
||||
| ________________^
|
||||
|
|
@ -154,5 +177,5 @@ LL | | };
|
|||
|
|
||||
= note: `-D clippy::match-like-matches-macro` implied by `-D warnings`
|
||||
|
||||
error: aborting due to 8 previous errors
|
||||
error: aborting due to 9 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ LL | | }
|
|||
|
|
||||
= note: `-D clippy::new-ret-no-self` implied by `-D warnings`
|
||||
|
||||
error: called `filter(..).next()` on an `Iterator`. This is more succinctly expressed by calling `.find(..)` instead.
|
||||
error: called `filter(..).next()` on an `Iterator`. This is more succinctly expressed by calling `.find(..)` instead
|
||||
--> $DIR/methods.rs:126:13
|
||||
|
|
||||
LL | let _ = v.iter().filter(|&x| {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
error: called `filter(..).next()` on an `Iterator`. This is more succinctly expressed by calling `.find(..)` instead.
|
||||
error: called `filter(..).next()` on an `Iterator`. This is more succinctly expressed by calling `.find(..)` instead
|
||||
--> $DIR/methods_fixable.rs:10:13
|
||||
|
|
||||
LL | let _ = v.iter().filter(|&x| *x < 0).next();
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ LL | #[cfg(linux)]
|
|||
| help: try: `target_os = "linux"`
|
||||
|
|
||||
= note: `-D clippy::mismatched-target-os` implied by `-D warnings`
|
||||
= help: Did you mean `unix`?
|
||||
= help: did you mean `unix`?
|
||||
|
||||
error: operating system used in target family position
|
||||
--> $DIR/mismatched_target_os_unix.rs:9:1
|
||||
|
|
@ -17,7 +17,7 @@ LL | #[cfg(freebsd)]
|
|||
| |
|
||||
| help: try: `target_os = "freebsd"`
|
||||
|
|
||||
= help: Did you mean `unix`?
|
||||
= help: did you mean `unix`?
|
||||
|
||||
error: operating system used in target family position
|
||||
--> $DIR/mismatched_target_os_unix.rs:12:1
|
||||
|
|
@ -27,7 +27,7 @@ LL | #[cfg(dragonfly)]
|
|||
| |
|
||||
| help: try: `target_os = "dragonfly"`
|
||||
|
|
||||
= help: Did you mean `unix`?
|
||||
= help: did you mean `unix`?
|
||||
|
||||
error: operating system used in target family position
|
||||
--> $DIR/mismatched_target_os_unix.rs:15:1
|
||||
|
|
@ -37,7 +37,7 @@ LL | #[cfg(openbsd)]
|
|||
| |
|
||||
| help: try: `target_os = "openbsd"`
|
||||
|
|
||||
= help: Did you mean `unix`?
|
||||
= help: did you mean `unix`?
|
||||
|
||||
error: operating system used in target family position
|
||||
--> $DIR/mismatched_target_os_unix.rs:18:1
|
||||
|
|
@ -47,7 +47,7 @@ LL | #[cfg(netbsd)]
|
|||
| |
|
||||
| help: try: `target_os = "netbsd"`
|
||||
|
|
||||
= help: Did you mean `unix`?
|
||||
= help: did you mean `unix`?
|
||||
|
||||
error: operating system used in target family position
|
||||
--> $DIR/mismatched_target_os_unix.rs:21:1
|
||||
|
|
@ -57,7 +57,7 @@ LL | #[cfg(macos)]
|
|||
| |
|
||||
| help: try: `target_os = "macos"`
|
||||
|
|
||||
= help: Did you mean `unix`?
|
||||
= help: did you mean `unix`?
|
||||
|
||||
error: operating system used in target family position
|
||||
--> $DIR/mismatched_target_os_unix.rs:24:1
|
||||
|
|
@ -67,7 +67,7 @@ LL | #[cfg(ios)]
|
|||
| |
|
||||
| help: try: `target_os = "ios"`
|
||||
|
|
||||
= help: Did you mean `unix`?
|
||||
= help: did you mean `unix`?
|
||||
|
||||
error: operating system used in target family position
|
||||
--> $DIR/mismatched_target_os_unix.rs:27:1
|
||||
|
|
@ -77,7 +77,7 @@ LL | #[cfg(android)]
|
|||
| |
|
||||
| help: try: `target_os = "android"`
|
||||
|
|
||||
= help: Did you mean `unix`?
|
||||
= help: did you mean `unix`?
|
||||
|
||||
error: operating system used in target family position
|
||||
--> $DIR/mismatched_target_os_unix.rs:30:1
|
||||
|
|
@ -87,7 +87,7 @@ LL | #[cfg(emscripten)]
|
|||
| |
|
||||
| help: try: `target_os = "emscripten"`
|
||||
|
|
||||
= help: Did you mean `unix`?
|
||||
= help: did you mean `unix`?
|
||||
|
||||
error: operating system used in target family position
|
||||
--> $DIR/mismatched_target_os_unix.rs:33:1
|
||||
|
|
@ -97,7 +97,7 @@ LL | #[cfg(fuchsia)]
|
|||
| |
|
||||
| help: try: `target_os = "fuchsia"`
|
||||
|
|
||||
= help: Did you mean `unix`?
|
||||
= help: did you mean `unix`?
|
||||
|
||||
error: operating system used in target family position
|
||||
--> $DIR/mismatched_target_os_unix.rs:36:1
|
||||
|
|
@ -107,7 +107,7 @@ LL | #[cfg(haiku)]
|
|||
| |
|
||||
| help: try: `target_os = "haiku"`
|
||||
|
|
||||
= help: Did you mean `unix`?
|
||||
= help: did you mean `unix`?
|
||||
|
||||
error: operating system used in target family position
|
||||
--> $DIR/mismatched_target_os_unix.rs:39:1
|
||||
|
|
@ -117,7 +117,7 @@ LL | #[cfg(illumos)]
|
|||
| |
|
||||
| help: try: `target_os = "illumos"`
|
||||
|
|
||||
= help: Did you mean `unix`?
|
||||
= help: did you mean `unix`?
|
||||
|
||||
error: operating system used in target family position
|
||||
--> $DIR/mismatched_target_os_unix.rs:42:1
|
||||
|
|
@ -127,7 +127,7 @@ LL | #[cfg(l4re)]
|
|||
| |
|
||||
| help: try: `target_os = "l4re"`
|
||||
|
|
||||
= help: Did you mean `unix`?
|
||||
= help: did you mean `unix`?
|
||||
|
||||
error: operating system used in target family position
|
||||
--> $DIR/mismatched_target_os_unix.rs:45:1
|
||||
|
|
@ -137,7 +137,7 @@ LL | #[cfg(redox)]
|
|||
| |
|
||||
| help: try: `target_os = "redox"`
|
||||
|
|
||||
= help: Did you mean `unix`?
|
||||
= help: did you mean `unix`?
|
||||
|
||||
error: operating system used in target family position
|
||||
--> $DIR/mismatched_target_os_unix.rs:48:1
|
||||
|
|
@ -147,7 +147,7 @@ LL | #[cfg(solaris)]
|
|||
| |
|
||||
| help: try: `target_os = "solaris"`
|
||||
|
|
||||
= help: Did you mean `unix`?
|
||||
= help: did you mean `unix`?
|
||||
|
||||
error: operating system used in target family position
|
||||
--> $DIR/mismatched_target_os_unix.rs:51:1
|
||||
|
|
@ -157,7 +157,7 @@ LL | #[cfg(vxworks)]
|
|||
| |
|
||||
| help: try: `target_os = "vxworks"`
|
||||
|
|
||||
= help: Did you mean `unix`?
|
||||
= help: did you mean `unix`?
|
||||
|
||||
error: operating system used in target family position
|
||||
--> $DIR/mismatched_target_os_unix.rs:55:1
|
||||
|
|
@ -165,7 +165,7 @@ error: operating system used in target family position
|
|||
LL | #[cfg(all(not(any(solaris, linux)), freebsd))]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: Did you mean `unix`?
|
||||
= help: did you mean `unix`?
|
||||
help: try
|
||||
|
|
||||
LL | #[cfg(all(not(any(target_os = "solaris", linux)), freebsd))]
|
||||
|
|
|
|||
5
tests/ui/missing_inline_executable.rs
Normal file
5
tests/ui/missing_inline_executable.rs
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
#![warn(clippy::missing_inline_in_public_items)]
|
||||
|
||||
pub fn foo() {}
|
||||
|
||||
fn main() {}
|
||||
23
tests/ui/missing_inline_proc_macro.rs
Normal file
23
tests/ui/missing_inline_proc_macro.rs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
#![warn(clippy::missing_inline_in_public_items)]
|
||||
#![crate_type = "proc-macro"]
|
||||
|
||||
extern crate proc_macro;
|
||||
|
||||
use proc_macro::TokenStream;
|
||||
|
||||
fn _foo() {}
|
||||
|
||||
#[proc_macro]
|
||||
pub fn function_like(_: TokenStream) -> TokenStream {
|
||||
TokenStream::new()
|
||||
}
|
||||
|
||||
#[proc_macro_attribute]
|
||||
pub fn attribute(_: TokenStream, _: TokenStream) -> TokenStream {
|
||||
TokenStream::new()
|
||||
}
|
||||
|
||||
#[proc_macro_derive(Derive)]
|
||||
pub fn derive(_: TokenStream) -> TokenStream {
|
||||
TokenStream::new()
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
// run-rustfix
|
||||
|
||||
#![allow(unused, clippy::suspicious_map)]
|
||||
#![allow(unused, clippy::suspicious_map, clippy::iter_count)]
|
||||
|
||||
use std::collections::{BTreeSet, HashMap, HashSet};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
// run-rustfix
|
||||
|
||||
#![allow(unused, clippy::suspicious_map)]
|
||||
#![allow(unused, clippy::suspicious_map, clippy::iter_count)]
|
||||
|
||||
use std::collections::{BTreeSet, HashMap, HashSet};
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ LL | | indirect_iter.into_iter().map(|x| (x, x + 1)).collect::<HashMap<_, _>
|
|||
| |____^
|
||||
|
|
||||
= note: `-D clippy::needless-collect` implied by `-D warnings`
|
||||
help: Use the original Iterator instead of collecting it and then producing a new one
|
||||
help: use the original Iterator instead of collecting it and then producing a new one
|
||||
|
|
||||
LL |
|
||||
LL | sample.iter().map(|x| (x, x + 1)).collect::<HashMap<_, _>>();
|
||||
|
|
@ -19,7 +19,7 @@ LL | / let indirect_len = sample.iter().collect::<VecDeque<_>>();
|
|||
LL | | indirect_len.len();
|
||||
| |____^
|
||||
|
|
||||
help: Take the original Iterator's count instead of collecting it and finding the length
|
||||
help: take the original Iterator's count instead of collecting it and finding the length
|
||||
|
|
||||
LL |
|
||||
LL | sample.iter().count();
|
||||
|
|
@ -32,7 +32,7 @@ LL | / let indirect_empty = sample.iter().collect::<VecDeque<_>>();
|
|||
LL | | indirect_empty.is_empty();
|
||||
| |____^
|
||||
|
|
||||
help: Check if the original Iterator has anything instead of collecting it and seeing if it's empty
|
||||
help: check if the original Iterator has anything instead of collecting it and seeing if it's empty
|
||||
|
|
||||
LL |
|
||||
LL | sample.iter().next().is_none();
|
||||
|
|
@ -45,7 +45,7 @@ LL | / let indirect_contains = sample.iter().collect::<VecDeque<_>>();
|
|||
LL | | indirect_contains.contains(&&5);
|
||||
| |____^
|
||||
|
|
||||
help: Check if the original Iterator contains an element instead of collecting then checking
|
||||
help: check if the original Iterator contains an element instead of collecting then checking
|
||||
|
|
||||
LL |
|
||||
LL | sample.iter().any(|x| x == &5);
|
||||
|
|
@ -58,7 +58,7 @@ LL | / let non_copy_contains = sample.into_iter().collect::<Vec<_>>();
|
|||
LL | | non_copy_contains.contains(&a);
|
||||
| |____^
|
||||
|
|
||||
help: Check if the original Iterator contains an element instead of collecting then checking
|
||||
help: check if the original Iterator contains an element instead of collecting then checking
|
||||
|
|
||||
LL |
|
||||
LL | sample.into_iter().any(|x| x == a);
|
||||
|
|
|
|||
|
|
@ -105,11 +105,7 @@ fn fn_bound_3_cannot_elide() {
|
|||
|
||||
// No error; multiple input refs.
|
||||
fn fn_bound_4<'a, F: FnOnce() -> &'a ()>(cond: bool, x: &'a (), f: F) -> &'a () {
|
||||
if cond {
|
||||
x
|
||||
} else {
|
||||
f()
|
||||
}
|
||||
if cond { x } else { f() }
|
||||
}
|
||||
|
||||
struct X {
|
||||
|
|
|
|||
|
|
@ -43,109 +43,109 @@ LL | fn fn_bound_2<'a, F, I>(_m: Lt<'a, I>, _f: F) -> Lt<'a, I>
|
|||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
|
||||
--> $DIR/needless_lifetimes.rs:120:5
|
||||
--> $DIR/needless_lifetimes.rs:116:5
|
||||
|
|
||||
LL | fn self_and_out<'s>(&'s self) -> &'s u8 {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
|
||||
--> $DIR/needless_lifetimes.rs:129:5
|
||||
--> $DIR/needless_lifetimes.rs:125:5
|
||||
|
|
||||
LL | fn distinct_self_and_in<'s, 't>(&'s self, _x: &'t u8) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
|
||||
--> $DIR/needless_lifetimes.rs:148:1
|
||||
--> $DIR/needless_lifetimes.rs:144:1
|
||||
|
|
||||
LL | fn struct_with_lt<'a>(_foo: Foo<'a>) -> &'a str {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
|
||||
--> $DIR/needless_lifetimes.rs:178:1
|
||||
--> $DIR/needless_lifetimes.rs:174:1
|
||||
|
|
||||
LL | fn trait_obj_elided2<'a>(_arg: &'a dyn Drop) -> &'a str {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
|
||||
--> $DIR/needless_lifetimes.rs:184:1
|
||||
--> $DIR/needless_lifetimes.rs:180:1
|
||||
|
|
||||
LL | fn alias_with_lt<'a>(_foo: FooAlias<'a>) -> &'a str {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
|
||||
--> $DIR/needless_lifetimes.rs:203:1
|
||||
--> $DIR/needless_lifetimes.rs:199:1
|
||||
|
|
||||
LL | fn named_input_elided_output<'a>(_arg: &'a str) -> &str {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
|
||||
--> $DIR/needless_lifetimes.rs:211:1
|
||||
--> $DIR/needless_lifetimes.rs:207:1
|
||||
|
|
||||
LL | fn trait_bound_ok<'a, T: WithLifetime<'static>>(_: &'a u8, _: T) {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
|
||||
--> $DIR/needless_lifetimes.rs:247:1
|
||||
--> $DIR/needless_lifetimes.rs:243:1
|
||||
|
|
||||
LL | fn out_return_type_lts<'a>(e: &'a str) -> Cow<'a> {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
|
||||
--> $DIR/needless_lifetimes.rs:254:9
|
||||
--> $DIR/needless_lifetimes.rs:250:9
|
||||
|
|
||||
LL | fn needless_lt<'a>(x: &'a u8) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
|
||||
--> $DIR/needless_lifetimes.rs:258:9
|
||||
--> $DIR/needless_lifetimes.rs:254:9
|
||||
|
|
||||
LL | fn needless_lt<'a>(_x: &'a u8) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
|
||||
--> $DIR/needless_lifetimes.rs:271:9
|
||||
--> $DIR/needless_lifetimes.rs:267:9
|
||||
|
|
||||
LL | fn baz<'a>(&'a self) -> impl Foo + 'a {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
|
||||
--> $DIR/needless_lifetimes.rs:300:5
|
||||
--> $DIR/needless_lifetimes.rs:296:5
|
||||
|
|
||||
LL | fn impl_trait_elidable_nested_named_lifetimes<'a>(i: &'a i32, f: impl for<'b> Fn(&'b i32) -> &'b i32) -> &'a i32 {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
|
||||
--> $DIR/needless_lifetimes.rs:303:5
|
||||
--> $DIR/needless_lifetimes.rs:299:5
|
||||
|
|
||||
LL | fn impl_trait_elidable_nested_anonymous_lifetimes<'a>(i: &'a i32, f: impl Fn(&i32) -> &i32) -> &'a i32 {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
|
||||
--> $DIR/needless_lifetimes.rs:312:5
|
||||
--> $DIR/needless_lifetimes.rs:308:5
|
||||
|
|
||||
LL | fn generics_elidable<'a, T: Fn(&i32) -> &i32>(i: &'a i32, f: T) -> &'a i32 {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
|
||||
--> $DIR/needless_lifetimes.rs:324:5
|
||||
--> $DIR/needless_lifetimes.rs:320:5
|
||||
|
|
||||
LL | fn where_clause_elidadable<'a, T>(i: &'a i32, f: T) -> &'a i32
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
|
||||
--> $DIR/needless_lifetimes.rs:339:5
|
||||
--> $DIR/needless_lifetimes.rs:335:5
|
||||
|
|
||||
LL | fn pointer_fn_elidable<'a>(i: &'a i32, f: fn(&i32) -> &i32) -> &'a i32 {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
|
||||
--> $DIR/needless_lifetimes.rs:352:5
|
||||
--> $DIR/needless_lifetimes.rs:348:5
|
||||
|
|
||||
LL | fn nested_fn_pointer_3<'a>(_: &'a i32) -> fn(fn(&i32) -> &i32) -> i32 {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
|
||||
--> $DIR/needless_lifetimes.rs:355:5
|
||||
--> $DIR/needless_lifetimes.rs:351:5
|
||||
|
|
||||
LL | fn nested_fn_pointer_4<'a>(_: &'a i32) -> impl Fn(fn(&i32)) {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
error: Question mark operator is useless here
|
||||
error: question mark operator is useless here
|
||||
--> $DIR/needless_question_mark.rs:23:12
|
||||
|
|
||||
LL | return Some(to.magic?);
|
||||
|
|
@ -6,79 +6,79 @@ LL | return Some(to.magic?);
|
|||
|
|
||||
= note: `-D clippy::needless-question-mark` implied by `-D warnings`
|
||||
|
||||
error: Question mark operator is useless here
|
||||
error: question mark operator is useless here
|
||||
--> $DIR/needless_question_mark.rs:31:12
|
||||
|
|
||||
LL | return Some(to.magic?)
|
||||
| ^^^^^^^^^^^^^^^ help: try: `to.magic`
|
||||
|
||||
error: Question mark operator is useless here
|
||||
error: question mark operator is useless here
|
||||
--> $DIR/needless_question_mark.rs:36:5
|
||||
|
|
||||
LL | Some(to.magic?)
|
||||
| ^^^^^^^^^^^^^^^ help: try: `to.magic`
|
||||
|
||||
error: Question mark operator is useless here
|
||||
error: question mark operator is useless here
|
||||
--> $DIR/needless_question_mark.rs:41:21
|
||||
|
|
||||
LL | to.and_then(|t| Some(t.magic?))
|
||||
| ^^^^^^^^^^^^^^ help: try: `t.magic`
|
||||
|
||||
error: Question mark operator is useless here
|
||||
error: question mark operator is useless here
|
||||
--> $DIR/needless_question_mark.rs:50:9
|
||||
|
|
||||
LL | Some(t.magic?)
|
||||
| ^^^^^^^^^^^^^^ help: try: `t.magic`
|
||||
|
||||
error: Question mark operator is useless here
|
||||
error: question mark operator is useless here
|
||||
--> $DIR/needless_question_mark.rs:55:12
|
||||
|
|
||||
LL | return Ok(tr.magic?);
|
||||
| ^^^^^^^^^^^^^ help: try: `tr.magic`
|
||||
|
||||
error: Question mark operator is useless here
|
||||
error: question mark operator is useless here
|
||||
--> $DIR/needless_question_mark.rs:62:12
|
||||
|
|
||||
LL | return Ok(tr.magic?)
|
||||
| ^^^^^^^^^^^^^ help: try: `tr.magic`
|
||||
|
||||
error: Question mark operator is useless here
|
||||
error: question mark operator is useless here
|
||||
--> $DIR/needless_question_mark.rs:66:5
|
||||
|
|
||||
LL | Ok(tr.magic?)
|
||||
| ^^^^^^^^^^^^^ help: try: `tr.magic`
|
||||
|
||||
error: Question mark operator is useless here
|
||||
error: question mark operator is useless here
|
||||
--> $DIR/needless_question_mark.rs:70:21
|
||||
|
|
||||
LL | tr.and_then(|t| Ok(t.magic?))
|
||||
| ^^^^^^^^^^^^ help: try: `t.magic`
|
||||
|
||||
error: Question mark operator is useless here
|
||||
error: question mark operator is useless here
|
||||
--> $DIR/needless_question_mark.rs:78:9
|
||||
|
|
||||
LL | Ok(t.magic?)
|
||||
| ^^^^^^^^^^^^ help: try: `t.magic`
|
||||
|
||||
error: Question mark operator is useless here
|
||||
error: question mark operator is useless here
|
||||
--> $DIR/needless_question_mark.rs:85:16
|
||||
|
|
||||
LL | return Ok(t.magic?);
|
||||
| ^^^^^^^^^^^^ help: try: `t.magic`
|
||||
|
||||
error: Question mark operator is useless here
|
||||
error: question mark operator is useless here
|
||||
--> $DIR/needless_question_mark.rs:138:9
|
||||
|
|
||||
LL | Ok(to.magic?) // should be triggered
|
||||
| ^^^^^^^^^^^^^ help: try: `to.magic`
|
||||
|
||||
error: Question mark operator is useless here
|
||||
error: question mark operator is useless here
|
||||
--> $DIR/needless_question_mark.rs:154:9
|
||||
|
|
||||
LL | Some(to.magic?) // should be triggered
|
||||
| ^^^^^^^^^^^^^^^ help: try: `to.magic`
|
||||
|
||||
error: Question mark operator is useless here
|
||||
error: question mark operator is useless here
|
||||
--> $DIR/needless_question_mark.rs:162:9
|
||||
|
|
||||
LL | Ok(to.magic?) // should be triggered
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
error: the loop variable `i` is only used to index `vec`.
|
||||
error: the loop variable `i` is only used to index `vec`
|
||||
--> $DIR/needless_range_loop.rs:10:14
|
||||
|
|
||||
LL | for i in 0..vec.len() {
|
||||
|
|
@ -10,7 +10,7 @@ help: consider using an iterator
|
|||
LL | for <item> in &vec {
|
||||
| ^^^^^^ ^^^^
|
||||
|
||||
error: the loop variable `i` is only used to index `vec`.
|
||||
error: the loop variable `i` is only used to index `vec`
|
||||
--> $DIR/needless_range_loop.rs:19:14
|
||||
|
|
||||
LL | for i in 0..vec.len() {
|
||||
|
|
@ -21,7 +21,7 @@ help: consider using an iterator
|
|||
LL | for <item> in &vec {
|
||||
| ^^^^^^ ^^^^
|
||||
|
||||
error: the loop variable `j` is only used to index `STATIC`.
|
||||
error: the loop variable `j` is only used to index `STATIC`
|
||||
--> $DIR/needless_range_loop.rs:24:14
|
||||
|
|
||||
LL | for j in 0..4 {
|
||||
|
|
@ -32,7 +32,7 @@ help: consider using an iterator
|
|||
LL | for <item> in &STATIC {
|
||||
| ^^^^^^ ^^^^^^^
|
||||
|
||||
error: the loop variable `j` is only used to index `CONST`.
|
||||
error: the loop variable `j` is only used to index `CONST`
|
||||
--> $DIR/needless_range_loop.rs:28:14
|
||||
|
|
||||
LL | for j in 0..4 {
|
||||
|
|
@ -54,7 +54,7 @@ help: consider using an iterator
|
|||
LL | for (i, <item>) in vec.iter().enumerate() {
|
||||
| ^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: the loop variable `i` is only used to index `vec2`.
|
||||
error: the loop variable `i` is only used to index `vec2`
|
||||
--> $DIR/needless_range_loop.rs:40:14
|
||||
|
|
||||
LL | for i in 0..vec.len() {
|
||||
|
|
@ -65,7 +65,7 @@ help: consider using an iterator
|
|||
LL | for <item> in vec2.iter().take(vec.len()) {
|
||||
| ^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: the loop variable `i` is only used to index `vec`.
|
||||
error: the loop variable `i` is only used to index `vec`
|
||||
--> $DIR/needless_range_loop.rs:44:14
|
||||
|
|
||||
LL | for i in 5..vec.len() {
|
||||
|
|
@ -76,7 +76,7 @@ help: consider using an iterator
|
|||
LL | for <item> in vec.iter().skip(5) {
|
||||
| ^^^^^^ ^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: the loop variable `i` is only used to index `vec`.
|
||||
error: the loop variable `i` is only used to index `vec`
|
||||
--> $DIR/needless_range_loop.rs:48:14
|
||||
|
|
||||
LL | for i in 0..MAX_LEN {
|
||||
|
|
@ -87,7 +87,7 @@ help: consider using an iterator
|
|||
LL | for <item> in vec.iter().take(MAX_LEN) {
|
||||
| ^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: the loop variable `i` is only used to index `vec`.
|
||||
error: the loop variable `i` is only used to index `vec`
|
||||
--> $DIR/needless_range_loop.rs:52:14
|
||||
|
|
||||
LL | for i in 0..=MAX_LEN {
|
||||
|
|
@ -98,7 +98,7 @@ help: consider using an iterator
|
|||
LL | for <item> in vec.iter().take(MAX_LEN + 1) {
|
||||
| ^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: the loop variable `i` is only used to index `vec`.
|
||||
error: the loop variable `i` is only used to index `vec`
|
||||
--> $DIR/needless_range_loop.rs:56:14
|
||||
|
|
||||
LL | for i in 5..10 {
|
||||
|
|
@ -109,7 +109,7 @@ help: consider using an iterator
|
|||
LL | for <item> in vec.iter().take(10).skip(5) {
|
||||
| ^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: the loop variable `i` is only used to index `vec`.
|
||||
error: the loop variable `i` is only used to index `vec`
|
||||
--> $DIR/needless_range_loop.rs:60:14
|
||||
|
|
||||
LL | for i in 5..=10 {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
error: the loop variable `i` is only used to index `ns`.
|
||||
error: the loop variable `i` is only used to index `ns`
|
||||
--> $DIR/needless_range_loop2.rs:10:14
|
||||
|
|
||||
LL | for i in 3..10 {
|
||||
|
|
@ -10,7 +10,7 @@ help: consider using an iterator
|
|||
LL | for <item> in ns.iter().take(10).skip(3) {
|
||||
| ^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: the loop variable `i` is only used to index `ms`.
|
||||
error: the loop variable `i` is only used to index `ms`
|
||||
--> $DIR/needless_range_loop2.rs:31:14
|
||||
|
|
||||
LL | for i in 0..ms.len() {
|
||||
|
|
@ -21,7 +21,7 @@ help: consider using an iterator
|
|||
LL | for <item> in &mut ms {
|
||||
| ^^^^^^ ^^^^^^^
|
||||
|
||||
error: the loop variable `i` is only used to index `ms`.
|
||||
error: the loop variable `i` is only used to index `ms`
|
||||
--> $DIR/needless_range_loop2.rs:37:14
|
||||
|
|
||||
LL | for i in 0..ms.len() {
|
||||
|
|
@ -32,7 +32,7 @@ help: consider using an iterator
|
|||
LL | for <item> in &mut ms {
|
||||
| ^^^^^^ ^^^^^^^
|
||||
|
||||
error: the loop variable `i` is only used to index `vec`.
|
||||
error: the loop variable `i` is only used to index `vec`
|
||||
--> $DIR/needless_range_loop2.rs:61:14
|
||||
|
|
||||
LL | for i in x..x + 4 {
|
||||
|
|
@ -43,7 +43,7 @@ help: consider using an iterator
|
|||
LL | for <item> in vec.iter_mut().skip(x).take(4) {
|
||||
| ^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: the loop variable `i` is only used to index `vec`.
|
||||
error: the loop variable `i` is only used to index `vec`
|
||||
--> $DIR/needless_range_loop2.rs:68:14
|
||||
|
|
||||
LL | for i in x..=x + 4 {
|
||||
|
|
@ -54,7 +54,7 @@ help: consider using an iterator
|
|||
LL | for <item> in vec.iter_mut().skip(x).take(4 + 1) {
|
||||
| ^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: the loop variable `i` is only used to index `arr`.
|
||||
error: the loop variable `i` is only used to index `arr`
|
||||
--> $DIR/needless_range_loop2.rs:74:14
|
||||
|
|
||||
LL | for i in 0..3 {
|
||||
|
|
@ -65,7 +65,7 @@ help: consider using an iterator
|
|||
LL | for <item> in &arr {
|
||||
| ^^^^^^ ^^^^
|
||||
|
||||
error: the loop variable `i` is only used to index `arr`.
|
||||
error: the loop variable `i` is only used to index `arr`
|
||||
--> $DIR/needless_range_loop2.rs:78:14
|
||||
|
|
||||
LL | for i in 0..2 {
|
||||
|
|
@ -76,7 +76,7 @@ help: consider using an iterator
|
|||
LL | for <item> in arr.iter().take(2) {
|
||||
| ^^^^^^ ^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: the loop variable `i` is only used to index `arr`.
|
||||
error: the loop variable `i` is only used to index `arr`
|
||||
--> $DIR/needless_range_loop2.rs:82:14
|
||||
|
|
||||
LL | for i in 1..3 {
|
||||
|
|
|
|||
|
|
@ -62,9 +62,15 @@ fn or_fun_call() {
|
|||
let mut map = HashMap::<u64, String>::new();
|
||||
map.entry(42).or_insert_with(String::new);
|
||||
|
||||
let mut map_vec = HashMap::<u64, Vec<i32>>::new();
|
||||
map_vec.entry(42).or_insert_with(Vec::new);
|
||||
|
||||
let mut btree = BTreeMap::<u64, String>::new();
|
||||
btree.entry(42).or_insert_with(String::new);
|
||||
|
||||
let mut btree_vec = BTreeMap::<u64, Vec<i32>>::new();
|
||||
btree_vec.entry(42).or_insert_with(Vec::new);
|
||||
|
||||
let stringy = Some(String::from(""));
|
||||
let _ = stringy.unwrap_or_else(|| "".to_owned());
|
||||
|
||||
|
|
|
|||
|
|
@ -62,9 +62,15 @@ fn or_fun_call() {
|
|||
let mut map = HashMap::<u64, String>::new();
|
||||
map.entry(42).or_insert(String::new());
|
||||
|
||||
let mut map_vec = HashMap::<u64, Vec<i32>>::new();
|
||||
map_vec.entry(42).or_insert(vec![]);
|
||||
|
||||
let mut btree = BTreeMap::<u64, String>::new();
|
||||
btree.entry(42).or_insert(String::new());
|
||||
|
||||
let mut btree_vec = BTreeMap::<u64, Vec<i32>>::new();
|
||||
btree_vec.entry(42).or_insert(vec![]);
|
||||
|
||||
let stringy = Some(String::from(""));
|
||||
let _ = stringy.unwrap_or("".to_owned());
|
||||
|
||||
|
|
|
|||
|
|
@ -67,40 +67,52 @@ LL | map.entry(42).or_insert(String::new());
|
|||
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `or_insert_with(String::new)`
|
||||
|
||||
error: use of `or_insert` followed by a function call
|
||||
--> $DIR/or_fun_call.rs:66:21
|
||||
--> $DIR/or_fun_call.rs:66:23
|
||||
|
|
||||
LL | map_vec.entry(42).or_insert(vec![]);
|
||||
| ^^^^^^^^^^^^^^^^^ help: try this: `or_insert_with(Vec::new)`
|
||||
|
||||
error: use of `or_insert` followed by a function call
|
||||
--> $DIR/or_fun_call.rs:69:21
|
||||
|
|
||||
LL | btree.entry(42).or_insert(String::new());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `or_insert_with(String::new)`
|
||||
|
||||
error: use of `or_insert` followed by a function call
|
||||
--> $DIR/or_fun_call.rs:72:25
|
||||
|
|
||||
LL | btree_vec.entry(42).or_insert(vec![]);
|
||||
| ^^^^^^^^^^^^^^^^^ help: try this: `or_insert_with(Vec::new)`
|
||||
|
||||
error: use of `unwrap_or` followed by a function call
|
||||
--> $DIR/or_fun_call.rs:69:21
|
||||
--> $DIR/or_fun_call.rs:75:21
|
||||
|
|
||||
LL | let _ = stringy.unwrap_or("".to_owned());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| "".to_owned())`
|
||||
|
||||
error: use of `unwrap_or` followed by a function call
|
||||
--> $DIR/or_fun_call.rs:77:21
|
||||
--> $DIR/or_fun_call.rs:83:21
|
||||
|
|
||||
LL | let _ = Some(1).unwrap_or(map[&1]);
|
||||
| ^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| map[&1])`
|
||||
|
||||
error: use of `unwrap_or` followed by a function call
|
||||
--> $DIR/or_fun_call.rs:79:21
|
||||
--> $DIR/or_fun_call.rs:85:21
|
||||
|
|
||||
LL | let _ = Some(1).unwrap_or(map[&1]);
|
||||
| ^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| map[&1])`
|
||||
|
||||
error: use of `or` followed by a function call
|
||||
--> $DIR/or_fun_call.rs:103:35
|
||||
--> $DIR/or_fun_call.rs:109:35
|
||||
|
|
||||
LL | let _ = Some("a".to_string()).or(Some("b".to_string()));
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `or_else(|| Some("b".to_string()))`
|
||||
|
||||
error: use of `or` followed by a function call
|
||||
--> $DIR/or_fun_call.rs:107:10
|
||||
--> $DIR/or_fun_call.rs:113:10
|
||||
|
|
||||
LL | .or(Some(Bar(b, Duration::from_secs(2))));
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `or_else(|| Some(Bar(b, Duration::from_secs(2))))`
|
||||
|
||||
error: aborting due to 17 previous errors
|
||||
error: aborting due to 19 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
error: writing `&Vec<_>` instead of `&[_]` involves one more reference and cannot be used with non-Vec-based slices.
|
||||
error: writing `&Vec<_>` instead of `&[_]` involves one more reference and cannot be used with non-Vec-based slices
|
||||
--> $DIR/ptr_arg.rs:7:14
|
||||
|
|
||||
LL | fn do_vec(x: &Vec<i64>) {
|
||||
|
|
@ -6,25 +6,25 @@ LL | fn do_vec(x: &Vec<i64>) {
|
|||
|
|
||||
= note: `-D clippy::ptr-arg` implied by `-D warnings`
|
||||
|
||||
error: writing `&String` instead of `&str` involves a new object where a slice will do.
|
||||
error: writing `&String` instead of `&str` involves a new object where a slice will do
|
||||
--> $DIR/ptr_arg.rs:16:14
|
||||
|
|
||||
LL | fn do_str(x: &String) {
|
||||
| ^^^^^^^ help: change this to: `&str`
|
||||
|
||||
error: writing `&PathBuf` instead of `&Path` involves a new object where a slice will do.
|
||||
error: writing `&PathBuf` instead of `&Path` involves a new object where a slice will do
|
||||
--> $DIR/ptr_arg.rs:25:15
|
||||
|
|
||||
LL | fn do_path(x: &PathBuf) {
|
||||
| ^^^^^^^^ help: change this to: `&Path`
|
||||
|
||||
error: writing `&Vec<_>` instead of `&[_]` involves one more reference and cannot be used with non-Vec-based slices.
|
||||
error: writing `&Vec<_>` instead of `&[_]` involves one more reference and cannot be used with non-Vec-based slices
|
||||
--> $DIR/ptr_arg.rs:38:18
|
||||
|
|
||||
LL | fn do_vec(x: &Vec<i64>);
|
||||
| ^^^^^^^^^ help: change this to: `&[i64]`
|
||||
|
||||
error: writing `&Vec<_>` instead of `&[_]` involves one more reference and cannot be used with non-Vec-based slices.
|
||||
error: writing `&Vec<_>` instead of `&[_]` involves one more reference and cannot be used with non-Vec-based slices
|
||||
--> $DIR/ptr_arg.rs:51:14
|
||||
|
|
||||
LL | fn cloned(x: &Vec<u8>) -> Vec<u8> {
|
||||
|
|
@ -43,7 +43,7 @@ help: change `x.clone()` to
|
|||
LL | x.to_owned()
|
||||
|
|
||||
|
||||
error: writing `&String` instead of `&str` involves a new object where a slice will do.
|
||||
error: writing `&String` instead of `&str` involves a new object where a slice will do
|
||||
--> $DIR/ptr_arg.rs:60:18
|
||||
|
|
||||
LL | fn str_cloned(x: &String) -> String {
|
||||
|
|
@ -66,7 +66,7 @@ help: change `x.clone()` to
|
|||
LL | x.to_string()
|
||||
|
|
||||
|
||||
error: writing `&PathBuf` instead of `&Path` involves a new object where a slice will do.
|
||||
error: writing `&PathBuf` instead of `&Path` involves a new object where a slice will do
|
||||
--> $DIR/ptr_arg.rs:68:19
|
||||
|
|
||||
LL | fn path_cloned(x: &PathBuf) -> PathBuf {
|
||||
|
|
@ -89,7 +89,7 @@ help: change `x.clone()` to
|
|||
LL | x.to_path_buf()
|
||||
|
|
||||
|
||||
error: writing `&String` instead of `&str` involves a new object where a slice will do.
|
||||
error: writing `&String` instead of `&str` involves a new object where a slice will do
|
||||
--> $DIR/ptr_arg.rs:76:44
|
||||
|
|
||||
LL | fn false_positive_capacity(x: &Vec<u8>, y: &String) {
|
||||
|
|
@ -108,13 +108,13 @@ help: change `y.as_str()` to
|
|||
LL | let c = y;
|
||||
| ^
|
||||
|
||||
error: using a reference to `Cow` is not recommended.
|
||||
error: using a reference to `Cow` is not recommended
|
||||
--> $DIR/ptr_arg.rs:90:25
|
||||
|
|
||||
LL | fn test_cow_with_ref(c: &Cow<[i32]>) {}
|
||||
| ^^^^^^^^^^^ help: change this to: `&[i32]`
|
||||
|
||||
error: writing `&Vec<_>` instead of `&[_]` involves one more reference and cannot be used with non-Vec-based slices.
|
||||
error: writing `&Vec<_>` instead of `&[_]` involves one more reference and cannot be used with non-Vec-based slices
|
||||
--> $DIR/ptr_arg.rs:143:21
|
||||
|
|
||||
LL | fn foo_vec(vec: &Vec<u8>) {
|
||||
|
|
@ -133,7 +133,7 @@ help: change `vec.clone()` to
|
|||
LL | let _ = vec.to_owned().clone();
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error: writing `&PathBuf` instead of `&Path` involves a new object where a slice will do.
|
||||
error: writing `&PathBuf` instead of `&Path` involves a new object where a slice will do
|
||||
--> $DIR/ptr_arg.rs:148:23
|
||||
|
|
||||
LL | fn foo_path(path: &PathBuf) {
|
||||
|
|
@ -152,7 +152,7 @@ help: change `path.clone()` to
|
|||
LL | let _ = path.to_path_buf().clone();
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: writing `&PathBuf` instead of `&Path` involves a new object where a slice will do.
|
||||
error: writing `&PathBuf` instead of `&Path` involves a new object where a slice will do
|
||||
--> $DIR/ptr_arg.rs:153:21
|
||||
|
|
||||
LL | fn foo_str(str: &PathBuf) {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
// run-rustfix
|
||||
// rustfix-only-machine-applicable
|
||||
|
||||
#![allow(clippy::implicit_clone)]
|
||||
use std::ffi::OsString;
|
||||
use std::path::Path;
|
||||
|
||||
|
|
@ -58,11 +59,7 @@ fn main() {
|
|||
#[derive(Clone)]
|
||||
struct Alpha;
|
||||
fn with_branch(a: Alpha, b: bool) -> (Alpha, Alpha) {
|
||||
if b {
|
||||
(a.clone(), a)
|
||||
} else {
|
||||
(Alpha, a)
|
||||
}
|
||||
if b { (a.clone(), a) } else { (Alpha, a) }
|
||||
}
|
||||
|
||||
fn cannot_double_move(a: Alpha) -> (Alpha, Alpha) {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
// run-rustfix
|
||||
// rustfix-only-machine-applicable
|
||||
|
||||
#![allow(clippy::implicit_clone)]
|
||||
use std::ffi::OsString;
|
||||
use std::path::Path;
|
||||
|
||||
|
|
@ -58,11 +59,7 @@ fn main() {
|
|||
#[derive(Clone)]
|
||||
struct Alpha;
|
||||
fn with_branch(a: Alpha, b: bool) -> (Alpha, Alpha) {
|
||||
if b {
|
||||
(a.clone(), a.clone())
|
||||
} else {
|
||||
(Alpha, a)
|
||||
}
|
||||
if b { (a.clone(), a.clone()) } else { (Alpha, a) }
|
||||
}
|
||||
|
||||
fn cannot_double_move(a: Alpha) -> (Alpha, Alpha) {
|
||||
|
|
|
|||
|
|
@ -1,168 +1,168 @@
|
|||
error: redundant clone
|
||||
--> $DIR/redundant_clone.rs:8:42
|
||||
--> $DIR/redundant_clone.rs:9:42
|
||||
|
|
||||
LL | let _s = ["lorem", "ipsum"].join(" ").to_string();
|
||||
| ^^^^^^^^^^^^ help: remove this
|
||||
|
|
||||
= note: `-D clippy::redundant-clone` implied by `-D warnings`
|
||||
note: this value is dropped without further use
|
||||
--> $DIR/redundant_clone.rs:8:14
|
||||
--> $DIR/redundant_clone.rs:9:14
|
||||
|
|
||||
LL | let _s = ["lorem", "ipsum"].join(" ").to_string();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: redundant clone
|
||||
--> $DIR/redundant_clone.rs:11:15
|
||||
--> $DIR/redundant_clone.rs:12:15
|
||||
|
|
||||
LL | let _s = s.clone();
|
||||
| ^^^^^^^^ help: remove this
|
||||
|
|
||||
note: this value is dropped without further use
|
||||
--> $DIR/redundant_clone.rs:11:14
|
||||
--> $DIR/redundant_clone.rs:12:14
|
||||
|
|
||||
LL | let _s = s.clone();
|
||||
| ^
|
||||
|
||||
error: redundant clone
|
||||
--> $DIR/redundant_clone.rs:14:15
|
||||
--> $DIR/redundant_clone.rs:15:15
|
||||
|
|
||||
LL | let _s = s.to_string();
|
||||
| ^^^^^^^^^^^^ help: remove this
|
||||
|
|
||||
note: this value is dropped without further use
|
||||
--> $DIR/redundant_clone.rs:14:14
|
||||
--> $DIR/redundant_clone.rs:15:14
|
||||
|
|
||||
LL | let _s = s.to_string();
|
||||
| ^
|
||||
|
||||
error: redundant clone
|
||||
--> $DIR/redundant_clone.rs:17:15
|
||||
--> $DIR/redundant_clone.rs:18:15
|
||||
|
|
||||
LL | let _s = s.to_owned();
|
||||
| ^^^^^^^^^^^ help: remove this
|
||||
|
|
||||
note: this value is dropped without further use
|
||||
--> $DIR/redundant_clone.rs:17:14
|
||||
--> $DIR/redundant_clone.rs:18:14
|
||||
|
|
||||
LL | let _s = s.to_owned();
|
||||
| ^
|
||||
|
||||
error: redundant clone
|
||||
--> $DIR/redundant_clone.rs:19:42
|
||||
--> $DIR/redundant_clone.rs:20:42
|
||||
|
|
||||
LL | let _s = Path::new("/a/b/").join("c").to_owned();
|
||||
| ^^^^^^^^^^^ help: remove this
|
||||
|
|
||||
note: this value is dropped without further use
|
||||
--> $DIR/redundant_clone.rs:19:14
|
||||
--> $DIR/redundant_clone.rs:20:14
|
||||
|
|
||||
LL | let _s = Path::new("/a/b/").join("c").to_owned();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: redundant clone
|
||||
--> $DIR/redundant_clone.rs:21:42
|
||||
--> $DIR/redundant_clone.rs:22:42
|
||||
|
|
||||
LL | let _s = Path::new("/a/b/").join("c").to_path_buf();
|
||||
| ^^^^^^^^^^^^^^ help: remove this
|
||||
|
|
||||
note: this value is dropped without further use
|
||||
--> $DIR/redundant_clone.rs:21:14
|
||||
--> $DIR/redundant_clone.rs:22:14
|
||||
|
|
||||
LL | let _s = Path::new("/a/b/").join("c").to_path_buf();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: redundant clone
|
||||
--> $DIR/redundant_clone.rs:23:29
|
||||
--> $DIR/redundant_clone.rs:24:29
|
||||
|
|
||||
LL | let _s = OsString::new().to_owned();
|
||||
| ^^^^^^^^^^^ help: remove this
|
||||
|
|
||||
note: this value is dropped without further use
|
||||
--> $DIR/redundant_clone.rs:23:14
|
||||
--> $DIR/redundant_clone.rs:24:14
|
||||
|
|
||||
LL | let _s = OsString::new().to_owned();
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
||||
error: redundant clone
|
||||
--> $DIR/redundant_clone.rs:25:29
|
||||
--> $DIR/redundant_clone.rs:26:29
|
||||
|
|
||||
LL | let _s = OsString::new().to_os_string();
|
||||
| ^^^^^^^^^^^^^^^ help: remove this
|
||||
|
|
||||
note: this value is dropped without further use
|
||||
--> $DIR/redundant_clone.rs:25:14
|
||||
--> $DIR/redundant_clone.rs:26:14
|
||||
|
|
||||
LL | let _s = OsString::new().to_os_string();
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
||||
error: redundant clone
|
||||
--> $DIR/redundant_clone.rs:32:19
|
||||
--> $DIR/redundant_clone.rs:33:19
|
||||
|
|
||||
LL | let _t = tup.0.clone();
|
||||
| ^^^^^^^^ help: remove this
|
||||
|
|
||||
note: this value is dropped without further use
|
||||
--> $DIR/redundant_clone.rs:32:14
|
||||
--> $DIR/redundant_clone.rs:33:14
|
||||
|
|
||||
LL | let _t = tup.0.clone();
|
||||
| ^^^^^
|
||||
|
||||
error: redundant clone
|
||||
--> $DIR/redundant_clone.rs:62:22
|
||||
--> $DIR/redundant_clone.rs:62:25
|
||||
|
|
||||
LL | (a.clone(), a.clone())
|
||||
| ^^^^^^^^ help: remove this
|
||||
LL | if b { (a.clone(), a.clone()) } else { (Alpha, a) }
|
||||
| ^^^^^^^^ help: remove this
|
||||
|
|
||||
note: this value is dropped without further use
|
||||
--> $DIR/redundant_clone.rs:62:21
|
||||
--> $DIR/redundant_clone.rs:62:24
|
||||
|
|
||||
LL | (a.clone(), a.clone())
|
||||
| ^
|
||||
LL | if b { (a.clone(), a.clone()) } else { (Alpha, a) }
|
||||
| ^
|
||||
|
||||
error: redundant clone
|
||||
--> $DIR/redundant_clone.rs:122:15
|
||||
--> $DIR/redundant_clone.rs:119:15
|
||||
|
|
||||
LL | let _s = s.clone();
|
||||
| ^^^^^^^^ help: remove this
|
||||
|
|
||||
note: this value is dropped without further use
|
||||
--> $DIR/redundant_clone.rs:122:14
|
||||
--> $DIR/redundant_clone.rs:119:14
|
||||
|
|
||||
LL | let _s = s.clone();
|
||||
| ^
|
||||
|
||||
error: redundant clone
|
||||
--> $DIR/redundant_clone.rs:123:15
|
||||
--> $DIR/redundant_clone.rs:120:15
|
||||
|
|
||||
LL | let _t = t.clone();
|
||||
| ^^^^^^^^ help: remove this
|
||||
|
|
||||
note: this value is dropped without further use
|
||||
--> $DIR/redundant_clone.rs:123:14
|
||||
--> $DIR/redundant_clone.rs:120:14
|
||||
|
|
||||
LL | let _t = t.clone();
|
||||
| ^
|
||||
|
||||
error: redundant clone
|
||||
--> $DIR/redundant_clone.rs:133:19
|
||||
--> $DIR/redundant_clone.rs:130:19
|
||||
|
|
||||
LL | let _f = f.clone();
|
||||
| ^^^^^^^^ help: remove this
|
||||
|
|
||||
note: this value is dropped without further use
|
||||
--> $DIR/redundant_clone.rs:133:18
|
||||
--> $DIR/redundant_clone.rs:130:18
|
||||
|
|
||||
LL | let _f = f.clone();
|
||||
| ^
|
||||
|
||||
error: redundant clone
|
||||
--> $DIR/redundant_clone.rs:145:14
|
||||
--> $DIR/redundant_clone.rs:142:14
|
||||
|
|
||||
LL | let y = x.clone().join("matthias");
|
||||
| ^^^^^^^^ help: remove this
|
||||
|
|
||||
note: cloned value is neither consumed nor mutated
|
||||
--> $DIR/redundant_clone.rs:145:13
|
||||
--> $DIR/redundant_clone.rs:142:13
|
||||
|
|
||||
LL | let y = x.clone().join("matthias");
|
||||
| ^^^^^^^^^
|
||||
|
|
|
|||
|
|
@ -1,166 +1,166 @@
|
|||
error: This sequence of operators looks suspiciously like a bug.
|
||||
error: this sequence of operators looks suspiciously like a bug
|
||||
--> $DIR/suspicious_operation_groupings.rs:14:9
|
||||
|
|
||||
LL | self.x == other.y && self.y == other.y && self.z == other.z
|
||||
| ^^^^^^^^^^^^^^^^^ help: I think you meant: `self.x == other.x`
|
||||
| ^^^^^^^^^^^^^^^^^ help: did you mean: `self.x == other.x`
|
||||
|
|
||||
= note: `-D clippy::suspicious-operation-groupings` implied by `-D warnings`
|
||||
|
||||
error: This sequence of operators looks suspiciously like a bug.
|
||||
error: this sequence of operators looks suspiciously like a bug
|
||||
--> $DIR/suspicious_operation_groupings.rs:14:9
|
||||
|
|
||||
LL | self.x == other.y && self.y == other.y && self.z == other.z
|
||||
| ^^^^^^^^^^^^^^^^^ help: I think you meant: `self.x == other.x`
|
||||
| ^^^^^^^^^^^^^^^^^ help: did you mean: `self.x == other.x`
|
||||
|
||||
error: This sequence of operators looks suspiciously like a bug.
|
||||
error: this sequence of operators looks suspiciously like a bug
|
||||
--> $DIR/suspicious_operation_groupings.rs:27:20
|
||||
|
|
||||
LL | s1.a < s2.a && s1.a < s2.b
|
||||
| ^^^^^^^^^^^ help: I think you meant: `s1.b < s2.b`
|
||||
| ^^^^^^^^^^^ help: did you mean: `s1.b < s2.b`
|
||||
|
||||
error: This sequence of operators looks suspiciously like a bug.
|
||||
error: this sequence of operators looks suspiciously like a bug
|
||||
--> $DIR/suspicious_operation_groupings.rs:75:33
|
||||
|
|
||||
LL | s1.a * s2.a + s1.b * s2.b + s1.c * s2.b + s1.d * s2.d
|
||||
| ^^^^^^^^^^^ help: I think you meant: `s1.c * s2.c`
|
||||
| ^^^^^^^^^^^ help: did you mean: `s1.c * s2.c`
|
||||
|
||||
error: This sequence of operators looks suspiciously like a bug.
|
||||
error: this sequence of operators looks suspiciously like a bug
|
||||
--> $DIR/suspicious_operation_groupings.rs:80:19
|
||||
|
|
||||
LL | s1.a * s2.a + s1.b * s2.c + s1.c * s2.c
|
||||
| ^^^^^^^^^^^ help: I think you meant: `s1.b * s2.b`
|
||||
| ^^^^^^^^^^^ help: did you mean: `s1.b * s2.b`
|
||||
|
||||
error: This sequence of operators looks suspiciously like a bug.
|
||||
error: this sequence of operators looks suspiciously like a bug
|
||||
--> $DIR/suspicious_operation_groupings.rs:80:19
|
||||
|
|
||||
LL | s1.a * s2.a + s1.b * s2.c + s1.c * s2.c
|
||||
| ^^^^^^^^^^^ help: I think you meant: `s1.b * s2.b`
|
||||
| ^^^^^^^^^^^ help: did you mean: `s1.b * s2.b`
|
||||
|
||||
error: This sequence of operators looks suspiciously like a bug.
|
||||
error: this sequence of operators looks suspiciously like a bug
|
||||
--> $DIR/suspicious_operation_groupings.rs:85:19
|
||||
|
|
||||
LL | s1.a * s2.a + s2.b * s2.b + s1.c * s2.c
|
||||
| ^^^^^^^^^^^ help: I think you meant: `s1.b * s2.b`
|
||||
| ^^^^^^^^^^^ help: did you mean: `s1.b * s2.b`
|
||||
|
||||
error: This sequence of operators looks suspiciously like a bug.
|
||||
error: this sequence of operators looks suspiciously like a bug
|
||||
--> $DIR/suspicious_operation_groupings.rs:90:19
|
||||
|
|
||||
LL | s1.a * s2.a + s1.b * s1.b + s1.c * s2.c
|
||||
| ^^^^^^^^^^^ help: I think you meant: `s1.b * s2.b`
|
||||
| ^^^^^^^^^^^ help: did you mean: `s1.b * s2.b`
|
||||
|
||||
error: This sequence of operators looks suspiciously like a bug.
|
||||
error: this sequence of operators looks suspiciously like a bug
|
||||
--> $DIR/suspicious_operation_groupings.rs:95:5
|
||||
|
|
||||
LL | s1.a * s1.a + s1.b * s2.b + s1.c * s2.c
|
||||
| ^^^^^^^^^^^ help: I think you meant: `s1.a * s2.a`
|
||||
| ^^^^^^^^^^^ help: did you mean: `s1.a * s2.a`
|
||||
|
||||
error: This sequence of operators looks suspiciously like a bug.
|
||||
error: this sequence of operators looks suspiciously like a bug
|
||||
--> $DIR/suspicious_operation_groupings.rs:100:33
|
||||
|
|
||||
LL | s1.a * s2.a + s1.b * s2.b + s1.c * s1.c
|
||||
| ^^^^^^^^^^^ help: I think you meant: `s1.c * s2.c`
|
||||
| ^^^^^^^^^^^ help: did you mean: `s1.c * s2.c`
|
||||
|
||||
error: This sequence of operators looks suspiciously like a bug.
|
||||
error: this sequence of operators looks suspiciously like a bug
|
||||
--> $DIR/suspicious_operation_groupings.rs:113:20
|
||||
|
|
||||
LL | (s1.a * s2.a + s1.b * s1.b)
|
||||
| ^^^^^^^^^^^ help: I think you meant: `s1.b * s2.b`
|
||||
| ^^^^^^^^^^^ help: did you mean: `s1.b * s2.b`
|
||||
|
||||
error: This sequence of operators looks suspiciously like a bug.
|
||||
error: this sequence of operators looks suspiciously like a bug
|
||||
--> $DIR/suspicious_operation_groupings.rs:118:34
|
||||
|
|
||||
LL | (s1.a * s2.a + s1.b * s2.b + s1.c * s2.b + s1.d * s2.d)
|
||||
| ^^^^^^^^^^^ help: I think you meant: `s1.c * s2.c`
|
||||
| ^^^^^^^^^^^ help: did you mean: `s1.c * s2.c`
|
||||
|
||||
error: This sequence of operators looks suspiciously like a bug.
|
||||
error: this sequence of operators looks suspiciously like a bug
|
||||
--> $DIR/suspicious_operation_groupings.rs:123:38
|
||||
|
|
||||
LL | (s1.a * s2.a) + (s1.b * s2.b) + (s1.c * s2.b) + (s1.d * s2.d)
|
||||
| ^^^^^^^^^^^ help: I think you meant: `s1.c * s2.c`
|
||||
| ^^^^^^^^^^^ help: did you mean: `s1.c * s2.c`
|
||||
|
||||
error: This sequence of operators looks suspiciously like a bug.
|
||||
error: this sequence of operators looks suspiciously like a bug
|
||||
--> $DIR/suspicious_operation_groupings.rs:128:39
|
||||
|
|
||||
LL | ((s1.a * s2.a) + (s1.b * s2.b) + (s1.c * s2.b) + (s1.d * s2.d))
|
||||
| ^^^^^^^^^^^ help: I think you meant: `s1.c * s2.c`
|
||||
| ^^^^^^^^^^^ help: did you mean: `s1.c * s2.c`
|
||||
|
||||
error: This sequence of operators looks suspiciously like a bug.
|
||||
error: this sequence of operators looks suspiciously like a bug
|
||||
--> $DIR/suspicious_operation_groupings.rs:133:42
|
||||
|
|
||||
LL | (((s1.a * s2.a) + (s1.b * s2.b)) + ((s1.c * s2.b) + (s1.d * s2.d)))
|
||||
| ^^^^^^^^^^^ help: I think you meant: `s1.c * s2.c`
|
||||
| ^^^^^^^^^^^ help: did you mean: `s1.c * s2.c`
|
||||
|
||||
error: This sequence of operators looks suspiciously like a bug.
|
||||
error: this sequence of operators looks suspiciously like a bug
|
||||
--> $DIR/suspicious_operation_groupings.rs:133:42
|
||||
|
|
||||
LL | (((s1.a * s2.a) + (s1.b * s2.b)) + ((s1.c * s2.b) + (s1.d * s2.d)))
|
||||
| ^^^^^^^^^^^ help: I think you meant: `s1.c * s2.c`
|
||||
| ^^^^^^^^^^^ help: did you mean: `s1.c * s2.c`
|
||||
|
||||
error: This sequence of operators looks suspiciously like a bug.
|
||||
error: this sequence of operators looks suspiciously like a bug
|
||||
--> $DIR/suspicious_operation_groupings.rs:138:40
|
||||
|
|
||||
LL | (((s1.a * s2.a) + (s1.b * s2.b) + (s1.c * s2.b)) + (s1.d * s2.d))
|
||||
| ^^^^^^^^^^^ help: I think you meant: `s1.c * s2.c`
|
||||
| ^^^^^^^^^^^ help: did you mean: `s1.c * s2.c`
|
||||
|
||||
error: This sequence of operators looks suspiciously like a bug.
|
||||
error: this sequence of operators looks suspiciously like a bug
|
||||
--> $DIR/suspicious_operation_groupings.rs:143:40
|
||||
|
|
||||
LL | ((s1.a * s2.a) + ((s1.b * s2.b) + (s1.c * s2.b) + (s1.d * s2.d)))
|
||||
| ^^^^^^^^^^^ help: I think you meant: `s1.c * s2.c`
|
||||
| ^^^^^^^^^^^ help: did you mean: `s1.c * s2.c`
|
||||
|
||||
error: This sequence of operators looks suspiciously like a bug.
|
||||
error: this sequence of operators looks suspiciously like a bug
|
||||
--> $DIR/suspicious_operation_groupings.rs:148:20
|
||||
|
|
||||
LL | (s1.a * s2.a + s2.b * s2.b) / 2
|
||||
| ^^^^^^^^^^^ help: I think you meant: `s1.b * s2.b`
|
||||
| ^^^^^^^^^^^ help: did you mean: `s1.b * s2.b`
|
||||
|
||||
error: This sequence of operators looks suspiciously like a bug.
|
||||
error: this sequence of operators looks suspiciously like a bug
|
||||
--> $DIR/suspicious_operation_groupings.rs:153:35
|
||||
|
|
||||
LL | i32::swap_bytes(s1.a * s2.a + s2.b * s2.b)
|
||||
| ^^^^^^^^^^^ help: I think you meant: `s1.b * s2.b`
|
||||
| ^^^^^^^^^^^ help: did you mean: `s1.b * s2.b`
|
||||
|
||||
error: This sequence of operators looks suspiciously like a bug.
|
||||
error: this sequence of operators looks suspiciously like a bug
|
||||
--> $DIR/suspicious_operation_groupings.rs:158:29
|
||||
|
|
||||
LL | s1.a > 0 && s1.b > 0 && s1.d == s2.c && s1.d == s2.d
|
||||
| ^^^^^^^^^^^^ help: I think you meant: `s1.c == s2.c`
|
||||
| ^^^^^^^^^^^^ help: did you mean: `s1.c == s2.c`
|
||||
|
||||
error: This sequence of operators looks suspiciously like a bug.
|
||||
error: this sequence of operators looks suspiciously like a bug
|
||||
--> $DIR/suspicious_operation_groupings.rs:163:17
|
||||
|
|
||||
LL | s1.a > 0 && s1.d == s2.c && s1.b > 0 && s1.d == s2.d
|
||||
| ^^^^^^^^^^^^ help: I think you meant: `s1.c == s2.c`
|
||||
| ^^^^^^^^^^^^ help: did you mean: `s1.c == s2.c`
|
||||
|
||||
error: This sequence of operators looks suspiciously like a bug.
|
||||
error: this sequence of operators looks suspiciously like a bug
|
||||
--> $DIR/suspicious_operation_groupings.rs:172:77
|
||||
|
|
||||
LL | (n1.inner.0).0 == (n2.inner.0).0 && (n1.inner.1).0 == (n2.inner.1).0 && (n1.inner.2).0 == (n2.inner.1).0
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: I think you meant: `(n1.inner.2).0 == (n2.inner.2).0`
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: did you mean: `(n1.inner.2).0 == (n2.inner.2).0`
|
||||
|
||||
error: This sequence of operators looks suspiciously like a bug.
|
||||
error: this sequence of operators looks suspiciously like a bug
|
||||
--> $DIR/suspicious_operation_groupings.rs:186:25
|
||||
|
|
||||
LL | s1.a <= s2.a && s1.a <= s2.b
|
||||
| ^^^^^^^^^^^^ help: I think you meant: `s1.b <= s2.b`
|
||||
| ^^^^^^^^^^^^ help: did you mean: `s1.b <= s2.b`
|
||||
|
||||
error: This sequence of operators looks suspiciously like a bug.
|
||||
error: this sequence of operators looks suspiciously like a bug
|
||||
--> $DIR/suspicious_operation_groupings.rs:192:23
|
||||
|
|
||||
LL | if s1.a < s2.a && s1.a < s2.b {
|
||||
| ^^^^^^^^^^^ help: I think you meant: `s1.b < s2.b`
|
||||
| ^^^^^^^^^^^ help: did you mean: `s1.b < s2.b`
|
||||
|
||||
error: This sequence of operators looks suspiciously like a bug.
|
||||
error: this sequence of operators looks suspiciously like a bug
|
||||
--> $DIR/suspicious_operation_groupings.rs:199:48
|
||||
|
|
||||
LL | -(-(-s1.a * -s2.a) + (-(-s1.b * -s2.b) + -(-s1.c * -s2.b) + -(-s1.d * -s2.d)))
|
||||
| ^^^^^^^^^^^^^ help: I think you meant: `-s1.c * -s2.c`
|
||||
| ^^^^^^^^^^^^^ help: did you mean: `-s1.c * -s2.c`
|
||||
|
||||
error: This sequence of operators looks suspiciously like a bug.
|
||||
error: this sequence of operators looks suspiciously like a bug
|
||||
--> $DIR/suspicious_operation_groupings.rs:204:27
|
||||
|
|
||||
LL | -(if -s1.a < -s2.a && -s1.a < -s2.b { s1.c } else { s2.a })
|
||||
| ^^^^^^^^^^^^^ help: I think you meant: `-s1.b < -s2.b`
|
||||
| ^^^^^^^^^^^^^ help: did you mean: `-s1.b < -s2.b`
|
||||
|
||||
error: aborting due to 27 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
error: `ref` directly on a function argument is ignored. Consider using a reference type instead.
|
||||
error: `ref` directly on a function argument is ignored. Consider using a reference type instead
|
||||
--> $DIR/toplevel_ref_arg_non_rustfix.rs:9:15
|
||||
|
|
||||
LL | fn the_answer(ref mut x: u8) {
|
||||
|
|
@ -6,7 +6,7 @@ LL | fn the_answer(ref mut x: u8) {
|
|||
|
|
||||
= note: `-D clippy::toplevel-ref-arg` implied by `-D warnings`
|
||||
|
||||
error: `ref` directly on a function argument is ignored. Consider using a reference type instead.
|
||||
error: `ref` directly on a function argument is ignored. Consider using a reference type instead
|
||||
--> $DIR/toplevel_ref_arg_non_rustfix.rs:15:24
|
||||
|
|
||||
LL | fn fun_example(ref _x: usize) {}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
error: transmuting a known null pointer into a reference.
|
||||
error: transmuting a known null pointer into a reference
|
||||
--> $DIR/transmuting_null.rs:10:23
|
||||
|
|
||||
LL | let _: &u64 = std::mem::transmute(0 as *const u64);
|
||||
|
|
@ -6,13 +6,13 @@ LL | let _: &u64 = std::mem::transmute(0 as *const u64);
|
|||
|
|
||||
= note: `-D clippy::transmuting-null` implied by `-D warnings`
|
||||
|
||||
error: transmuting a known null pointer into a reference.
|
||||
error: transmuting a known null pointer into a reference
|
||||
--> $DIR/transmuting_null.rs:11:23
|
||||
|
|
||||
LL | let _: &u64 = std::mem::transmute(std::ptr::null::<u64>());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: transmuting a known null pointer into a reference.
|
||||
error: transmuting a known null pointer into a reference
|
||||
--> $DIR/transmuting_null.rs:21:23
|
||||
|
|
||||
LL | let _: &u64 = std::mem::transmute(ZPTR);
|
||||
|
|
|
|||
|
|
@ -27,6 +27,30 @@ impl Bar {
|
|||
}
|
||||
}
|
||||
|
||||
fn baz<T: Debug>(t: T) {
|
||||
foo(t);
|
||||
}
|
||||
|
||||
trait Tr {
|
||||
type Args;
|
||||
fn do_it(args: Self::Args);
|
||||
}
|
||||
|
||||
struct A;
|
||||
impl Tr for A {
|
||||
type Args = ();
|
||||
fn do_it(_: Self::Args) {}
|
||||
}
|
||||
|
||||
struct B;
|
||||
impl Tr for B {
|
||||
type Args = <A as Tr>::Args;
|
||||
|
||||
fn do_it(args: Self::Args) {
|
||||
A::do_it(args)
|
||||
}
|
||||
}
|
||||
|
||||
fn bad() {
|
||||
foo({
|
||||
1;
|
||||
|
|
@ -59,7 +83,7 @@ fn bad() {
|
|||
None.or(Some(foo(2)));
|
||||
// in this case, the suggestion can be inlined, no need for a surrounding block
|
||||
// foo(()); foo(()) instead of { foo(()); foo(()) }
|
||||
foo(foo(()))
|
||||
foo(foo(()));
|
||||
}
|
||||
|
||||
fn ok() {
|
||||
|
|
@ -71,6 +95,10 @@ fn ok() {
|
|||
b.bar({ 1 });
|
||||
b.bar(());
|
||||
question_mark();
|
||||
let named_unit_arg = ();
|
||||
foo(named_unit_arg);
|
||||
baz(());
|
||||
B::do_it(());
|
||||
}
|
||||
|
||||
fn question_mark() -> Result<(), ()> {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
error: passing a unit value to a function
|
||||
--> $DIR/unit_arg.rs:31:5
|
||||
--> $DIR/unit_arg.rs:55:5
|
||||
|
|
||||
LL | / foo({
|
||||
LL | | 1;
|
||||
|
|
@ -20,7 +20,7 @@ LL | foo(());
|
|||
|
|
||||
|
||||
error: passing a unit value to a function
|
||||
--> $DIR/unit_arg.rs:34:5
|
||||
--> $DIR/unit_arg.rs:58:5
|
||||
|
|
||||
LL | foo(foo(1));
|
||||
| ^^^^^^^^^^^
|
||||
|
|
@ -32,7 +32,7 @@ LL | foo(());
|
|||
|
|
||||
|
||||
error: passing a unit value to a function
|
||||
--> $DIR/unit_arg.rs:35:5
|
||||
--> $DIR/unit_arg.rs:59:5
|
||||
|
|
||||
LL | / foo({
|
||||
LL | | foo(1);
|
||||
|
|
@ -54,7 +54,7 @@ LL | foo(());
|
|||
|
|
||||
|
||||
error: passing a unit value to a function
|
||||
--> $DIR/unit_arg.rs:40:5
|
||||
--> $DIR/unit_arg.rs:64:5
|
||||
|
|
||||
LL | / b.bar({
|
||||
LL | | 1;
|
||||
|
|
@ -74,7 +74,7 @@ LL | b.bar(());
|
|||
|
|
||||
|
||||
error: passing unit values to a function
|
||||
--> $DIR/unit_arg.rs:43:5
|
||||
--> $DIR/unit_arg.rs:67:5
|
||||
|
|
||||
LL | taking_multiple_units(foo(0), foo(1));
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
@ -87,7 +87,7 @@ LL | taking_multiple_units((), ());
|
|||
|
|
||||
|
||||
error: passing unit values to a function
|
||||
--> $DIR/unit_arg.rs:44:5
|
||||
--> $DIR/unit_arg.rs:68:5
|
||||
|
|
||||
LL | / taking_multiple_units(foo(0), {
|
||||
LL | | foo(1);
|
||||
|
|
@ -110,7 +110,7 @@ LL | taking_multiple_units((), ());
|
|||
|
|
||||
|
||||
error: passing unit values to a function
|
||||
--> $DIR/unit_arg.rs:48:5
|
||||
--> $DIR/unit_arg.rs:72:5
|
||||
|
|
||||
LL | / taking_multiple_units(
|
||||
LL | | {
|
||||
|
|
@ -140,7 +140,7 @@ LL | foo(2);
|
|||
...
|
||||
|
||||
error: passing a unit value to a function
|
||||
--> $DIR/unit_arg.rs:59:13
|
||||
--> $DIR/unit_arg.rs:83:13
|
||||
|
|
||||
LL | None.or(Some(foo(2)));
|
||||
| ^^^^^^^^^^^^
|
||||
|
|
@ -154,19 +154,19 @@ LL | });
|
|||
|
|
||||
|
||||
error: passing a unit value to a function
|
||||
--> $DIR/unit_arg.rs:62:5
|
||||
--> $DIR/unit_arg.rs:86:5
|
||||
|
|
||||
LL | foo(foo(()))
|
||||
LL | foo(foo(()));
|
||||
| ^^^^^^^^^^^^
|
||||
|
|
||||
help: move the expression in front of the call and replace it with the unit literal `()`
|
||||
|
|
||||
LL | foo(());
|
||||
LL | foo(())
|
||||
LL | foo(());
|
||||
|
|
||||
|
||||
error: passing a unit value to a function
|
||||
--> $DIR/unit_arg.rs:95:5
|
||||
--> $DIR/unit_arg.rs:123:5
|
||||
|
|
||||
LL | Some(foo(1))
|
||||
| ^^^^^^^^^^^^
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ error: unnecessary closure used to substitute value for `Option::None`
|
|||
--> $DIR/unnecessary_lazy_eval.rs:35:13
|
||||
|
|
||||
LL | let _ = opt.unwrap_or_else(|| 2);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: Use `unwrap_or` instead: `opt.unwrap_or(2)`
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: use `unwrap_or` instead: `opt.unwrap_or(2)`
|
||||
|
|
||||
= note: `-D clippy::unnecessary-lazy-evaluations` implied by `-D warnings`
|
||||
|
||||
|
|
@ -10,187 +10,187 @@ error: unnecessary closure used to substitute value for `Option::None`
|
|||
--> $DIR/unnecessary_lazy_eval.rs:36:13
|
||||
|
|
||||
LL | let _ = opt.unwrap_or_else(|| astronomers_pi);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: Use `unwrap_or` instead: `opt.unwrap_or(astronomers_pi)`
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `unwrap_or` instead: `opt.unwrap_or(astronomers_pi)`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Option::None`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:37:13
|
||||
|
|
||||
LL | let _ = opt.unwrap_or_else(|| ext_str.some_field);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: Use `unwrap_or` instead: `opt.unwrap_or(ext_str.some_field)`
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `unwrap_or` instead: `opt.unwrap_or(ext_str.some_field)`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Option::None`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:39:13
|
||||
|
|
||||
LL | let _ = opt.and_then(|_| ext_opt);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: Use `and` instead: `opt.and(ext_opt)`
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `and` instead: `opt.and(ext_opt)`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Option::None`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:40:13
|
||||
|
|
||||
LL | let _ = opt.or_else(|| ext_opt);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^ help: Use `or` instead: `opt.or(ext_opt)`
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^ help: use `or` instead: `opt.or(ext_opt)`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Option::None`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:41:13
|
||||
|
|
||||
LL | let _ = opt.or_else(|| None);
|
||||
| ^^^^^^^^^^^^^^^^^^^^ help: Use `or` instead: `opt.or(None)`
|
||||
| ^^^^^^^^^^^^^^^^^^^^ help: use `or` instead: `opt.or(None)`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Option::None`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:42:13
|
||||
|
|
||||
LL | let _ = opt.get_or_insert_with(|| 2);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: Use `get_or_insert` instead: `opt.get_or_insert(2)`
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `get_or_insert` instead: `opt.get_or_insert(2)`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Option::None`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:43:13
|
||||
|
|
||||
LL | let _ = opt.ok_or_else(|| 2);
|
||||
| ^^^^^^^^^^^^^^^^^^^^ help: Use `ok_or` instead: `opt.ok_or(2)`
|
||||
| ^^^^^^^^^^^^^^^^^^^^ help: use `ok_or` instead: `opt.ok_or(2)`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Option::None`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:44:13
|
||||
|
|
||||
LL | let _ = nested_tuple_opt.unwrap_or_else(|| Some((1, 2)));
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: Use `unwrap_or` instead: `nested_tuple_opt.unwrap_or(Some((1, 2)))`
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `unwrap_or` instead: `nested_tuple_opt.unwrap_or(Some((1, 2)))`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Option::None`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:47:13
|
||||
|
|
||||
LL | let _ = Some(10).unwrap_or_else(|| 2);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: Use `unwrap_or` instead: `Some(10).unwrap_or(2)`
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `unwrap_or` instead: `Some(10).unwrap_or(2)`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Option::None`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:48:13
|
||||
|
|
||||
LL | let _ = Some(10).and_then(|_| ext_opt);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: Use `and` instead: `Some(10).and(ext_opt)`
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `and` instead: `Some(10).and(ext_opt)`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Option::None`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:49:28
|
||||
|
|
||||
LL | let _: Option<usize> = None.or_else(|| ext_opt);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: Use `or` instead: `None.or(ext_opt)`
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: use `or` instead: `None.or(ext_opt)`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Option::None`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:50:13
|
||||
|
|
||||
LL | let _ = None.get_or_insert_with(|| 2);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: Use `get_or_insert` instead: `None.get_or_insert(2)`
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `get_or_insert` instead: `None.get_or_insert(2)`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Option::None`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:51:35
|
||||
|
|
||||
LL | let _: Result<usize, usize> = None.ok_or_else(|| 2);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^ help: Use `ok_or` instead: `None.ok_or(2)`
|
||||
| ^^^^^^^^^^^^^^^^^^^^^ help: use `ok_or` instead: `None.ok_or(2)`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Option::None`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:52:28
|
||||
|
|
||||
LL | let _: Option<usize> = None.or_else(|| None);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^ help: Use `or` instead: `None.or(None)`
|
||||
| ^^^^^^^^^^^^^^^^^^^^^ help: use `or` instead: `None.or(None)`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Option::None`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:55:13
|
||||
|
|
||||
LL | let _ = deep.0.unwrap_or_else(|| 2);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: Use `unwrap_or` instead: `deep.0.unwrap_or(2)`
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `unwrap_or` instead: `deep.0.unwrap_or(2)`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Option::None`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:56:13
|
||||
|
|
||||
LL | let _ = deep.0.and_then(|_| ext_opt);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: Use `and` instead: `deep.0.and(ext_opt)`
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `and` instead: `deep.0.and(ext_opt)`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Option::None`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:57:13
|
||||
|
|
||||
LL | let _ = deep.0.or_else(|| None);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^ help: Use `or` instead: `deep.0.or(None)`
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^ help: use `or` instead: `deep.0.or(None)`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Option::None`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:58:13
|
||||
|
|
||||
LL | let _ = deep.0.get_or_insert_with(|| 2);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: Use `get_or_insert` instead: `deep.0.get_or_insert(2)`
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `get_or_insert` instead: `deep.0.get_or_insert(2)`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Option::None`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:59:13
|
||||
|
|
||||
LL | let _ = deep.0.ok_or_else(|| 2);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^ help: Use `ok_or` instead: `deep.0.ok_or(2)`
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^ help: use `ok_or` instead: `deep.0.ok_or(2)`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Option::None`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:79:28
|
||||
|
|
||||
LL | let _: Option<usize> = None.or_else(|| Some(3));
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: Use `or` instead: `None.or(Some(3))`
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: use `or` instead: `None.or(Some(3))`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Option::None`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:80:13
|
||||
|
|
||||
LL | let _ = deep.0.or_else(|| Some(3));
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: Use `or` instead: `deep.0.or(Some(3))`
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `or` instead: `deep.0.or(Some(3))`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Option::None`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:81:13
|
||||
|
|
||||
LL | let _ = opt.or_else(|| Some(3));
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^ help: Use `or` instead: `opt.or(Some(3))`
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^ help: use `or` instead: `opt.or(Some(3))`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Result::Err`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:87:13
|
||||
|
|
||||
LL | let _ = res2.unwrap_or_else(|_| 2);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: Use `unwrap_or` instead: `res2.unwrap_or(2)`
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `unwrap_or` instead: `res2.unwrap_or(2)`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Result::Err`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:88:13
|
||||
|
|
||||
LL | let _ = res2.unwrap_or_else(|_| astronomers_pi);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: Use `unwrap_or` instead: `res2.unwrap_or(astronomers_pi)`
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `unwrap_or` instead: `res2.unwrap_or(astronomers_pi)`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Result::Err`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:89:13
|
||||
|
|
||||
LL | let _ = res2.unwrap_or_else(|_| ext_str.some_field);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: Use `unwrap_or` instead: `res2.unwrap_or(ext_str.some_field)`
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `unwrap_or` instead: `res2.unwrap_or(ext_str.some_field)`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Result::Err`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:111:35
|
||||
|
|
||||
LL | let _: Result<usize, usize> = res.and_then(|_| Err(2));
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: Use `and` instead: `res.and(Err(2))`
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: use `and` instead: `res.and(Err(2))`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Result::Err`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:112:35
|
||||
|
|
||||
LL | let _: Result<usize, usize> = res.and_then(|_| Err(astronomers_pi));
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: Use `and` instead: `res.and(Err(astronomers_pi))`
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `and` instead: `res.and(Err(astronomers_pi))`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Result::Err`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:113:35
|
||||
|
|
||||
LL | let _: Result<usize, usize> = res.and_then(|_| Err(ext_str.some_field));
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: Use `and` instead: `res.and(Err(ext_str.some_field))`
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `and` instead: `res.and(Err(ext_str.some_field))`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Result::Err`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:115:35
|
||||
|
|
||||
LL | let _: Result<usize, usize> = res.or_else(|_| Ok(2));
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^ help: Use `or` instead: `res.or(Ok(2))`
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^ help: use `or` instead: `res.or(Ok(2))`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Result::Err`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:116:35
|
||||
|
|
||||
LL | let _: Result<usize, usize> = res.or_else(|_| Ok(astronomers_pi));
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: Use `or` instead: `res.or(Ok(astronomers_pi))`
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `or` instead: `res.or(Ok(astronomers_pi))`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Result::Err`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:117:35
|
||||
|
|
||||
LL | let _: Result<usize, usize> = res.or_else(|_| Ok(ext_str.some_field));
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: Use `or` instead: `res.or(Ok(ext_str.some_field))`
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `or` instead: `res.or(Ok(ext_str.some_field))`
|
||||
|
||||
error: aborting due to 32 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ error: unnecessary closure used to substitute value for `Result::Err`
|
|||
--> $DIR/unnecessary_lazy_eval_unfixable.rs:12:13
|
||||
|
|
||||
LL | let _ = Ok(1).unwrap_or_else(|()| 2);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: Use `unwrap_or` instead: `Ok(1).unwrap_or(2)`
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `unwrap_or` instead: `Ok(1).unwrap_or(2)`
|
||||
|
|
||||
= note: `-D clippy::unnecessary-lazy-evaluations` implied by `-D warnings`
|
||||
|
||||
|
|
@ -10,13 +10,13 @@ error: unnecessary closure used to substitute value for `Result::Err`
|
|||
--> $DIR/unnecessary_lazy_eval_unfixable.rs:16:13
|
||||
|
|
||||
LL | let _ = Ok(1).unwrap_or_else(|e::E| 2);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: Use `unwrap_or` instead: `Ok(1).unwrap_or(2)`
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `unwrap_or` instead: `Ok(1).unwrap_or(2)`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Result::Err`
|
||||
--> $DIR/unnecessary_lazy_eval_unfixable.rs:17:13
|
||||
|
|
||||
LL | let _ = Ok(1).unwrap_or_else(|SomeStruct { .. }| 2);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: Use `unwrap_or` instead: `Ok(1).unwrap_or(2)`
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `unwrap_or` instead: `Ok(1).unwrap_or(2)`
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -22,29 +22,17 @@ fn func2(a: bool, b: bool) -> Option<i32> {
|
|||
if a && b {
|
||||
return Some(10);
|
||||
}
|
||||
if a {
|
||||
Some(20)
|
||||
} else {
|
||||
Some(30)
|
||||
}
|
||||
if a { Some(20) } else { Some(30) }
|
||||
}
|
||||
|
||||
// public fns should not be linted
|
||||
pub fn func3(a: bool) -> Option<i32> {
|
||||
if a {
|
||||
Some(1)
|
||||
} else {
|
||||
Some(1)
|
||||
}
|
||||
if a { Some(1) } else { Some(1) }
|
||||
}
|
||||
|
||||
// should not be linted
|
||||
fn func4(a: bool) -> Option<i32> {
|
||||
if a {
|
||||
Some(1)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
if a { Some(1) } else { None }
|
||||
}
|
||||
|
||||
// should be linted
|
||||
|
|
@ -64,11 +52,7 @@ fn func7() -> Result<i32, ()> {
|
|||
|
||||
// should not be linted
|
||||
fn func8(a: bool) -> Result<i32, ()> {
|
||||
if a {
|
||||
Ok(1)
|
||||
} else {
|
||||
Err(())
|
||||
}
|
||||
if a { Ok(1) } else { Err(()) }
|
||||
}
|
||||
|
||||
// should not be linted
|
||||
|
|
@ -143,20 +127,12 @@ fn issue_6640_2(a: bool, b: bool) -> Result<(), i32> {
|
|||
|
||||
// should not be linted
|
||||
fn issue_6640_3() -> Option<()> {
|
||||
if true {
|
||||
Some(())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
if true { Some(()) } else { None }
|
||||
}
|
||||
|
||||
// should not be linted
|
||||
fn issue_6640_4() -> Result<(), ()> {
|
||||
if true {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(())
|
||||
}
|
||||
if true { Ok(()) } else { Err(()) }
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
|
|
|||
|
|
@ -32,8 +32,7 @@ LL | / fn func2(a: bool, b: bool) -> Option<i32> {
|
|||
LL | | if a && b {
|
||||
LL | | return Some(10);
|
||||
LL | | }
|
||||
... |
|
||||
LL | | }
|
||||
LL | | if a { Some(20) } else { Some(30) }
|
||||
LL | | }
|
||||
| |_^
|
||||
|
|
||||
|
|
@ -45,14 +44,11 @@ help: ...and then change returning expressions
|
|||
|
|
||||
LL | return 10;
|
||||
LL | }
|
||||
LL | if a {
|
||||
LL | 20
|
||||
LL | } else {
|
||||
LL | 30
|
||||
LL | if a { 20 } else { 30 }
|
||||
|
|
||||
|
||||
error: this function's return value is unnecessarily wrapped by `Option`
|
||||
--> $DIR/unnecessary_wraps.rs:51:1
|
||||
--> $DIR/unnecessary_wraps.rs:39:1
|
||||
|
|
||||
LL | / fn func5() -> Option<i32> {
|
||||
LL | | Some(1)
|
||||
|
|
@ -69,7 +65,7 @@ LL | 1
|
|||
|
|
||||
|
||||
error: this function's return value is unnecessarily wrapped by `Result`
|
||||
--> $DIR/unnecessary_wraps.rs:61:1
|
||||
--> $DIR/unnecessary_wraps.rs:49:1
|
||||
|
|
||||
LL | / fn func7() -> Result<i32, ()> {
|
||||
LL | | Ok(1)
|
||||
|
|
@ -86,7 +82,7 @@ LL | 1
|
|||
|
|
||||
|
||||
error: this function's return value is unnecessarily wrapped by `Option`
|
||||
--> $DIR/unnecessary_wraps.rs:93:5
|
||||
--> $DIR/unnecessary_wraps.rs:77:5
|
||||
|
|
||||
LL | / fn func12() -> Option<i32> {
|
||||
LL | | Some(1)
|
||||
|
|
@ -103,7 +99,7 @@ LL | 1
|
|||
|
|
||||
|
||||
error: this function's return value is unnecessary
|
||||
--> $DIR/unnecessary_wraps.rs:120:1
|
||||
--> $DIR/unnecessary_wraps.rs:104:1
|
||||
|
|
||||
LL | / fn issue_6640_1(a: bool, b: bool) -> Option<()> {
|
||||
LL | | if a && b {
|
||||
|
|
@ -129,7 +125,7 @@ LL | } else {
|
|||
...
|
||||
|
||||
error: this function's return value is unnecessary
|
||||
--> $DIR/unnecessary_wraps.rs:133:1
|
||||
--> $DIR/unnecessary_wraps.rs:117:1
|
||||
|
|
||||
LL | / fn issue_6640_2(a: bool, b: bool) -> Result<(), i32> {
|
||||
LL | | if a && b {
|
||||
|
|
|
|||
|
|
@ -16,7 +16,8 @@ enum Flags {
|
|||
FIN,
|
||||
}
|
||||
|
||||
struct GCCLLVMSomething; // linted with cfg option, beware that lint suggests `GccllvmSomething` instead of
|
||||
// `GccLlvmSomething`
|
||||
// linted with cfg option, beware that lint suggests `GccllvmSomething` instead of
|
||||
// `GccLlvmSomething`
|
||||
struct GCCLLVMSomething;
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -329,11 +329,7 @@ mod issue4140 {
|
|||
type To = Self;
|
||||
|
||||
fn from(value: bool) -> Self {
|
||||
if value {
|
||||
100
|
||||
} else {
|
||||
0
|
||||
}
|
||||
if value { 100 } else { 0 }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -458,3 +454,10 @@ mod nested_paths {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
mod issue6818 {
|
||||
#[derive(serde::Deserialize)]
|
||||
struct A {
|
||||
a: i32,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -329,11 +329,7 @@ mod issue4140 {
|
|||
type To = Self;
|
||||
|
||||
fn from(value: bool) -> Self {
|
||||
if value {
|
||||
100
|
||||
} else {
|
||||
0
|
||||
}
|
||||
if value { 100 } else { 0 }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -458,3 +454,10 @@ mod nested_paths {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
mod issue6818 {
|
||||
#[derive(serde::Deserialize)]
|
||||
struct A {
|
||||
a: i32,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -169,7 +169,7 @@ LL | type To = T::To;
|
|||
| ^^^^^ help: use the applicable keyword: `Self`
|
||||
|
||||
error: unnecessary structure name repetition
|
||||
--> $DIR/use_self.rs:457:13
|
||||
--> $DIR/use_self.rs:453:13
|
||||
|
|
||||
LL | A::new::<submod::B>(submod::B {})
|
||||
| ^ help: use the applicable keyword: `Self`
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
error: used binding `_foo` which is prefixed with an underscore. A leading underscore signals that a binding will not be used.
|
||||
error: used binding `_foo` which is prefixed with an underscore. A leading underscore signals that a binding will not be used
|
||||
--> $DIR/used_underscore_binding.rs:26:5
|
||||
|
|
||||
LL | _foo + 1
|
||||
|
|
@ -6,31 +6,31 @@ LL | _foo + 1
|
|||
|
|
||||
= note: `-D clippy::used-underscore-binding` implied by `-D warnings`
|
||||
|
||||
error: used binding `_foo` which is prefixed with an underscore. A leading underscore signals that a binding will not be used.
|
||||
error: used binding `_foo` which is prefixed with an underscore. A leading underscore signals that a binding will not be used
|
||||
--> $DIR/used_underscore_binding.rs:31:20
|
||||
|
|
||||
LL | println!("{}", _foo);
|
||||
| ^^^^
|
||||
|
||||
error: used binding `_foo` which is prefixed with an underscore. A leading underscore signals that a binding will not be used.
|
||||
error: used binding `_foo` which is prefixed with an underscore. A leading underscore signals that a binding will not be used
|
||||
--> $DIR/used_underscore_binding.rs:32:16
|
||||
|
|
||||
LL | assert_eq!(_foo, _foo);
|
||||
| ^^^^
|
||||
|
||||
error: used binding `_foo` which is prefixed with an underscore. A leading underscore signals that a binding will not be used.
|
||||
error: used binding `_foo` which is prefixed with an underscore. A leading underscore signals that a binding will not be used
|
||||
--> $DIR/used_underscore_binding.rs:32:22
|
||||
|
|
||||
LL | assert_eq!(_foo, _foo);
|
||||
| ^^^^
|
||||
|
||||
error: used binding `_underscore_field` which is prefixed with an underscore. A leading underscore signals that a binding will not be used.
|
||||
error: used binding `_underscore_field` which is prefixed with an underscore. A leading underscore signals that a binding will not be used
|
||||
--> $DIR/used_underscore_binding.rs:45:5
|
||||
|
|
||||
LL | s._underscore_field += 1;
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: used binding `_i` which is prefixed with an underscore. A leading underscore signals that a binding will not be used.
|
||||
error: used binding `_i` which is prefixed with an underscore. A leading underscore signals that a binding will not be used
|
||||
--> $DIR/used_underscore_binding.rs:100:16
|
||||
|
|
||||
LL | uses_i(_i);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
error: `Vec<T>` is already on the heap, the boxing is unnecessary.
|
||||
error: `Vec<T>` is already on the heap, the boxing is unnecessary
|
||||
--> $DIR/vec_box_sized.rs:14:21
|
||||
|
|
||||
LL | sized_type: Vec<Box<SizedStruct>>,
|
||||
|
|
@ -6,19 +6,19 @@ LL | sized_type: Vec<Box<SizedStruct>>,
|
|||
|
|
||||
= note: `-D clippy::vec-box` implied by `-D warnings`
|
||||
|
||||
error: `Vec<T>` is already on the heap, the boxing is unnecessary.
|
||||
error: `Vec<T>` is already on the heap, the boxing is unnecessary
|
||||
--> $DIR/vec_box_sized.rs:17:14
|
||||
|
|
||||
LL | struct A(Vec<Box<SizedStruct>>);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^ help: try: `Vec<SizedStruct>`
|
||||
|
||||
error: `Vec<T>` is already on the heap, the boxing is unnecessary.
|
||||
error: `Vec<T>` is already on the heap, the boxing is unnecessary
|
||||
--> $DIR/vec_box_sized.rs:18:18
|
||||
|
|
||||
LL | struct B(Vec<Vec<Box<(u32)>>>);
|
||||
| ^^^^^^^^^^^^^^^ help: try: `Vec<u32>`
|
||||
|
||||
error: `Vec<T>` is already on the heap, the boxing is unnecessary.
|
||||
error: `Vec<T>` is already on the heap, the boxing is unnecessary
|
||||
--> $DIR/vec_box_sized.rs:46:23
|
||||
|
|
||||
LL | pub fn f() -> Vec<Box<S>> {
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue