Merge commit 'a98e7ab8b9' into clippyup

This commit is contained in:
flip1995 2022-01-27 15:12:45 +01:00
commit cce9231c19
No known key found for this signature in database
GPG key ID: 1CA0DF2AF59D68A5
102 changed files with 1850 additions and 1006 deletions

View file

@ -328,15 +328,9 @@ fn run_ui_cargo(config: &mut compiletest::Config) {
}
}
fn prepare_env() {
set_var("CLIPPY_DISABLE_DOCS_LINKS", "true");
set_var("__CLIPPY_INTERNAL_TESTS", "true");
//set_var("RUST_BACKTRACE", "0");
}
#[test]
fn compile_test() {
prepare_env();
set_var("CLIPPY_DISABLE_DOCS_LINKS", "true");
let mut config = default_config();
run_ui(&mut config);
run_ui_test(&mut config);

View file

@ -1,6 +1,7 @@
#![allow(clippy::redundant_clone)]
#![warn(clippy::manual_non_exhaustive)]
#![allow(clippy::redundant_clone, clippy::unnecessary_operation)]
#![warn(clippy::manual_non_exhaustive, clippy::borrow_as_ptr, clippy::manual_bits)]
use std::mem::{size_of, size_of_val};
use std::ops::Deref;
mod enums {
@ -68,6 +69,24 @@ fn check_index_refutable_slice() {
}
}
fn map_clone_suggest_copied() {
// This should still trigger the lint but suggest `cloned()` instead of `copied()`
let _: Option<u64> = Some(&16).map(|b| *b);
}
fn borrow_as_ptr() {
let val = 1;
let _p = &val as *const i32;
let mut val_mut = 1;
let _p_mut = &mut val_mut as *mut i32;
}
fn manual_bits() {
size_of::<i8>() * 8;
size_of_val(&0u32) * 8;
}
fn main() {
option_as_ref_deref();
match_like_matches();
@ -75,4 +94,5 @@ fn main() {
match_same_arms2();
manual_strip_msrv();
check_index_refutable_slice();
borrow_as_ptr();
}

View file

@ -0,0 +1,10 @@
error: you are using an explicit closure for copying elements
--> $DIR/min_rust_version.rs:74:26
|
LL | let _: Option<u64> = Some(&16).map(|b| *b);
| ^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `cloned` method: `Some(&16).cloned()`
|
= note: `-D clippy::map-clone` implied by `-D warnings`
error: aborting due to previous error

View file

@ -1,9 +1,5 @@
#![warn(clippy::borrow_interior_mutable_const)]
#![allow(
clippy::declare_interior_mutable_const,
clippy::ref_in_deref,
clippy::needless_borrow
)]
#![allow(clippy::declare_interior_mutable_const, clippy::needless_borrow)]
#![allow(const_item_mutation)]
use std::borrow::Cow;

View file

@ -1,5 +1,5 @@
error: a `const` item with interior mutability should not be borrowed
--> $DIR/others.rs:58:5
--> $DIR/others.rs:54:5
|
LL | ATOMIC.store(1, Ordering::SeqCst); //~ ERROR interior mutability
| ^^^^^^
@ -8,7 +8,7 @@ LL | ATOMIC.store(1, Ordering::SeqCst); //~ ERROR interior mutability
= help: assign this const to a local or static variable, and use the variable here
error: a `const` item with interior mutability should not be borrowed
--> $DIR/others.rs:59:16
--> $DIR/others.rs:55:16
|
LL | assert_eq!(ATOMIC.load(Ordering::SeqCst), 5); //~ ERROR interior mutability
| ^^^^^^
@ -16,7 +16,7 @@ LL | assert_eq!(ATOMIC.load(Ordering::SeqCst), 5); //~ ERROR interior mutabi
= help: assign this const to a local or static variable, and use the variable here
error: a `const` item with interior mutability should not be borrowed
--> $DIR/others.rs:62:22
--> $DIR/others.rs:58:22
|
LL | let _once_ref = &ONCE_INIT; //~ ERROR interior mutability
| ^^^^^^^^^
@ -24,7 +24,7 @@ LL | let _once_ref = &ONCE_INIT; //~ ERROR interior mutability
= help: assign this const to a local or static variable, and use the variable here
error: a `const` item with interior mutability should not be borrowed
--> $DIR/others.rs:63:25
--> $DIR/others.rs:59:25
|
LL | let _once_ref_2 = &&ONCE_INIT; //~ ERROR interior mutability
| ^^^^^^^^^
@ -32,7 +32,7 @@ LL | let _once_ref_2 = &&ONCE_INIT; //~ ERROR interior mutability
= help: assign this const to a local or static variable, and use the variable here
error: a `const` item with interior mutability should not be borrowed
--> $DIR/others.rs:64:27
--> $DIR/others.rs:60:27
|
LL | let _once_ref_4 = &&&&ONCE_INIT; //~ ERROR interior mutability
| ^^^^^^^^^
@ -40,7 +40,7 @@ LL | let _once_ref_4 = &&&&ONCE_INIT; //~ ERROR interior mutability
= help: assign this const to a local or static variable, and use the variable here
error: a `const` item with interior mutability should not be borrowed
--> $DIR/others.rs:65:26
--> $DIR/others.rs:61:26
|
LL | let _once_mut = &mut ONCE_INIT; //~ ERROR interior mutability
| ^^^^^^^^^
@ -48,7 +48,7 @@ LL | let _once_mut = &mut ONCE_INIT; //~ ERROR interior mutability
= help: assign this const to a local or static variable, and use the variable here
error: a `const` item with interior mutability should not be borrowed
--> $DIR/others.rs:76:14
--> $DIR/others.rs:72:14
|
LL | let _ = &ATOMIC_TUPLE; //~ ERROR interior mutability
| ^^^^^^^^^^^^
@ -56,7 +56,7 @@ LL | let _ = &ATOMIC_TUPLE; //~ ERROR interior mutability
= help: assign this const to a local or static variable, and use the variable here
error: a `const` item with interior mutability should not be borrowed
--> $DIR/others.rs:77:14
--> $DIR/others.rs:73:14
|
LL | let _ = &ATOMIC_TUPLE.0; //~ ERROR interior mutability
| ^^^^^^^^^^^^
@ -64,7 +64,7 @@ LL | let _ = &ATOMIC_TUPLE.0; //~ ERROR interior mutability
= help: assign this const to a local or static variable, and use the variable here
error: a `const` item with interior mutability should not be borrowed
--> $DIR/others.rs:78:19
--> $DIR/others.rs:74:19
|
LL | let _ = &(&&&&ATOMIC_TUPLE).0; //~ ERROR interior mutability
| ^^^^^^^^^^^^
@ -72,7 +72,7 @@ LL | let _ = &(&&&&ATOMIC_TUPLE).0; //~ ERROR interior mutability
= help: assign this const to a local or static variable, and use the variable here
error: a `const` item with interior mutability should not be borrowed
--> $DIR/others.rs:79:14
--> $DIR/others.rs:75:14
|
LL | let _ = &ATOMIC_TUPLE.0[0]; //~ ERROR interior mutability
| ^^^^^^^^^^^^
@ -80,7 +80,7 @@ LL | let _ = &ATOMIC_TUPLE.0[0]; //~ ERROR interior mutability
= help: assign this const to a local or static variable, and use the variable here
error: a `const` item with interior mutability should not be borrowed
--> $DIR/others.rs:80:13
--> $DIR/others.rs:76:13
|
LL | let _ = ATOMIC_TUPLE.0[0].load(Ordering::SeqCst); //~ ERROR interior mutability
| ^^^^^^^^^^^^
@ -88,7 +88,7 @@ LL | let _ = ATOMIC_TUPLE.0[0].load(Ordering::SeqCst); //~ ERROR interior mu
= help: assign this const to a local or static variable, and use the variable here
error: a `const` item with interior mutability should not be borrowed
--> $DIR/others.rs:86:13
--> $DIR/others.rs:82:13
|
LL | let _ = ATOMIC_TUPLE.0[0]; //~ ERROR interior mutability
| ^^^^^^^^^^^^
@ -96,7 +96,7 @@ LL | let _ = ATOMIC_TUPLE.0[0]; //~ ERROR interior mutability
= help: assign this const to a local or static variable, and use the variable here
error: a `const` item with interior mutability should not be borrowed
--> $DIR/others.rs:91:5
--> $DIR/others.rs:87:5
|
LL | CELL.set(2); //~ ERROR interior mutability
| ^^^^
@ -104,7 +104,7 @@ LL | CELL.set(2); //~ ERROR interior mutability
= help: assign this const to a local or static variable, and use the variable here
error: a `const` item with interior mutability should not be borrowed
--> $DIR/others.rs:92:16
--> $DIR/others.rs:88:16
|
LL | assert_eq!(CELL.get(), 6); //~ ERROR interior mutability
| ^^^^

View file

@ -1,3 +1,5 @@
#![allow(clippy::needless_borrow)]
#[deny(clippy::naive_bytecount)]
fn main() {
let x = vec![0_u8; 16];

View file

@ -1,23 +1,23 @@
error: you appear to be counting bytes the naive way
--> $DIR/bytecount.rs:5:13
--> $DIR/bytecount.rs:7:13
|
LL | let _ = x.iter().filter(|&&a| a == 0).count(); // naive byte count
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using the bytecount crate: `bytecount::count(x, 0)`
|
note: the lint level is defined here
--> $DIR/bytecount.rs:1:8
--> $DIR/bytecount.rs:3:8
|
LL | #[deny(clippy::naive_bytecount)]
| ^^^^^^^^^^^^^^^^^^^^^^^
error: you appear to be counting bytes the naive way
--> $DIR/bytecount.rs:7:13
--> $DIR/bytecount.rs:9:13
|
LL | let _ = (&x[..]).iter().filter(|&a| *a == 0).count(); // naive byte count
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using the bytecount crate: `bytecount::count((&x[..]), 0)`
error: you appear to be counting bytes the naive way
--> $DIR/bytecount.rs:19:13
--> $DIR/bytecount.rs:21:13
|
LL | let _ = x.iter().filter(|a| b + 1 == **a).count(); // naive byte count
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using the bytecount crate: `bytecount::count(x, b + 1)`

View file

@ -7,7 +7,8 @@
clippy::no_effect,
clippy::unnecessary_operation,
clippy::vec_init_then_push,
clippy::toplevel_ref_arg
clippy::toplevel_ref_arg,
clippy::needless_borrow
)]
use std::cell::RefCell;

View file

@ -7,7 +7,8 @@
clippy::no_effect,
clippy::unnecessary_operation,
clippy::vec_init_then_push,
clippy::toplevel_ref_arg
clippy::toplevel_ref_arg,
clippy::needless_borrow
)]
use std::cell::RefCell;

View file

@ -1,5 +1,5 @@
error: using `clone` on type `i32` which implements the `Copy` trait
--> $DIR/clone_on_copy.rs:24:5
--> $DIR/clone_on_copy.rs:25:5
|
LL | 42.clone();
| ^^^^^^^^^^ help: try removing the `clone` call: `42`
@ -7,43 +7,43 @@ LL | 42.clone();
= note: `-D clippy::clone-on-copy` implied by `-D warnings`
error: using `clone` on type `i32` which implements the `Copy` trait
--> $DIR/clone_on_copy.rs:28:5
--> $DIR/clone_on_copy.rs:29:5
|
LL | (&42).clone();
| ^^^^^^^^^^^^^ help: try dereferencing it: `*(&42)`
error: using `clone` on type `i32` which implements the `Copy` trait
--> $DIR/clone_on_copy.rs:31:5
--> $DIR/clone_on_copy.rs:32:5
|
LL | rc.borrow().clone();
| ^^^^^^^^^^^^^^^^^^^ help: try dereferencing it: `*rc.borrow()`
error: using `clone` on type `u32` which implements the `Copy` trait
--> $DIR/clone_on_copy.rs:34:5
--> $DIR/clone_on_copy.rs:35:5
|
LL | x.clone().rotate_left(1);
| ^^^^^^^^^ help: try removing the `clone` call: `x`
error: using `clone` on type `i32` which implements the `Copy` trait
--> $DIR/clone_on_copy.rs:48:5
--> $DIR/clone_on_copy.rs:49:5
|
LL | m!(42).clone();
| ^^^^^^^^^^^^^^ help: try removing the `clone` call: `m!(42)`
error: using `clone` on type `[u32; 2]` which implements the `Copy` trait
--> $DIR/clone_on_copy.rs:58:5
--> $DIR/clone_on_copy.rs:59:5
|
LL | x.clone()[0];
| ^^^^^^^^^ help: try dereferencing it: `(*x)`
error: using `clone` on type `char` which implements the `Copy` trait
--> $DIR/clone_on_copy.rs:68:14
--> $DIR/clone_on_copy.rs:69:14
|
LL | is_ascii('z'.clone());
| ^^^^^^^^^^^ help: try removing the `clone` call: `'z'`
error: using `clone` on type `i32` which implements the `Copy` trait
--> $DIR/clone_on_copy.rs:72:14
--> $DIR/clone_on_copy.rs:73:14
|
LL | vec.push(42.clone());
| ^^^^^^^^^^ help: try removing the `clone` call: `42`

