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

This commit is contained in:
Philipp Krones 2024-10-03 14:42:56 +02:00
commit d300cdfcda
No known key found for this signature in database
GPG key ID: 1CA0DF2AF59D68A5
190 changed files with 2531 additions and 865 deletions

View file

@ -1,7 +1,7 @@
#![allow(unused)]
#![warn(clippy::as_ptr_cast_mut)]
#![allow(clippy::wrong_self_convention, clippy::unnecessary_cast)]
//@no-rustfix
//@no-rustfix: incorrect suggestion
struct MutPtrWrapper(Vec<u8>);
impl MutPtrWrapper {

133
tests/ui/borrow_box.fixed Normal file
View file

@ -0,0 +1,133 @@
#![deny(clippy::borrowed_box)]
#![allow(dead_code, unused_variables)]
#![allow(
clippy::uninlined_format_args,
clippy::disallowed_names,
clippy::needless_pass_by_ref_mut,
clippy::needless_lifetimes
)]
use std::fmt::Display;
pub fn test1(foo: &mut Box<bool>) {
// Although this function could be changed to "&mut bool",
// avoiding the Box, mutable references to boxes are not
// flagged by this lint.
//
// This omission is intentional: By passing a mutable Box,
// the memory location of the pointed-to object could be
// modified. By passing a mutable reference, the contents
// could change, but not the location.
println!("{:?}", foo)
}
pub fn test2() {
let foo: &bool;
//~^ ERROR: you seem to be trying to use `&Box<T>`. Consider using just `&T`
}
struct Test3<'a> {
foo: &'a bool,
//~^ ERROR: you seem to be trying to use `&Box<T>`. Consider using just `&T`
}
trait Test4 {
fn test4(a: &bool);
//~^ ERROR: you seem to be trying to use `&Box<T>`. Consider using just `&T`
}
use std::any::Any;
pub fn test5(foo: &mut Box<dyn Any>) {
println!("{:?}", foo)
}
pub fn test6() {
let foo: &Box<dyn Any>;
}
struct Test7<'a> {
foo: &'a Box<dyn Any>,
}
trait Test8 {
fn test8(a: &Box<dyn Any>);
}
impl<'a> Test8 for Test7<'a> {
fn test8(a: &Box<dyn Any>) {
unimplemented!();
}
}
pub fn test9(foo: &mut Box<dyn Any + Send + Sync>) {
let _ = foo;
}
pub fn test10() {
let foo: &Box<dyn Any + Send + 'static>;
}
struct Test11<'a> {
foo: &'a Box<dyn Any + Send>,
}
trait Test12 {
fn test4(a: &Box<dyn Any + 'static>);
}
impl<'a> Test12 for Test11<'a> {
fn test4(a: &Box<dyn Any + 'static>) {
unimplemented!();
}
}
pub fn test13(boxed_slice: &mut Box<[i32]>) {
// Unconditionally replaces the box pointer.
//
// This cannot be accomplished if "&mut [i32]" is passed,
// and provides a test case where passing a reference to
// a Box is valid.
let mut data = vec![12];
*boxed_slice = data.into_boxed_slice();
}
// The suggestion should include proper parentheses to avoid a syntax error.
pub fn test14(_display: &dyn Display) {}
//~^ ERROR: you seem to be trying to use `&Box<T>`. Consider using just `&T`
pub fn test15(_display: &(dyn Display + Send)) {}
//~^ ERROR: you seem to be trying to use `&Box<T>`. Consider using just `&T`
pub fn test16<'a>(_display: &'a (dyn Display + 'a)) {}
//~^ ERROR: you seem to be trying to use `&Box<T>`. Consider using just `&T`
pub fn test17(_display: &impl Display) {}
//~^ ERROR: you seem to be trying to use `&Box<T>`. Consider using just `&T`
pub fn test18(_display: &(impl Display + Send)) {}
//~^ ERROR: you seem to be trying to use `&Box<T>`. Consider using just `&T`
pub fn test19<'a>(_display: &'a (impl Display + 'a)) {}
//~^ ERROR: you seem to be trying to use `&Box<T>`. Consider using just `&T`
// This exists only to check what happens when parentheses are already present.
// Even though the current implementation doesn't put extra parentheses,
// it's fine that unnecessary parentheses appear in the future for some reason.
pub fn test20(_display: &(dyn Display + Send)) {}
//~^ ERROR: you seem to be trying to use `&Box<T>`. Consider using just `&T`
#[allow(clippy::borrowed_box)]
trait Trait {
fn f(b: &Box<bool>);
}
// Trait impls are not linted
impl Trait for () {
fn f(_: &Box<bool>) {}
}
fn main() {
test1(&mut Box::new(false));
test2();
test5(&mut (Box::new(false) as Box<dyn Any>));
test6();
test9(&mut (Box::new(false) as Box<dyn Any + Send + Sync>));
test10();
}

View file

@ -3,9 +3,9 @@
#![allow(
clippy::uninlined_format_args,
clippy::disallowed_names,
clippy::needless_pass_by_ref_mut
clippy::needless_pass_by_ref_mut,
clippy::needless_lifetimes
)]
//@no-rustfix
use std::fmt::Display;
@ -36,12 +36,6 @@ trait Test4 {
//~^ ERROR: you seem to be trying to use `&Box<T>`. Consider using just `&T`
}
impl<'a> Test4 for Test3<'a> {
fn test4(a: &Box<bool>) {
unimplemented!();
}
}
use std::any::Any;
pub fn test5(foo: &mut Box<dyn Any>) {
@ -119,6 +113,16 @@ pub fn test19<'a>(_display: &'a Box<impl Display + 'a>) {}
pub fn test20(_display: &Box<(dyn Display + Send)>) {}
//~^ ERROR: you seem to be trying to use `&Box<T>`. Consider using just `&T`
#[allow(clippy::borrowed_box)]
trait Trait {
fn f(b: &Box<bool>);
}
// Trait impls are not linted
impl Trait for () {
fn f(_: &Box<bool>) {}
}
fn main() {
test1(&mut Box::new(false));
test2();

View file

@ -23,43 +23,43 @@ LL | fn test4(a: &Box<bool>);
| ^^^^^^^^^^ help: try: `&bool`
error: you seem to be trying to use `&Box<T>`. Consider using just `&T`
--> tests/ui/borrow_box.rs:102:25
--> tests/ui/borrow_box.rs:96:25
|
LL | pub fn test14(_display: &Box<dyn Display>) {}
| ^^^^^^^^^^^^^^^^^ help: try: `&dyn Display`
error: you seem to be trying to use `&Box<T>`. Consider using just `&T`
--> tests/ui/borrow_box.rs:104:25
--> tests/ui/borrow_box.rs:98:25
|
LL | pub fn test15(_display: &Box<dyn Display + Send>) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&(dyn Display + Send)`
error: you seem to be trying to use `&Box<T>`. Consider using just `&T`
--> tests/ui/borrow_box.rs:106:29
--> tests/ui/borrow_box.rs:100:29
|
LL | pub fn test16<'a>(_display: &'a Box<dyn Display + 'a>) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&'a (dyn Display + 'a)`
error: you seem to be trying to use `&Box<T>`. Consider using just `&T`
--> tests/ui/borrow_box.rs:109:25
--> tests/ui/borrow_box.rs:103:25
|
LL | pub fn test17(_display: &Box<impl Display>) {}
| ^^^^^^^^^^^^^^^^^^ help: try: `&impl Display`
error: you seem to be trying to use `&Box<T>`. Consider using just `&T`
--> tests/ui/borrow_box.rs:111:25
--> tests/ui/borrow_box.rs:105:25
|
LL | pub fn test18(_display: &Box<impl Display + Send>) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&(impl Display + Send)`
error: you seem to be trying to use `&Box<T>`. Consider using just `&T`
--> tests/ui/borrow_box.rs:113:29
--> tests/ui/borrow_box.rs:107:29
|
LL | pub fn test19<'a>(_display: &'a Box<impl Display + 'a>) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&'a (impl Display + 'a)`
error: you seem to be trying to use `&Box<T>`. Consider using just `&T`
--> tests/ui/borrow_box.rs:119:25
--> tests/ui/borrow_box.rs:113:25
|
LL | pub fn test20(_display: &Box<(dyn Display + Send)>) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&(dyn Display + Send)`

View file

@ -3,7 +3,8 @@
clippy::needless_pass_by_value,
clippy::unused_unit,
clippy::redundant_clone,
clippy::match_single_binding
clippy::match_single_binding,
clippy::needless_lifetimes
)]
#![warn(clippy::boxed_local)]

View file

@ -1,5 +1,5 @@
error: local variable doesn't need to be boxed here
--> tests/ui/boxed_local.rs:39:13
--> tests/ui/boxed_local.rs:40:13
|
LL | fn warn_arg(x: Box<A>) {
| ^
@ -8,19 +8,19 @@ LL | fn warn_arg(x: Box<A>) {
= help: to override `-D warnings` add `#[allow(clippy::boxed_local)]`
error: local variable doesn't need to be boxed here
--> tests/ui/boxed_local.rs:122:12
--> tests/ui/boxed_local.rs:123:12
|
LL | pub fn new(_needs_name: Box<PeekableSeekable<&()>>) -> () {}
| ^^^^^^^^^^^
error: local variable doesn't need to be boxed here
--> tests/ui/boxed_local.rs:187:44
--> tests/ui/boxed_local.rs:188:44
|
LL | fn default_impl_x(self: Box<Self>, x: Box<u32>) -> u32 {
| ^
error: local variable doesn't need to be boxed here
--> tests/ui/boxed_local.rs:195:16
--> tests/ui/boxed_local.rs:196:16
|
LL | fn foo(x: Box<u32>) {}
| ^

View file

@ -1,4 +1,4 @@
//@no-rustfix
//@no-rustfix: suggests external crate
#![allow(clippy::needless_borrow, clippy::useless_vec)]

View file

@ -9,7 +9,7 @@ struct Baz<'a> {
bar: &'a Bar,
}
impl<'a> Foo for Baz<'a> {}
impl Foo for Baz<'_> {}
impl Bar {
fn baz(&self) -> impl Foo + '_ {

View file

@ -1,8 +1,8 @@
error: the following explicit lifetimes could be elided: 'a
--> tests/ui/crashes/needless_lifetimes_impl_trait.rs:15:12
--> tests/ui/crashes/needless_lifetimes_impl_trait.rs:12:6
|
LL | fn baz<'a>(&'a self) -> impl Foo + 'a {
| ^^ ^^ ^^
LL | impl<'a> Foo for Baz<'a> {}
| ^^ ^^
|
note: the lint level is defined here
--> tests/ui/crashes/needless_lifetimes_impl_trait.rs:1:9
@ -11,9 +11,21 @@ LL | #![deny(clippy::needless_lifetimes)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
help: elide the lifetimes
|
LL - impl<'a> Foo for Baz<'a> {}
LL + impl Foo for Baz<'_> {}
|
error: the following explicit lifetimes could be elided: 'a
--> tests/ui/crashes/needless_lifetimes_impl_trait.rs:15:12
|
LL | fn baz<'a>(&'a self) -> impl Foo + 'a {
| ^^ ^^ ^^
|
help: elide the lifetimes
|
LL - fn baz<'a>(&'a self) -> impl Foo + 'a {
LL + fn baz(&self) -> impl Foo + '_ {
|
error: aborting due to 1 previous error
error: aborting due to 2 previous errors

View file

@ -1,5 +1,5 @@
// This test can't work with run-rustfix because it needs two passes of test+fix
//@no-rustfix
//@no-rustfix: this test can't work with run-rustfix because it needs two passes of test+fix
#[warn(clippy::deref_addrof)]
#[allow(unused_variables, unused_mut)]
fn main() {

View file

@ -1,7 +1,11 @@
#![allow(clippy::non_canonical_clone_impl, clippy::non_canonical_partial_ord_impl, dead_code)]
#![allow(
clippy::non_canonical_clone_impl,
clippy::non_canonical_partial_ord_impl,
clippy::needless_lifetimes,
dead_code
)]
#![warn(clippy::expl_impl_clone_on_copy)]
#[derive(Copy)]
struct Qux;

View file

@ -1,5 +1,5 @@
error: you are implementing `Clone` explicitly on a `Copy` type
--> tests/ui/derive.rs:8:1
--> tests/ui/derive.rs:12:1
|
LL | / impl Clone for Qux {
LL | |
@ -10,7 +10,7 @@ LL | | }
| |_^
|
note: consider deriving `Clone` or removing `Copy`
--> tests/ui/derive.rs:8:1
--> tests/ui/derive.rs:12:1
|
LL | / impl Clone for Qux {
LL | |
@ -23,7 +23,7 @@ LL | | }
= help: to override `-D warnings` add `#[allow(clippy::expl_impl_clone_on_copy)]`
error: you are implementing `Clone` explicitly on a `Copy` type
--> tests/ui/derive.rs:33:1
--> tests/ui/derive.rs:37:1
|
LL | / impl<'a> Clone for Lt<'a> {
LL | |
@ -34,7 +34,7 @@ LL | | }
| |_^
|
note: consider deriving `Clone` or removing `Copy`
--> tests/ui/derive.rs:33:1
--> tests/ui/derive.rs:37:1
|
LL | / impl<'a> Clone for Lt<'a> {
LL | |
@ -45,7 +45,7 @@ LL | | }
| |_^
error: you are implementing `Clone` explicitly on a `Copy` type
--> tests/ui/derive.rs:45:1
--> tests/ui/derive.rs:49:1
|
LL | / impl Clone for BigArray {
LL | |
@ -56,7 +56,7 @@ LL | | }
| |_^
|
note: consider deriving `Clone` or removing `Copy`
--> tests/ui/derive.rs:45:1
--> tests/ui/derive.rs:49:1
|
LL | / impl Clone for BigArray {
LL | |
@ -67,7 +67,7 @@ LL | | }
| |_^
error: you are implementing `Clone` explicitly on a `Copy` type
--> tests/ui/derive.rs:57:1
--> tests/ui/derive.rs:61:1
|
LL | / impl Clone for FnPtr {
LL | |
@ -78,7 +78,7 @@ LL | | }
| |_^
|
note: consider deriving `Clone` or removing `Copy`
--> tests/ui/derive.rs:57:1
--> tests/ui/derive.rs:61:1
|
LL | / impl Clone for FnPtr {
LL | |
@ -89,7 +89,7 @@ LL | | }
| |_^
error: you are implementing `Clone` explicitly on a `Copy` type
--> tests/ui/derive.rs:78:1
--> tests/ui/derive.rs:82:1
|
LL | / impl<T: Clone> Clone for Generic2<T> {
LL | |
@ -100,7 +100,7 @@ LL | | }
| |_^
|
note: consider deriving `Clone` or removing `Copy`
--> tests/ui/derive.rs:78:1
--> tests/ui/derive.rs:82:1
|
LL | / impl<T: Clone> Clone for Generic2<T> {
LL | |

View file

@ -9,7 +9,8 @@
clippy::redundant_closure_call,
clippy::uninlined_format_args,
clippy::useless_vec,
clippy::unnecessary_map_on_constructor
clippy::unnecessary_map_on_constructor,
clippy::needless_lifetimes
)]
use std::path::{Path, PathBuf};

View file

@ -9,7 +9,8 @@
clippy::redundant_closure_call,
clippy::uninlined_format_args,
clippy::useless_vec,
clippy::unnecessary_map_on_constructor
clippy::unnecessary_map_on_constructor,
clippy::needless_lifetimes
)]
use std::path::{Path, PathBuf};

View file