View file

@ -1,5 +1,5 @@
// run-rustfix
#![allow(dead_code)]
#![allow(dead_code, clippy::needless_borrow)]
#![warn(clippy::duration_subsec)]
use std::time::Duration;

View file

@ -1,5 +1,5 @@
// run-rustfix
#![allow(dead_code)]
#![allow(dead_code, clippy::needless_borrow)]
#![warn(clippy::duration_subsec)]
use std::time::Duration;

View file

@ -151,4 +151,11 @@ enum North {
NoRight,
}
// #8324
enum Phase {
PreLookup,
Lookup,
PostLookup,
}
fn main() {}

View file

@ -5,13 +5,10 @@
clippy::no_effect,
clippy::redundant_closure_call,
clippy::needless_pass_by_value,
clippy::option_map_unit_fn
)]
#![warn(
clippy::redundant_closure,
clippy::redundant_closure_for_method_calls,
clippy::option_map_unit_fn,
clippy::needless_borrow
)]
#![warn(clippy::redundant_closure, clippy::redundant_closure_for_method_calls)]
use std::path::{Path, PathBuf};
@ -34,7 +31,7 @@ fn main() {
Some(1).map(closure_mac!()); // don't lint closure in macro expansion
let _: Option<Vec<u8>> = true.then(std::vec::Vec::new); // special case vec!
let d = Some(1u8).map(|a| foo(foo2(a))); //is adjusted?
all(&[1, 2, 3], &2, below); //is adjusted
all(&[1, 2, 3], &&2, below); //is adjusted
unsafe {
Some(1u8).map(|a| unsafe_fn(a)); // unsafe fn
}

View file

@ -5,13 +5,10 @@
clippy::no_effect,
clippy::redundant_closure_call,
clippy::needless_pass_by_value,
clippy::option_map_unit_fn
)]
#![warn(
clippy::redundant_closure,
clippy::redundant_closure_for_method_calls,
clippy::option_map_unit_fn,
clippy::needless_borrow
)]
#![warn(clippy::redundant_closure, clippy::redundant_closure_for_method_calls)]
use std::path::{Path, PathBuf};

View file

@ -1,5 +1,5 @@
error: redundant closure
--> $DIR/eta.rs:31:27
--> $DIR/eta.rs:28:27
|
LL | let a = Some(1u8).map(|a| foo(a));
| ^^^^^^^^^^ help: replace the closure with the function itself: `foo`
@ -7,45 +7,37 @@ LL | let a = Some(1u8).map(|a| foo(a));
= note: `-D clippy::redundant-closure` implied by `-D warnings`
error: redundant closure
--> $DIR/eta.rs:35:40
--> $DIR/eta.rs:32: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
--> $DIR/eta.rs:36:35
--> $DIR/eta.rs:33: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: this expression borrows a reference (`&u8`) that is immediately dereferenced by the compiler
--> $DIR/eta.rs:37:21
|
LL | all(&[1, 2, 3], &&2, |x, y| below(x, y)); //is adjusted
| ^^^ help: change this to: `&2`
|
= note: `-D clippy::needless-borrow` implied by `-D warnings`
error: redundant closure
--> $DIR/eta.rs:37:26
--> $DIR/eta.rs:34: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
--> $DIR/eta.rs:43:27
--> $DIR/eta.rs:40:27
|
LL | let e = Some(1u8).map(|a| divergent(a));
| ^^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `divergent`
error: redundant closure
--> $DIR/eta.rs:44:27
--> $DIR/eta.rs:41:27
|
LL | let e = Some(1u8).map(|a| generic(a));
| ^^^^^^^^^^^^^^ help: replace the closure with the function itself: `generic`
error: redundant closure
--> $DIR/eta.rs:90:51
--> $DIR/eta.rs:87:51
|
LL | let e = Some(TestStruct { some_ref: &i }).map(|a| a.foo());
| ^^^^^^^^^^^ help: replace the closure with the method itself: `TestStruct::foo`
@ -53,82 +45,82 @@ LL | let e = Some(TestStruct { some_ref: &i }).map(|a| a.foo());
= note: `-D clippy::redundant-closure-for-method-calls` implied by `-D warnings`
error: redundant closure
--> $DIR/eta.rs:91:51
--> $DIR/eta.rs:88: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
--> $DIR/eta.rs:93:42
--> $DIR/eta.rs:90: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
--> $DIR/eta.rs:97:29
--> $DIR/eta.rs:94: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
--> $DIR/eta.rs:98:27
--> $DIR/eta.rs:95: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
--> $DIR/eta.rs:100:65
--> $DIR/eta.rs:97: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
--> $DIR/eta.rs:163:22
--> $DIR/eta.rs:160:22
|
LL | requires_fn_once(|| x());
| ^^^^^^ help: replace the closure with the function itself: `x`
error: redundant closure
--> $DIR/eta.rs:170:27
--> $DIR/eta.rs:167:27
|
LL | let a = Some(1u8).map(|a| foo_ptr(a));
| ^^^^^^^^^^^^^^ help: replace the closure with the function itself: `foo_ptr`
error: redundant closure
--> $DIR/eta.rs:175:27
--> $DIR/eta.rs:172:27
|
LL | let a = Some(1u8).map(|a| closure(a));
| ^^^^^^^^^^^^^^ help: replace the closure with the function itself: `closure`
error: redundant closure
--> $DIR/eta.rs:207:28
--> $DIR/eta.rs:204: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
--> $DIR/eta.rs:208:28
--> $DIR/eta.rs:205: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
--> $DIR/eta.rs:209:28
--> $DIR/eta.rs:206: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
--> $DIR/eta.rs:216:21
--> $DIR/eta.rs:213:21
|
LL | Some(1).map(|n| closure(n));
| ^^^^^^^^^^^^^^ help: replace the closure with the function itself: `&mut closure`
error: redundant closure
--> $DIR/eta.rs:235:21
--> $DIR/eta.rs:232:21
|
LL | map_str_to_path(|s| s.as_ref());
| ^^^^^^^^^^^^^^ help: replace the closure with the method itself: `std::convert::AsRef::as_ref`
error: aborting due to 21 previous errors
error: aborting due to 20 previous errors

View file

@ -1,6 +1,6 @@
// run-rustfix
#![allow(unused_variables, clippy::clone_double_ref)]
#![allow(unused_variables, clippy::clone_double_ref, clippy::needless_borrow)]
#![warn(clippy::explicit_deref_methods)]
use std::ops::{Deref, DerefMut};

View file

@ -1,6 +1,6 @@
// run-rustfix
#![allow(unused_variables, clippy::clone_double_ref)]
#![allow(unused_variables, clippy::clone_double_ref, clippy::needless_borrow)]
#![warn(clippy::explicit_deref_methods)]
use std::ops::{Deref, DerefMut};

View file

@ -23,7 +23,12 @@ impl Unrelated {
clippy::iter_next_loop,
clippy::for_kv_map
)]
#[allow(clippy::linkedlist, clippy::unnecessary_mut_passed, clippy::similar_names)]
#[allow(
clippy::linkedlist,
clippy::unnecessary_mut_passed,
clippy::similar_names,
clippy::needless_borrow
)]
#[allow(unused_variables)]
fn main() {
let mut vec = vec![1, 2, 3, 4];

View file

@ -23,7 +23,12 @@ impl Unrelated {
clippy::iter_next_loop,
clippy::for_kv_map
)]
#[allow(clippy::linkedlist, clippy::unnecessary_mut_passed, clippy::similar_names)]
#[allow(
clippy::linkedlist,
clippy::unnecessary_mut_passed,
clippy::similar_names,
clippy::needless_borrow
)]
#[allow(unused_variables)]
fn main() {
let mut vec = vec![1, 2, 3, 4];

View file

@ -1,5 +1,5 @@
error: it is more concise to loop over references to containers instead of using explicit iteration methods
--> $DIR/for_loop_fixable.rs:38:15
--> $DIR/for_loop_fixable.rs:43:15
|
LL | for _v in vec.iter() {}
| ^^^^^^^^^^ help: to write this more concisely, try: `&vec`
@ -7,13 +7,13 @@ LL | for _v in vec.iter() {}
= note: `-D clippy::explicit-iter-loop` implied by `-D warnings`
error: it is more concise to loop over references to containers instead of using explicit iteration methods
--> $DIR/for_loop_fixable.rs:40:15
--> $DIR/for_loop_fixable.rs:45:15
|
LL | for _v in vec.iter_mut() {}
| ^^^^^^^^^^^^^^ help: to write this more concisely, try: `&mut vec`
error: it is more concise to loop over containers instead of using explicit iteration methods
--> $DIR/for_loop_fixable.rs:43:15
--> $DIR/for_loop_fixable.rs:48:15
|
LL | for _v in out_vec.into_iter() {}
| ^^^^^^^^^^^^^^^^^^^ help: to write this more concisely, try: `out_vec`
@ -21,73 +21,73 @@ LL | for _v in out_vec.into_iter() {}
= note: `-D clippy::explicit-into-iter-loop` implied by `-D warnings`
error: it is more concise to loop over references to containers instead of using explicit iteration methods
--> $DIR/for_loop_fixable.rs:48:15
--> $DIR/for_loop_fixable.rs:53:15
|
LL | for _v in [1, 2, 3].iter() {}
| ^^^^^^^^^^^^^^^^ help: to write this more concisely, try: `&[1, 2, 3]`
error: it is more concise to loop over references to containers instead of using explicit iteration methods
--> $DIR/for_loop_fixable.rs:52:15
--> $DIR/for_loop_fixable.rs:57:15
|
LL | for _v in [0; 32].iter() {}
| ^^^^^^^^^^^^^^ help: to write this more concisely, try: `&[0; 32]`
error: it is more concise to loop over references to containers instead of using explicit iteration methods
--> $DIR/for_loop_fixable.rs:57:15
--> $DIR/for_loop_fixable.rs:62:15
|
LL | for _v in ll.iter() {}
| ^^^^^^^^^ help: to write this more concisely, try: `&ll`
error: it is more concise to loop over references to containers instead of using explicit iteration methods
--> $DIR/for_loop_fixable.rs:60:15
--> $DIR/for_loop_fixable.rs:65:15
|
LL | for _v in vd.iter() {}
| ^^^^^^^^^ help: to write this more concisely, try: `&vd`
error: it is more concise to loop over references to containers instead of using explicit iteration methods
--> $DIR/for_loop_fixable.rs:63:15
--> $DIR/for_loop_fixable.rs:68:15
|
LL | for _v in bh.iter() {}
| ^^^^^^^^^ help: to write this more concisely, try: `&bh`
error: it is more concise to loop over references to containers instead of using explicit iteration methods
--> $DIR/for_loop_fixable.rs:66:15
--> $DIR/for_loop_fixable.rs:71:15
|
LL | for _v in hm.iter() {}
| ^^^^^^^^^ help: to write this more concisely, try: `&hm`
error: it is more concise to loop over references to containers instead of using explicit iteration methods
--> $DIR/for_loop_fixable.rs:69:15
--> $DIR/for_loop_fixable.rs:74:15
|
LL | for _v in bt.iter() {}
| ^^^^^^^^^ help: to write this more concisely, try: `&bt`
error: it is more concise to loop over references to containers instead of using explicit iteration methods
--> $DIR/for_loop_fixable.rs:72:15
--> $DIR/for_loop_fixable.rs:77:15
|
LL | for _v in hs.iter() {}
| ^^^^^^^^^ help: to write this more concisely, try: `&hs`
error: it is more concise to loop over references to containers instead of using explicit iteration methods
--> $DIR/for_loop_fixable.rs:75:15
--> $DIR/for_loop_fixable.rs:80:15
|
LL | for _v in bs.iter() {}
| ^^^^^^^^^ help: to write this more concisely, try: `&bs`
error: it is more concise to loop over containers instead of using explicit iteration methods
--> $DIR/for_loop_fixable.rs:250:18
--> $DIR/for_loop_fixable.rs:255:18
|
LL | for i in iterator.into_iter() {
| ^^^^^^^^^^^^^^^^^^^^ help: to write this more concisely, try: `iterator`
error: it is more concise to loop over references to containers instead of using explicit iteration methods
--> $DIR/for_loop_fixable.rs:270:18
--> $DIR/for_loop_fixable.rs:275:18
|
LL | for _ in t.into_iter() {}
| ^^^^^^^^^^^^^ help: to write this more concisely, try: `&t`
error: it is more concise to loop over containers instead of using explicit iteration methods
--> $DIR/for_loop_fixable.rs:272:18
--> $DIR/for_loop_fixable.rs:277:18
|
LL | for _ in r.into_iter() {}
| ^^^^^^^^^^^^^ help: to write this more concisely, try: `r`

View file

@ -1,6 +1,11 @@
// run-rustfix
#![allow(clippy::print_literal, clippy::redundant_clone, clippy::to_string_in_format_args)]
#![allow(
clippy::print_literal,
clippy::redundant_clone,
clippy::to_string_in_format_args,
clippy::needless_borrow
)]
#![warn(clippy::useless_format)]
struct Foo(pub String);

View file

@ -1,6 +1,11 @@
// run-rustfix
#![allow(clippy::print_literal, clippy::redundant_clone, clippy::to_string_in_format_args)]
#![allow(
clippy::print_literal,
clippy::redundant_clone,
clippy::to_string_in_format_args,
clippy::needless_borrow
)]
#![warn(clippy::useless_format)]
struct Foo(pub String);

View file

@ -1,5 +1,5 @@
error: useless use of `format!`
--> $DIR/format.rs:13:5
--> $DIR/format.rs:18:5
|
LL | format!("foo");
| ^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"foo".to_string()`
@ -7,19 +7,19 @@ LL | format!("foo");
= note: `-D clippy::useless-format` implied by `-D warnings`
error: useless use of `format!`
--> $DIR/format.rs:14:5
--> $DIR/format.rs:19:5
|
LL | format!("{{}}");
| ^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"{}".to_string()`
error: useless use of `format!`
--> $DIR/format.rs:15:5
--> $DIR/format.rs:20:5
|
LL | format!("{{}} abc {{}}");
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"{} abc {}".to_string()`
error: useless use of `format!`
--> $DIR/format.rs:16:5
--> $DIR/format.rs:21:5
|
LL | / format!(
LL | | r##"foo {{}}
@ -34,79 +34,79 @@ LL ~ " bar"##.to_string();
|
error: useless use of `format!`
--> $DIR/format.rs:21:13
--> $DIR/format.rs:26:13
|
LL | let _ = format!("");
| ^^^^^^^^^^^ help: consider using `String::new()`: `String::new()`
error: useless use of `format!`
--> $DIR/format.rs:23:5
--> $DIR/format.rs:28:5
|
LL | format!("{}", "foo");
| ^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"foo".to_string()`
error: useless use of `format!`
--> $DIR/format.rs:27:5
--> $DIR/format.rs:32:5
|
LL | format!("{:+}", "foo"); // Warn when the format makes no difference.
| ^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"foo".to_string()`
error: useless use of `format!`
--> $DIR/format.rs:28:5
--> $DIR/format.rs:33:5
|
LL | format!("{:<}", "foo"); // Warn when the format makes no difference.
| ^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"foo".to_string()`
error: useless use of `format!`
--> $DIR/format.rs:33:5
--> $DIR/format.rs:38:5
|
LL | format!("{}", arg);
| ^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `arg.to_string()`
error: useless use of `format!`
--> $DIR/format.rs:37:5
--> $DIR/format.rs:42:5
|
LL | format!("{:+}", arg); // Warn when the format makes no difference.
| ^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `arg.to_string()`
error: useless use of `format!`
--> $DIR/format.rs:38:5
--> $DIR/format.rs:43:5
|
LL | format!("{:<}", arg); // Warn when the format makes no difference.
| ^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `arg.to_string()`
error: useless use of `format!`
--> $DIR/format.rs:65:5
--> $DIR/format.rs:70:5
|
LL | format!("{}", 42.to_string());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `42.to_string()`
error: useless use of `format!`
--> $DIR/format.rs:67:5
--> $DIR/format.rs:72:5
|
LL | format!("{}", x.display().to_string());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `x.display().to_string()`
error: useless use of `format!`
--> $DIR/format.rs:71:18
--> $DIR/format.rs:76:18
|
LL | let _ = Some(format!("{}", a + "bar"));
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `a + "bar"`
error: useless use of `format!`
--> $DIR/format.rs:75:22
--> $DIR/format.rs:80:22
|
LL | let _s: String = format!("{}", &*v.join("/n"));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `(&*v.join("/n")).to_string()`
error: useless use of `format!`
--> $DIR/format.rs:81:13
--> $DIR/format.rs:86:13
|
LL | let _ = format!("{x}");
| ^^^^^^^^^^^^^^ help: consider using `.to_string()`: `x.to_string()`
error: useless use of `format!`
--> $DIR/format.rs:83:13
--> $DIR/format.rs:88:13
|
LL | let _ = format!("{y}", y = x);
| ^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `x.to_string()`

View file

@ -45,6 +45,33 @@ fn main() {
let b = &mut b;
x(b);
}
// Issue #8191
let mut x = 5;
let mut x = &mut x;
mut_ref(x);
mut_ref(x);
let y: &mut i32 = x;
let y: &mut i32 = x;
let y = match 0 {
// Don't lint. Removing the borrow would move 'x'
0 => &mut x,
_ => &mut *x,
};
*x = 5;
let s = String::new();
let _ = s.len();
let _ = s.capacity();
let _ = s.capacity();
let x = (1, 2);
let _ = x.0;
let x = &x as *const (i32, i32);
let _ = unsafe { (*x).0 };
}
#[allow(clippy::needless_borrowed_reference)]

View file

@ -45,6 +45,33 @@ fn main() {
let b = &mut b;
x(&b);
}
// Issue #8191
let mut x = 5;
let mut x = &mut x;
mut_ref(&mut x);
mut_ref(&mut &mut x);
let y: &mut i32 = &mut x;
let y: &mut i32 = &mut &mut x;
let y = match 0 {
// Don't lint. Removing the borrow would move 'x'
0 => &mut x,
_ => &mut *x,
};
*x = 5;
let s = String::new();
let _ = (&s).len();
let _ = (&s).capacity();
let _ = (&&s).capacity();
let x = (1, 2);
let _ = (&x).0;
let x = &x as *const (i32, i32);
let _ = unsafe { (&*x).0 };
}
#[allow(clippy::needless_borrowed_reference)]

View file

@ -1,4 +1,4 @@
error: this expression borrows a reference (`&i32`) that is immediately dereferenced by the compiler
error: this expression creates a reference which is immediately dereferenced by the compiler
--> $DIR/needless_borrow.rs:9:15
|
LL | let _ = x(&&a); // warn
@ -6,59 +6,113 @@ LL | let _ = x(&&a); // warn
|
= note: `-D clippy::needless-borrow` implied by `-D warnings`
error: this expression borrows a reference (`&mut i32`) that is immediately dereferenced by the compiler
error: this expression creates a reference which is immediately dereferenced by the compiler
--> $DIR/needless_borrow.rs:13:13
|
LL | mut_ref(&mut &mut b); // warn
| ^^^^^^^^^^^ help: change this to: `&mut b`
error: this expression borrows a reference (`&i32`) that is immediately dereferenced by the compiler
error: this expression creates a reference which is immediately dereferenced by the compiler
--> $DIR/needless_borrow.rs:25:13
|
LL | &&a
| ^^^ help: change this to: `&a`
error: this expression borrows a reference (`&i32`) that is immediately dereferenced by the compiler
error: this expression creates a reference which is immediately dereferenced by the compiler
--> $DIR/needless_borrow.rs:27:15
|
LL | 46 => &&a,
| ^^^ help: change this to: `&a`
error: this expression borrows a reference (`&i32`) that is immediately dereferenced by the compiler
error: this expression creates a reference which is immediately dereferenced by the compiler
--> $DIR/needless_borrow.rs:33:27
|
LL | break &ref_a;
| ^^^^^^ help: change this to: `ref_a`
error: this expression borrows a reference (`&i32`) that is immediately dereferenced by the compiler
error: this expression creates a reference which is immediately dereferenced by the compiler
--> $DIR/needless_borrow.rs:40:15
|
LL | let _ = x(&&&a);
| ^^^^ help: change this to: `&a`
error: this expression borrows a reference (`&i32`) that is immediately dereferenced by the compiler
error: this expression creates a reference which is immediately dereferenced by the compiler
--> $DIR/needless_borrow.rs:41:15
|
LL | let _ = x(&mut &&a);
| ^^^^^^^^ help: change this to: `&a`
error: this expression borrows a reference (`&mut i32`) that is immediately dereferenced by the compiler
error: this expression creates a reference which is immediately dereferenced by the compiler
--> $DIR/needless_borrow.rs:42:15
|
LL | let _ = x(&&&mut b);
| ^^^^^^^^ help: change this to: `&mut b`
error: this expression borrows a reference (`&i32`) that is immediately dereferenced by the compiler
error: this expression creates a reference which is immediately dereferenced by the compiler
--> $DIR/needless_borrow.rs:43:15
|
LL | let _ = x(&&ref_a);
| ^^^^^^^ help: change this to: `ref_a`
error: this expression borrows a reference (`&mut i32`) that is immediately dereferenced by the compiler
error: this expression creates a reference which is immediately dereferenced by the compiler
--> $DIR/needless_borrow.rs:46:11
|
LL | x(&b);
| ^^ help: change this to: `b`
error: aborting due to 10 previous errors
error: this expression creates a reference which is immediately dereferenced by the compiler
--> $DIR/needless_borrow.rs:53:13
|
LL | mut_ref(&mut x);
| ^^^^^^ help: change this to: `x`
error: this expression creates a reference which is immediately dereferenced by the compiler
--> $DIR/needless_borrow.rs:54: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
--> $DIR/needless_borrow.rs:55: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
--> $DIR/needless_borrow.rs:56:23
|
LL | let y: &mut i32 = &mut &mut x;
| ^^^^^^^^^^^ help: change this to: `x`
error: this expression borrows a value the compiler would automatically borrow
--> $DIR/needless_borrow.rs:67:13
|
LL | let _ = (&s).len();
| ^^^^ help: change this to: `s`
error: this expression borrows a value the compiler would automatically borrow
--> $DIR/needless_borrow.rs:68:13
|
LL | let _ = (&s).capacity();
| ^^^^ help: change this to: `s`
error: this expression creates a reference which is immediately dereferenced by the compiler
--> $DIR/needless_borrow.rs:69:13
|
LL | let _ = (&&s).capacity();
| ^^^^^ help: change this to: `s`
error: this expression borrows a value the compiler would automatically borrow
--> $DIR/needless_borrow.rs:72:13
|
LL | let _ = (&x).0;
| ^^^^ help: change this to: `x`
error: this expression borrows a value the compiler would automatically borrow
--> $DIR/needless_borrow.rs:74:22
|
LL | let _ = unsafe { (&*x).0 };
| ^^^^^ help: change this to: `(*x)`
error: aborting due to 19 previous errors

View file