@ -1,5 +1,5 @@
error: redundant closure
--> tests/ui/eta.rs:30:27
--> tests/ui/eta.rs:31:27
|
LL | let a = Some(1u8).map(|a| foo(a));
| ^^^^^^^^^^ help: replace the closure with the function itself: `foo`
@ -8,31 +8,31 @@ LL | let a = Some(1u8).map(|a| foo(a));
= help: to override `-D warnings` add `#[allow(clippy::redundant_closure)]`
error: redundant closure
--> tests/ui/eta.rs:34:40
--> tests/ui/eta.rs:35:40
|
LL | let _: Option<Vec<u8>> = true.then(|| vec![]); // special case vec!
| ^^^^^^^^^ help: replace the closure with `Vec::new`: `std::vec::Vec::new`
error: redundant closure
--> tests/ui/eta.rs:35:35
--> tests/ui/eta.rs:36:35
|
LL | let d = Some(1u8).map(|a| foo((|b| foo2(b))(a))); //is adjusted?
| ^^^^^^^^^^^^^ help: replace the closure with the function itself: `foo2`
error: redundant closure
--> tests/ui/eta.rs:36:26
--> tests/ui/eta.rs:37:26
|
LL | all(&[1, 2, 3], &&2, |x, y| below(x, y)); //is adjusted
| ^^^^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `below`
error: redundant closure
--> tests/ui/eta.rs:43:27
--> tests/ui/eta.rs:44:27
|
LL | let e = Some(1u8).map(|a| generic(a));
| ^^^^^^^^^^^^^^ help: replace the closure with the function itself: `generic`
error: redundant closure
--> tests/ui/eta.rs:95:51
--> tests/ui/eta.rs:96:51
|
LL | let e = Some(TestStruct { some_ref: &i }).map(|a| a.foo());
| ^^^^^^^^^^^ help: replace the closure with the method itself: `TestStruct::foo`
@ -41,169 +41,169 @@ LL | let e = Some(TestStruct { some_ref: &i }).map(|a| a.foo());
= help: to override `-D warnings` add `#[allow(clippy::redundant_closure_for_method_calls)]`
error: redundant closure
--> tests/ui/eta.rs:96:51
--> tests/ui/eta.rs:97:51
|
LL | let e = Some(TestStruct { some_ref: &i }).map(|a| a.trait_foo());
| ^^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `TestTrait::trait_foo`
error: redundant closure
--> tests/ui/eta.rs:98:42
--> tests/ui/eta.rs:99:42
|
LL | let e = Some(&mut vec![1, 2, 3]).map(|v| v.clear());
| ^^^^^^^^^^^^^ help: replace the closure with the method itself: `std::vec::Vec::clear`
error: redundant closure
--> tests/ui/eta.rs:102:29
--> tests/ui/eta.rs:103:29
|
LL | let e = Some("str").map(|s| s.to_string());
| ^^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `std::string::ToString::to_string`
error: redundant closure
--> tests/ui/eta.rs:103:27
--> tests/ui/eta.rs:104:27
|
LL | let e = Some('a').map(|s| s.to_uppercase());
| ^^^^^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `char::to_uppercase`
error: redundant closure
--> tests/ui/eta.rs:105:65
--> tests/ui/eta.rs:106:65
|
LL | let e: std::vec::Vec<char> = vec!['a', 'b', 'c'].iter().map(|c| c.to_ascii_uppercase()).collect();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `char::to_ascii_uppercase`
error: redundant closure
--> tests/ui/eta.rs:168:22
--> tests/ui/eta.rs:169:22
|
LL | requires_fn_once(|| x());
| ^^^^^^ help: replace the closure with the function itself: `x`
error: redundant closure
--> tests/ui/eta.rs:175:27
--> tests/ui/eta.rs:176:27
|
LL | let a = Some(1u8).map(|a| foo_ptr(a));
| ^^^^^^^^^^^^^^ help: replace the closure with the function itself: `foo_ptr`
error: redundant closure
--> tests/ui/eta.rs:180:27
--> tests/ui/eta.rs:181:27
|
LL | let a = Some(1u8).map(|a| closure(a));
| ^^^^^^^^^^^^^^ help: replace the closure with the function itself: `closure`
error: redundant closure
--> tests/ui/eta.rs:212:28
--> tests/ui/eta.rs:213:28
|
LL | x.into_iter().for_each(|x| add_to_res(x));
| ^^^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `&mut add_to_res`
error: redundant closure
--> tests/ui/eta.rs:213:28
--> tests/ui/eta.rs:214:28
|
LL | y.into_iter().for_each(|x| add_to_res(x));
| ^^^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `&mut add_to_res`
error: redundant closure
--> tests/ui/eta.rs:214:28
--> tests/ui/eta.rs:215:28
|
LL | z.into_iter().for_each(|x| add_to_res(x));
| ^^^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `add_to_res`
error: redundant closure
--> tests/ui/eta.rs:221:21
--> tests/ui/eta.rs:222:21
|
LL | Some(1).map(|n| closure(n));
| ^^^^^^^^^^^^^^ help: replace the closure with the function itself: `&mut closure`
error: redundant closure
--> tests/ui/eta.rs:225:21
--> tests/ui/eta.rs:226:21
|
LL | Some(1).map(|n| in_loop(n));
| ^^^^^^^^^^^^^^ help: replace the closure with the function itself: `in_loop`
error: redundant closure
--> tests/ui/eta.rs:318:18
--> tests/ui/eta.rs:319:18
|
LL | takes_fn_mut(|| f());
| ^^^^^^ help: replace the closure with the function itself: `&mut f`
error: redundant closure
--> tests/ui/eta.rs:321:19
--> tests/ui/eta.rs:322:19
|
LL | takes_fn_once(|| f());
| ^^^^^^ help: replace the closure with the function itself: `&mut f`
error: redundant closure
--> tests/ui/eta.rs:325:26
--> tests/ui/eta.rs:326:26
|
LL | move || takes_fn_mut(|| f_used_once())
| ^^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `&mut f_used_once`
error: redundant closure
--> tests/ui/eta.rs:337:19
--> tests/ui/eta.rs:338:19
|
LL | array_opt.map(|a| a.as_slice());
| ^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `<[u8; 3]>::as_slice`
error: redundant closure
--> tests/ui/eta.rs:340:19
--> tests/ui/eta.rs:341:19
|
LL | slice_opt.map(|s| s.len());
| ^^^^^^^^^^^ help: replace the closure with the method itself: `<[u8]>::len`
error: redundant closure
--> tests/ui/eta.rs:343:17
--> tests/ui/eta.rs:344:17
|
LL | ptr_opt.map(|p| p.is_null());
| ^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `<*const usize>::is_null`
error: redundant closure
--> tests/ui/eta.rs:347:17
--> tests/ui/eta.rs:348:17
|
LL | dyn_opt.map(|d| d.method_on_dyn());
| ^^^^^^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `<dyn TestTrait>::method_on_dyn`
error: redundant closure
--> tests/ui/eta.rs:407:19
--> tests/ui/eta.rs:408:19
|
LL | let _ = f(&0, |x, y| f2(x, y));
| ^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `f2`
error: redundant closure
--> tests/ui/eta.rs:435:22
--> tests/ui/eta.rs:436:22
|
LL | test.map(|t| t.method())
| ^^^^^^^^^^^^^^ help: replace the closure with the method itself: `Test::method`
error: redundant closure
--> tests/ui/eta.rs:439:22
--> tests/ui/eta.rs:440:22
|
LL | test.map(|t| t.method())
| ^^^^^^^^^^^^^^ help: replace the closure with the method itself: `super::Outer::method`
error: redundant closure
--> tests/ui/eta.rs:452:18
--> tests/ui/eta.rs:453:18
|
LL | test.map(|t| t.method())
| ^^^^^^^^^^^^^^ help: replace the closure with the method itself: `test_mod::Test::method`
error: redundant closure
--> tests/ui/eta.rs:459:30
--> tests/ui/eta.rs:460:30
|
LL | test.map(|t| t.method())
| ^^^^^^^^^^^^^^ help: replace the closure with the method itself: `crate::issue_10854::d::Test::method`
error: redundant closure
--> tests/ui/eta.rs:478:38
--> tests/ui/eta.rs:479:38
|
LL | let x = Box::new(|| None.map(|x| f(x)));
| ^^^^^^^^ help: replace the closure with the function itself: `&f`
error: redundant closure
--> tests/ui/eta.rs:482:38
--> tests/ui/eta.rs:483:38
|
LL | let x = Box::new(|| None.map(|x| f(x)));
| ^^^^^^^^ help: replace the closure with the function itself: `f`
error: redundant closure
--> tests/ui/eta.rs:499:35
--> tests/ui/eta.rs:500:35
|
LL | let _field = bind.or_else(|| get_default()).unwrap();
| ^^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `get_default`

View file

@ -10,7 +10,8 @@
clippy::redundant_field_names,
clippy::too_many_arguments,
clippy::borrow_deref_ref,
clippy::let_unit_value
clippy::let_unit_value,
clippy::needless_lifetimes
)]
trait CallableStr {

View file

@ -10,7 +10,8 @@
clippy::redundant_field_names,
clippy::too_many_arguments,
clippy::borrow_deref_ref,
clippy::let_unit_value
clippy::let_unit_value,
clippy::needless_lifetimes
)]
trait CallableStr {

View file

@ -1,5 +1,5 @@
error: deref which would be done by auto-deref
--> tests/ui/explicit_auto_deref.rs:68:19
--> tests/ui/explicit_auto_deref.rs:69:19
|
LL | let _: &str = &*s;
| ^^^ help: try: `&s`
@ -8,271 +8,271 @@ LL | let _: &str = &*s;
= help: to override `-D warnings` add `#[allow(clippy::explicit_auto_deref)]`
error: deref which would be done by auto-deref
--> tests/ui/explicit_auto_deref.rs:69:19
--> tests/ui/explicit_auto_deref.rs:70:19
|
LL | let _: &str = &*{ String::new() };
| ^^^^^^^^^^^^^^^^^^^ help: try: `&{ String::new() }`
error: deref which would be done by auto-deref
--> tests/ui/explicit_auto_deref.rs:70:19
--> tests/ui/explicit_auto_deref.rs:71:19
|
LL | let _: &str = &mut *{ String::new() };
| ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&mut { String::new() }`
error: deref which would be done by auto-deref
--> tests/ui/explicit_auto_deref.rs:74:11
--> tests/ui/explicit_auto_deref.rs:75:11
|
LL | f_str(&*s);
| ^^^ help: try: `&s`
error: deref which would be done by auto-deref
--> tests/ui/explicit_auto_deref.rs:78:13
--> tests/ui/explicit_auto_deref.rs:79:13
|
LL | f_str_t(&*s, &*s); // Don't lint second param.
| ^^^ help: try: `&s`
error: deref which would be done by auto-deref
--> tests/ui/explicit_auto_deref.rs:81:24
--> tests/ui/explicit_auto_deref.rs:82:24
|
LL | let _: &Box<i32> = &**b;
| ^^^^ help: try: `&b`
error: deref which would be done by auto-deref
--> tests/ui/explicit_auto_deref.rs:87:7
--> tests/ui/explicit_auto_deref.rs:88:7
|
LL | c(&*s);
| ^^^ help: try: `&s`
error: deref which would be done by auto-deref
--> tests/ui/explicit_auto_deref.rs:93:9
--> tests/ui/explicit_auto_deref.rs:94:9
|
LL | &**x
| ^^^^ help: try: `x`
error: deref which would be done by auto-deref
--> tests/ui/explicit_auto_deref.rs:97:11
--> tests/ui/explicit_auto_deref.rs:98:11
|
LL | { &**x }
| ^^^^ help: try: `x`
error: deref which would be done by auto-deref
--> tests/ui/explicit_auto_deref.rs:101:9
--> tests/ui/explicit_auto_deref.rs:102:9
|
LL | &**{ x }
| ^^^^^^^^ help: try: `{ x }`
error: deref which would be done by auto-deref
--> tests/ui/explicit_auto_deref.rs:105:9
--> tests/ui/explicit_auto_deref.rs:106:9
|
LL | &***x
| ^^^^^ help: try: `x`
error: deref which would be done by auto-deref
--> tests/ui/explicit_auto_deref.rs:122:12
--> tests/ui/explicit_auto_deref.rs:123:12
|
LL | f1(&*x);
| ^^^ help: try: `&x`
error: deref which would be done by auto-deref
--> tests/ui/explicit_auto_deref.rs:123:12
--> tests/ui/explicit_auto_deref.rs:124:12
|
LL | f2(&*x);
| ^^^ help: try: `&x`
error: deref which would be done by auto-deref
--> tests/ui/explicit_auto_deref.rs:124:12
--> tests/ui/explicit_auto_deref.rs:125:12
|
LL | f3(&*x);
| ^^^ help: try: `&x`
error: deref which would be done by auto-deref
--> tests/ui/explicit_auto_deref.rs:125:27
--> tests/ui/explicit_auto_deref.rs:126:27
|
LL | f4.callable_str()(&*x);
| ^^^ help: try: `&x`
error: deref which would be done by auto-deref
--> tests/ui/explicit_auto_deref.rs:126:12
--> tests/ui/explicit_auto_deref.rs:127:12
|
LL | f5(&*x);
| ^^^ help: try: `&x`
error: deref which would be done by auto-deref
--> tests/ui/explicit_auto_deref.rs:127:12
--> tests/ui/explicit_auto_deref.rs:128:12
|
LL | f6(&*x);
| ^^^ help: try: `&x`
error: deref which would be done by auto-deref
--> tests/ui/explicit_auto_deref.rs:128:27
--> tests/ui/explicit_auto_deref.rs:129:27
|
LL | f7.callable_str()(&*x);
| ^^^ help: try: `&x`
error: deref which would be done by auto-deref
--> tests/ui/explicit_auto_deref.rs:129:25
--> tests/ui/explicit_auto_deref.rs:130:25
|
LL | f8.callable_t()(&*x);
| ^^^ help: try: `&x`
error: deref which would be done by auto-deref
--> tests/ui/explicit_auto_deref.rs:130:12
--> tests/ui/explicit_auto_deref.rs:131:12
|
LL | f9(&*x);
| ^^^ help: try: `&x`
error: deref which would be done by auto-deref
--> tests/ui/explicit_auto_deref.rs:131:13
--> tests/ui/explicit_auto_deref.rs:132:13
|
LL | f10(&*x);
| ^^^ help: try: `&x`
error: deref which would be done by auto-deref
--> tests/ui/explicit_auto_deref.rs:132:26
--> tests/ui/explicit_auto_deref.rs:133:26
|
LL | f11.callable_t()(&*x);
| ^^^ help: try: `&x`
error: deref which would be done by auto-deref
--> tests/ui/explicit_auto_deref.rs:136:16
--> tests/ui/explicit_auto_deref.rs:137:16
|
LL | let _ = S1(&*s);
| ^^^ help: try: `&s`
error: deref which would be done by auto-deref
--> tests/ui/explicit_auto_deref.rs:141:21
--> tests/ui/explicit_auto_deref.rs:142:21
|
LL | let _ = S2 { s: &*s };
| ^^^ help: try: `&s`
error: deref which would be done by auto-deref
--> tests/ui/explicit_auto_deref.rs:157:30
--> tests/ui/explicit_auto_deref.rs:158:30
|
LL | let _ = Self::S1(&**s);
| ^^^^ help: try: `s`
error: deref which would be done by auto-deref
--> tests/ui/explicit_auto_deref.rs:158:35
--> tests/ui/explicit_auto_deref.rs:159:35
|
LL | let _ = Self::S2 { s: &**s };
| ^^^^ help: try: `s`
error: deref which would be done by auto-deref
--> tests/ui/explicit_auto_deref.rs:161:20
--> tests/ui/explicit_auto_deref.rs:162:20
|
LL | let _ = E1::S1(&*s);
| ^^^ help: try: `&s`
error: deref which would be done by auto-deref
--> tests/ui/explicit_auto_deref.rs:162:25
--> tests/ui/explicit_auto_deref.rs:163:25
|
LL | let _ = E1::S2 { s: &*s };
| ^^^ help: try: `&s`
error: deref which would be done by auto-deref
--> tests/ui/explicit_auto_deref.rs:180:13
--> tests/ui/explicit_auto_deref.rs:181:13
|
LL | let _ = (*b).foo;
| ^^^^ help: try: `b`
error: deref which would be done by auto-deref
--> tests/ui/explicit_auto_deref.rs:181:13
--> tests/ui/explicit_auto_deref.rs:182:13
|
LL | let _ = (**b).foo;
| ^^^^^ help: try: `b`
error: deref which would be done by auto-deref
--> tests/ui/explicit_auto_deref.rs:196:19
--> tests/ui/explicit_auto_deref.rs:197:19
|
LL | let _ = f_str(*ref_str);
| ^^^^^^^^ help: try: `ref_str`
error: deref which would be done by auto-deref
--> tests/ui/explicit_auto_deref.rs:198:19
--> tests/ui/explicit_auto_deref.rs:199:19
|
LL | let _ = f_str(**ref_ref_str);
| ^^^^^^^^^^^^^ help: try: `ref_ref_str`
error: deref which would be done by auto-deref
--> tests/ui/explicit_auto_deref.rs:208:12
--> tests/ui/explicit_auto_deref.rs:209:12
|
LL | f_str(&&*ref_str); // `needless_borrow` will suggest removing both references
| ^^^^^^^^^ help: try: `ref_str`
error: deref which would be done by auto-deref
--> tests/ui/explicit_auto_deref.rs:209:12
--> tests/ui/explicit_auto_deref.rs:210:12
|
LL | f_str(&&**ref_str); // `needless_borrow` will suggest removing only one reference
| ^^^^^^^^^^ help: try: `ref_str`
error: deref which would be done by auto-deref
--> tests/ui/explicit_auto_deref.rs:218:41
--> tests/ui/explicit_auto_deref.rs:219:41
|
LL | let _ = || -> &'static str { return *s };
| ^^ help: try: `s`
error: deref which would be done by auto-deref
--> tests/ui/explicit_auto_deref.rs:237:9
--> tests/ui/explicit_auto_deref.rs:238:9
|
LL | &**x
| ^^^^ help: try: `x`
error: deref which would be done by auto-deref
--> tests/ui/explicit_auto_deref.rs:260:8
--> tests/ui/explicit_auto_deref.rs:261:8
|
LL | c1(*x);
| ^^ help: try: `x`
error: deref which would be done by auto-deref
--> tests/ui/explicit_auto_deref.rs:263:20
--> tests/ui/explicit_auto_deref.rs:264:20
|
LL | return *x;
| ^^ help: try: `x`
error: deref which would be done by auto-deref
--> tests/ui/explicit_auto_deref.rs:265:9
--> tests/ui/explicit_auto_deref.rs:266:9
|
LL | *x
| ^^ help: try: `x`
error: deref which would be done by auto-deref
--> tests/ui/explicit_auto_deref.rs:299:20
--> tests/ui/explicit_auto_deref.rs:300:20
|
LL | Some(x) => &mut *x,
| ^^^^^^^ help: try: `x`
error: deref which would be done by auto-deref
--> tests/ui/explicit_auto_deref.rs:332:22
--> tests/ui/explicit_auto_deref.rs:333:22
|
LL | let _ = &mut (*{ x.u }).x;
| ^^^^^^^^^^ help: try: `{ x.u }`
error: deref which would be done by auto-deref
--> tests/ui/explicit_auto_deref.rs:338:22
--> tests/ui/explicit_auto_deref.rs:339:22
|
LL | let _ = &mut (**x.u).x;
| ^^^^^^^ help: try: `(*x.u)`
error: deref which would be done by auto-deref
--> tests/ui/explicit_auto_deref.rs:339:22
--> tests/ui/explicit_auto_deref.rs:340:22
|
LL | let _ = &mut (**{ x.u }).x;
| ^^^^^^^^^^^ help: try: `{ x.u }`
error: deref which would be done by auto-deref
--> tests/ui/explicit_auto_deref.rs:343:22
--> tests/ui/explicit_auto_deref.rs:344:22
|
LL | let _ = &mut (*x.u).x;
| ^^^^^^ help: try: `x.u`
error: deref which would be done by auto-deref
--> tests/ui/explicit_auto_deref.rs:344:22
--> tests/ui/explicit_auto_deref.rs:345:22
|
LL | let _ = &mut (*{ x.u }).x;
| ^^^^^^^^^^ help: try: `{ x.u }`
error: deref which would be done by auto-deref
--> tests/ui/explicit_auto_deref.rs:367:13
--> tests/ui/explicit_auto_deref.rs:368:13
|
LL | foo(&*wrapped_bar);
| ^^^^^^^^^^^^^ help: try: `&wrapped_bar`

View file

@ -114,9 +114,17 @@ mod second_case {
fn hey();
}
// Should lint. The response to the above comment incorrectly called this a false positive. The
// lifetime `'a` can be removed, as demonstrated below.
impl<'a, T: Source + ?Sized + 'a> Source for Box<T> {
fn hey() {}
}
struct OtherBox<T: ?Sized>(Box<T>);
impl<T: Source + ?Sized> Source for OtherBox<T> {
fn hey() {}
}
}
// Should not lint

View file

@ -37,5 +37,11 @@ error: this lifetime isn't used in the function definition
LL | pub fn something<'c>() -> Self {
| ^^
error: aborting due to 6 previous errors
error: this lifetime isn't used in the impl
--> tests/ui/extra_unused_lifetimes.rs:119:10
|
LL | impl<'a, T: Source + ?Sized + 'a> Source for Box<T> {
| ^^
error: aborting due to 7 previous errors

View file

@ -8,7 +8,7 @@
clippy::unnecessary_operation,
clippy::cast_lossless
)]
//@no-rustfix
//@no-rustfix: suggestions have an error margin placeholder
use std::ops::Add;
const ZERO: f32 = 0.0;

View file

@ -1,5 +1,4 @@
// does not test any rustfixable lints
//@no-rustfix
//@no-rustfix: suggestions have an error margin placeholder
#![warn(clippy::float_cmp_const)]
#![allow(clippy::float_cmp)]
#![allow(unused, clippy::no_effect, clippy::unnecessary_operation)]