@ -1,5 +1,11 @@
#![warn(clippy::needless_lifetimes)]
#![allow(dead_code, clippy::needless_pass_by_value, clippy::unnecessary_wraps, dyn_drop)]
#![allow(
dead_code,
clippy::boxed_local,
clippy::needless_pass_by_value,
clippy::unnecessary_wraps,
dyn_drop
)]
fn distinct_lifetimes<'a, 'b>(_x: &'a u8, _y: &'b u8, _z: u8) {}
@ -369,4 +375,47 @@ mod issue6159 {
}
}
mod issue7296 {
use std::rc::Rc;
use std::sync::Arc;
struct Foo;
impl Foo {
fn implicit<'a>(&'a self) -> &'a () {
&()
}
fn implicit_mut<'a>(&'a mut self) -> &'a () {
&()
}
fn explicit<'a>(self: &'a Arc<Self>) -> &'a () {
&()
}
fn explicit_mut<'a>(self: &'a mut Rc<Self>) -> &'a () {
&()
}
fn lifetime_elsewhere<'a>(self: Box<Self>, here: &'a ()) -> &'a () {
&()
}
}
trait Bar {
fn implicit<'a>(&'a self) -> &'a ();
fn implicit_provided<'a>(&'a self) -> &'a () {
&()
}
fn explicit<'a>(self: &'a Arc<Self>) -> &'a ();
fn explicit_provided<'a>(self: &'a Arc<Self>) -> &'a () {
&()
}
fn lifetime_elsewhere<'a>(self: Box<Self>, here: &'a ()) -> &'a ();
fn lifetime_elsewhere_provided<'a>(self: Box<Self>, here: &'a ()) -> &'a () {
&()
}
}
}
fn main() {}

View file

@ -1,5 +1,5 @@
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
--> $DIR/needless_lifetimes.rs:4:1
--> $DIR/needless_lifetimes.rs:10:1
|
LL | fn distinct_lifetimes<'a, 'b>(_x: &'a u8, _y: &'b u8, _z: u8) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -7,148 +7,190 @@ LL | fn distinct_lifetimes<'a, 'b>(_x: &'a u8, _y: &'b u8, _z: u8) {}
= note: `-D clippy::needless-lifetimes` implied by `-D warnings`
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
--> $DIR/needless_lifetimes.rs:6:1
--> $DIR/needless_lifetimes.rs:12:1
|
LL | fn distinct_and_static<'a, 'b>(_x: &'a u8, _y: &'b u8, _z: &'static u8) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
--> $DIR/needless_lifetimes.rs:16:1
--> $DIR/needless_lifetimes.rs:22:1
|
LL | fn in_and_out<'a>(x: &'a u8, _y: u8) -> &'a u8 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
--> $DIR/needless_lifetimes.rs:50:1
--> $DIR/needless_lifetimes.rs:56:1
|
LL | fn deep_reference_3<'a>(x: &'a u8, _y: u8) -> Result<&'a u8, ()> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
--> $DIR/needless_lifetimes.rs:55:1
--> $DIR/needless_lifetimes.rs:61:1
|
LL | fn where_clause_without_lt<'a, T>(x: &'a u8, _y: u8) -> Result<&'a u8, ()>
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
--> $DIR/needless_lifetimes.rs:67:1
--> $DIR/needless_lifetimes.rs:73:1
|
LL | fn lifetime_param_2<'a, 'b>(_x: Ref<'a>, _y: &'b u8) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
--> $DIR/needless_lifetimes.rs:91:1
--> $DIR/needless_lifetimes.rs:97:1
|
LL | fn fn_bound_2<'a, F, I>(_m: Lt<'a, I>, _f: F) -> Lt<'a, I>
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
--> $DIR/needless_lifetimes.rs:121:5
--> $DIR/needless_lifetimes.rs:127:5
|
LL | fn self_and_out<'s>(&'s self) -> &'s u8 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
--> $DIR/needless_lifetimes.rs:130:5
--> $DIR/needless_lifetimes.rs:136:5
|
LL | fn distinct_self_and_in<'s, 't>(&'s self, _x: &'t u8) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
--> $DIR/needless_lifetimes.rs:149:1
--> $DIR/needless_lifetimes.rs:155:1
|
LL | fn struct_with_lt<'a>(_foo: Foo<'a>) -> &'a str {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
--> $DIR/needless_lifetimes.rs:179:1
--> $DIR/needless_lifetimes.rs:185:1
|
LL | fn trait_obj_elided2<'a>(_arg: &'a dyn Drop) -> &'a str {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
--> $DIR/needless_lifetimes.rs:185:1
--> $DIR/needless_lifetimes.rs:191:1
|
LL | fn alias_with_lt<'a>(_foo: FooAlias<'a>) -> &'a str {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
--> $DIR/needless_lifetimes.rs:204:1
--> $DIR/needless_lifetimes.rs:210:1
|
LL | fn named_input_elided_output<'a>(_arg: &'a str) -> &str {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
--> $DIR/needless_lifetimes.rs:212:1
--> $DIR/needless_lifetimes.rs:218:1
|
LL | fn trait_bound_ok<'a, T: WithLifetime<'static>>(_: &'a u8, _: T) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
--> $DIR/needless_lifetimes.rs:248:1
--> $DIR/needless_lifetimes.rs:254:1
|
LL | fn out_return_type_lts<'a>(e: &'a str) -> Cow<'a> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
--> $DIR/needless_lifetimes.rs:255:9
--> $DIR/needless_lifetimes.rs:261:9
|
LL | fn needless_lt<'a>(x: &'a u8) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
--> $DIR/needless_lifetimes.rs:259:9
--> $DIR/needless_lifetimes.rs:265:9
|
LL | fn needless_lt<'a>(_x: &'a u8) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
--> $DIR/needless_lifetimes.rs:272:9
--> $DIR/needless_lifetimes.rs:278:9
|
LL | fn baz<'a>(&'a self) -> impl Foo + 'a {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
--> $DIR/needless_lifetimes.rs:301:5
--> $DIR/needless_lifetimes.rs:307:5
|
LL | fn impl_trait_elidable_nested_named_lifetimes<'a>(i: &'a i32, f: impl for<'b> Fn(&'b i32) -> &'b i32) -> &'a i32 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
--> $DIR/needless_lifetimes.rs:304:5
--> $DIR/needless_lifetimes.rs:310:5
|
LL | fn impl_trait_elidable_nested_anonymous_lifetimes<'a>(i: &'a i32, f: impl Fn(&i32) -> &i32) -> &'a i32 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
--> $DIR/needless_lifetimes.rs:313:5
--> $DIR/needless_lifetimes.rs:319:5
|
LL | fn generics_elidable<'a, T: Fn(&i32) -> &i32>(i: &'a i32, f: T) -> &'a i32 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
--> $DIR/needless_lifetimes.rs:325:5
--> $DIR/needless_lifetimes.rs:331:5
|
LL | fn where_clause_elidadable<'a, T>(i: &'a i32, f: T) -> &'a i32
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
--> $DIR/needless_lifetimes.rs:340:5
--> $DIR/needless_lifetimes.rs:346:5
|
LL | fn pointer_fn_elidable<'a>(i: &'a i32, f: fn(&i32) -> &i32) -> &'a i32 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
--> $DIR/needless_lifetimes.rs:353:5
--> $DIR/needless_lifetimes.rs:359:5
|
LL | fn nested_fn_pointer_3<'a>(_: &'a i32) -> fn(fn(&i32) -> &i32) -> i32 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
--> $DIR/needless_lifetimes.rs:356:5
--> $DIR/needless_lifetimes.rs:362:5
|
LL | fn nested_fn_pointer_4<'a>(_: &'a i32) -> impl Fn(fn(&i32)) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 25 previous errors
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
--> $DIR/needless_lifetimes.rs:384:9
|
LL | fn implicit<'a>(&'a self) -> &'a () {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
--> $DIR/needless_lifetimes.rs:387:9
|
LL | fn implicit_mut<'a>(&'a mut self) -> &'a () {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
--> $DIR/needless_lifetimes.rs:398:9
|
LL | fn lifetime_elsewhere<'a>(self: Box<Self>, here: &'a ()) -> &'a () {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
--> $DIR/needless_lifetimes.rs:404:9
|
LL | fn implicit<'a>(&'a self) -> &'a ();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
--> $DIR/needless_lifetimes.rs:405:9
|
LL | fn implicit_provided<'a>(&'a self) -> &'a () {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
--> $DIR/needless_lifetimes.rs:414:9
|
LL | fn lifetime_elsewhere<'a>(self: Box<Self>, here: &'a ()) -> &'a ();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
--> $DIR/needless_lifetimes.rs:415:9
|
LL | fn lifetime_elsewhere_provided<'a>(self: Box<Self>, here: &'a ()) -> &'a () {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 32 previous errors

View file

@ -125,3 +125,16 @@ pub fn test2() {
let x = Some(3);
let _x = some_and_qmark_in_macro!(x?);
}
async fn async_option_bad(to: TO) -> Option<usize> {
let _ = Some(3);
to.magic
}
async fn async_deref_ref(s: Option<&String>) -> Option<&str> {
Some(s?)
}
async fn async_result_bad(s: TR) -> Result<usize, bool> {
s.magic
}

View file

@ -125,3 +125,16 @@ pub fn test2() {
let x = Some(3);
let _x = some_and_qmark_in_macro!(x?);
}
async fn async_option_bad(to: TO) -> Option<usize> {
let _ = Some(3);
Some(to.magic?)
}
async fn async_deref_ref(s: Option<&String>) -> Option<&str> {
Some(s?)
}
async fn async_result_bad(s: TR) -> Result<usize, bool> {
Ok(s.magic?)
}

View file