View file

@ -1,5 +1,5 @@
error: strict comparison of `f32` or `f64` constant
--> tests/ui/float_cmp_const.rs:16:5
--> tests/ui/float_cmp_const.rs:15:5
|
LL | 1f32 == ONE;
| ^^^^^^^^^^^ help: consider comparing them within some margin of error: `(1f32 - ONE).abs() < error_margin`
@ -8,43 +8,43 @@ LL | 1f32 == ONE;
= help: to override `-D warnings` add `#[allow(clippy::float_cmp_const)]`
error: strict comparison of `f32` or `f64` constant
--> tests/ui/float_cmp_const.rs:18:5
--> tests/ui/float_cmp_const.rs:17:5
|
LL | TWO == ONE;
| ^^^^^^^^^^ help: consider comparing them within some margin of error: `(TWO - ONE).abs() < error_margin`
error: strict comparison of `f32` or `f64` constant
--> tests/ui/float_cmp_const.rs:20:5
--> tests/ui/float_cmp_const.rs:19:5
|
LL | TWO != ONE;
| ^^^^^^^^^^ help: consider comparing them within some margin of error: `(TWO - ONE).abs() > error_margin`
error: strict comparison of `f32` or `f64` constant
--> tests/ui/float_cmp_const.rs:22:5
--> tests/ui/float_cmp_const.rs:21:5
|
LL | ONE + ONE == TWO;
| ^^^^^^^^^^^^^^^^ help: consider comparing them within some margin of error: `(ONE + ONE - TWO).abs() < error_margin`
error: strict comparison of `f32` or `f64` constant
--> tests/ui/float_cmp_const.rs:25:5
--> tests/ui/float_cmp_const.rs:24:5
|
LL | x as f32 == ONE;
| ^^^^^^^^^^^^^^^ help: consider comparing them within some margin of error: `(x as f32 - ONE).abs() < error_margin`
error: strict comparison of `f32` or `f64` constant
--> tests/ui/float_cmp_const.rs:29:5
--> tests/ui/float_cmp_const.rs:28:5
|
LL | v == ONE;
| ^^^^^^^^ help: consider comparing them within some margin of error: `(v - ONE).abs() < error_margin`
error: strict comparison of `f32` or `f64` constant
--> tests/ui/float_cmp_const.rs:31:5
--> tests/ui/float_cmp_const.rs:30:5
|
LL | v != ONE;
| ^^^^^^^^ help: consider comparing them within some margin of error: `(v - ONE).abs() > error_margin`
error: strict comparison of `f32` or `f64` constant arrays
--> tests/ui/float_cmp_const.rs:64:5
--> tests/ui/float_cmp_const.rs:63:5
|
LL | NON_ZERO_ARRAY == NON_ZERO_ARRAY2;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View file

@ -1,5 +1,5 @@
#![warn(clippy::float_equality_without_abs)]
//@no-rustfix
//@no-rustfix: suggestions cause type ambiguity
// FIXME(f16_f128): add tests for these types when abs is available

View file

@ -1,5 +1,5 @@
#![deny(clippy::index_refutable_slice)]
#![allow(clippy::uninlined_format_args)]
#![allow(clippy::uninlined_format_args, clippy::needless_lifetimes)]
//@no-rustfix: need to change the suggestion to a multipart suggestion

View file

@ -24,11 +24,8 @@ fn main() {
let _a: A = std::ptr::read_volatile(core::ptr::NonNull::dangling().as_ptr());
let _a: A = std::ptr::replace(core::ptr::NonNull::dangling().as_ptr(), A);
let _slice: *const [usize] = std::ptr::slice_from_raw_parts(core::ptr::NonNull::dangling().as_ptr(), 0);
let _slice: *const [usize] = std::ptr::slice_from_raw_parts(core::ptr::NonNull::dangling().as_ptr(), 0);
let _slice: *const [usize] = std::ptr::slice_from_raw_parts_mut(core::ptr::NonNull::dangling().as_ptr(), 0);
let _slice: *const [usize] = std::ptr::slice_from_raw_parts(std::ptr::null_mut(), 0); // shouldn't lint
let _slice: *const [usize] = std::ptr::slice_from_raw_parts_mut(std::ptr::null_mut(), 0);
std::ptr::swap::<A>(core::ptr::NonNull::dangling().as_ptr(), &mut A);
std::ptr::swap::<A>(&mut A, core::ptr::NonNull::dangling().as_ptr());

View file

@ -24,10 +24,7 @@ fn main() {
let _a: A = std::ptr::read_volatile(std::ptr::null_mut());
let _a: A = std::ptr::replace(std::ptr::null_mut(), A);
let _slice: *const [usize] = std::ptr::slice_from_raw_parts(std::ptr::null(), 0);
let _slice: *const [usize] = std::ptr::slice_from_raw_parts(std::ptr::null_mut(), 0);
let _slice: *const [usize] = std::ptr::slice_from_raw_parts(std::ptr::null_mut(), 0); // shouldn't lint
let _slice: *const [usize] = std::ptr::slice_from_raw_parts_mut(std::ptr::null_mut(), 0);
std::ptr::swap::<A>(std::ptr::null_mut(), &mut A);

View file

@ -85,70 +85,52 @@ LL | let _a: A = std::ptr::replace(std::ptr::null_mut(), A);
| ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()`
error: pointer must be non-null
--> tests/ui/invalid_null_ptr_usage.rs:28:69
|
LL | let _slice: *const [usize] = std::ptr::slice_from_raw_parts(std::ptr::null(), 0);
| ^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()`
error: pointer must be non-null
--> tests/ui/invalid_null_ptr_usage.rs:29:69
|
LL | let _slice: *const [usize] = std::ptr::slice_from_raw_parts(std::ptr::null_mut(), 0);
| ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()`
error: pointer must be non-null
--> tests/ui/invalid_null_ptr_usage.rs:31:73
|
LL | let _slice: *const [usize] = std::ptr::slice_from_raw_parts_mut(std::ptr::null_mut(), 0);
| ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()`
error: pointer must be non-null
--> tests/ui/invalid_null_ptr_usage.rs:33:29
--> tests/ui/invalid_null_ptr_usage.rs:30:29
|
LL | std::ptr::swap::<A>(std::ptr::null_mut(), &mut A);
| ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()`
error: pointer must be non-null
--> tests/ui/invalid_null_ptr_usage.rs:34:37
--> tests/ui/invalid_null_ptr_usage.rs:31:37
|
LL | std::ptr::swap::<A>(&mut A, std::ptr::null_mut());
| ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()`
error: pointer must be non-null
--> tests/ui/invalid_null_ptr_usage.rs:36:44
--> tests/ui/invalid_null_ptr_usage.rs:33:44
|
LL | std::ptr::swap_nonoverlapping::<A>(std::ptr::null_mut(), &mut A, 0);
| ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()`
error: pointer must be non-null
--> tests/ui/invalid_null_ptr_usage.rs:37:52
--> tests/ui/invalid_null_ptr_usage.rs:34:52
|
LL | std::ptr::swap_nonoverlapping::<A>(&mut A, std::ptr::null_mut(), 0);
| ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()`
error: pointer must be non-null
--> tests/ui/invalid_null_ptr_usage.rs:39:25
--> tests/ui/invalid_null_ptr_usage.rs:36:25
|
LL | std::ptr::write(std::ptr::null_mut(), A);
| ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()`
error: pointer must be non-null
--> tests/ui/invalid_null_ptr_usage.rs:41:35
--> tests/ui/invalid_null_ptr_usage.rs:38:35
|
LL | std::ptr::write_unaligned(std::ptr::null_mut(), A);
| ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()`
error: pointer must be non-null
--> tests/ui/invalid_null_ptr_usage.rs:43:34
--> tests/ui/invalid_null_ptr_usage.rs:40:34
|
LL | std::ptr::write_volatile(std::ptr::null_mut(), A);
| ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()`
error: pointer must be non-null
--> tests/ui/invalid_null_ptr_usage.rs:45:40
--> tests/ui/invalid_null_ptr_usage.rs:42:40
|
LL | std::ptr::write_bytes::<usize>(std::ptr::null_mut(), 42, 0);
| ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()`
error: aborting due to 25 previous errors
error: aborting due to 22 previous errors

View file

@ -1,6 +1,7 @@
//@no-rustfix
//@aux-build:proc_macros.rs
#![warn(clippy::iter_without_into_iter)]
#![allow(clippy::needless_lifetimes)]
extern crate proc_macros;
pub struct S1;

View file

@ -1,5 +1,5 @@
error: `iter` method without an `IntoIterator` impl for `&S1`
--> tests/ui/iter_without_into_iter.rs:8:5
--> tests/ui/iter_without_into_iter.rs:9:5
|
LL | / pub fn iter(&self) -> std::slice::Iter<'_, u8> {
LL | |
@ -22,7 +22,7 @@ LL + }
|
error: `iter_mut` method without an `IntoIterator` impl for `&mut S1`
--> tests/ui/iter_without_into_iter.rs:12:5
--> tests/ui/iter_without_into_iter.rs:13:5
|
LL | / pub fn iter_mut(&mut self) -> std::slice::IterMut<'_, u8> {
LL | |
@ -43,7 +43,7 @@ LL + }
|
error: `iter` method without an `IntoIterator` impl for `&S3<'a>`
--> tests/ui/iter_without_into_iter.rs:28:5
--> tests/ui/iter_without_into_iter.rs:29:5
|
LL | / pub fn iter(&self) -> std::slice::Iter<'_, u8> {
LL | |
@ -64,7 +64,7 @@ LL + }
|
error: `iter_mut` method without an `IntoIterator` impl for `&mut S3<'a>`
--> tests/ui/iter_without_into_iter.rs:32:5
--> tests/ui/iter_without_into_iter.rs:33:5
|
LL | / pub fn iter_mut(&mut self) -> std::slice::IterMut<'_, u8> {
LL | |
@ -85,7 +85,7 @@ LL + }
|
error: `iter` method without an `IntoIterator` impl for `&S8<T>`
--> tests/ui/iter_without_into_iter.rs:69:5
--> tests/ui/iter_without_into_iter.rs:70:5
|
LL | / pub fn iter(&self) -> std::slice::Iter<'static, T> {
LL | | todo!()
@ -105,7 +105,7 @@ LL + }
|
error: `iter` method without an `IntoIterator` impl for `&S9<T>`
--> tests/ui/iter_without_into_iter.rs:77:5
--> tests/ui/iter_without_into_iter.rs:78:5
|
LL | / pub fn iter(&self) -> std::slice::Iter<'_, T> {
LL | |
@ -126,7 +126,7 @@ LL + }
|
error: `iter_mut` method without an `IntoIterator` impl for `&mut S9<T>`
--> tests/ui/iter_without_into_iter.rs:81:5
--> tests/ui/iter_without_into_iter.rs:82:5
|
LL | / pub fn iter_mut(&mut self) -> std::slice::IterMut<'_, T> {
LL | |
@ -147,7 +147,7 @@ LL + }
|
error: `iter` method without an `IntoIterator` impl for `&Issue12037`
--> tests/ui/iter_without_into_iter.rs:130:13
--> tests/ui/iter_without_into_iter.rs:131:13
|
LL | / fn iter(&self) -> std::slice::Iter<'_, u8> {
LL | | todo!()

View file

@ -1,6 +1,5 @@
#![allow(unused)]
#![allow(unused, clippy::needless_lifetimes)]
#![warn(
clippy::all,
clippy::style,
clippy::mem_replace_option_with_none,
clippy::mem_replace_with_default

View file

@ -1,6 +1,5 @@
#![allow(unused)]
#![allow(unused, clippy::needless_lifetimes)]
#![warn(
clippy::all,
clippy::style,
clippy::mem_replace_option_with_none,
clippy::mem_replace_with_default

View file

@ -1,5 +1,5 @@
error: replacing an `Option` with `None`
--> tests/ui/mem_replace.rs:14:13
--> tests/ui/mem_replace.rs:13:13
|
LL | let _ = mem::replace(&mut an_option, None);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider `Option::take()` instead: `an_option.take()`
@ -8,13 +8,13 @@ LL | let _ = mem::replace(&mut an_option, None);
= help: to override `-D warnings` add `#[allow(clippy::mem_replace_option_with_none)]`
error: replacing an `Option` with `None`
--> tests/ui/mem_replace.rs:16:13
--> tests/ui/mem_replace.rs:15:13
|
LL | let _ = mem::replace(an_option, None);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider `Option::take()` instead: `an_option.take()`
error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
--> tests/ui/mem_replace.rs:21:13
--> tests/ui/mem_replace.rs:20:13
|
LL | let _ = std::mem::replace(&mut s, String::default());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut s)`
@ -23,127 +23,127 @@ LL | let _ = std::mem::replace(&mut s, String::default());
= help: to override `-D warnings` add `#[allow(clippy::mem_replace_with_default)]`
error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
--> tests/ui/mem_replace.rs:24:13
--> tests/ui/mem_replace.rs:23:13
|
LL | let _ = std::mem::replace(s, String::default());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(s)`
error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
--> tests/ui/mem_replace.rs:25:13
--> tests/ui/mem_replace.rs:24:13
|
LL | let _ = std::mem::replace(s, Default::default());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(s)`
error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
--> tests/ui/mem_replace.rs:28:13
--> tests/ui/mem_replace.rs:27:13
|
LL | let _ = std::mem::replace(&mut v, Vec::default());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut v)`
error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
--> tests/ui/mem_replace.rs:29:13
--> tests/ui/mem_replace.rs:28:13
|
LL | let _ = std::mem::replace(&mut v, Default::default());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut v)`
error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
--> tests/ui/mem_replace.rs:30:13
--> tests/ui/mem_replace.rs:29:13
|
LL | let _ = std::mem::replace(&mut v, Vec::new());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut v)`
error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
--> tests/ui/mem_replace.rs:31:13
--> tests/ui/mem_replace.rs:30:13
|
LL | let _ = std::mem::replace(&mut v, vec![]);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut v)`
error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
--> tests/ui/mem_replace.rs:34:13
--> tests/ui/mem_replace.rs:33:13
|
LL | let _ = std::mem::replace(&mut hash_map, HashMap::new());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut hash_map)`
error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
--> tests/ui/mem_replace.rs:37:13
--> tests/ui/mem_replace.rs:36:13
|
LL | let _ = std::mem::replace(&mut btree_map, BTreeMap::new());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut btree_map)`
error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
--> tests/ui/mem_replace.rs:40:13
--> tests/ui/mem_replace.rs:39:13
|
LL | let _ = std::mem::replace(&mut vd, VecDeque::new());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut vd)`
error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
--> tests/ui/mem_replace.rs:43:13
--> tests/ui/mem_replace.rs:42:13
|
LL | let _ = std::mem::replace(&mut hash_set, HashSet::new());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut hash_set)`
error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
--> tests/ui/mem_replace.rs:46:13
--> tests/ui/mem_replace.rs:45:13
|
LL | let _ = std::mem::replace(&mut btree_set, BTreeSet::new());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut btree_set)`
error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
--> tests/ui/mem_replace.rs:49:13
--> tests/ui/mem_replace.rs:48:13
|
LL | let _ = std::mem::replace(&mut list, LinkedList::new());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut list)`
error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
--> tests/ui/mem_replace.rs:52:13
--> tests/ui/mem_replace.rs:51:13
|
LL | let _ = std::mem::replace(&mut binary_heap, BinaryHeap::new());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut binary_heap)`
error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
--> tests/ui/mem_replace.rs:55:13
--> tests/ui/mem_replace.rs:54:13
|
LL | let _ = std::mem::replace(&mut tuple, (vec![], BinaryHeap::new()));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut tuple)`
error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
--> tests/ui/mem_replace.rs:58:13
--> tests/ui/mem_replace.rs:57:13
|
LL | let _ = std::mem::replace(&mut refstr, "");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut refstr)`
error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
--> tests/ui/mem_replace.rs:61:13
--> tests/ui/mem_replace.rs:60:13
|
LL | let _ = std::mem::replace(&mut slice, &[]);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut slice)`
error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
--> tests/ui/mem_replace.rs:97:13
--> tests/ui/mem_replace.rs:96:13
|
LL | let _ = std::mem::replace(&mut s, String::default());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut s)`
error: replacing an `Option` with `None`
--> tests/ui/mem_replace.rs:127:13
--> tests/ui/mem_replace.rs:126:13
|
LL | let _ = std::mem::replace(&mut f.0, None);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider `Option::take()` instead: `f.0.take()`
error: replacing an `Option` with `None`
--> tests/ui/mem_replace.rs:128:13
--> tests/ui/mem_replace.rs:127:13
|
LL | let _ = std::mem::replace(&mut *f, None);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider `Option::take()` instead: `(*f).take()`
error: replacing an `Option` with `None`
--> tests/ui/mem_replace.rs:129:13
--> tests/ui/mem_replace.rs:128:13
|
LL | let _ = std::mem::replace(&mut b.opt, None);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider `Option::take()` instead: `b.opt.take()`
error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
--> tests/ui/mem_replace.rs:131:13
--> tests/ui/mem_replace.rs:130:13
|
LL | let _ = std::mem::replace(&mut b.val, String::default());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut b.val)`

View file

@ -1,6 +1,5 @@
#![allow(unused)]
#![allow(unused, clippy::needless_lifetimes)]
#![warn(
clippy::all,
clippy::style,
clippy::mem_replace_option_with_none,
clippy::mem_replace_with_default

View file

@ -1,6 +1,5 @@
#![allow(unused)]
#![allow(unused, clippy::needless_lifetimes)]
#![warn(
clippy::all,
clippy::style,
clippy::mem_replace_option_with_none,
clippy::mem_replace_with_default

View file

@ -1,5 +1,5 @@
error: replacing an `Option` with `None`
--> tests/ui/mem_replace_no_std.rs:24:13
--> tests/ui/mem_replace_no_std.rs:23:13
|
LL | let _ = mem::replace(&mut an_option, None);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider `Option::take()` instead: `an_option.take()`
@ -8,13 +8,13 @@ LL | let _ = mem::replace(&mut an_option, None);
= help: to override `-D warnings` add `#[allow(clippy::mem_replace_option_with_none)]`
error: replacing an `Option` with `None`
--> tests/ui/mem_replace_no_std.rs:26:13
--> tests/ui/mem_replace_no_std.rs:25:13
|
LL | let _ = mem::replace(an_option, None);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider `Option::take()` instead: `an_option.take()`
error: replacing a value of type `T` with `T::default()` is better expressed using `core::mem::take`
--> tests/ui/mem_replace_no_std.rs:31:13
--> tests/ui/mem_replace_no_std.rs:30:13
|
LL | let _ = mem::replace(&mut refstr, "");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `core::mem::take(&mut refstr)`
@ -23,25 +23,25 @@ LL | let _ = mem::replace(&mut refstr, "");
= help: to override `-D warnings` add `#[allow(clippy::mem_replace_with_default)]`
error: replacing a value of type `T` with `T::default()` is better expressed using `core::mem::take`
--> tests/ui/mem_replace_no_std.rs:34:13
--> tests/ui/mem_replace_no_std.rs:33:13
|
LL | let _ = mem::replace(&mut slice, &[]);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `core::mem::take(&mut slice)`
error: replacing an `Option` with `None`
--> tests/ui/mem_replace_no_std.rs:77:13
--> tests/ui/mem_replace_no_std.rs:76:13
|
LL | let _ = mem::replace(&mut f.0, None);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider `Option::take()` instead: `f.0.take()`
error: replacing an `Option` with `None`
--> tests/ui/mem_replace_no_std.rs:78:13
--> tests/ui/mem_replace_no_std.rs:77:13
|
LL | let _ = mem::replace(&mut *f, None);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider `Option::take()` instead: `(*f).take()`
error: replacing an `Option` with `None`
--> tests/ui/mem_replace_no_std.rs:79:13
--> tests/ui/mem_replace_no_std.rs:78:13
|
LL | let _ = mem::replace(&mut b.opt, None);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider `Option::take()` instead: `b.opt.take()`

View file

@ -1,5 +1,5 @@
#![warn(clippy::mismatching_type_param_order)]
#![allow(clippy::disallowed_names)]
#![allow(clippy::disallowed_names, clippy::needless_lifetimes)]
fn main() {
struct Foo<A, B> {

View file

@ -9,6 +9,11 @@ fn mut_mutex_lock() {
let mut value = value_mutex.get_mut().unwrap();
*value += 1;
let mut value_mutex = Mutex::new(42_u8);
let mut_ref_mut_ref_mutex = &mut &mut value_mutex;
let mut value = mut_ref_mut_ref_mutex.get_mut().unwrap();
*value += 1;
}
fn no_owned_mutex_lock() {
@ -24,4 +29,11 @@ fn issue9415() {
*guard += 1;
}
fn mut_ref_ref_mutex_lock() {
let mutex = Mutex::new(42_u8);
let mut_ref_ref_mutex = &mut &mutex;
let mut guard = mut_ref_ref_mutex.lock().unwrap();
*guard += 1;
}
fn main() {}

View file

@ -9,6 +9,11 @@ fn mut_mutex_lock() {
let mut value = value_mutex.lock().unwrap();
*value += 1;
let mut value_mutex = Mutex::new(42_u8);
let mut_ref_mut_ref_mutex = &mut &mut value_mutex;
let mut value = mut_ref_mut_ref_mutex.lock().unwrap();
*value += 1;
}
fn no_owned_mutex_lock() {
@ -24,4 +29,11 @@ fn issue9415() {
*guard += 1;
}
fn mut_ref_ref_mutex_lock() {
let mutex = Mutex::new(42_u8);
let mut_ref_ref_mutex = &mut &mutex;
let mut guard = mut_ref_ref_mutex.lock().unwrap();
*guard += 1;
}
fn main() {}

View file

@ -7,5 +7,11 @@ LL | let mut value = value_mutex.lock().unwrap();
= note: `-D clippy::mut-mutex-lock` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::mut_mutex_lock)]`
error: aborting due to 1 previous error
error: calling `&mut Mutex::lock` unnecessarily locks an exclusive (mutable) reference
--> tests/ui/mut_mutex_lock.rs:15:43
|
LL | let mut value = mut_ref_mut_ref_mutex.lock().unwrap();
| ^^^^ help: change this to: `get_mut`
error: aborting due to 2 previous errors

View file

@ -4,7 +4,8 @@
clippy::uninlined_format_args,
clippy::unnecessary_mut_passed,
clippy::unnecessary_to_owned,
clippy::unnecessary_literal_unwrap
clippy::unnecessary_literal_unwrap,
clippy::needless_lifetimes
)]
#![warn(clippy::needless_borrow)]

View file

@ -4,7 +4,8 @@
clippy::uninlined_format_args,
clippy::unnecessary_mut_passed,
clippy::unnecessary_to_owned,
clippy::unnecessary_literal_unwrap
clippy::unnecessary_literal_unwrap,
clippy::needless_lifetimes
)]
#![warn(clippy::needless_borrow)]

View file

@ -1,5 +1,5 @@
error: this expression creates a reference which is immediately dereferenced by the compiler
--> tests/ui/needless_borrow.rs:15:15
--> tests/ui/needless_borrow.rs:16:15
|
LL | let _ = x(&&a); // warn
| ^^^ help: change this to: `&a`
@ -8,163 +8,163 @@ LL | let _ = x(&&a); // warn
= help: to override `-D warnings` add `#[allow(clippy::needless_borrow)]`
error: this expression creates a reference which is immediately dereferenced by the compiler
--> tests/ui/needless_borrow.rs:19:13
--> tests/ui/needless_borrow.rs:20:13
|
LL | mut_ref(&mut &mut b); // warn
| ^^^^^^^^^^^ help: change this to: `&mut b`
error: this expression creates a reference which is immediately dereferenced by the compiler
--> tests/ui/needless_borrow.rs:31:13
--> tests/ui/needless_borrow.rs:32:13
|
LL | &&a
| ^^^ help: change this to: `&a`
error: this expression creates a reference which is immediately dereferenced by the compiler
--> tests/ui/needless_borrow.rs:33:15
--> tests/ui/needless_borrow.rs:34:15
|
LL | 46 => &&a,
| ^^^ help: change this to: `&a`
error: this expression creates a reference which is immediately dereferenced by the compiler
--> tests/ui/needless_borrow.rs:39:27
--> tests/ui/needless_borrow.rs:40:27
|
LL | break &ref_a;
| ^^^^^^ help: change this to: `ref_a`
error: this expression creates a reference which is immediately dereferenced by the compiler
--> tests/ui/needless_borrow.rs:46:15
--> tests/ui/needless_borrow.rs:47:15
|
LL | let _ = x(&&&a);
| ^^^^ help: change this to: `&a`
error: this expression creates a reference which is immediately dereferenced by the compiler
--> tests/ui/needless_borrow.rs:47:15
--> tests/ui/needless_borrow.rs:48:15
|
LL | let _ = x(&mut &&a);
| ^^^^^^^^ help: change this to: `&a`
error: this expression creates a reference which is immediately dereferenced by the compiler
--> tests/ui/needless_borrow.rs:48:15
--> tests/ui/needless_borrow.rs:49:15
|
LL | let _ = x(&&&mut b);
| ^^^^^^^^ help: change this to: `&mut b`
error: this expression creates a reference which is immediately dereferenced by the compiler
--> tests/ui/needless_borrow.rs:49:15
--> tests/ui/needless_borrow.rs:50:15
|
LL | let _ = x(&&ref_a);
| ^^^^^^^ help: change this to: `ref_a`
error: this expression creates a reference which is immediately dereferenced by the compiler
--> tests/ui/needless_borrow.rs:52:11
--> tests/ui/needless_borrow.rs:53:11
|
LL | x(&b);
| ^^ help: change this to: `b`
error: this expression creates a reference which is immediately dereferenced by the compiler
--> tests/ui/needless_borrow.rs:59:13
--> tests/ui/needless_borrow.rs:60:13
|
LL | mut_ref(&mut x);
| ^^^^^^ help: change this to: `x`
error: this expression creates a reference which is immediately dereferenced by the compiler
--> tests/ui/needless_borrow.rs:60:13
--> tests/ui/needless_borrow.rs:61:13
|
LL | mut_ref(&mut &mut x);
| ^^^^^^^^^^^ help: change this to: `x`
error: this expression creates a reference which is immediately dereferenced by the compiler
--> tests/ui/needless_borrow.rs:61:23
--> tests/ui/needless_borrow.rs:62:23
|
LL | let y: &mut i32 = &mut x;
| ^^^^^^ help: change this to: `x`
error: this expression creates a reference which is immediately dereferenced by the compiler
--> tests/ui/needless_borrow.rs:62:23
--> tests/ui/needless_borrow.rs:63:23
|
LL | let y: &mut i32 = &mut &mut x;
| ^^^^^^^^^^^ help: change this to: `x`
error: this expression creates a reference which is immediately dereferenced by the compiler
--> tests/ui/needless_borrow.rs:71:14
--> tests/ui/needless_borrow.rs:72:14
|
LL | 0 => &mut x,
| ^^^^^^ help: change this to: `x`
error: this expression creates a reference which is immediately dereferenced by the compiler
--> tests/ui/needless_borrow.rs:77:14
--> tests/ui/needless_borrow.rs:78:14
|
LL | 0 => &mut x,
| ^^^^^^ help: change this to: `x`
error: this expression borrows a value the compiler would automatically borrow
--> tests/ui/needless_borrow.rs:89:13
--> tests/ui/needless_borrow.rs:90:13
|
LL | let _ = (&x).0;
| ^^^^ help: change this to: `x`
error: this expression borrows a value the compiler would automatically borrow
--> tests/ui/needless_borrow.rs:91:22
--> tests/ui/needless_borrow.rs:92:22
|
LL | let _ = unsafe { (&*x).0 };
| ^^^^^ help: change this to: `(*x)`
error: this expression creates a reference which is immediately dereferenced by the compiler
--> tests/ui/needless_borrow.rs:101:5
--> tests/ui/needless_borrow.rs:102:5
|
LL | (&&()).foo();
| ^^^^^^ help: change this to: `(&())`
error: this expression creates a reference which is immediately dereferenced by the compiler
--> tests/ui/needless_borrow.rs:110:5
--> tests/ui/needless_borrow.rs:111:5
|
LL | (&&5).foo();
| ^^^^^ help: change this to: `(&5)`
error: this expression creates a reference which is immediately dereferenced by the compiler
--> tests/ui/needless_borrow.rs:136:23
--> tests/ui/needless_borrow.rs:137:23
|
LL | let x: (&str,) = (&"",);
| ^^^ help: change this to: `""`
error: this expression borrows a value the compiler would automatically borrow
--> tests/ui/needless_borrow.rs:178:13
--> tests/ui/needless_borrow.rs:179:13
|
LL | (&self.f)()
| ^^^^^^^^^ help: change this to: `(self.f)`
error: this expression borrows a value the compiler would automatically borrow
--> tests/ui/needless_borrow.rs:187:13
--> tests/ui/needless_borrow.rs:188:13
|
LL | (&mut self.f)()
| ^^^^^^^^^^^^^ help: change this to: `(self.f)`
error: this expression borrows a value the compiler would automatically borrow
--> tests/ui/needless_borrow.rs:224:22
--> tests/ui/needless_borrow.rs:225:22
|
LL | let _ = &mut (&mut { x.u }).x;
| ^^^^^^^^^^^^^^ help: change this to: `{ x.u }`
error: this expression borrows a value the compiler would automatically borrow
--> tests/ui/needless_borrow.rs:231:22
--> tests/ui/needless_borrow.rs:232:22
|
LL | let _ = &mut (&mut { x.u }).x;
| ^^^^^^^^^^^^^^ help: change this to: `{ x.u }`
error: this expression borrows a value the compiler would automatically borrow
--> tests/ui/needless_borrow.rs:235:22
--> tests/ui/needless_borrow.rs:236:22
|
LL | let _ = &mut (&mut x.u).x;
| ^^^^^^^^^^ help: change this to: `x.u`
error: this expression borrows a value the compiler would automatically borrow
--> tests/ui/needless_borrow.rs:236:22
--> tests/ui/needless_borrow.rs:237:22
|
LL | let _ = &mut (&mut { x.u }).x;
| ^^^^^^^^^^^^^^ help: change this to: `{ x.u }`
error: this expression creates a reference which is immediately dereferenced by the compiler
--> tests/ui/needless_borrow.rs:257:23
--> tests/ui/needless_borrow.rs:258:23
|
LL | option.unwrap_or((&x.0,));
| ^^^^ help: change this to: `x.0`

View file

@ -10,7 +10,7 @@
/// unimplemented!();
/// }
/// ```
///
///
/// With an explicit return type it should lint too
/// ```edition2015
/// fn main() -> () {
@ -18,7 +18,7 @@
/// unimplemented!();
/// }
/// ```
///
///
/// This should, too.
/// ```rust
/// fn main() {
@ -26,7 +26,7 @@
/// unimplemented!();
/// }
/// ```
///
///
/// This one too.
/// ```no_run
/// // the fn is not always the first line

View file

@ -329,7 +329,7 @@ mod issue2944 {
bar: &'a Bar,
}
impl<'a> Foo for Baz<'a> {}
impl Foo for Baz<'_> {}
impl Bar {
fn baz(&self) -> impl Foo + '_ {
Baz { bar: self }
@ -384,7 +384,7 @@ mod nested_elision_sites {
f()
}
// lint
fn where_clause_elidadable<T>(i: &i32, f: T) -> &i32
fn where_clause_elidable<T>(i: &i32, f: T) -> &i32
where
T: Fn(&i32) -> &i32,
{
@ -543,4 +543,23 @@ mod issue5787 {
}
}
// https://github.com/rust-lang/rust-clippy/pull/13286#issuecomment-2374245772
mod rayon {
trait ParallelIterator {
type Item;
}
struct Copied<I: ParallelIterator> {
base: I,
}
impl<'a, T, I> ParallelIterator for Copied<I>
where
I: ParallelIterator<Item = &'a T>,
T: 'a + Copy + Send + Sync,
{
type Item = T;
}
}
fn main() {}

View file

@ -384,7 +384,7 @@ mod nested_elision_sites {
f()
}
// lint
fn where_clause_elidadable<'a, T>(i: &'a i32, f: T) -> &'a i32
fn where_clause_elidable<'a, T>(i: &'a i32, f: T) -> &'a i32
where
T: Fn(&i32) -> &i32,
{
@ -543,4 +543,23 @@ mod issue5787 {
}
}
// https://github.com/rust-lang/rust-clippy/pull/13286#issuecomment-2374245772
mod rayon {
trait ParallelIterator {
type Item;
}
struct Copied<I: ParallelIterator> {
base: I,
}
impl<'a, T, I> ParallelIterator for Copied<I>
where
I: ParallelIterator<Item = &'a T>,
T: 'a + Copy + Send + Sync,
{
type Item = T;
}
}
fn main() {}

View file

@ -335,6 +335,18 @@ LL - fn needless_lt<'a>(_x: &'a u8) {}
LL + fn needless_lt(_x: &u8) {}
|
error: the following explicit lifetimes could be elided: 'a
--> tests/ui/needless_lifetimes.rs:332:10
|
LL | impl<'a> Foo for Baz<'a> {}
| ^^ ^^
|
help: elide the lifetimes
|
LL - impl<'a> Foo for Baz<'a> {}
LL + impl Foo for Baz<'_> {}
|
error: the following explicit lifetimes could be elided: 'a
--> tests/ui/needless_lifetimes.rs:334:16
|
@ -372,15 +384,15 @@ LL + fn generics_elidable<T: Fn(&i32) -> &i32>(i: &i32, f: T) -> &i32 {
|
error: the following explicit lifetimes could be elided: 'a
--> tests/ui/needless_lifetimes.rs:387:32
--> tests/ui/needless_lifetimes.rs:387:30
|
LL | fn where_clause_elidadable<'a, T>(i: &'a i32, f: T) -> &'a i32
| ^^ ^^ ^^
LL | fn where_clause_elidable<'a, T>(i: &'a i32, f: T) -> &'a i32
| ^^ ^^ ^^
|
help: elide the lifetimes
|
LL - fn where_clause_elidadable<'a, T>(i: &'a i32, f: T) -> &'a i32
LL + fn where_clause_elidadable<T>(i: &i32, f: T) -> &i32
LL - fn where_clause_elidable<'a, T>(i: &'a i32, f: T) -> &'a i32
LL + fn where_clause_elidable<T>(i: &i32, f: T) -> &i32
|
error: the following explicit lifetimes could be elided: 'a
@ -564,5 +576,5 @@ LL - fn one_input<'a>(x: &'a u8) -> &'a u8 {
LL + fn one_input(x: &u8) -> &u8 {
|
error: aborting due to 47 previous errors
error: aborting due to 48 previous errors

View file

@ -5,7 +5,8 @@
clippy::redundant_clone,
clippy::redundant_pattern_matching,
clippy::single_match,
clippy::uninlined_format_args
clippy::uninlined_format_args,
clippy::needless_lifetimes
)]
//@no-rustfix
use std::borrow::Borrow;

View file