@ -77,5 +77,17 @@ LL | let _x = some_and_qmark_in_macro!(x?);
|
= note: this error originates in the macro `some_and_qmark_in_macro` (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to 12 previous errors
error: question mark operator is useless here
--> $DIR/needless_question_mark.rs:131:5
|
LL | Some(to.magic?)
| ^^^^^^^^^^^^^^^ help: try removing question mark and `Some()`: `to.magic`
error: question mark operator is useless here
--> $DIR/needless_question_mark.rs:139:5
|
LL | Ok(s.magic?)
| ^^^^^^^^^^^^ help: try removing question mark and `Ok()`: `s.magic`
error: aborting due to 14 previous errors

View file

@ -1,7 +1,7 @@
#![allow(unused_variables, clippy::blacklisted_name)]
#![warn(clippy::op_ref)]
use std::collections::HashSet;
use std::ops::BitAnd;
use std::ops::{BitAnd, Mul};
fn main() {
let tracked_fds: HashSet<i32> = HashSet::new();
@ -55,3 +55,40 @@ fn main() {
let y = Y(2);
let z = x & &y;
}
#[derive(Clone, Copy)]
struct A(i32);
#[derive(Clone, Copy)]
struct B(i32);
impl Mul<&A> for B {
type Output = i32;
fn mul(self, rhs: &A) -> Self::Output {
self.0 * rhs.0
}
}
impl Mul<A> for B {
type Output = i32;
fn mul(self, rhs: A) -> Self::Output {
// Should not lint because removing the reference would lead to unconditional recursion
self * &rhs
}
}
impl Mul<&A> for A {
type Output = i32;
fn mul(self, rhs: &A) -> Self::Output {
self.0 * rhs.0
}
}
impl Mul<A> for A {
type Output = i32;
fn mul(self, rhs: A) -> Self::Output {
let one = B(1);
let two = 2;
let three = 3;
let _ = one * &self;
let _ = two + &three;
// Removing the reference would lead to unconditional recursion
self * &rhs
}
}

View file

@ -18,5 +18,21 @@ LL | let z = x & &y;
| |
| help: use the right value directly: `y`
error: aborting due to 2 previous errors
error: taken reference of right operand
--> $DIR/op_ref.rs:89:17
|
LL | let _ = one * &self;
| ^^^^^^-----
| |
| help: use the right value directly: `self`
error: taken reference of right operand
--> $DIR/op_ref.rs:90:17
|
LL | let _ = two + &three;
| ^^^^^^------
| |
| help: use the right value directly: `three`
error: aborting due to 4 previous errors

View file

@ -9,7 +9,6 @@ fn do_vec(x: &Vec<i64>) {
}
fn do_vec_mut(x: &mut Vec<i64>) {
// no error here
//Nothing here
}
@ -18,7 +17,6 @@ fn do_str(x: &String) {
}
fn do_str_mut(x: &mut String) {
// no error here
//Nothing here either
}
@ -27,7 +25,6 @@ fn do_path(x: &PathBuf) {
}
fn do_path_mut(x: &mut PathBuf) {
// no error here
//Nothing here either
}
@ -52,7 +49,7 @@ fn cloned(x: &Vec<u8>) -> Vec<u8> {
let e = x.clone();
let f = e.clone(); // OK
let g = x;
let h = g.clone(); // Alas, we cannot reliably detect this without following data.
let h = g.clone();
let i = (e).clone();
x.clone()
}
@ -156,6 +153,30 @@ mod issue6509 {
}
}
fn mut_vec_slice_methods(v: &mut Vec<u32>) {
v.copy_within(1..5, 10);
}
fn mut_vec_vec_methods(v: &mut Vec<u32>) {
v.clear();
}
fn vec_contains(v: &Vec<u32>) -> bool {
[vec![], vec![0]].as_slice().contains(v)
}
fn fn_requires_vec(v: &Vec<u32>) -> bool {
vec_contains(v)
}
fn impl_fn_requires_vec(v: &Vec<u32>, f: impl Fn(&Vec<u32>)) {
f(v);
}
fn dyn_fn_requires_vec(v: &Vec<u32>, f: &dyn Fn(&Vec<u32>)) {
f(v);
}
// No error for types behind an alias (#7699)
type A = Vec<u8>;
fn aliased(a: &A) {}

View file

@ -1,4 +1,4 @@
error: writing `&Vec<_>` instead of `&[_]` involves one more reference and cannot be used with non-Vec-based slices
error: writing `&Vec` instead of `&[_]` involves a new object where a slice will do
--> $DIR/ptr_arg.rs:7:14
|
LL | fn do_vec(x: &Vec<i64>) {
@ -6,170 +6,154 @@ LL | fn do_vec(x: &Vec<i64>) {
|
= note: `-D clippy::ptr-arg` implied by `-D warnings`
error: writing `&mut Vec` instead of `&mut [_]` involves a new object where a slice will do
--> $DIR/ptr_arg.rs:11:18
|
LL | fn do_vec_mut(x: &mut Vec<i64>) {
| ^^^^^^^^^^^^^ help: change this to: `&mut [i64]`
error: writing `&String` instead of `&str` involves a new object where a slice will do
--> $DIR/ptr_arg.rs:16:14
--> $DIR/ptr_arg.rs:15:14
|
LL | fn do_str(x: &String) {
| ^^^^^^^ help: change this to: `&str`
error: writing `&mut String` instead of `&mut str` involves a new object where a slice will do
--> $DIR/ptr_arg.rs:19:18
|
LL | fn do_str_mut(x: &mut String) {
| ^^^^^^^^^^^ help: change this to: `&mut str`
error: writing `&PathBuf` instead of `&Path` involves a new object where a slice will do
--> $DIR/ptr_arg.rs:25:15
--> $DIR/ptr_arg.rs:23:15
|
LL | fn do_path(x: &PathBuf) {
| ^^^^^^^^ help: change this to: `&Path`
error: writing `&Vec<_>` instead of `&[_]` involves one more reference and cannot be used with non-Vec-based slices
--> $DIR/ptr_arg.rs:38:18
error: writing `&mut PathBuf` instead of `&mut Path` involves a new object where a slice will do
--> $DIR/ptr_arg.rs:27:19
|
LL | fn do_path_mut(x: &mut PathBuf) {
| ^^^^^^^^^^^^ help: change this to: `&mut Path`
error: writing `&Vec` instead of `&[_]` involves a new object where a slice will do
--> $DIR/ptr_arg.rs:35:18
|
LL | fn do_vec(x: &Vec<i64>);
| ^^^^^^^^^ help: change this to: `&[i64]`
error: writing `&Vec<_>` instead of `&[_]` involves one more reference and cannot be used with non-Vec-based slices
--> $DIR/ptr_arg.rs:51:14
error: writing `&Vec` instead of `&[_]` involves a new object where a slice will do
--> $DIR/ptr_arg.rs:48:14
|
LL | fn cloned(x: &Vec<u8>) -> Vec<u8> {
| ^^^^^^^^
|
help: change this to
|
LL | fn cloned(x: &[u8]) -> Vec<u8> {
| ~~~~~
help: change `x.clone()` to
|
LL | let e = x.to_owned();
| ~~~~~~~~~~~~
help: change `x.clone()` to
|
LL | x.to_owned()
|
LL ~ fn cloned(x: &[u8]) -> Vec<u8> {
LL ~ let e = x.to_owned();
LL | let f = e.clone(); // OK
LL | let g = x;
LL ~ let h = g.to_owned();
LL | let i = (e).clone();
...
error: writing `&String` instead of `&str` involves a new object where a slice will do
--> $DIR/ptr_arg.rs:60:18
--> $DIR/ptr_arg.rs:57:18
|
LL | fn str_cloned(x: &String) -> String {
| ^^^^^^^
|
help: change this to
|
LL | fn str_cloned(x: &str) -> String {
| ~~~~
help: change `x.clone()` to
|
LL | let a = x.to_string();
| ~~~~~~~~~~~~~
help: change `x.clone()` to
|
LL | let b = x.to_string();
| ~~~~~~~~~~~~~
help: change `x.clone()` to
|
LL | x.to_string()
LL ~ fn str_cloned(x: &str) -> String {
LL ~ let a = x.to_owned();
LL ~ let b = x.to_owned();
LL | let c = b.clone();
LL | let d = a.clone().clone().clone();
LL ~ x.to_owned()
|
error: writing `&PathBuf` instead of `&Path` involves a new object where a slice will do
--> $DIR/ptr_arg.rs:68:19
--> $DIR/ptr_arg.rs:65:19
|
LL | fn path_cloned(x: &PathBuf) -> PathBuf {
| ^^^^^^^^
|
help: change this to
|
LL | fn path_cloned(x: &Path) -> PathBuf {
| ~~~~~
help: change `x.clone()` to
|
LL | let a = x.to_path_buf();
| ~~~~~~~~~~~~~~~
help: change `x.clone()` to
|
LL | let b = x.to_path_buf();
| ~~~~~~~~~~~~~~~
help: change `x.clone()` to
|
LL | x.to_path_buf()
LL ~ fn path_cloned(x: &Path) -> PathBuf {
LL ~ let a = x.to_path_buf();
LL ~ let b = x.to_path_buf();
LL | let c = b.clone();
LL | let d = a.clone().clone().clone();
LL ~ x.to_path_buf()
|
error: writing `&String` instead of `&str` involves a new object where a slice will do
--> $DIR/ptr_arg.rs:76:44
--> $DIR/ptr_arg.rs:73:44
|
LL | fn false_positive_capacity(x: &Vec<u8>, y: &String) {
| ^^^^^^^
|
help: change this to
|
LL | fn false_positive_capacity(x: &Vec<u8>, y: &str) {
| ~~~~
help: change `y.clone()` to
LL ~ fn false_positive_capacity(x: &Vec<u8>, y: &str) {
LL | let a = x.capacity();
LL ~ let b = y.to_owned();
LL ~ let c = y;
|
LL | let b = y.to_string();
| ~~~~~~~~~~~~~
help: change `y.as_str()` to
|
LL | let c = y;
| ~
error: using a reference to `Cow` is not recommended
--> $DIR/ptr_arg.rs:90:25
--> $DIR/ptr_arg.rs:87:25
|
LL | fn test_cow_with_ref(c: &Cow<[i32]>) {}
| ^^^^^^^^^^^ help: change this to: `&[i32]`
error: writing `&Vec<_>` instead of `&[_]` involves one more reference and cannot be used with non-Vec-based slices
--> $DIR/ptr_arg.rs:143:21
error: writing `&Vec` instead of `&[_]` involves a new object where a slice will do
--> $DIR/ptr_arg.rs:140:21
|
LL | fn foo_vec(vec: &Vec<u8>) {
| ^^^^^^^^
|
help: change this to
|
LL | fn foo_vec(vec: &[u8]) {
| ~~~~~
help: change `vec.clone()` to
LL ~ fn foo_vec(vec: &[u8]) {
LL ~ let _ = vec.to_owned().pop();
LL ~ let _ = vec.to_owned().clone();
|
LL | let _ = vec.to_owned().pop();
| ~~~~~~~~~~~~~~
help: change `vec.clone()` to
|
LL | let _ = vec.to_owned().clone();
| ~~~~~~~~~~~~~~
error: writing `&PathBuf` instead of `&Path` involves a new object where a slice will do
--> $DIR/ptr_arg.rs:148:23
--> $DIR/ptr_arg.rs:145:23
|
LL | fn foo_path(path: &PathBuf) {
| ^^^^^^^^
|
help: change this to
|
LL | fn foo_path(path: &Path) {
| ~~~~~
help: change `path.clone()` to
LL ~ fn foo_path(path: &Path) {
LL ~ let _ = path.to_path_buf().pop();
LL ~ let _ = path.to_path_buf().clone();
|
LL | let _ = path.to_path_buf().pop();
| ~~~~~~~~~~~~~~~~~~
help: change `path.clone()` to
|
LL | let _ = path.to_path_buf().clone();
| ~~~~~~~~~~~~~~~~~~
error: writing `&PathBuf` instead of `&Path` involves a new object where a slice will do
--> $DIR/ptr_arg.rs:153:21
--> $DIR/ptr_arg.rs:150:21
|
LL | fn foo_str(str: &PathBuf) {
| ^^^^^^^^
|
help: change this to
|
LL | fn foo_str(str: &Path) {
| ~~~~~
help: change `str.clone()` to
LL ~ fn foo_str(str: &Path) {
LL ~ let _ = str.to_path_buf().pop();
LL ~ let _ = str.to_path_buf().clone();
|
LL | let _ = str.to_path_buf().pop();
| ~~~~~~~~~~~~~~~~~
help: change `str.clone()` to
error: writing `&mut Vec` instead of `&mut [_]` involves a new object where a slice will do
--> $DIR/ptr_arg.rs:156:29
|
LL | let _ = str.to_path_buf().clone();
| ~~~~~~~~~~~~~~~~~
LL | fn mut_vec_slice_methods(v: &mut Vec<u32>) {
| ^^^^^^^^^^^^^ help: change this to: `&mut [u32]`
error: aborting due to 12 previous errors
error: aborting due to 16 previous errors

View file

@ -81,7 +81,7 @@ const fn issue6067() {
None::<()>.is_none();
}
#[allow(clippy::deref_addrof, dead_code)]
#[allow(clippy::deref_addrof, dead_code, clippy::needless_borrow)]
fn issue7921() {
if (&None::<()>).is_none() {}
if (&None::<()>).is_none() {}

View file

@ -96,7 +96,7 @@ const fn issue6067() {
};
}
#[allow(clippy::deref_addrof, dead_code)]
#[allow(clippy::deref_addrof, dead_code, clippy::needless_borrow)]
fn issue7921() {
if let None = *(&None::<()>) {}
if let None = *&None::<()> {}

View file

@ -54,6 +54,7 @@
#![warn(clippy::match_result_ok)]
#![warn(clippy::disallowed_types)]
#![warn(clippy::disallowed_methods)]
#![warn(clippy::needless_borrow)]
// uplifted lints
#![warn(invalid_value)]
#![warn(array_into_iter)]

View file

@ -54,6 +54,7 @@
#![warn(clippy::if_let_some_result)]
#![warn(clippy::disallowed_type)]
#![warn(clippy::disallowed_method)]
#![warn(clippy::ref_in_deref)]
// uplifted lints
#![warn(clippy::invalid_ref)]
#![warn(clippy::into_iter_on_array)]

View file

@ -138,59 +138,65 @@ error: lint `clippy::disallowed_method` has been renamed to `clippy::disallowed_
LL | #![warn(clippy::disallowed_method)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::disallowed_methods`
error: lint `clippy::ref_in_deref` has been renamed to `clippy::needless_borrow`
--> $DIR/rename.rs:57:9
|
LL | #![warn(clippy::ref_in_deref)]
| ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::needless_borrow`
error: lint `clippy::invalid_ref` has been renamed to `invalid_value`
--> $DIR/rename.rs:58:9
--> $DIR/rename.rs:59:9
|
LL | #![warn(clippy::invalid_ref)]
| ^^^^^^^^^^^^^^^^^^^ help: use the new name: `invalid_value`
error: lint `clippy::into_iter_on_array` has been renamed to `array_into_iter`
--> $DIR/rename.rs:59:9
--> $DIR/rename.rs:60:9
|
LL | #![warn(clippy::into_iter_on_array)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `array_into_iter`
error: lint `clippy::unused_label` has been renamed to `unused_labels`
--> $DIR/rename.rs:60:9
--> $DIR/rename.rs:61:9
|
LL | #![warn(clippy::unused_label)]
| ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `unused_labels`
error: lint `clippy::drop_bounds` has been renamed to `drop_bounds`
--> $DIR/rename.rs:61:9
--> $DIR/rename.rs:62:9
|
LL | #![warn(clippy::drop_bounds)]
| ^^^^^^^^^^^^^^^^^^^ help: use the new name: `drop_bounds`
error: lint `clippy::temporary_cstring_as_ptr` has been renamed to `temporary_cstring_as_ptr`
--> $DIR/rename.rs:62:9
--> $DIR/rename.rs:63:9
|
LL | #![warn(clippy::temporary_cstring_as_ptr)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `temporary_cstring_as_ptr`
error: lint `clippy::panic_params` has been renamed to `non_fmt_panics`
--> $DIR/rename.rs:63:9
--> $DIR/rename.rs:64:9
|
LL | #![warn(clippy::panic_params)]
| ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `non_fmt_panics`
error: lint `clippy::unknown_clippy_lints` has been renamed to `unknown_lints`
--> $DIR/rename.rs:64:9
--> $DIR/rename.rs:65:9
|
LL | #![warn(clippy::unknown_clippy_lints)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `unknown_lints`
error: lint `clippy::invalid_atomic_ordering` has been renamed to `invalid_atomic_ordering`
--> $DIR/rename.rs:65:9
--> $DIR/rename.rs:66:9
|
LL | #![warn(clippy::invalid_atomic_ordering)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `invalid_atomic_ordering`
error: lint `clippy::mem_discriminant_non_enum` has been renamed to `enum_intrinsics_non_enums`
--> $DIR/rename.rs:66:9
--> $DIR/rename.rs:67:9
|
LL | #![warn(clippy::mem_discriminant_non_enum)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `enum_intrinsics_non_enums`
error: aborting due to 32 previous errors
error: aborting due to 33 previous errors

View file

@ -189,7 +189,7 @@ mod issue7392 {
let _ = [&(&1, 2), &(&3, 4), &(&5, 4)].iter().find(|&(&x, y)| x == *y).is_none();
}
fn test_string_1(s: &String) -> bool {
fn test_string_1(s: &str) -> bool {
s.is_empty()
}

View file

@ -251,14 +251,6 @@ error: called `is_none()` after searching an `Iterator` with `find`
LL | let _ = [&(&1, 2), &(&3, 4), &(&5, 4)].iter().find(|&(&x, y)| x == *y).is_none();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `![&(&1, 2), &(&3, 4), &(&5, 4)].iter().any(|(&x, y)| x == *y)`
error: writing `&String` instead of `&str` involves a new object where a slice will do
--> $DIR/search_is_some_fixable_none.rs:192:25
|
LL | fn test_string_1(s: &String) -> bool {
| ^^^^^^^ help: change this to: `&str`
|
= note: `-D clippy::ptr-arg` implied by `-D warnings`
error: called `is_none()` after searching an `Iterator` with `find`
--> $DIR/search_is_some_fixable_none.rs:208:17
|
@ -289,5 +281,5 @@ error: called `is_none()` after searching an `Iterator` with `find`
LL | let _ = v.iter().find(|fp| test_u32_2(*fp.field)).is_none();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `!v.iter().any(|fp| test_u32_2(*fp.field))`
error: aborting due to 44 previous errors
error: aborting due to 43 previous errors

View file

@ -188,7 +188,7 @@ mod issue7392 {
let _ = [&(&1, 2), &(&3, 4), &(&5, 4)].iter().find(|&(&x, y)| x == *y).is_some();
}
fn test_string_1(s: &String) -> bool {
fn test_string_1(s: &str) -> bool {
s.is_empty()
}

View file

@ -234,14 +234,6 @@ error: called `is_some()` after searching an `Iterator` with `find`
LL | let _ = [&(&1, 2), &(&3, 4), &(&5, 4)].iter().find(|&(&x, y)| x == *y).is_some();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|(&x, y)| x == *y)`
error: writing `&String` instead of `&str` involves a new object where a slice will do
--> $DIR/search_is_some_fixable_some.rs:191:25
|
LL | fn test_string_1(s: &String) -> bool {
| ^^^^^^^ help: change this to: `&str`
|
= note: `-D clippy::ptr-arg` implied by `-D warnings`
error: called `is_some()` after searching an `Iterator` with `find`
--> $DIR/search_is_some_fixable_some.rs:207:26
|
@ -272,5 +264,5 @@ error: called `is_some()` after searching an `Iterator` with `find`
LL | let _ = v.iter().find(|fp| test_u32_2(*fp.field)).is_some();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|fp| test_u32_2(*fp.field))`
error: aborting due to 44 previous errors
error: aborting due to 43 previous errors

View file

@ -53,7 +53,7 @@ fn resize_vector() {
vec1.resize(10, 0);
}
fn do_stuff(vec: &mut Vec<u8>) {}
fn do_stuff(vec: &mut [u8]) {}
fn extend_vector_with_manipulations_between() {
let len = 300;

View file

@ -1,5 +1,6 @@
#![deny(clippy::trait_duplication_in_bounds)]
use std::collections::BTreeMap;
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign};
fn bad_foo<T: Clone + Default, Z: Copy>(arg0: T, arg1: Z)
@ -73,4 +74,25 @@ impl U for Life {
fn f() {}
}
// should not warn
trait Iter: Iterator {
fn into_group_btreemap<K, V>(self) -> BTreeMap<K, Vec<V>>
where
Self: Iterator<Item = (K, V)> + Sized,
K: Ord + Eq,
{
unimplemented!();
}
}
struct Foo {}
trait FooIter: Iterator<Item = Foo> {
fn bar()
where
Self: Iterator<Item = Foo>,
{
}
}
fn main() {}

View file

@ -1,5 +1,5 @@
error: this trait bound is already specified in the where clause
--> $DIR/trait_duplication_in_bounds.rs:5:15
--> $DIR/trait_duplication_in_bounds.rs:6:15
|
LL | fn bad_foo<T: Clone + Default, Z: Copy>(arg0: T, arg1: Z)
| ^^^^^
@ -12,7 +12,7 @@ LL | #![deny(clippy::trait_duplication_in_bounds)]
= help: consider removing this trait bound
error: this trait bound is already specified in the where clause
--> $DIR/trait_duplication_in_bounds.rs:5:23
--> $DIR/trait_duplication_in_bounds.rs:6:23
|
LL | fn bad_foo<T: Clone + Default, Z: Copy>(arg0: T, arg1: Z)
| ^^^^^^^
@ -20,7 +20,7 @@ LL | fn bad_foo<T: Clone + Default, Z: Copy>(arg0: T, arg1: Z)
= help: consider removing this trait bound
error: this trait bound is already specified in trait declaration
--> $DIR/trait_duplication_in_bounds.rs:34:15
--> $DIR/trait_duplication_in_bounds.rs:35:15
|
LL | Self: Default;
| ^^^^^^^
@ -28,7 +28,7 @@ LL | Self: Default;
= help: consider removing this trait bound
error: this trait bound is already specified in trait declaration
--> $DIR/trait_duplication_in_bounds.rs:48:15
--> $DIR/trait_duplication_in_bounds.rs:49:15
|
LL | Self: Default + Clone;
| ^^^^^^^
@ -36,7 +36,7 @@ LL | Self: Default + Clone;
= help: consider removing this trait bound
error: this trait bound is already specified in trait declaration
--> $DIR/trait_duplication_in_bounds.rs:54:15
--> $DIR/trait_duplication_in_bounds.rs:55:15
|
LL | Self: Default + Clone;
| ^^^^^^^
@ -44,7 +44,7 @@ LL | Self: Default + Clone;
= help: consider removing this trait bound
error: this trait bound is already specified in trait declaration
--> $DIR/trait_duplication_in_bounds.rs:54:25
--> $DIR/trait_duplication_in_bounds.rs:55:25
|
LL | Self: Default + Clone;
| ^^^^^
@ -52,12 +52,20 @@ LL | Self: Default + Clone;
= help: consider removing this trait bound
error: this trait bound is already specified in trait declaration
--> $DIR/trait_duplication_in_bounds.rs:57:15
--> $DIR/trait_duplication_in_bounds.rs:58:15
|
LL | Self: Default;
| ^^^^^^^
|
= help: consider removing this trait bound
error: aborting due to 7 previous errors
error: this trait bound is already specified in trait declaration
--> $DIR/trait_duplication_in_bounds.rs:93:15
|
LL | Self: Iterator<Item = Foo>,
| ^^^^^^^^^^^^^^^^^^^^
|
= help: consider removing this trait bound
error: aborting due to 8 previous errors

View file

@ -1,6 +1,7 @@
#![warn(clippy::unnecessary_cast)]
#![allow(clippy::no_effect)]
#[rustfmt::skip]
fn main() {
// Test cast_unnecessary
1i32 as i32;
@ -8,6 +9,12 @@ fn main() {
false as bool;
&1i32 as &i32;
-1_i32 as i32;
- 1_i32 as i32;
-1f32 as f32;
1_i32 as i32;
1_f32 as f32;
// macro version
macro_rules! foo {
($a:ident, $b:ident) => {

View file

@ -1,5 +1,5 @@
error: casting integer literal to `i32` is unnecessary
--> $DIR/unnecessary_cast.rs:6:5
--> $DIR/unnecessary_cast.rs:7:5
|
LL | 1i32 as i32;
| ^^^^^^^^^^^ help: try: `1_i32`
@ -7,16 +7,46 @@ LL | 1i32 as i32;
= note: `-D clippy::unnecessary-cast` implied by `-D warnings`
error: casting float literal to `f32` is unnecessary
--> $DIR/unnecessary_cast.rs:7:5
--> $DIR/unnecessary_cast.rs:8:5
|
LL | 1f32 as f32;
| ^^^^^^^^^^^ help: try: `1_f32`
error: casting to the same type is unnecessary (`bool` -> `bool`)
--> $DIR/unnecessary_cast.rs:8:5
--> $DIR/unnecessary_cast.rs:9:5
|
LL | false as bool;
| ^^^^^^^^^^^^^ help: try: `false`
error: aborting due to 3 previous errors
error: casting integer literal to `i32` is unnecessary
--> $DIR/unnecessary_cast.rs:12:5
|
LL | -1_i32 as i32;
| ^^^^^^^^^^^^^ help: try: `-1_i32`
error: casting integer literal to `i32` is unnecessary
--> $DIR/unnecessary_cast.rs:13:5
|
LL | - 1_i32 as i32;
| ^^^^^^^^^^^^^^ help: try: `- 1_i32`
error: casting float literal to `f32` is unnecessary
--> $DIR/unnecessary_cast.rs:14:5
|
LL | -1f32 as f32;
| ^^^^^^^^^^^^ help: try: `-1_f32`
error: casting integer literal to `i32` is unnecessary
--> $DIR/unnecessary_cast.rs:15:5
|
LL | 1_i32 as i32;
| ^^^^^^^^^^^^ help: try: `1_i32`
error: casting float literal to `f32` is unnecessary
--> $DIR/unnecessary_cast.rs:16:5
|
LL | 1_f32 as f32;
| ^^^^^^^^^^^^ help: try: `1_f32`
error: aborting due to 8 previous errors

View file

@ -1,23 +0,0 @@
// run-rustfix
#![feature(stmt_expr_attributes)]
#![allow(unused_variables, dead_code)]
struct Outer {
inner: u32,
}
#[deny(clippy::ref_in_deref)]
fn main() {
let outer = Outer { inner: 0 };
let inner = outer.inner;
}
struct Apple;
impl Apple {
fn hello(&self) {}
}
struct Package(pub *const Apple);
fn foobar(package: *const Package) {
unsafe { &*(*package).0 }.hello();
}

View file

@ -1,23 +0,0 @@
// run-rustfix
#![feature(stmt_expr_attributes)]
#![allow(unused_variables, dead_code)]
struct Outer {
inner: u32,
}
#[deny(clippy::ref_in_deref)]
fn main() {
let outer = Outer { inner: 0 };
let inner = (&outer).inner;
}
struct Apple;
impl Apple {
fn hello(&self) {}
}
struct Package(pub *const Apple);
fn foobar(package: *const Package) {
unsafe { &*(&*package).0 }.hello();
}

View file

@ -1,22 +0,0 @@
error: creating a reference that is immediately dereferenced
--> $DIR/unnecessary_ref.rs:13:17
|
LL | let inner = (&outer).inner;
| ^^^^^^^^ help: try this: `outer`
|
note: the lint level is defined here
--> $DIR/unnecessary_ref.rs:10:8
|
LL | #[deny(clippy::ref_in_deref)]
| ^^^^^^^^^^^^^^^^^^^^
error: creating a reference that is immediately dereferenced
--> $DIR/unnecessary_ref.rs:22:16
|
LL | unsafe { &*(&*package).0 }.hello();
| ^^^^^^^^^^^ help: try this: `(*package)`
|
= note: `-D clippy::ref-in-deref` implied by `-D warnings`
error: aborting due to 2 previous errors

View file

@ -67,7 +67,7 @@ fn not_ok() {
foo_rslice(mrrrrrslice);
foo_rslice(mrrrrrslice);
}
#[allow(unused_parens, clippy::double_parens)]
#[allow(unused_parens, clippy::double_parens, clippy::needless_borrow)]
foo_rrrrmr((&&&&MoreRef));
generic_not_ok(mrslice);

View file

@ -67,7 +67,7 @@ fn not_ok() {
foo_rslice(mrrrrrslice.as_ref());
foo_rslice(mrrrrrslice);
}
#[allow(unused_parens, clippy::double_parens)]
#[allow(unused_parens, clippy::double_parens, clippy::needless_borrow)]
foo_rrrrmr((&&&&MoreRef).as_ref());
generic_not_ok(mrslice);

View file

@ -7,37 +7,37 @@ fn main() {
let mut v = Vec::new();
// these should be fine
write!(&mut v, "Hello");
writeln!(&mut v, "Hello");
write!(v, "Hello");
writeln!(v, "Hello");
let world = "world";
writeln!(&mut v, "Hello {}", world);
writeln!(&mut v, "Hello {world}", world = world);
writeln!(&mut v, "3 in hex is {:X}", 3);
writeln!(&mut v, "2 + 1 = {:.4}", 3);
writeln!(&mut v, "2 + 1 = {:5.4}", 3);
writeln!(&mut v, "Debug test {:?}", "hello, world");
writeln!(&mut v, "{0:8} {1:>8}", "hello", "world");
writeln!(&mut v, "{1:8} {0:>8}", "hello", "world");
writeln!(&mut v, "{foo:8} {bar:>8}", foo = "hello", bar = "world");
writeln!(&mut v, "{bar:8} {foo:>8}", foo = "hello", bar = "world");
writeln!(&mut v, "{number:>width$}", number = 1, width = 6);
writeln!(&mut v, "{number:>0width$}", number = 1, width = 6);
writeln!(&mut v, "{} of {:b} people know binary, the other half doesn't", 1, 2);
writeln!(&mut v, "10 / 4 is {}", 2.5);
writeln!(&mut v, "2 + 1 = {}", 3);
writeln!(v, "Hello {}", world);
writeln!(v, "Hello {world}", world = world);
writeln!(v, "3 in hex is {:X}", 3);
writeln!(v, "2 + 1 = {:.4}", 3);
writeln!(v, "2 + 1 = {:5.4}", 3);
writeln!(v, "Debug test {:?}", "hello, world");
writeln!(v, "{0:8} {1:>8}", "hello", "world");
writeln!(v, "{1:8} {0:>8}", "hello", "world");
writeln!(v, "{foo:8} {bar:>8}", foo = "hello", bar = "world");
writeln!(v, "{bar:8} {foo:>8}", foo = "hello", bar = "world");
writeln!(v, "{number:>width$}", number = 1, width = 6);
writeln!(v, "{number:>0width$}", number = 1, width = 6);
writeln!(v, "{} of {:b} people know binary, the other half doesn't", 1, 2);
writeln!(v, "10 / 4 is {}", 2.5);
writeln!(v, "2 + 1 = {}", 3);
// these should throw warnings
write!(&mut v, "Hello {}", "world");
writeln!(&mut v, "Hello {} {}", world, "world");
writeln!(&mut v, "Hello {}", "world");
write!(v, "Hello {}", "world");
writeln!(v, "Hello {} {}", world, "world");
writeln!(v, "Hello {}", "world");
// positional args don't change the fact
// that we're using a literal -- this should
// throw a warning
writeln!(&mut v, "{0} {1}", "hello", "world");
writeln!(&mut v, "{1} {0}", "hello", "world");
writeln!(v, "{0} {1}", "hello", "world");
writeln!(v, "{1} {0}", "hello", "world");
// named args shouldn't change anything either
writeln!(&mut v, "{foo} {bar}", foo = "hello", bar = "world");
writeln!(&mut v, "{bar} {foo}", foo = "hello", bar = "world");
writeln!(v, "{foo} {bar}", foo = "hello", bar = "world");
writeln!(v, "{bar} {foo}", foo = "hello", bar = "world");
}

View file

@ -1,134 +1,134 @@
error: literal with an empty format string
--> $DIR/write_literal.rs:30:32
--> $DIR/write_literal.rs:30:27
|
LL | write!(&mut v, "Hello {}", "world");
| ^^^^^^^
LL | write!(v, "Hello {}", "world");
| ^^^^^^^
|
= note: `-D clippy::write-literal` implied by `-D warnings`
help: try this
|
LL - write!(&mut v, "Hello {}", "world");
LL + write!(&mut v, "Hello world");
LL - write!(v, "Hello {}", "world");
LL + write!(v, "Hello world");
|
error: literal with an empty format string
--> $DIR/write_literal.rs:31:44
--> $DIR/write_literal.rs:31:39
|
LL | writeln!(&mut v, "Hello {} {}", world, "world");
| ^^^^^^^
LL | writeln!(v, "Hello {} {}", world, "world");
| ^^^^^^^
|
help: try this
|
LL - writeln!(&mut v, "Hello {} {}", world, "world");
LL + writeln!(&mut v, "Hello {} world", world);
LL - writeln!(v, "Hello {} {}", world, "world");
LL + writeln!(v, "Hello {} world", world);
|
error: literal with an empty format string
--> $DIR/write_literal.rs:32:34
--> $DIR/write_literal.rs:32:29
|
LL | writeln!(&mut v, "Hello {}", "world");
| ^^^^^^^
LL | writeln!(v, "Hello {}", "world");
| ^^^^^^^
|
help: try this
|
LL - writeln!(&mut v, "Hello {}", "world");
LL + writeln!(&mut v, "Hello world");
LL - writeln!(v, "Hello {}", "world");
LL + writeln!(v, "Hello world");
|
error: literal with an empty format string
--> $DIR/write_literal.rs:37:33
--> $DIR/write_literal.rs:37:28
|
LL | writeln!(&mut v, "{0} {1}", "hello", "world");
| ^^^^^^^
LL | writeln!(v, "{0} {1}", "hello", "world");
| ^^^^^^^
|
help: try this
|
LL - writeln!(&mut v, "{0} {1}", "hello", "world");
LL + writeln!(&mut v, "hello {1}", "world");
LL - writeln!(v, "{0} {1}", "hello", "world");
LL + writeln!(v, "hello {1}", "world");
|
error: literal with an empty format string
--> $DIR/write_literal.rs:37:42
--> $DIR/write_literal.rs:37:37
|
LL | writeln!(&mut v, "{0} {1}", "hello", "world");
| ^^^^^^^
LL | writeln!(v, "{0} {1}", "hello", "world");
| ^^^^^^^
|
help: try this
|
LL - writeln!(&mut v, "{0} {1}", "hello", "world");
LL + writeln!(&mut v, "{0} world", "hello");
LL - writeln!(v, "{0} {1}", "hello", "world");
LL + writeln!(v, "{0} world", "hello");
|
error: literal with an empty format string
--> $DIR/write_literal.rs:38:33
--> $DIR/write_literal.rs:38:28
|
LL | writeln!(&mut v, "{1} {0}", "hello", "world");
| ^^^^^^^
LL | writeln!(v, "{1} {0}", "hello", "world");
| ^^^^^^^
|
help: try this
|
LL - writeln!(&mut v, "{1} {0}", "hello", "world");
LL + writeln!(&mut v, "{1} hello", "world");
LL - writeln!(v, "{1} {0}", "hello", "world");
LL + writeln!(v, "{1} hello", "world");
|
error: literal with an empty format string
--> $DIR/write_literal.rs:38:42
--> $DIR/write_literal.rs:38:37
|
LL | writeln!(&mut v, "{1} {0}", "hello", "world");
| ^^^^^^^
LL | writeln!(v, "{1} {0}", "hello", "world");
| ^^^^^^^
|
help: try this
|
LL - writeln!(&mut v, "{1} {0}", "hello", "world");
LL + writeln!(&mut v, "world {0}", "hello");
LL - writeln!(v, "{1} {0}", "hello", "world");
LL + writeln!(v, "world {0}", "hello");
|
error: literal with an empty format string
--> $DIR/write_literal.rs:41:37
--> $DIR/write_literal.rs:41:32
|
LL | writeln!(&mut v, "{foo} {bar}", foo = "hello", bar = "world");
| ^^^^^^^^^^^^^
LL | writeln!(v, "{foo} {bar}", foo = "hello", bar = "world");
| ^^^^^^^^^^^^^
|
help: try this
|
LL - writeln!(&mut v, "{foo} {bar}", foo = "hello", bar = "world");
LL + writeln!(&mut v, "hello {bar}", bar = "world");
LL - writeln!(v, "{foo} {bar}", foo = "hello", bar = "world");
LL + writeln!(v, "hello {bar}", bar = "world");
|
error: literal with an empty format string
--> $DIR/write_literal.rs:41:52
--> $DIR/write_literal.rs:41:47
|
LL | writeln!(&mut v, "{foo} {bar}", foo = "hello", bar = "world");
| ^^^^^^^^^^^^^
LL | writeln!(v, "{foo} {bar}", foo = "hello", bar = "world");
| ^^^^^^^^^^^^^
|
help: try this
|
LL - writeln!(&mut v, "{foo} {bar}", foo = "hello", bar = "world");
LL + writeln!(&mut v, "{foo} world", foo = "hello");
LL - writeln!(v, "{foo} {bar}", foo = "hello", bar = "world");
LL + writeln!(v, "{foo} world", foo = "hello");
|
error: literal with an empty format string
--> $DIR/write_literal.rs:42:37
--> $DIR/write_literal.rs:42:32
|
LL | writeln!(&mut v, "{bar} {foo}", foo = "hello", bar = "world");
| ^^^^^^^^^^^^^
LL | writeln!(v, "{bar} {foo}", foo = "hello", bar = "world");
| ^^^^^^^^^^^^^
|
help: try this
|
LL - writeln!(&mut v, "{bar} {foo}", foo = "hello", bar = "world");
LL + writeln!(&mut v, "{bar} hello", bar = "world");
LL - writeln!(v, "{bar} {foo}", foo = "hello", bar = "world");
LL + writeln!(v, "{bar} hello", bar = "world");
|
error: literal with an empty format string
--> $DIR/write_literal.rs:42:52
--> $DIR/write_literal.rs:42:47
|
LL | writeln!(&mut v, "{bar} {foo}", foo = "hello", bar = "world");
| ^^^^^^^^^^^^^
LL | writeln!(v, "{bar} {foo}", foo = "hello", bar = "world");
| ^^^^^^^^^^^^^
|
help: try this
|
LL - writeln!(&mut v, "{bar} {foo}", foo = "hello", bar = "world");
LL + writeln!(&mut v, "world {foo}", foo = "hello");
LL - writeln!(v, "{bar} {foo}", foo = "hello", bar = "world");
LL + writeln!(v, "world {foo}", foo = "hello");
|
error: aborting due to 11 previous errors

View file

@ -6,20 +6,20 @@ use std::io::Write;
fn main() {
let mut v = Vec::new();
writeln!(&mut v, "{}", "{hello}");
writeln!(&mut v, r"{}", r"{hello}");
writeln!(&mut v, "{}", '\'');
writeln!(&mut v, "{}", '"');
writeln!(&mut v, r"{}", '"'); // don't lint
writeln!(&mut v, r"{}", '\'');
writeln!(v, "{}", "{hello}");
writeln!(v, r"{}", r"{hello}");
writeln!(v, "{}", '\'');
writeln!(v, "{}", '"');
writeln!(v, r"{}", '"'); // don't lint
writeln!(v, r"{}", '\'');
writeln!(
&mut v,
v,
"some {}",
"hello \
world!"
);
writeln!(
&mut v,
v,
"some {}\
{} \\ {}",
"1", "2", "3",

View file

@ -1,62 +1,62 @@
error: literal with an empty format string
--> $DIR/write_literal_2.rs:9:28
--> $DIR/write_literal_2.rs:9:23
|
LL | writeln!(&mut v, "{}", "{hello}");
| ^^^^^^^^^
LL | writeln!(v, "{}", "{hello}");
| ^^^^^^^^^
|
= note: `-D clippy::write-literal` implied by `-D warnings`
help: try this
|
LL - writeln!(&mut v, "{}", "{hello}");
LL + writeln!(&mut v, "{{hello}}");
LL - writeln!(v, "{}", "{hello}");
LL + writeln!(v, "{{hello}}");
|
error: literal with an empty format string
--> $DIR/write_literal_2.rs:10:29
--> $DIR/write_literal_2.rs:10:24
|
LL | writeln!(&mut v, r"{}", r"{hello}");
| ^^^^^^^^^^
LL | writeln!(v, r"{}", r"{hello}");
| ^^^^^^^^^^
|
help: try this
|
LL - writeln!(&mut v, r"{}", r"{hello}");
LL + writeln!(&mut v, r"{{hello}}");
LL - writeln!(v, r"{}", r"{hello}");
LL + writeln!(v, r"{{hello}}");
|
error: literal with an empty format string
--> $DIR/write_literal_2.rs:11:28
--> $DIR/write_literal_2.rs:11:23
|
LL | writeln!(&mut v, "{}", '/'');
| ^^^^
LL | writeln!(v, "{}", '/'');
| ^^^^
|
help: try this
|
LL - writeln!(&mut v, "{}", '/'');
LL + writeln!(&mut v, "'");
LL - writeln!(v, "{}", '/'');
LL + writeln!(v, "'");
|
error: literal with an empty format string
--> $DIR/write_literal_2.rs:12:28
--> $DIR/write_literal_2.rs:12:23
|
LL | writeln!(&mut v, "{}", '"');
| ^^^
LL | writeln!(v, "{}", '"');
| ^^^
|
help: try this
|
LL - writeln!(&mut v, "{}", '"');
LL + writeln!(&mut v, "/"");
LL - writeln!(v, "{}", '"');
LL + writeln!(v, "/"");
|
error: literal with an empty format string
--> $DIR/write_literal_2.rs:14:29
--> $DIR/write_literal_2.rs:14:24
|
LL | writeln!(&mut v, r"{}", '/'');
| ^^^^
LL | writeln!(v, r"{}", '/'');
| ^^^^
|
help: try this
|
LL - writeln!(&mut v, r"{}", '/'');
LL + writeln!(&mut v, r"'");
LL - writeln!(v, r"{}", '/'');
LL + writeln!(v, r"'");
|
error: literal with an empty format string

View file

@ -10,50 +10,50 @@ fn main() {
let mut v = Vec::new();
// These should fail
write!(&mut v, "Hello\n");
write!(&mut v, "Hello {}\n", "world");
write!(&mut v, "Hello {} {}\n", "world", "#2");
write!(&mut v, "{}\n", 1265);
write!(&mut v, "\n");
write!(v, "Hello\n");
write!(v, "Hello {}\n", "world");
write!(v, "Hello {} {}\n", "world", "#2");
write!(v, "{}\n", 1265);
write!(v, "\n");
// These should be fine
write!(&mut v, "");
write!(&mut v, "Hello");
writeln!(&mut v, "Hello");
writeln!(&mut v, "Hello\n");
writeln!(&mut v, "Hello {}\n", "world");
write!(&mut v, "Issue\n{}", 1265);
write!(&mut v, "{}", 1265);
write!(&mut v, "\n{}", 1275);
write!(&mut v, "\n\n");
write!(&mut v, "like eof\n\n");
write!(&mut v, "Hello {} {}\n\n", "world", "#2");
writeln!(&mut v, "\ndon't\nwarn\nfor\nmultiple\nnewlines\n"); // #3126
writeln!(&mut v, "\nbla\n\n"); // #3126
write!(v, "");
write!(v, "Hello");
writeln!(v, "Hello");
writeln!(v, "Hello\n");
writeln!(v, "Hello {}\n", "world");
write!(v, "Issue\n{}", 1265);
write!(v, "{}", 1265);
write!(v, "\n{}", 1275);
write!(v, "\n\n");
write!(v, "like eof\n\n");
write!(v, "Hello {} {}\n\n", "world", "#2");
writeln!(v, "\ndon't\nwarn\nfor\nmultiple\nnewlines\n"); // #3126
writeln!(v, "\nbla\n\n"); // #3126
// Escaping
write!(&mut v, "\\n"); // #3514
write!(&mut v, "\\\n"); // should fail
write!(&mut v, "\\\\n");
write!(v, "\\n"); // #3514
write!(v, "\\\n"); // should fail
write!(v, "\\\\n");
// Raw strings
write!(&mut v, r"\n"); // #3778
write!(v, r"\n"); // #3778
// Literal newlines should also fail
write!(
&mut v,
v,
"
"
);
write!(
&mut v,
v,
r"
"
);
// Don't warn on CRLF (#4208)
write!(&mut v, "\r\n");
write!(&mut v, "foo\r\n");
write!(&mut v, "\\r\n"); //~ ERROR
write!(&mut v, "foo\rbar\n");
write!(v, "\r\n");
write!(v, "foo\r\n");
write!(v, "\\r\n"); //~ ERROR
write!(v, "foo\rbar\n");
}

View file

@ -1,81 +1,81 @@
error: using `write!()` with a format string that ends in a single newline
--> $DIR/write_with_newline.rs:13:5
|
LL | write!(&mut v, "Hello/n");
| ^^^^^^^^^^^^^^^^^^^^^^^^^
LL | write!(v, "Hello/n");
| ^^^^^^^^^^^^^^^^^^^^
|
= note: `-D clippy::write-with-newline` implied by `-D warnings`
help: use `writeln!()` instead
|
LL - write!(&mut v, "Hello/n");
LL + writeln!(&mut v, "Hello");
LL - write!(v, "Hello/n");
LL + writeln!(v, "Hello");
|
error: using `write!()` with a format string that ends in a single newline
--> $DIR/write_with_newline.rs:14:5
|
LL | write!(&mut v, "Hello {}/n", "world");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | write!(v, "Hello {}/n", "world");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: use `writeln!()` instead
|
LL - write!(&mut v, "Hello {}/n", "world");
LL + writeln!(&mut v, "Hello {}", "world");
LL - write!(v, "Hello {}/n", "world");
LL + writeln!(v, "Hello {}", "world");
|
error: using `write!()` with a format string that ends in a single newline
--> $DIR/write_with_newline.rs:15:5
|
LL | write!(&mut v, "Hello {} {}/n", "world", "#2");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | write!(v, "Hello {} {}/n", "world", "#2");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: use `writeln!()` instead
|
LL - write!(&mut v, "Hello {} {}/n", "world", "#2");
LL + writeln!(&mut v, "Hello {} {}", "world", "#2");
LL - write!(v, "Hello {} {}/n", "world", "#2");
LL + writeln!(v, "Hello {} {}", "world", "#2");
|
error: using `write!()` with a format string that ends in a single newline
--> $DIR/write_with_newline.rs:16:5
|
LL | write!(&mut v, "{}/n", 1265);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | write!(v, "{}/n", 1265);
| ^^^^^^^^^^^^^^^^^^^^^^^
|
help: use `writeln!()` instead
|
LL - write!(&mut v, "{}/n", 1265);
LL + writeln!(&mut v, "{}", 1265);
LL - write!(v, "{}/n", 1265);
LL + writeln!(v, "{}", 1265);
|
error: using `write!()` with a format string that ends in a single newline
--> $DIR/write_with_newline.rs:17:5
|
LL | write!(&mut v, "/n");
| ^^^^^^^^^^^^^^^^^^^^
LL | write!(v, "/n");
| ^^^^^^^^^^^^^^^
|
help: use `writeln!()` instead
|
LL - write!(&mut v, "/n");
LL + writeln!(&mut v);
LL - write!(v, "/n");
LL + writeln!(v);
|
error: using `write!()` with a format string that ends in a single newline
--> $DIR/write_with_newline.rs:36:5
|
LL | write!(&mut v, "//n"); // should fail
| ^^^^^^^^^^^^^^^^^^^^^^
LL | write!(v, "//n"); // should fail
| ^^^^^^^^^^^^^^^^^
|
help: use `writeln!()` instead
|
LL - write!(&mut v, "//n"); // should fail
LL + writeln!(&mut v, "/"); // should fail
LL - write!(v, "//n"); // should fail
LL + writeln!(v, "/"); // should fail
|
error: using `write!()` with a format string that ends in a single newline
--> $DIR/write_with_newline.rs:43:5
|
LL | / write!(
LL | | &mut v,
LL | | v,
LL | | "
LL | | "
LL | | );
@ -84,7 +84,7 @@ LL | | );
help: use `writeln!()` instead
|
LL ~ writeln!(
LL | &mut v,
LL | v,
LL ~ ""
|
@ -92,7 +92,7 @@ error: using `write!()` with a format string that ends in a single newline
--> $DIR/write_with_newline.rs:48:5
|
LL | / write!(
LL | | &mut v,
LL | | v,
LL | | r"
LL | | "
LL | | );
@ -101,32 +101,32 @@ LL | | );
help: use `writeln!()` instead
|
LL ~ writeln!(
LL | &mut v,
LL | v,
LL ~ r""
|
error: using `write!()` with a format string that ends in a single newline
--> $DIR/write_with_newline.rs:57:5
|
LL | write!(&mut v, "/r/n"); //~ ERROR
| ^^^^^^^^^^^^^^^^^^^^^^^
LL | write!(v, "/r/n"); //~ ERROR
| ^^^^^^^^^^^^^^^^^^
|
help: use `writeln!()` instead
|
LL - write!(&mut v, "/r/n"); //~ ERROR
LL + writeln!(&mut v, "/r"); //~ ERROR
LL - write!(v, "/r/n"); //~ ERROR
LL + writeln!(v, "/r"); //~ ERROR
|
error: using `write!()` with a format string that ends in a single newline
--> $DIR/write_with_newline.rs:58:5
|
LL | write!(&mut v, "foo/rbar/n");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | write!(v, "foo/rbar/n");
| ^^^^^^^^^^^^^^^^^^^^^^^
|
help: use `writeln!()` instead
|
LL - write!(&mut v, "foo/rbar/n");
LL + writeln!(&mut v, "foo/rbar");
LL - write!(v, "foo/rbar/n");
LL + writeln!(v, "foo/rbar");
|
error: aborting due to 10 previous errors

View file

@ -8,13 +8,13 @@ fn main() {
let mut v = Vec::new();
// These should fail
writeln!(&mut v);
writeln!(v);
let mut suggestion = Vec::new();
writeln!(&mut suggestion);
writeln!(suggestion);
// These should be fine
writeln!(&mut v);
writeln!(&mut v, " ");
write!(&mut v, "");
writeln!(v);
writeln!(v, " ");
write!(v, "");
}

View file

@ -8,13 +8,13 @@ fn main() {
let mut v = Vec::new();
// These should fail
writeln!(&mut v, "");
writeln!(v, "");
let mut suggestion = Vec::new();
writeln!(&mut suggestion, "");
writeln!(suggestion, "");
// These should be fine
writeln!(&mut v);
writeln!(&mut v, " ");
write!(&mut v, "");
writeln!(v);
writeln!(v, " ");
write!(v, "");
}

View file

@ -1,16 +1,16 @@
error: using `writeln!(&mut v, "")`
error: using `writeln!(v, "")`
--> $DIR/writeln_empty_string.rs:11:5
|
LL | writeln!(&mut v, "");
| ^^^^^^^^^^^^^^^^^^^^ help: replace it with: `writeln!(&mut v)`
LL | writeln!(v, "");
| ^^^^^^^^^^^^^^^ help: replace it with: `writeln!(v)`
|
= note: `-D clippy::writeln-empty-string` implied by `-D warnings`
error: using `writeln!(&mut suggestion, "")`
error: using `writeln!(suggestion, "")`
--> $DIR/writeln_empty_string.rs:14:5
|
LL | writeln!(&mut suggestion, "");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `writeln!(&mut suggestion)`
LL | writeln!(suggestion, "");
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `writeln!(suggestion)`
error: aborting due to 2 previous errors