@ -1,5 +1,5 @@
error: this argument is passed by value, but not consumed in the function body
--> tests/ui/needless_pass_by_value.rs:18:23
--> tests/ui/needless_pass_by_value.rs:19:23
|
LL | fn foo<T: Default>(v: Vec<T>, w: Vec<T>, mut x: Vec<T>, y: Vec<T>) -> Vec<T> {
| ^^^^^^ help: consider changing the type to: `&[T]`
@ -8,55 +8,55 @@ LL | fn foo<T: Default>(v: Vec<T>, w: Vec<T>, mut x: Vec<T>, y: Vec<T>) -> Vec<T
= help: to override `-D warnings` add `#[allow(clippy::needless_pass_by_value)]`
error: this argument is passed by value, but not consumed in the function body
--> tests/ui/needless_pass_by_value.rs:34:11
--> tests/ui/needless_pass_by_value.rs:35:11
|
LL | fn bar(x: String, y: Wrapper) {
| ^^^^^^ help: consider changing the type to: `&str`
error: this argument is passed by value, but not consumed in the function body
--> tests/ui/needless_pass_by_value.rs:34:22
--> tests/ui/needless_pass_by_value.rs:35:22
|
LL | fn bar(x: String, y: Wrapper) {
| ^^^^^^^ help: consider taking a reference instead: `&Wrapper`
error: this argument is passed by value, but not consumed in the function body
--> tests/ui/needless_pass_by_value.rs:42:71
--> tests/ui/needless_pass_by_value.rs:43:71
|
LL | fn test_borrow_trait<T: Borrow<str>, U: AsRef<str>, V>(t: T, u: U, v: V) {
| ^ help: consider taking a reference instead: `&V`
error: this argument is passed by value, but not consumed in the function body
--> tests/ui/needless_pass_by_value.rs:55:18
--> tests/ui/needless_pass_by_value.rs:56:18
|
LL | fn test_match(x: Option<Option<String>>, y: Option<Option<String>>) {
| ^^^^^^^^^^^^^^^^^^^^^^ help: consider taking a reference instead: `&Option<Option<String>>`
error: this argument is passed by value, but not consumed in the function body
--> tests/ui/needless_pass_by_value.rs:69:24
--> tests/ui/needless_pass_by_value.rs:70:24
|
LL | fn test_destructure(x: Wrapper, y: Wrapper, z: Wrapper) {
| ^^^^^^^ help: consider taking a reference instead: `&Wrapper`
error: this argument is passed by value, but not consumed in the function body
--> tests/ui/needless_pass_by_value.rs:69:36
--> tests/ui/needless_pass_by_value.rs:70:36
|
LL | fn test_destructure(x: Wrapper, y: Wrapper, z: Wrapper) {
| ^^^^^^^ help: consider taking a reference instead: `&Wrapper`
error: this argument is passed by value, but not consumed in the function body
--> tests/ui/needless_pass_by_value.rs:87:49
--> tests/ui/needless_pass_by_value.rs:88:49
|
LL | fn test_blanket_ref<T: Foo, S: Serialize>(vals: T, serializable: S) {}
| ^ help: consider taking a reference instead: `&T`
error: this argument is passed by value, but not consumed in the function body
--> tests/ui/needless_pass_by_value.rs:90:18
--> tests/ui/needless_pass_by_value.rs:91:18
|
LL | fn issue_2114(s: String, t: String, u: Vec<i32>, v: Vec<i32>) {
| ^^^^^^ help: consider taking a reference instead: `&String`
error: this argument is passed by value, but not consumed in the function body
--> tests/ui/needless_pass_by_value.rs:90:29
--> tests/ui/needless_pass_by_value.rs:91:29
|
LL | fn issue_2114(s: String, t: String, u: Vec<i32>, v: Vec<i32>) {
| ^^^^^^
@ -71,13 +71,13 @@ LL | let _ = t.to_string();
| ~~~~~~~~~~~~~
error: this argument is passed by value, but not consumed in the function body
--> tests/ui/needless_pass_by_value.rs:90:40
--> tests/ui/needless_pass_by_value.rs:91:40
|
LL | fn issue_2114(s: String, t: String, u: Vec<i32>, v: Vec<i32>) {
| ^^^^^^^^ help: consider taking a reference instead: `&Vec<i32>`
error: this argument is passed by value, but not consumed in the function body
--> tests/ui/needless_pass_by_value.rs:90:53
--> tests/ui/needless_pass_by_value.rs:91:53
|
LL | fn issue_2114(s: String, t: String, u: Vec<i32>, v: Vec<i32>) {
| ^^^^^^^^
@ -92,85 +92,85 @@ LL | let _ = v.to_owned();
| ~~~~~~~~~~~~
error: this argument is passed by value, but not consumed in the function body
--> tests/ui/needless_pass_by_value.rs:107:12
--> tests/ui/needless_pass_by_value.rs:108:12
|
LL | s: String,
| ^^^^^^ help: consider changing the type to: `&str`
error: this argument is passed by value, but not consumed in the function body
--> tests/ui/needless_pass_by_value.rs:109:12
--> tests/ui/needless_pass_by_value.rs:110:12
|
LL | t: String,
| ^^^^^^ help: consider taking a reference instead: `&String`
error: this argument is passed by value, but not consumed in the function body
--> tests/ui/needless_pass_by_value.rs:119:23
--> tests/ui/needless_pass_by_value.rs:120:23
|
LL | fn baz(&self, uu: U, ss: Self) {}
| ^ help: consider taking a reference instead: `&U`
error: this argument is passed by value, but not consumed in the function body
--> tests/ui/needless_pass_by_value.rs:119:30
--> tests/ui/needless_pass_by_value.rs:120:30
|
LL | fn baz(&self, uu: U, ss: Self) {}
| ^^^^ help: consider taking a reference instead: `&Self`
error: this argument is passed by value, but not consumed in the function body
--> tests/ui/needless_pass_by_value.rs:143:24
--> tests/ui/needless_pass_by_value.rs:144:24
|
LL | fn bar_copy(x: u32, y: CopyWrapper) {
| ^^^^^^^^^^^ help: consider taking a reference instead: `&CopyWrapper`
|
help: or consider marking this type as `Copy`
--> tests/ui/needless_pass_by_value.rs:141:1
--> tests/ui/needless_pass_by_value.rs:142:1
|
LL | struct CopyWrapper(u32);
| ^^^^^^^^^^^^^^^^^^
error: this argument is passed by value, but not consumed in the function body
--> tests/ui/needless_pass_by_value.rs:150:29
--> tests/ui/needless_pass_by_value.rs:151:29
|
LL | fn test_destructure_copy(x: CopyWrapper, y: CopyWrapper, z: CopyWrapper) {
| ^^^^^^^^^^^ help: consider taking a reference instead: `&CopyWrapper`
|
help: or consider marking this type as `Copy`
--> tests/ui/needless_pass_by_value.rs:141:1
--> tests/ui/needless_pass_by_value.rs:142:1
|
LL | struct CopyWrapper(u32);
| ^^^^^^^^^^^^^^^^^^
error: this argument is passed by value, but not consumed in the function body
--> tests/ui/needless_pass_by_value.rs:150:45
--> tests/ui/needless_pass_by_value.rs:151:45
|
LL | fn test_destructure_copy(x: CopyWrapper, y: CopyWrapper, z: CopyWrapper) {
| ^^^^^^^^^^^ help: consider taking a reference instead: `&CopyWrapper`
|
help: or consider marking this type as `Copy`
--> tests/ui/needless_pass_by_value.rs:141:1
--> tests/ui/needless_pass_by_value.rs:142:1
|
LL | struct CopyWrapper(u32);
| ^^^^^^^^^^^^^^^^^^
error: this argument is passed by value, but not consumed in the function body
--> tests/ui/needless_pass_by_value.rs:150:61
--> tests/ui/needless_pass_by_value.rs:151:61
|
LL | fn test_destructure_copy(x: CopyWrapper, y: CopyWrapper, z: CopyWrapper) {
| ^^^^^^^^^^^ help: consider taking a reference instead: `&CopyWrapper`
|
help: or consider marking this type as `Copy`
--> tests/ui/needless_pass_by_value.rs:141:1
--> tests/ui/needless_pass_by_value.rs:142:1
|
LL | struct CopyWrapper(u32);
| ^^^^^^^^^^^^^^^^^^
error: this argument is passed by value, but not consumed in the function body
--> tests/ui/needless_pass_by_value.rs:165:40
--> tests/ui/needless_pass_by_value.rs:166:40
|
LL | fn some_fun<'b, S: Bar<'b, ()>>(items: S) {}
| ^ help: consider taking a reference instead: `&S`
error: this argument is passed by value, but not consumed in the function body
--> tests/ui/needless_pass_by_value.rs:171:20
--> tests/ui/needless_pass_by_value.rs:172:20
|
LL | fn more_fun(items: impl Club<'static, i32>) {}
| ^^^^^^^^^^^^^^^^^^^^^^^ help: consider taking a reference instead: `&impl Club<'static, i32>`

View file

@ -360,3 +360,23 @@ fn issue12907() -> String {
}
fn main() {}
fn a(x: Option<u8>) -> Option<u8> {
match x {
Some(_) => None,
None => {
#[expect(clippy::needless_return, reason = "Use early return for errors.")]
return None;
},
}
}
fn b(x: Option<u8>) -> Option<u8> {
match x {
Some(_) => None,
None => {
#[expect(clippy::needless_return)]
return None;
},
}
}

View file

@ -370,3 +370,23 @@ fn issue12907() -> String {
}
fn main() {}
fn a(x: Option<u8>) -> Option<u8> {
match x {
Some(_) => None,
None => {
#[expect(clippy::needless_return, reason = "Use early return for errors.")]
return None;
},
}
}
fn b(x: Option<u8>) -> Option<u8> {
match x {
Some(_) => None,
None => {
#[expect(clippy::needless_return)]
return None;
},
}
}

View file

@ -2,7 +2,8 @@
dead_code,
clippy::missing_safety_doc,
clippy::extra_unused_lifetimes,
clippy::extra_unused_type_parameters
clippy::extra_unused_type_parameters,
clippy::needless_lifetimes
)]
#![warn(clippy::new_without_default)]

View file

@ -2,7 +2,8 @@
dead_code,
clippy::missing_safety_doc,
clippy::extra_unused_lifetimes,
clippy::extra_unused_type_parameters
clippy::extra_unused_type_parameters,
clippy::needless_lifetimes
)]
#![warn(clippy::new_without_default)]

View file

@ -1,5 +1,5 @@
error: you should consider adding a `Default` implementation for `Foo`
--> tests/ui/new_without_default.rs:12:5
--> tests/ui/new_without_default.rs:13:5
|
LL | / pub fn new() -> Foo {
LL | |
@ -20,7 +20,7 @@ LL + }
|
error: you should consider adding a `Default` implementation for `Bar`
--> tests/ui/new_without_default.rs:22:5
--> tests/ui/new_without_default.rs:23:5
|
LL | / pub fn new() -> Self {
LL | |
@ -38,7 +38,7 @@ LL + }
|
error: you should consider adding a `Default` implementation for `LtKo<'c>`
--> tests/ui/new_without_default.rs:87:5
--> tests/ui/new_without_default.rs:88:5
|
LL | / pub fn new() -> LtKo<'c> {
LL | |
@ -56,7 +56,7 @@ LL + }
|
error: you should consider adding a `Default` implementation for `Const`
--> tests/ui/new_without_default.rs:120:5
--> tests/ui/new_without_default.rs:121:5
|
LL | / pub const fn new() -> Const {
LL | | Const
@ -73,7 +73,7 @@ LL + }
|
error: you should consider adding a `Default` implementation for `NewNotEqualToDerive`
--> tests/ui/new_without_default.rs:180:5
--> tests/ui/new_without_default.rs:181:5
|
LL | / pub fn new() -> Self {
LL | |
@ -91,7 +91,7 @@ LL + }
|
error: you should consider adding a `Default` implementation for `FooGenerics<T>`
--> tests/ui/new_without_default.rs:189:5
--> tests/ui/new_without_default.rs:190:5
|
LL | / pub fn new() -> Self {
LL | |
@ -109,7 +109,7 @@ LL + }
|
error: you should consider adding a `Default` implementation for `BarGenerics<T>`
--> tests/ui/new_without_default.rs:197:5
--> tests/ui/new_without_default.rs:198:5
|
LL | / pub fn new() -> Self {
LL | |
@ -127,7 +127,7 @@ LL + }
|
error: you should consider adding a `Default` implementation for `Foo<T>`
--> tests/ui/new_without_default.rs:209:9
--> tests/ui/new_without_default.rs:210:9
|
LL | / pub fn new() -> Self {
LL | |
@ -147,7 +147,7 @@ LL ~ impl<T> Foo<T> {
|
error: you should consider adding a `Default` implementation for `MyStruct<K, V>`
--> tests/ui/new_without_default.rs:255:5
--> tests/ui/new_without_default.rs:256:5
|
LL | / pub fn new() -> Self {
LL | | Self { _kv: None }

View file

@ -115,4 +115,66 @@ fn issue_12625() {
if a as u64 > b {} //~ ERROR: this boolean expression can be simplified
}
fn issue_13436() {
fn not_zero(x: i32) -> bool {
x != 0
}
let opt = Some(500);
_ = opt.is_some_and(|x| x < 1000);
_ = opt.is_some_and(|x| x <= 1000);
_ = opt.is_some_and(|x| x > 1000);
_ = opt.is_some_and(|x| x >= 1000);
_ = opt.is_some_and(|x| x == 1000);
_ = opt.is_some_and(|x| x != 1000);
_ = opt.is_some_and(not_zero);
_ = opt.is_none_or(|x| x >= 1000); //~ ERROR: this boolean expression can be simplified
_ = opt.is_none_or(|x| x > 1000); //~ ERROR: this boolean expression can be simplified
_ = opt.is_none_or(|x| x <= 1000); //~ ERROR: this boolean expression can be simplified
_ = opt.is_none_or(|x| x < 1000); //~ ERROR: this boolean expression can be simplified
_ = opt.is_none_or(|x| x != 1000); //~ ERROR: this boolean expression can be simplified
_ = opt.is_none_or(|x| x == 1000); //~ ERROR: this boolean expression can be simplified
_ = !opt.is_some_and(not_zero);
_ = opt.is_none_or(|x| x < 1000);
_ = opt.is_none_or(|x| x <= 1000);
_ = opt.is_none_or(|x| x > 1000);
_ = opt.is_none_or(|x| x >= 1000);
_ = opt.is_none_or(|x| x == 1000);
_ = opt.is_none_or(|x| x != 1000);
_ = opt.is_none_or(not_zero);
_ = opt.is_some_and(|x| x >= 1000); //~ ERROR: this boolean expression can be simplified
_ = opt.is_some_and(|x| x > 1000); //~ ERROR: this boolean expression can be simplified
_ = opt.is_some_and(|x| x <= 1000); //~ ERROR: this boolean expression can be simplified
_ = opt.is_some_and(|x| x < 1000); //~ ERROR: this boolean expression can be simplified
_ = opt.is_some_and(|x| x != 1000); //~ ERROR: this boolean expression can be simplified
_ = opt.is_some_and(|x| x == 1000); //~ ERROR: this boolean expression can be simplified
_ = !opt.is_none_or(not_zero);
let opt = Some(true);
_ = opt.is_some_and(|x| x);
_ = opt.is_some_and(|x| !x);
_ = !opt.is_some_and(|x| x);
_ = opt.is_none_or(|x| x); //~ ERROR: this boolean expression can be simplified
_ = opt.is_none_or(|x| x);
_ = opt.is_none_or(|x| !x);
_ = !opt.is_none_or(|x| x);
_ = opt.is_some_and(|x| x); //~ ERROR: this boolean expression can be simplified
let opt: Option<Result<i32, i32>> = Some(Ok(123));
_ = opt.is_some_and(|x| x.is_ok());
_ = opt.is_some_and(|x| x.is_err());
_ = opt.is_none_or(|x| x.is_ok());
_ = opt.is_none_or(|x| x.is_err());
_ = opt.is_none_or(|x| x.is_err()); //~ ERROR: this boolean expression can be simplified
_ = opt.is_none_or(|x| x.is_ok()); //~ ERROR: this boolean expression can be simplified
_ = opt.is_some_and(|x| x.is_err()); //~ ERROR: this boolean expression can be simplified
_ = opt.is_some_and(|x| x.is_ok()); //~ ERROR: this boolean expression can be simplified
#[clippy::msrv = "1.81"]
fn before_stabilization() {
let opt = Some(500);
_ = !opt.is_some_and(|x| x < 1000);
}
}
fn main() {}

View file

@ -115,4 +115,66 @@ fn issue_12625() {
if !(a as u64 <= b) {} //~ ERROR: this boolean expression can be simplified
}
fn issue_13436() {
fn not_zero(x: i32) -> bool {
x != 0
}
let opt = Some(500);
_ = opt.is_some_and(|x| x < 1000);
_ = opt.is_some_and(|x| x <= 1000);
_ = opt.is_some_and(|x| x > 1000);
_ = opt.is_some_and(|x| x >= 1000);
_ = opt.is_some_and(|x| x == 1000);
_ = opt.is_some_and(|x| x != 1000);
_ = opt.is_some_and(not_zero);
_ = !opt.is_some_and(|x| x < 1000); //~ ERROR: this boolean expression can be simplified
_ = !opt.is_some_and(|x| x <= 1000); //~ ERROR: this boolean expression can be simplified
_ = !opt.is_some_and(|x| x > 1000); //~ ERROR: this boolean expression can be simplified
_ = !opt.is_some_and(|x| x >= 1000); //~ ERROR: this boolean expression can be simplified
_ = !opt.is_some_and(|x| x == 1000); //~ ERROR: this boolean expression can be simplified
_ = !opt.is_some_and(|x| x != 1000); //~ ERROR: this boolean expression can be simplified
_ = !opt.is_some_and(not_zero);
_ = opt.is_none_or(|x| x < 1000);
_ = opt.is_none_or(|x| x <= 1000);
_ = opt.is_none_or(|x| x > 1000);
_ = opt.is_none_or(|x| x >= 1000);
_ = opt.is_none_or(|x| x == 1000);
_ = opt.is_none_or(|x| x != 1000);
_ = opt.is_none_or(not_zero);
_ = !opt.is_none_or(|x| x < 1000); //~ ERROR: this boolean expression can be simplified
_ = !opt.is_none_or(|x| x <= 1000); //~ ERROR: this boolean expression can be simplified
_ = !opt.is_none_or(|x| x > 1000); //~ ERROR: this boolean expression can be simplified
_ = !opt.is_none_or(|x| x >= 1000); //~ ERROR: this boolean expression can be simplified
_ = !opt.is_none_or(|x| x == 1000); //~ ERROR: this boolean expression can be simplified
_ = !opt.is_none_or(|x| x != 1000); //~ ERROR: this boolean expression can be simplified
_ = !opt.is_none_or(not_zero);
let opt = Some(true);
_ = opt.is_some_and(|x| x);
_ = opt.is_some_and(|x| !x);
_ = !opt.is_some_and(|x| x);
_ = !opt.is_some_and(|x| !x); //~ ERROR: this boolean expression can be simplified
_ = opt.is_none_or(|x| x);
_ = opt.is_none_or(|x| !x);
_ = !opt.is_none_or(|x| x);
_ = !opt.is_none_or(|x| !x); //~ ERROR: this boolean expression can be simplified
let opt: Option<Result<i32, i32>> = Some(Ok(123));
_ = opt.is_some_and(|x| x.is_ok());
_ = opt.is_some_and(|x| x.is_err());
_ = opt.is_none_or(|x| x.is_ok());
_ = opt.is_none_or(|x| x.is_err());
_ = !opt.is_some_and(|x| x.is_ok()); //~ ERROR: this boolean expression can be simplified
_ = !opt.is_some_and(|x| x.is_err()); //~ ERROR: this boolean expression can be simplified
_ = !opt.is_none_or(|x| x.is_ok()); //~ ERROR: this boolean expression can be simplified
_ = !opt.is_none_or(|x| x.is_err()); //~ ERROR: this boolean expression can be simplified
#[clippy::msrv = "1.81"]
fn before_stabilization() {
let opt = Some(500);
_ = !opt.is_some_and(|x| x < 1000);
}
}
fn main() {}

View file

@ -97,5 +97,113 @@ error: this boolean expression can be simplified
LL | if !(a as u64 <= b) {}
| ^^^^^^^^^^^^^^^^ help: try: `a as u64 > b`
error: aborting due to 16 previous errors
error: this boolean expression can be simplified
--> tests/ui/nonminimal_bool_methods.rs:131:9
|
LL | _ = !opt.is_some_and(|x| x < 1000);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_none_or(|x| x >= 1000)`
error: this boolean expression can be simplified
--> tests/ui/nonminimal_bool_methods.rs:132:9
|
LL | _ = !opt.is_some_and(|x| x <= 1000);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_none_or(|x| x > 1000)`
error: this boolean expression can be simplified
--> tests/ui/nonminimal_bool_methods.rs:133:9
|
LL | _ = !opt.is_some_and(|x| x > 1000);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_none_or(|x| x <= 1000)`
error: this boolean expression can be simplified
--> tests/ui/nonminimal_bool_methods.rs:134:9
|
LL | _ = !opt.is_some_and(|x| x >= 1000);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_none_or(|x| x < 1000)`
error: this boolean expression can be simplified
--> tests/ui/nonminimal_bool_methods.rs:135:9
|
LL | _ = !opt.is_some_and(|x| x == 1000);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_none_or(|x| x != 1000)`
error: this boolean expression can be simplified
--> tests/ui/nonminimal_bool_methods.rs:136:9
|
LL | _ = !opt.is_some_and(|x| x != 1000);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_none_or(|x| x == 1000)`
error: this boolean expression can be simplified
--> tests/ui/nonminimal_bool_methods.rs:145:9
|
LL | _ = !opt.is_none_or(|x| x < 1000);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_some_and(|x| x >= 1000)`
error: this boolean expression can be simplified
--> tests/ui/nonminimal_bool_methods.rs:146:9
|
LL | _ = !opt.is_none_or(|x| x <= 1000);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_some_and(|x| x > 1000)`
error: this boolean expression can be simplified
--> tests/ui/nonminimal_bool_methods.rs:147:9
|
LL | _ = !opt.is_none_or(|x| x > 1000);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_some_and(|x| x <= 1000)`
error: this boolean expression can be simplified
--> tests/ui/nonminimal_bool_methods.rs:148:9
|
LL | _ = !opt.is_none_or(|x| x >= 1000);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_some_and(|x| x < 1000)`
error: this boolean expression can be simplified
--> tests/ui/nonminimal_bool_methods.rs:149:9
|
LL | _ = !opt.is_none_or(|x| x == 1000);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_some_and(|x| x != 1000)`
error: this boolean expression can be simplified
--> tests/ui/nonminimal_bool_methods.rs:150:9
|
LL | _ = !opt.is_none_or(|x| x != 1000);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_some_and(|x| x == 1000)`
error: this boolean expression can be simplified
--> tests/ui/nonminimal_bool_methods.rs:157:9
|
LL | _ = !opt.is_some_and(|x| !x);
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_none_or(|x| x)`
error: this boolean expression can be simplified
--> tests/ui/nonminimal_bool_methods.rs:161:9
|
LL | _ = !opt.is_none_or(|x| !x);
| ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_some_and(|x| x)`
error: this boolean expression can be simplified
--> tests/ui/nonminimal_bool_methods.rs:168:9
|
LL | _ = !opt.is_some_and(|x| x.is_ok());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_none_or(|x| x.is_err())`
error: this boolean expression can be simplified
--> tests/ui/nonminimal_bool_methods.rs:169:9
|
LL | _ = !opt.is_some_and(|x| x.is_err());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_none_or(|x| x.is_ok())`
error: this boolean expression can be simplified
--> tests/ui/nonminimal_bool_methods.rs:170:9
|
LL | _ = !opt.is_none_or(|x| x.is_ok());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_some_and(|x| x.is_err())`
error: this boolean expression can be simplified
--> tests/ui/nonminimal_bool_methods.rs:171:9
|
LL | _ = !opt.is_none_or(|x| x.is_err());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_some_and(|x| x.is_ok())`
error: aborting due to 34 previous errors

View file

@ -0,0 +1,9 @@
#![warn(clippy::nonminimal_bool)]
//@no-rustfix
fn issue_13436() {
let opt_opt = Some(Some(500));
_ = !opt_opt.is_some_and(|x| !x.is_some_and(|y| y != 1000)); //~ ERROR: this boolean expression can be simplified
}
fn main() {}

View file

@ -0,0 +1,17 @@
error: this boolean expression can be simplified
--> tests/ui/nonminimal_bool_methods_unfixable.rs:6:9
|
LL | _ = !opt_opt.is_some_and(|x| !x.is_some_and(|y| y != 1000));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt_opt.is_none_or(|x| x.is_some_and(|y| y != 1000))`
|
= note: `-D clippy::nonminimal-bool` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::nonminimal_bool)]`
error: this boolean expression can be simplified
--> tests/ui/nonminimal_bool_methods_unfixable.rs:6:34
|
LL | _ = !opt_opt.is_some_and(|x| !x.is_some_and(|y| y != 1000));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `x.is_none_or(|y| y == 1000)`
error: aborting due to 2 previous errors

View file

@ -1,5 +1,5 @@
#![warn(clippy::ref_as_ptr)]
#![allow(clippy::unnecessary_mut_passed)]
#![allow(clippy::unnecessary_mut_passed, clippy::needless_lifetimes)]
fn f<T>(_: T) {}

View file

@ -1,5 +1,5 @@
#![warn(clippy::ref_as_ptr)]
#![allow(clippy::unnecessary_mut_passed)]
#![allow(clippy::unnecessary_mut_passed, clippy::needless_lifetimes)]
fn f<T>(_: T) {}

View file

@ -0,0 +1 @@
avoid-breaking-exported-api = false

View file

@ -0,0 +1 @@
avoid-breaking-exported-api = true

View file

@ -0,0 +1,62 @@
//@revisions: private all
//@[private] rustc-env:CLIPPY_CONF_DIR=tests/ui/ref_option/private
//@[all] rustc-env:CLIPPY_CONF_DIR=tests/ui/ref_option/all
#![allow(unused, clippy::needless_lifetimes, clippy::borrowed_box)]
#![warn(clippy::ref_option)]
fn opt_u8(a: Option<&u8>) {}
fn opt_gen<T>(a: Option<&T>) {}
fn opt_string(a: std::option::Option<&String>) {}
fn ret_string<'a>(p: &'a str) -> Option<&'a u8> {
panic!()
}
fn ret_string_static() -> Option<&'static u8> {
panic!()
}
fn mult_string(a: Option<&String>, b: Option<&Vec<u8>>) {}
fn ret_box<'a>() -> Option<&'a Box<u8>> {
panic!()
}
pub fn pub_opt_string(a: Option<&String>) {}
pub fn pub_mult_string(a: Option<&String>, b: Option<&Vec<u8>>) {}
pub trait PubTrait {
fn pub_trait_opt(&self, a: Option<&Vec<u8>>);
fn pub_trait_ret(&self) -> Option<&Vec<u8>>;
}
trait PrivateTrait {
fn trait_opt(&self, a: Option<&String>);
fn trait_ret(&self) -> Option<&String>;
}
pub struct PubStruct;
impl PubStruct {
pub fn pub_opt_params(&self, a: Option<&()>) {}
pub fn pub_opt_ret(&self) -> Option<&String> {
panic!()
}
fn private_opt_params(&self, a: Option<&()>) {}
fn private_opt_ret(&self) -> Option<&String> {
panic!()
}
}
// valid, don't change
fn mut_u8(a: &mut Option<u8>) {}
pub fn pub_mut_u8(a: &mut Option<String>) {}
// might be good to catch in the future
fn mut_u8_ref(a: &mut &Option<u8>) {}
pub fn pub_mut_u8_ref(a: &mut &Option<String>) {}
fn lambdas() {
// Not handled for now, not sure if we should
let x = |a: &Option<String>| {};
let x = |a: &Option<String>| -> &Option<String> { panic!() };
}
fn main() {}

View file

@ -0,0 +1,162 @@
error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>`
--> tests/ui/ref_option/ref_option.rs:8:1
|
LL | fn opt_u8(a: &Option<u8>) {}
| ^^^^^^^^^^^^^-----------^^^^
| |
| help: change this to: `Option<&u8>`
|
= note: `-D clippy::ref-option` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::ref_option)]`
error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>`
--> tests/ui/ref_option/ref_option.rs:9:1
|
LL | fn opt_gen<T>(a: &Option<T>) {}
| ^^^^^^^^^^^^^^^^^----------^^^^
| |
| help: change this to: `Option<&T>`
error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>`
--> tests/ui/ref_option/ref_option.rs:10:1
|
LL | fn opt_string(a: &std::option::Option<String>) {}
| ^^^^^^^^^^^^^^^^^----------------------------^^^^
| |
| help: change this to: `std::option::Option<&String>`
error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>`
--> tests/ui/ref_option/ref_option.rs:11:1
|
LL | fn ret_string<'a>(p: &'a str) -> &'a Option<u8> {
| ^ -------------- help: change this to: `Option<&'a u8>`
| _|
| |
LL | | panic!()
LL | | }
| |_^
error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>`
--> tests/ui/ref_option/ref_option.rs:14:1
|
LL | fn ret_string_static() -> &'static Option<u8> {
| ^ ------------------- help: change this to: `Option<&'static u8>`
| _|
| |
LL | | panic!()
LL | | }
| |_^
error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>`
--> tests/ui/ref_option/ref_option.rs:17:1
|
LL | fn mult_string(a: &Option<String>, b: &Option<Vec<u8>>) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: change this to
|
LL | fn mult_string(a: Option<&String>, b: Option<&Vec<u8>>) {}
| ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~
error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>`
--> tests/ui/ref_option/ref_option.rs:18:1
|
LL | fn ret_box<'a>() -> &'a Option<Box<u8>> {
| ^ ------------------- help: change this to: `Option<&'a Box<u8>>`
| _|
| |
LL | | panic!()
LL | | }
| |_^
error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>`
--> tests/ui/ref_option/ref_option.rs:22:1
|
LL | pub fn pub_opt_string(a: &Option<String>) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^---------------^^^^
| |
| help: change this to: `Option<&String>`
error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>`
--> tests/ui/ref_option/ref_option.rs:23:1
|
LL | pub fn pub_mult_string(a: &Option<String>, b: &Option<Vec<u8>>) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: change this to
|
LL | pub fn pub_mult_string(a: Option<&String>, b: Option<&Vec<u8>>) {}
| ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~
error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>`
--> tests/ui/ref_option/ref_option.rs:26:5
|
LL | fn pub_trait_opt(&self, a: &Option<Vec<u8>>);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^----------------^^
| |
| help: change this to: `Option<&Vec<u8>>`
error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>`
--> tests/ui/ref_option/ref_option.rs:27:5
|
LL | fn pub_trait_ret(&self) -> &Option<Vec<u8>>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^----------------^
| |
| help: change this to: `Option<&Vec<u8>>`
error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>`
--> tests/ui/ref_option/ref_option.rs:31:5
|
LL | fn trait_opt(&self, a: &Option<String>);
| ^^^^^^^^^^^^^^^^^^^^^^^---------------^^
| |
| help: change this to: `Option<&String>`
error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>`
--> tests/ui/ref_option/ref_option.rs:32:5
|
LL | fn trait_ret(&self) -> &Option<String>;
| ^^^^^^^^^^^^^^^^^^^^^^^---------------^
| |
| help: change this to: `Option<&String>`
error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>`
--> tests/ui/ref_option/ref_option.rs:38:5
|
LL | pub fn pub_opt_params(&self, a: &Option<()>) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-----------^^^^
| |
| help: change this to: `Option<&()>`
error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>`
--> tests/ui/ref_option/ref_option.rs:39:5
|
LL | pub fn pub_opt_ret(&self) -> &Option<String> {
| ^ --------------- help: change this to: `Option<&String>`
| _____|
| |
LL | | panic!()
LL | | }
| |_____^
error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>`
--> tests/ui/ref_option/ref_option.rs:43:5
|
LL | fn private_opt_params(&self, a: &Option<()>) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-----------^^^^
| |
| help: change this to: `Option<&()>`
error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>`
--> tests/ui/ref_option/ref_option.rs:44:5
|
LL | fn private_opt_ret(&self) -> &Option<String> {
| ^ --------------- help: change this to: `Option<&String>`
| _____|
| |
LL | | panic!()
LL | | }
| |_____^
error: aborting due to 17 previous errors

View file

@ -0,0 +1,62 @@
//@revisions: private all
//@[private] rustc-env:CLIPPY_CONF_DIR=tests/ui/ref_option/private
//@[all] rustc-env:CLIPPY_CONF_DIR=tests/ui/ref_option/all
#![allow(unused, clippy::needless_lifetimes, clippy::borrowed_box)]
#![warn(clippy::ref_option)]
fn opt_u8(a: Option<&u8>) {}
fn opt_gen<T>(a: Option<&T>) {}
fn opt_string(a: std::option::Option<&String>) {}
fn ret_string<'a>(p: &'a str) -> Option<&'a u8> {
panic!()
}
fn ret_string_static() -> Option<&'static u8> {
panic!()
}
fn mult_string(a: Option<&String>, b: Option<&Vec<u8>>) {}
fn ret_box<'a>() -> Option<&'a Box<u8>> {
panic!()
}
pub fn pub_opt_string(a: &Option<String>) {}
pub fn pub_mult_string(a: &Option<String>, b: &Option<Vec<u8>>) {}
pub trait PubTrait {
fn pub_trait_opt(&self, a: &Option<Vec<u8>>);
fn pub_trait_ret(&self) -> &Option<Vec<u8>>;
}
trait PrivateTrait {
fn trait_opt(&self, a: Option<&String>);
fn trait_ret(&self) -> Option<&String>;
}
pub struct PubStruct;
impl PubStruct {
pub fn pub_opt_params(&self, a: &Option<()>) {}
pub fn pub_opt_ret(&self) -> &Option<String> {
panic!()
}
fn private_opt_params(&self, a: Option<&()>) {}
fn private_opt_ret(&self) -> Option<&String> {
panic!()
}
}
// valid, don't change
fn mut_u8(a: &mut Option<u8>) {}
pub fn pub_mut_u8(a: &mut Option<String>) {}
// might be good to catch in the future
fn mut_u8_ref(a: &mut &Option<u8>) {}
pub fn pub_mut_u8_ref(a: &mut &Option<String>) {}
fn lambdas() {
// Not handled for now, not sure if we should
let x = |a: &Option<String>| {};
let x = |a: &Option<String>| -> &Option<String> { panic!() };
}
fn main() {}

View file

@ -0,0 +1,108 @@
error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>`
--> tests/ui/ref_option/ref_option.rs:8:1
|
LL | fn opt_u8(a: &Option<u8>) {}
| ^^^^^^^^^^^^^-----------^^^^
| |
| help: change this to: `Option<&u8>`
|
= note: `-D clippy::ref-option` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::ref_option)]`
error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>`
--> tests/ui/ref_option/ref_option.rs:9:1
|
LL | fn opt_gen<T>(a: &Option<T>) {}
| ^^^^^^^^^^^^^^^^^----------^^^^
| |
| help: change this to: `Option<&T>`
error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>`
--> tests/ui/ref_option/ref_option.rs:10:1
|
LL | fn opt_string(a: &std::option::Option<String>) {}
| ^^^^^^^^^^^^^^^^^----------------------------^^^^
| |
| help: change this to: `std::option::Option<&String>`
error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>`
--> tests/ui/ref_option/ref_option.rs:11:1
|
LL | fn ret_string<'a>(p: &'a str) -> &'a Option<u8> {
| ^ -------------- help: change this to: `Option<&'a u8>`
| _|
| |
LL | | panic!()
LL | | }
| |_^
error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>`
--> tests/ui/ref_option/ref_option.rs:14:1
|
LL | fn ret_string_static() -> &'static Option<u8> {
| ^ ------------------- help: change this to: `Option<&'static u8>`
| _|
| |
LL | | panic!()
LL | | }
| |_^
error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>`
--> tests/ui/ref_option/ref_option.rs:17:1
|
LL | fn mult_string(a: &Option<String>, b: &Option<Vec<u8>>) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: change this to
|
LL | fn mult_string(a: Option<&String>, b: Option<&Vec<u8>>) {}
| ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~
error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>`
--> tests/ui/ref_option/ref_option.rs:18:1
|
LL | fn ret_box<'a>() -> &'a Option<Box<u8>> {
| ^ ------------------- help: change this to: `Option<&'a Box<u8>>`
| _|
| |
LL | | panic!()
LL | | }
| |_^
error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>`
--> tests/ui/ref_option/ref_option.rs:31:5
|
LL | fn trait_opt(&self, a: &Option<String>);
| ^^^^^^^^^^^^^^^^^^^^^^^---------------^^
| |
| help: change this to: `Option<&String>`
error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>`
--> tests/ui/ref_option/ref_option.rs:32:5
|
LL | fn trait_ret(&self) -> &Option<String>;
| ^^^^^^^^^^^^^^^^^^^^^^^---------------^
| |
| help: change this to: `Option<&String>`
error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>`
--> tests/ui/ref_option/ref_option.rs:43:5
|
LL | fn private_opt_params(&self, a: &Option<()>) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-----------^^^^
| |
| help: change this to: `Option<&()>`
error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>`
--> tests/ui/ref_option/ref_option.rs:44:5
|
LL | fn private_opt_ret(&self) -> &Option<String> {
| ^ --------------- help: change this to: `Option<&String>`
| _____|
| |
LL | | panic!()
LL | | }
| |_____^
error: aborting due to 11 previous errors

View file

@ -0,0 +1,62 @@
//@revisions: private all
//@[private] rustc-env:CLIPPY_CONF_DIR=tests/ui/ref_option/private
//@[all] rustc-env:CLIPPY_CONF_DIR=tests/ui/ref_option/all
#![allow(unused, clippy::needless_lifetimes, clippy::borrowed_box)]
#![warn(clippy::ref_option)]
fn opt_u8(a: &Option<u8>) {}
fn opt_gen<T>(a: &Option<T>) {}
fn opt_string(a: &std::option::Option<String>) {}
fn ret_string<'a>(p: &'a str) -> &'a Option<u8> {
panic!()
}
fn ret_string_static() -> &'static Option<u8> {
panic!()
}
fn mult_string(a: &Option<String>, b: &Option<Vec<u8>>) {}
fn ret_box<'a>() -> &'a Option<Box<u8>> {
panic!()
}
pub fn pub_opt_string(a: &Option<String>) {}
pub fn pub_mult_string(a: &Option<String>, b: &Option<Vec<u8>>) {}
pub trait PubTrait {
fn pub_trait_opt(&self, a: &Option<Vec<u8>>);
fn pub_trait_ret(&self) -> &Option<Vec<u8>>;
}
trait PrivateTrait {
fn trait_opt(&self, a: &Option<String>);
fn trait_ret(&self) -> &Option<String>;
}
pub struct PubStruct;
impl PubStruct {
pub fn pub_opt_params(&self, a: &Option<()>) {}
pub fn pub_opt_ret(&self) -> &Option<String> {
panic!()
}
fn private_opt_params(&self, a: &Option<()>) {}
fn private_opt_ret(&self) -> &Option<String> {
panic!()
}
}
// valid, don't change
fn mut_u8(a: &mut Option<u8>) {}
pub fn pub_mut_u8(a: &mut Option<String>) {}
// might be good to catch in the future
fn mut_u8_ref(a: &mut &Option<u8>) {}
pub fn pub_mut_u8_ref(a: &mut &Option<String>) {}
fn lambdas() {
// Not handled for now, not sure if we should
let x = |a: &Option<String>| {};
let x = |a: &Option<String>| -> &Option<String> { panic!() };
}
fn main() {}

View file

@ -0,0 +1,37 @@
error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>`
--> tests/ui/ref_option/ref_option_traits.rs:10:5
|
LL | fn pub_trait_opt(&self, a: &Option<Vec<u8>>);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^----------------^^
| |
| help: change this to: `Option<&Vec<u8>>`
|
= note: `-D clippy::ref-option` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::ref_option)]`
error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>`
--> tests/ui/ref_option/ref_option_traits.rs:11:5
|
LL | fn pub_trait_ret(&self) -> &Option<Vec<u8>>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^----------------^
| |
| help: change this to: `Option<&Vec<u8>>`
error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>`
--> tests/ui/ref_option/ref_option_traits.rs:15:5
|
LL | fn trait_opt(&self, a: &Option<String>);
| ^^^^^^^^^^^^^^^^^^^^^^^---------------^^
| |
| help: change this to: `Option<&String>`
error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>`
--> tests/ui/ref_option/ref_option_traits.rs:16:5
|
LL | fn trait_ret(&self) -> &Option<String>;
| ^^^^^^^^^^^^^^^^^^^^^^^---------------^
| |
| help: change this to: `Option<&String>`
error: aborting due to 4 previous errors

View file

@ -0,0 +1,21 @@
error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>`
--> tests/ui/ref_option/ref_option_traits.rs:15:5
|
LL | fn trait_opt(&self, a: &Option<String>);
| ^^^^^^^^^^^^^^^^^^^^^^^---------------^^
| |
| help: change this to: `Option<&String>`
|
= note: `-D clippy::ref-option` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::ref_option)]`
error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>`
--> tests/ui/ref_option/ref_option_traits.rs:16:5
|
LL | fn trait_ret(&self) -> &Option<String>;
| ^^^^^^^^^^^^^^^^^^^^^^^---------------^
| |
| help: change this to: `Option<&String>`
error: aborting due to 2 previous errors

View file

@ -0,0 +1,37 @@
//@no-rustfix: fixes are only done to traits, not the impls
//@revisions: private all
//@[private] rustc-env:CLIPPY_CONF_DIR=tests/ui/ref_option/private
//@[all] rustc-env:CLIPPY_CONF_DIR=tests/ui/ref_option/all
#![allow(unused, clippy::all)]
#![warn(clippy::ref_option)]
pub trait PubTrait {
fn pub_trait_opt(&self, a: &Option<Vec<u8>>);
fn pub_trait_ret(&self) -> &Option<Vec<u8>>;
}
trait PrivateTrait {
fn trait_opt(&self, a: &Option<String>);
fn trait_ret(&self) -> &Option<String>;
}
pub struct PubStruct;
impl PubTrait for PubStruct {
fn pub_trait_opt(&self, a: &Option<Vec<u8>>) {}
fn pub_trait_ret(&self) -> &Option<Vec<u8>> {
panic!()
}
}
struct PrivateStruct;
impl PrivateTrait for PrivateStruct {
fn trait_opt(&self, a: &Option<String>) {}
fn trait_ret(&self) -> &Option<String> {
panic!()
}
}
fn main() {}

View file

@ -1,5 +1,5 @@
#![warn(clippy::serde_api_misuse)]
#![allow(dead_code)]
#![allow(dead_code, clippy::needless_lifetimes)]
extern crate serde;

View file

@ -2,7 +2,12 @@
//@no-rustfix
#![warn(clippy::significant_drop_in_scrutinee)]
#![allow(dead_code, unused_assignments)]
#![allow(clippy::match_single_binding, clippy::single_match, clippy::uninlined_format_args)]
#![allow(
clippy::match_single_binding,
clippy::single_match,
clippy::uninlined_format_args,
clippy::needless_lifetimes
)]
use std::num::ParseIntError;
use std::ops::Deref;

View file

@ -1,5 +1,5 @@
error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression
--> tests/ui/significant_drop_in_scrutinee.rs:55:11
--> tests/ui/significant_drop_in_scrutinee.rs:60:11
|
LL | match mutex.lock().unwrap().foo() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -20,7 +20,7 @@ LL ~ match value {
|
error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression
--> tests/ui/significant_drop_in_scrutinee.rs:143:11
--> tests/ui/significant_drop_in_scrutinee.rs:148:11
|
LL | match s.lock_m().get_the_value() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -42,7 +42,7 @@ LL ~ match value {
|
error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression
--> tests/ui/significant_drop_in_scrutinee.rs:166:11
--> tests/ui/significant_drop_in_scrutinee.rs:171:11
|
LL | match s.lock_m_m().get_the_value() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -64,7 +64,7 @@ LL ~ match value {
|
error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression
--> tests/ui/significant_drop_in_scrutinee.rs:216:11
--> tests/ui/significant_drop_in_scrutinee.rs:221:11
|
LL | match counter.temp_increment().len() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -80,7 +80,7 @@ LL ~ match value {
|
error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression
--> tests/ui/significant_drop_in_scrutinee.rs:241:16
--> tests/ui/significant_drop_in_scrutinee.rs:246:16
|
LL | match (mutex1.lock().unwrap().s.len(), true) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -99,7 +99,7 @@ LL ~ match (value, true) {
|
error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression
--> tests/ui/significant_drop_in_scrutinee.rs:252:22
--> tests/ui/significant_drop_in_scrutinee.rs:257:22
|
LL | match (true, mutex1.lock().unwrap().s.len(), true) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -118,7 +118,7 @@ LL ~ match (true, value, true) {
|
error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression
--> tests/ui/significant_drop_in_scrutinee.rs:264:16
--> tests/ui/significant_drop_in_scrutinee.rs:269:16
|
LL | match (mutex1.lock().unwrap().s.len(), true, mutex2.lock().unwrap().s.len()) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -139,7 +139,7 @@ LL ~ match (value, true, mutex2.lock().unwrap().s.len()) {
|
error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression
--> tests/ui/significant_drop_in_scrutinee.rs:264:54
--> tests/ui/significant_drop_in_scrutinee.rs:269:54
|
LL | match (mutex1.lock().unwrap().s.len(), true, mutex2.lock().unwrap().s.len()) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -160,7 +160,7 @@ LL ~ match (mutex1.lock().unwrap().s.len(), true, value) {
|
error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression
--> tests/ui/significant_drop_in_scrutinee.rs:319:11
--> tests/ui/significant_drop_in_scrutinee.rs:324:11
|
LL | match mutex.lock().unwrap().s.len() > 1 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -179,7 +179,7 @@ LL ~ match value > 1 {
|
error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression
--> tests/ui/significant_drop_in_scrutinee.rs:328:15
--> tests/ui/significant_drop_in_scrutinee.rs:333:15
|
LL | match 1 < mutex.lock().unwrap().s.len() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -198,7 +198,7 @@ LL ~ match 1 < value {
|
error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression
--> tests/ui/significant_drop_in_scrutinee.rs:348:11
--> tests/ui/significant_drop_in_scrutinee.rs:353:11
|
LL | match mutex1.lock().unwrap().s.len() < mutex2.lock().unwrap().s.len() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -219,7 +219,7 @@ LL ~ match value < mutex2.lock().unwrap().s.len() {
|
error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression
--> tests/ui/significant_drop_in_scrutinee.rs:348:44
--> tests/ui/significant_drop_in_scrutinee.rs:353:44
|
LL | match mutex1.lock().unwrap().s.len() < mutex2.lock().unwrap().s.len() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -240,7 +240,7 @@ LL ~ match mutex1.lock().unwrap().s.len() < value {
|
error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression
--> tests/ui/significant_drop_in_scrutinee.rs:361:11
--> tests/ui/significant_drop_in_scrutinee.rs:366:11
|
LL | match mutex1.lock().unwrap().s.len() >= mutex2.lock().unwrap().s.len() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -261,7 +261,7 @@ LL ~ match value >= mutex2.lock().unwrap().s.len() {
|
error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression
--> tests/ui/significant_drop_in_scrutinee.rs:361:45
--> tests/ui/significant_drop_in_scrutinee.rs:366:45
|
LL | match mutex1.lock().unwrap().s.len() >= mutex2.lock().unwrap().s.len() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -282,7 +282,7 @@ LL ~ match mutex1.lock().unwrap().s.len() >= value {
|
error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression
--> tests/ui/significant_drop_in_scrutinee.rs:398:11
--> tests/ui/significant_drop_in_scrutinee.rs:403:11
|
LL | match get_mutex_guard().s.len() > 1 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^
@ -301,7 +301,7 @@ LL ~ match value > 1 {
|
error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression
--> tests/ui/significant_drop_in_scrutinee.rs:417:11
--> tests/ui/significant_drop_in_scrutinee.rs:422:11
|
LL | match match i {
| ___________^
@ -334,7 +334,7 @@ LL ~ match value
|
error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression
--> tests/ui/significant_drop_in_scrutinee.rs:445:11
--> tests/ui/significant_drop_in_scrutinee.rs:450:11
|
LL | match if i > 1 {
| ___________^
@ -368,7 +368,7 @@ LL ~ match value
|
error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression
--> tests/ui/significant_drop_in_scrutinee.rs:501:11
--> tests/ui/significant_drop_in_scrutinee.rs:506:11
|
LL | match s.lock().deref().deref() {
| ^^^^^^^^^^^^^^^^^^^^^^^^
@ -386,7 +386,7 @@ LL ~ match (&value) {
|
error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression
--> tests/ui/significant_drop_in_scrutinee.rs:551:11
--> tests/ui/significant_drop_in_scrutinee.rs:556:11
|
LL | match mutex.lock().unwrap().i = i {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -405,7 +405,7 @@ LL ~ match () {
|
error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression
--> tests/ui/significant_drop_in_scrutinee.rs:559:15
--> tests/ui/significant_drop_in_scrutinee.rs:564:15
|
LL | match i = mutex.lock().unwrap().i {
| ^^^^^^^^^^^^^^^^^^^^^^^
@ -424,7 +424,7 @@ LL ~ match i = value {
|
error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression
--> tests/ui/significant_drop_in_scrutinee.rs:567:11
--> tests/ui/significant_drop_in_scrutinee.rs:572:11
|
LL | match mutex.lock().unwrap().i += 1 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -443,7 +443,7 @@ LL ~ match () {
|
error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression
--> tests/ui/significant_drop_in_scrutinee.rs:575:16
--> tests/ui/significant_drop_in_scrutinee.rs:580:16
|
LL | match i += mutex.lock().unwrap().i {
| ^^^^^^^^^^^^^^^^^^^^^^^
@ -462,7 +462,7 @@ LL ~ match i += value {
|
error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression
--> tests/ui/significant_drop_in_scrutinee.rs:640:11
--> tests/ui/significant_drop_in_scrutinee.rs:645:11
|
LL | match rwlock.read().unwrap().to_number() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -478,7 +478,7 @@ LL ~ match value {
|
error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression
--> tests/ui/significant_drop_in_scrutinee.rs:668:11
--> tests/ui/significant_drop_in_scrutinee.rs:673:11
|
LL | match mutex.lock().unwrap().foo() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -494,7 +494,7 @@ LL ~ match value {
|
error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression
--> tests/ui/significant_drop_in_scrutinee.rs:731:11
--> tests/ui/significant_drop_in_scrutinee.rs:736:11
|
LL | match guard.take().len() {
| ^^^^^^^^^^^^^^^^^^
@ -510,7 +510,7 @@ LL ~ match value {
|
error: temporary with significant `Drop` in `for` loop condition will live until the end of the `for` expression
--> tests/ui/significant_drop_in_scrutinee.rs:757:16
--> tests/ui/significant_drop_in_scrutinee.rs:762:16
|
LL | for val in mutex.lock().unwrap().copy_old_lifetime() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -526,7 +526,7 @@ LL ~ for val in value {
|
error: temporary with significant `Drop` in `for` loop condition will live until the end of the `for` expression
--> tests/ui/significant_drop_in_scrutinee.rs:797:17
--> tests/ui/significant_drop_in_scrutinee.rs:802:17
|
LL | for val in [mutex.lock().unwrap()[0], 2] {
| ^^^^^^^^^^^^^^^^^^^^^^^^
@ -542,7 +542,7 @@ LL ~ for val in [value, 2] {
|
error: temporary with significant `Drop` in `if let` scrutinee will live until the end of the `if let` expression
--> tests/ui/significant_drop_in_scrutinee.rs:807:24
--> tests/ui/significant_drop_in_scrutinee.rs:812:24
|
LL | if let Some(val) = mutex.lock().unwrap().first().copied() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -558,7 +558,7 @@ LL ~ if let Some(val) = value {
|
error: temporary with significant `Drop` in `while let` scrutinee will live until the end of the `while let` expression
--> tests/ui/significant_drop_in_scrutinee.rs:823:27
--> tests/ui/significant_drop_in_scrutinee.rs:828:27
|
LL | while let Some(val) = mutex.lock().unwrap().pop() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^

View file

@ -1,4 +1,5 @@
#![warn(clippy::str_split_at_newline)]
#![allow(clippy::needless_lifetimes)]
use core::str::Split;
use std::ops::Deref;

View file

@ -1,4 +1,5 @@
#![warn(clippy::str_split_at_newline)]
#![allow(clippy::needless_lifetimes)]
use core::str::Split;
use std::ops::Deref;

View file

@ -1,5 +1,5 @@
error: using `str.trim().split()` with hard-coded newlines
--> tests/ui/str_split.rs:59:13
--> tests/ui/str_split.rs:60:13
|
LL | let _ = s1.trim().split('\n');
| ^^^^^^^^^^^^^^^^^^^^^ help: use `str.lines()` instead: `s1.lines()`
@ -8,55 +8,55 @@ LL | let _ = s1.trim().split('\n');
= help: to override `-D warnings` add `#[allow(clippy::str_split_at_newline)]`
error: using `str.trim().split()` with hard-coded newlines
--> tests/ui/str_split.rs:61:13
--> tests/ui/str_split.rs:62:13
|
LL | let _ = s1.trim().split("\n");
| ^^^^^^^^^^^^^^^^^^^^^ help: use `str.lines()` instead: `s1.lines()`
error: using `str.trim().split()` with hard-coded newlines
--> tests/ui/str_split.rs:62:13
--> tests/ui/str_split.rs:63:13
|
LL | let _ = s1.trim().split("\r\n");
| ^^^^^^^^^^^^^^^^^^^^^^^ help: use `str.lines()` instead: `s1.lines()`
error: using `str.trim().split()` with hard-coded newlines
--> tests/ui/str_split.rs:65:13
--> tests/ui/str_split.rs:66:13
|
LL | let _ = s2.trim().split('\n');
| ^^^^^^^^^^^^^^^^^^^^^ help: use `str.lines()` instead: `s2.lines()`
error: using `str.trim().split()` with hard-coded newlines
--> tests/ui/str_split.rs:67:13
--> tests/ui/str_split.rs:68:13
|
LL | let _ = s2.trim().split("\n");
| ^^^^^^^^^^^^^^^^^^^^^ help: use `str.lines()` instead: `s2.lines()`
error: using `str.trim().split()` with hard-coded newlines
--> tests/ui/str_split.rs:68:13
--> tests/ui/str_split.rs:69:13
|
LL | let _ = s2.trim().split("\r\n");
| ^^^^^^^^^^^^^^^^^^^^^^^ help: use `str.lines()` instead: `s2.lines()`
error: using `str.trim().split()` with hard-coded newlines
--> tests/ui/str_split.rs:72:13
--> tests/ui/str_split.rs:73:13
|
LL | let _ = s3.trim().split('\n');
| ^^^^^^^^^^^^^^^^^^^^^ help: use `str.lines()` instead: `s3.lines()`
error: using `str.trim().split()` with hard-coded newlines
--> tests/ui/str_split.rs:74:13
--> tests/ui/str_split.rs:75:13
|
LL | let _ = s3.trim().split("\n");
| ^^^^^^^^^^^^^^^^^^^^^ help: use `str.lines()` instead: `s3.lines()`
error: using `str.trim().split()` with hard-coded newlines
--> tests/ui/str_split.rs:75:13
--> tests/ui/str_split.rs:76:13
|
LL | let _ = s3.trim().split("\r\n");
| ^^^^^^^^^^^^^^^^^^^^^^^ help: use `str.lines()` instead: `s3.lines()`
error: using `str.trim().split()` with hard-coded newlines
--> tests/ui/str_split.rs:78:13
--> tests/ui/str_split.rs:79:13
|
LL | let _ = make_str!(s1).trim().split('\n');
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `str.lines()` instead: `make_str!(s1).lines()`

View file

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

View file

@ -0,0 +1,8 @@
//@compile-flags: -C incremental=target/debug/test/incr
// see https://github.com/rust-lang/rust-clippy/issues/10969
fn main() {
let s = "Hello, world!";
println!("{}", s);
}

View file

@ -0,0 +1,8 @@
//@compile-flags: -C incremental=target/debug/test/incr
// see https://github.com/rust-lang/rust-clippy/issues/10969
fn main() {
let s = "Hello, world!";
println!("{}", s.to_string());
}

View file

@ -0,0 +1,11 @@
error: `to_string` applied to a type that implements `Display` in `println!` args
--> tests/ui/to_string_in_format_args_incremental.rs:7:21
|
LL | println!("{}", s.to_string());
| ^^^^^^^^^^^^ help: remove this
|
= note: `-D clippy::to-string-in-format-args` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::to_string_in_format_args)]`
error: aborting due to 1 previous error

View file

@ -4,7 +4,8 @@
#![allow(
clippy::partialeq_ne_impl,
clippy::default_constructed_unit_structs,
clippy::only_used_in_recursion
clippy::only_used_in_recursion,
clippy::needless_lifetimes
)]
enum Foo {

View file

@ -1,5 +1,5 @@
error: function cannot return without recursing
--> tests/ui/unconditional_recursion.rs:46:5
--> tests/ui/unconditional_recursion.rs:47:5
|
LL | fn ne(&self, other: &Self) -> bool {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot return without recursing
@ -12,7 +12,7 @@ LL | self.ne(other)
= help: to override `-D warnings` add `#[allow(unconditional_recursion)]`
error: function cannot return without recursing
--> tests/ui/unconditional_recursion.rs:50:5
--> tests/ui/unconditional_recursion.rs:51:5
|
LL | fn eq(&self, other: &Self) -> bool {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot return without recursing
@ -23,7 +23,7 @@ LL | self.eq(other)
= help: a `loop` may express intention better if this is on purpose
error: function cannot return without recursing
--> tests/ui/unconditional_recursion.rs:215:5
--> tests/ui/unconditional_recursion.rs:216:5
|
LL | fn to_string(&self) -> String {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot return without recursing
@ -34,7 +34,7 @@ LL | self.to_string()
= help: a `loop` may express intention better if this is on purpose
error: function cannot return without recursing
--> tests/ui/unconditional_recursion.rs:225:5
--> tests/ui/unconditional_recursion.rs:226:5
|
LL | fn to_string(&self) -> String {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot return without recursing
@ -45,7 +45,7 @@ LL | x.to_string()
= help: a `loop` may express intention better if this is on purpose
error: function cannot return without recursing
--> tests/ui/unconditional_recursion.rs:236:5
--> tests/ui/unconditional_recursion.rs:237:5
|
LL | fn to_string(&self) -> String {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot return without recursing
@ -56,7 +56,7 @@ LL | (self as &Self).to_string()
= help: a `loop` may express intention better if this is on purpose
error: function cannot return without recursing
--> tests/ui/unconditional_recursion.rs:16:5
--> tests/ui/unconditional_recursion.rs:17:5
|
LL | / fn ne(&self, other: &Self) -> bool {
LL | |
@ -65,7 +65,7 @@ LL | | }
| |_____^
|
note: recursive call site
--> tests/ui/unconditional_recursion.rs:18:9
--> tests/ui/unconditional_recursion.rs:19:9
|
LL | self != other
| ^^^^^^^^^^^^^
@ -73,7 +73,7 @@ LL | self != other
= help: to override `-D warnings` add `#[allow(clippy::unconditional_recursion)]`
error: function cannot return without recursing
--> tests/ui/unconditional_recursion.rs:20:5
--> tests/ui/unconditional_recursion.rs:21:5
|
LL | / fn eq(&self, other: &Self) -> bool {
LL | |
@ -82,13 +82,13 @@ LL | | }
| |_____^
|
note: recursive call site
--> tests/ui/unconditional_recursion.rs:22:9
--> tests/ui/unconditional_recursion.rs:23:9
|
LL | self == other
| ^^^^^^^^^^^^^
error: function cannot return without recursing
--> tests/ui/unconditional_recursion.rs:32:5
--> tests/ui/unconditional_recursion.rs:33:5
|
LL | / fn ne(&self, other: &Self) -> bool {
LL | | self != &Foo2::B // no error here
@ -96,13 +96,13 @@ LL | | }
| |_____^
|
note: recursive call site
--> tests/ui/unconditional_recursion.rs:33:9
--> tests/ui/unconditional_recursion.rs:34:9
|
LL | self != &Foo2::B // no error here
| ^^^^^^^^^^^^^^^^
error: function cannot return without recursing
--> tests/ui/unconditional_recursion.rs:35:5
--> tests/ui/unconditional_recursion.rs:36:5
|
LL | / fn eq(&self, other: &Self) -> bool {
LL | | self == &Foo2::B // no error here
@ -110,13 +110,13 @@ LL | | }
| |_____^
|
note: recursive call site
--> tests/ui/unconditional_recursion.rs:36:9
--> tests/ui/unconditional_recursion.rs:37:9
|
LL | self == &Foo2::B // no error here
| ^^^^^^^^^^^^^^^^
error: function cannot return without recursing
--> tests/ui/unconditional_recursion.rs:46:5
--> tests/ui/unconditional_recursion.rs:47:5
|
LL | / fn ne(&self, other: &Self) -> bool {
LL | |
@ -125,13 +125,13 @@ LL | | }
| |_____^
|
note: recursive call site
--> tests/ui/unconditional_recursion.rs:48:9
--> tests/ui/unconditional_recursion.rs:49:9
|
LL | self.ne(other)
| ^^^^^^^^^^^^^^
error: function cannot return without recursing
--> tests/ui/unconditional_recursion.rs:50:5
--> tests/ui/unconditional_recursion.rs:51:5
|
LL | / fn eq(&self, other: &Self) -> bool {
LL | |
@ -140,13 +140,13 @@ LL | | }
| |_____^
|
note: recursive call site
--> tests/ui/unconditional_recursion.rs:52:9
--> tests/ui/unconditional_recursion.rs:53:9
|
LL | self.eq(other)
| ^^^^^^^^^^^^^^
error: function cannot return without recursing
--> tests/ui/unconditional_recursion.rs:94:5
--> tests/ui/unconditional_recursion.rs:95:5
|
LL | / fn ne(&self, other: &Self) -> bool {
LL | |
@ -155,13 +155,13 @@ LL | | }
| |_____^
|
note: recursive call site
--> tests/ui/unconditional_recursion.rs:96:9
--> tests/ui/unconditional_recursion.rs:97:9
|
LL | other != self
| ^^^^^^^^^^^^^
error: function cannot return without recursing
--> tests/ui/unconditional_recursion.rs:98:5
--> tests/ui/unconditional_recursion.rs:99:5
|
LL | / fn eq(&self, other: &Self) -> bool {
LL | |
@ -170,13 +170,13 @@ LL | | }
| |_____^
|
note: recursive call site
--> tests/ui/unconditional_recursion.rs:100:9
--> tests/ui/unconditional_recursion.rs:101:9
|
LL | other == self
| ^^^^^^^^^^^^^
error: function cannot return without recursing
--> tests/ui/unconditional_recursion.rs:108:5
--> tests/ui/unconditional_recursion.rs:109:5
|
LL | / fn ne(&self, other: &Self) -> bool {
LL | |
@ -185,13 +185,13 @@ LL | | }
| |_____^
|
note: recursive call site
--> tests/ui/unconditional_recursion.rs:110:9
--> tests/ui/unconditional_recursion.rs:111:9
|
LL | other != other
| ^^^^^^^^^^^^^^
error: equal expressions as operands to `!=`
--> tests/ui/unconditional_recursion.rs:110:9
--> tests/ui/unconditional_recursion.rs:111:9
|
LL | other != other
| ^^^^^^^^^^^^^^
@ -199,7 +199,7 @@ LL | other != other
= note: `#[deny(clippy::eq_op)]` on by default
error: function cannot return without recursing
--> tests/ui/unconditional_recursion.rs:112:5
--> tests/ui/unconditional_recursion.rs:113:5
|
LL | / fn eq(&self, other: &Self) -> bool {
LL | |
@ -208,19 +208,19 @@ LL | | }
| |_____^
|
note: recursive call site
--> tests/ui/unconditional_recursion.rs:114:9
--> tests/ui/unconditional_recursion.rs:115:9
|
LL | other == other
| ^^^^^^^^^^^^^^
error: equal expressions as operands to `==`
--> tests/ui/unconditional_recursion.rs:114:9
--> tests/ui/unconditional_recursion.rs:115:9
|
LL | other == other
| ^^^^^^^^^^^^^^
error: function cannot return without recursing
--> tests/ui/unconditional_recursion.rs:121:5
--> tests/ui/unconditional_recursion.rs:122:5
|
LL | / fn ne(&self, _other: &Self) -> bool {
LL | |
@ -229,19 +229,19 @@ LL | | }
| |_____^
|
note: recursive call site
--> tests/ui/unconditional_recursion.rs:123:9
--> tests/ui/unconditional_recursion.rs:124:9
|
LL | self != self
| ^^^^^^^^^^^^
error: equal expressions as operands to `!=`
--> tests/ui/unconditional_recursion.rs:123:9
--> tests/ui/unconditional_recursion.rs:124:9
|
LL | self != self
| ^^^^^^^^^^^^
error: function cannot return without recursing
--> tests/ui/unconditional_recursion.rs:125:5
--> tests/ui/unconditional_recursion.rs:126:5
|
LL | / fn eq(&self, _other: &Self) -> bool {
LL | |
@ -250,19 +250,19 @@ LL | | }
| |_____^
|
note: recursive call site
--> tests/ui/unconditional_recursion.rs:127:9
--> tests/ui/unconditional_recursion.rs:128:9
|
LL | self == self
| ^^^^^^^^^^^^
error: equal expressions as operands to `==`
--> tests/ui/unconditional_recursion.rs:127:9
--> tests/ui/unconditional_recursion.rs:128:9
|
LL | self == self
| ^^^^^^^^^^^^
error: function cannot return without recursing
--> tests/ui/unconditional_recursion.rs:153:13
--> tests/ui/unconditional_recursion.rs:154:13
|
LL | / fn eq(&self, other: &Self) -> bool {
LL | |
@ -274,7 +274,7 @@ LL | impl_partial_eq!(S5);
| -------------------- in this macro invocation
|
note: recursive call site
--> tests/ui/unconditional_recursion.rs:155:17
--> tests/ui/unconditional_recursion.rs:156:17
|
LL | self == other
| ^^^^^^^^^^^^^
@ -284,7 +284,7 @@ LL | impl_partial_eq!(S5);
= note: this error originates in the macro `impl_partial_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
error: function cannot return without recursing
--> tests/ui/unconditional_recursion.rs:182:5
--> tests/ui/unconditional_recursion.rs:183:5
|
LL | / fn eq(&self, other: &Self) -> bool {
LL | |
@ -295,13 +295,13 @@ LL | | }
| |_____^
|
note: recursive call site
--> tests/ui/unconditional_recursion.rs:186:9
--> tests/ui/unconditional_recursion.rs:187:9
|
LL | mine == theirs
| ^^^^^^^^^^^^^^
error: function cannot return without recursing
--> tests/ui/unconditional_recursion.rs:251:5
--> tests/ui/unconditional_recursion.rs:252:5
|
LL | / fn new() -> Self {
LL | |
@ -310,13 +310,13 @@ LL | | }
| |_____^
|
note: recursive call site
--> tests/ui/unconditional_recursion.rs:253:9
--> tests/ui/unconditional_recursion.rs:254:9
|
LL | Self::default()
| ^^^^^^^^^^^^^^^
error: function cannot return without recursing
--> tests/ui/unconditional_recursion.rs:290:5
--> tests/ui/unconditional_recursion.rs:291:5
|
LL | / fn eq(&self, other: &Self) -> bool {
LL | |
@ -327,13 +327,13 @@ LL | | }
| |_____^
|
note: recursive call site
--> tests/ui/unconditional_recursion.rs:294:9
--> tests/ui/unconditional_recursion.rs:295:9
|
LL | mine.eq(theirs)
| ^^^^^^^^^^^^^^^
error: function cannot return without recursing
--> tests/ui/unconditional_recursion.rs:361:5
--> tests/ui/unconditional_recursion.rs:362:5
|
LL | / fn from(f: BadFromTy1<'a>) -> Self {
LL | | f.into()
@ -341,13 +341,13 @@ LL | | }
| |_____^
|
note: recursive call site
--> tests/ui/unconditional_recursion.rs:362:9
--> tests/ui/unconditional_recursion.rs:363:9
|
LL | f.into()
| ^^^^^^^^
error: function cannot return without recursing
--> tests/ui/unconditional_recursion.rs:370:5
--> tests/ui/unconditional_recursion.rs:371:5
|
LL | / fn from(f: BadFromTy2<'a>) -> Self {
LL | | Into::into(f)
@ -355,7 +355,7 @@ LL | | }
| |_____^
|
note: recursive call site
--> tests/ui/unconditional_recursion.rs:371:9
--> tests/ui/unconditional_recursion.rs:372:9
|
LL | Into::into(f)
| ^^^^^^^^^^^^^

View file

@ -55,6 +55,22 @@ mod issue9695 {
}
}
mod issue13466 {
use std::future::Future;
struct Wrap<F>(F);
impl<F> From<F> for Wrap<F> {
fn from(f: F) -> Self {
Self(f)
}
}
fn takes_fut<F: Fn() -> Fut, Fut: Future>(_: Wrap<F>) {}
async fn unused_async() {}
fn fp() {
takes_fut(unused_async.into());
}
}
async fn foo() -> i32 {
//~^ ERROR: unused `async` for function with no await statements
4

View file

@ -27,7 +27,7 @@ LL | async fn f3() {}
= help: consider removing the `async` from this function
error: unused `async` for function with no await statements
--> tests/ui/unused_async.rs:58:1
--> tests/ui/unused_async.rs:74:1
|
LL | / async fn foo() -> i32 {
LL | |
@ -38,7 +38,7 @@ LL | | }
= help: consider removing the `async` from this function
error: unused `async` for function with no await statements
--> tests/ui/unused_async.rs:70:5
--> tests/ui/unused_async.rs:86:5
|
LL | / async fn unused(&self) -> i32 {
LL | |

View file

@ -0,0 +1,35 @@
#![warn(clippy::unused_format_specs)]
#![allow(unused)]
macro_rules! format_args_from_macro {
() => {
format_args!("from macro")
};
}
fn main() {
// prints `.`, not ` .`
println!("{:5}.", format!(""));
//~^ ERROR: format specifiers have no effect on `format_args!()`
//~| NOTE: `-D clippy::unused-format-specs` implied by `-D warnings`
//prints `abcde`, not `abc`
println!("{:.3}", format!("abcde"));
//~^ ERROR: format specifiers have no effect on `format_args!()`
println!("{}.", format_args_from_macro!());
//~^ ERROR: format specifiers have no effect on `format_args!()`
let args = format_args!("");
println!("{args}");
//~^ ERROR: format specifiers have no effect on `format_args!()`
}
fn should_not_lint() {
println!("{}", format_args!(""));
// Technically the same as `{}`, but the `format_args` docs specifically mention that you can use
// debug formatting so allow it
println!("{:?}", format_args!(""));
let args = format_args!("");
println!("{args}");
}

View file

@ -0,0 +1,35 @@
#![warn(clippy::unused_format_specs)]
#![allow(unused)]
macro_rules! format_args_from_macro {
() => {
format_args!("from macro")
};
}
fn main() {
// prints `.`, not ` .`
println!("{}.", format_args!(""));
//~^ ERROR: format specifiers have no effect on `format_args!()`
//~| NOTE: `-D clippy::unused-format-specs` implied by `-D warnings`
//prints `abcde`, not `abc`
println!("{}", format_args!("abcde"));
//~^ ERROR: format specifiers have no effect on `format_args!()`
println!("{}.", format_args_from_macro!());
//~^ ERROR: format specifiers have no effect on `format_args!()`
let args = format_args!("");
println!("{args}");
//~^ ERROR: format specifiers have no effect on `format_args!()`
}
fn should_not_lint() {
println!("{}", format_args!(""));
// Technically the same as `{}`, but the `format_args` docs specifically mention that you can use
// debug formatting so allow it
println!("{:?}", format_args!(""));
let args = format_args!("");
println!("{args}");
}

View file

@ -1,6 +1,6 @@
#![warn(clippy::unused_format_specs)]
#![allow(unused)]
//@no-rustfix
macro_rules! format_args_from_macro {
() => {
format_args!("from macro")

View file

@ -1,5 +1,5 @@
error: format specifiers have no effect on `format_args!()`
--> tests/ui/unused_format_specs_unfixable.rs:12:15
--> tests/ui/unused_format_specs.rs:12:15
|
LL | println!("{:5}.", format_args!(""));
| ^^^^
@ -17,7 +17,7 @@ LL + println!("{}.", format_args!(""));
|
error: format specifiers have no effect on `format_args!()`
--> tests/ui/unused_format_specs_unfixable.rs:16:15
--> tests/ui/unused_format_specs.rs:16:15
|
LL | println!("{:.3}", format_args!("abcde"));
| ^^^^^
@ -33,7 +33,7 @@ LL + println!("{}", format_args!("abcde"));
|
error: format specifiers have no effect on `format_args!()`
--> tests/ui/unused_format_specs_unfixable.rs:19:15
--> tests/ui/unused_format_specs.rs:19:15
|
LL | println!("{:5}.", format_args_from_macro!());
| ^^^^
@ -46,7 +46,7 @@ LL + println!("{}.", format_args_from_macro!());
|
error: format specifiers have no effect on `format_args!()`
--> tests/ui/unused_format_specs_unfixable.rs:23:15
--> tests/ui/unused_format_specs.rs:23:15
|
LL | println!("{args:5}");
| ^^^^^^^^

View file

@ -1,4 +1,5 @@
#![deny(clippy::useless_asref)]
#![allow(clippy::needless_lifetimes)]
trait Trait {
fn as_ptr(&self);

View file

@ -37,4 +37,72 @@ fn main() {
dbg!("matched (bar or) wild");
},
};
// shouldn't lint
#[non_exhaustive]
pub enum NonExhaustiveEnum<'a> {
Message(&'a str),
Quit(&'a str),
Other,
}
match NonExhaustiveEnum::Message("Pass") {
NonExhaustiveEnum::Message(_) => dbg!("message"),
NonExhaustiveEnum::Quit(_) => dbg!("quit"),
NonExhaustiveEnum::Other | _ => dbg!("wildcard"),
};
// should lint
enum ExhaustiveEnum {
Quit,
Write(String),
ChangeColor(i32, i32, i32),
}
match ExhaustiveEnum::ChangeColor(0, 160, 255) {
ExhaustiveEnum::Write(text) => {
dbg!("Write");
},
ExhaustiveEnum::ChangeColor(r, g, b) => {
dbg!("Change the color");
},
ExhaustiveEnum::Quit | _ => {
dbg!("Quit or other");
},
};
// shouldn't lint
#[non_exhaustive]
struct NonExhaustiveStruct {
a: u32,
b: u32,
c: u64,
}
let b = NonExhaustiveStruct { a: 5, b: 42, c: 342 };
match b {
NonExhaustiveStruct { a: 5, b: 42, .. } => {},
NonExhaustiveStruct { a: 0, b: 0, c: 128 } => {},
NonExhaustiveStruct { a: 0, b: 0, c: 128, .. } | _ => {},
}
// should lint
struct ExhaustiveStruct {
x: i32,
y: i32,
}
let p = ExhaustiveStruct { x: 0, y: 7 };
match p {
ExhaustiveStruct { x: 0, y: 0 } => {
dbg!("On the x axis at {x}");
},
ExhaustiveStruct { x: 0, y: 1 } => {
dbg!("On the y axis at {y}");
},
ExhaustiveStruct { x: 1, y: 1 } | _ => {
dbg!("On neither axis: ({x}, {y})");
},
}
}

View file

@ -32,5 +32,21 @@ LL | _ | "bar" => {
|
= help: consider handling `_` separately
error: aborting due to 4 previous errors
error: wildcard pattern covers any other pattern as it will match anyway
--> tests/ui/wild_in_or_pats.rs:69:9
|
LL | ExhaustiveEnum::Quit | _ => {
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: consider handling `_` separately
error: wildcard pattern covers any other pattern as it will match anyway
--> tests/ui/wild_in_or_pats.rs:104:9
|
LL | ExhaustiveStruct { x: 1, y: 1 } | _ => {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: consider handling `_` separately
error: aborting due to 6 previous errors

View file

@ -131,6 +131,13 @@ fn main() {
}
x.wait().unwrap();
}
{
let mut x = Command::new("").spawn().unwrap();
std::thread::spawn(move || {
x.wait().unwrap();
});
}
}
fn process_child(c: Child) {