diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ui/as_ptr_cast_mut.rs | 2 | ||||
| -rw-r--r-- | tests/ui/borrow_box.fixed | 132 | ||||
| -rw-r--r-- | tests/ui/borrow_box.rs | 17 | ||||
| -rw-r--r-- | tests/ui/borrow_box.stderr | 20 | ||||
| -rw-r--r-- | tests/ui/bytecount.rs | 2 | ||||
| -rw-r--r-- | tests/ui/comparison_to_empty.fixed | 8 | ||||
| -rw-r--r-- | tests/ui/comparison_to_empty.rs | 8 | ||||
| -rw-r--r-- | tests/ui/comparison_to_empty.stderr | 26 | ||||
| -rw-r--r-- | tests/ui/deref_addrof_double_trigger.rs | 4 | ||||
| -rw-r--r-- | tests/ui/float_cmp.rs | 2 | ||||
| -rw-r--r-- | tests/ui/float_cmp_const.rs | 3 | ||||
| -rw-r--r-- | tests/ui/float_cmp_const.stderr | 16 | ||||
| -rw-r--r-- | tests/ui/float_equality_without_abs.rs | 2 | ||||
| -rw-r--r-- | tests/ui/invalid_null_ptr_usage.fixed | 7 | ||||
| -rw-r--r-- | tests/ui/invalid_null_ptr_usage.rs | 5 | ||||
| -rw-r--r-- | tests/ui/invalid_null_ptr_usage.stderr | 36 | ||||
| -rw-r--r-- | tests/ui/unused_format_specs.1.fixed | 35 | ||||
| -rw-r--r-- | tests/ui/unused_format_specs.2.fixed | 35 | ||||
| -rw-r--r-- | tests/ui/unused_format_specs.rs (renamed from tests/ui/unused_format_specs_unfixable.rs) | 2 | ||||
| -rw-r--r-- | tests/ui/unused_format_specs.stderr (renamed from tests/ui/unused_format_specs_unfixable.stderr) | 8 |
20 files changed, 295 insertions, 75 deletions
diff --git a/tests/ui/as_ptr_cast_mut.rs b/tests/ui/as_ptr_cast_mut.rs index 297a53b1bbf..9e862320f4e 100644 --- a/tests/ui/as_ptr_cast_mut.rs +++ b/tests/ui/as_ptr_cast_mut.rs @@ -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 { diff --git a/tests/ui/borrow_box.fixed b/tests/ui/borrow_box.fixed new file mode 100644 index 00000000000..5984cc4e930 --- /dev/null +++ b/tests/ui/borrow_box.fixed @@ -0,0 +1,132 @@ +#![deny(clippy::borrowed_box)] +#![allow(dead_code, unused_variables)] +#![allow( + clippy::uninlined_format_args, + clippy::disallowed_names, + clippy::needless_pass_by_ref_mut +)] + +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(); +} diff --git a/tests/ui/borrow_box.rs b/tests/ui/borrow_box.rs index e9994aac845..7f15fc83a1d 100644 --- a/tests/ui/borrow_box.rs +++ b/tests/ui/borrow_box.rs @@ -5,7 +5,6 @@ clippy::disallowed_names, clippy::needless_pass_by_ref_mut )] -//@no-rustfix use std::fmt::Display; @@ -36,12 +35,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 +112,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(); diff --git a/tests/ui/borrow_box.stderr b/tests/ui/borrow_box.stderr index 34e8f11dfd7..ed4308161bb 100644 --- a/tests/ui/borrow_box.stderr +++ b/tests/ui/borrow_box.stderr @@ -1,5 +1,5 @@ error: you seem to be trying to use `&Box<T>`. Consider using just `&T` - --> tests/ui/borrow_box.rs:25:14 + --> tests/ui/borrow_box.rs:24:14 | LL | let foo: &Box<bool>; | ^^^^^^^^^^ help: try: `&bool` @@ -11,55 +11,55 @@ LL | #![deny(clippy::borrowed_box)] | ^^^^^^^^^^^^^^^^^^^^ error: you seem to be trying to use `&Box<T>`. Consider using just `&T` - --> tests/ui/borrow_box.rs:30:10 + --> tests/ui/borrow_box.rs:29:10 | LL | foo: &'a Box<bool>, | ^^^^^^^^^^^^^ help: try: `&'a bool` error: you seem to be trying to use `&Box<T>`. Consider using just `&T` - --> tests/ui/borrow_box.rs:35:17 + --> tests/ui/borrow_box.rs:34:17 | 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:95: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:97: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:99: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:102: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:104: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:106: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:112:25 | LL | pub fn test20(_display: &Box<(dyn Display + Send)>) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&(dyn Display + Send)` diff --git a/tests/ui/bytecount.rs b/tests/ui/bytecount.rs index 3794fc5d441..f3b02fda8a8 100644 --- a/tests/ui/bytecount.rs +++ b/tests/ui/bytecount.rs @@ -1,4 +1,4 @@ -//@no-rustfix +//@no-rustfix: suggests external crate #![allow(clippy::needless_borrow, clippy::useless_vec)] diff --git a/tests/ui/comparison_to_empty.fixed b/tests/ui/comparison_to_empty.fixed index e102b13a761..a2a3dd9086d 100644 --- a/tests/ui/comparison_to_empty.fixed +++ b/tests/ui/comparison_to_empty.fixed @@ -33,4 +33,12 @@ fn main() { if let [0] = &*s && s == [0] {} + + // Also lint the `PartialEq` methods + let s = String::new(); + let _ = s.is_empty(); + let _ = !s.is_empty(); + let v = vec![0]; + let _ = v.is_empty(); + let _ = !v.is_empty(); } diff --git a/tests/ui/comparison_to_empty.rs b/tests/ui/comparison_to_empty.rs index 69a6c967d38..7c5689a4bbe 100644 --- a/tests/ui/comparison_to_empty.rs +++ b/tests/ui/comparison_to_empty.rs @@ -33,4 +33,12 @@ fn main() { if let [0] = &*s && s == [0] {} + + // Also lint the `PartialEq` methods + let s = String::new(); + let _ = s.eq(""); + let _ = s.ne(""); + let v = vec![0]; + let _ = v.eq(&[]); + let _ = v.ne(&[]); } diff --git a/tests/ui/comparison_to_empty.stderr b/tests/ui/comparison_to_empty.stderr index 6b027459ed3..2ee0efc7dbb 100644 --- a/tests/ui/comparison_to_empty.stderr +++ b/tests/ui/comparison_to_empty.stderr @@ -55,5 +55,29 @@ error: comparison to empty slice LL | && s == [] | ^^^^^^^ help: using `is_empty` is clearer and more explicit: `s.is_empty()` -error: aborting due to 9 previous errors +error: comparison to empty slice + --> tests/ui/comparison_to_empty.rs:39:13 + | +LL | let _ = s.eq(""); + | ^^^^^^^^ help: using `is_empty` is clearer and more explicit: `s.is_empty()` + +error: comparison to empty slice + --> tests/ui/comparison_to_empty.rs:40:13 + | +LL | let _ = s.ne(""); + | ^^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!s.is_empty()` + +error: comparison to empty slice + --> tests/ui/comparison_to_empty.rs:42:13 + | +LL | let _ = v.eq(&[]); + | ^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `v.is_empty()` + +error: comparison to empty slice + --> tests/ui/comparison_to_empty.rs:43:13 + | +LL | let _ = v.ne(&[]); + | ^^^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!v.is_empty()` + +error: aborting due to 13 previous errors diff --git a/tests/ui/deref_addrof_double_trigger.rs b/tests/ui/deref_addrof_double_trigger.rs index 32582a3a8bf..6f997875777 100644 --- a/tests/ui/deref_addrof_double_trigger.rs +++ b/tests/ui/deref_addrof_double_trigger.rs @@ -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() { diff --git a/tests/ui/float_cmp.rs b/tests/ui/float_cmp.rs index 78dd2c6c01c..a1dfd1954fc 100644 --- a/tests/ui/float_cmp.rs +++ b/tests/ui/float_cmp.rs @@ -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; diff --git a/tests/ui/float_cmp_const.rs b/tests/ui/float_cmp_const.rs index 08180556437..ba760a18f28 100644 --- a/tests/ui/float_cmp_const.rs +++ b/tests/ui/float_cmp_const.rs @@ -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)] diff --git a/tests/ui/float_cmp_const.stderr b/tests/ui/float_cmp_const.stderr index 4f88746e958..e0cd6faf4b3 100644 --- a/tests/ui/float_cmp_const.stderr +++ b/tests/ui/float_cmp_const.stderr @@ -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; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/float_equality_without_abs.rs b/tests/ui/float_equality_without_abs.rs index 2b67c8bec10..500b3035390 100644 --- a/tests/ui/float_equality_without_abs.rs +++ b/tests/ui/float_equality_without_abs.rs @@ -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 diff --git a/tests/ui/invalid_null_ptr_usage.fixed b/tests/ui/invalid_null_ptr_usage.fixed index eeddc2349a1..092e875a255 100644 --- a/tests/ui/invalid_null_ptr_usage.fixed +++ b/tests/ui/invalid_null_ptr_usage.fixed @@ -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()); diff --git a/tests/ui/invalid_null_ptr_usage.rs b/tests/ui/invalid_null_ptr_usage.rs index 8569b774084..480b6642a3e 100644 --- a/tests/ui/invalid_null_ptr_usage.rs +++ b/tests/ui/invalid_null_ptr_usage.rs @@ -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); diff --git a/tests/ui/invalid_null_ptr_usage.stderr b/tests/ui/invalid_null_ptr_usage.stderr index 54d79ba1aeb..a0be2c0ad75 100644 --- a/tests/ui/invalid_null_ptr_usage.stderr +++ b/tests/ui/invalid_null_ptr_usage.stderr @@ -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 diff --git a/tests/ui/unused_format_specs.1.fixed b/tests/ui/unused_format_specs.1.fixed new file mode 100644 index 00000000000..b7d1cce2870 --- /dev/null +++ b/tests/ui/unused_format_specs.1.fixed @@ -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}"); +} diff --git a/tests/ui/unused_format_specs.2.fixed b/tests/ui/unused_format_specs.2.fixed new file mode 100644 index 00000000000..94bb6b7036b --- /dev/null +++ b/tests/ui/unused_format_specs.2.fixed @@ -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}"); +} diff --git a/tests/ui/unused_format_specs_unfixable.rs b/tests/ui/unused_format_specs.rs index be991935366..2c85e371149 100644 --- a/tests/ui/unused_format_specs_unfixable.rs +++ b/tests/ui/unused_format_specs.rs @@ -1,6 +1,6 @@ #![warn(clippy::unused_format_specs)] #![allow(unused)] -//@no-rustfix + macro_rules! format_args_from_macro { () => { format_args!("from macro") diff --git a/tests/ui/unused_format_specs_unfixable.stderr b/tests/ui/unused_format_specs.stderr index d3b334c6092..2b5c81c63d6 100644 --- a/tests/ui/unused_format_specs_unfixable.stderr +++ b/tests/ui/unused_format_specs.stderr @@ -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}"); | ^^^^^^^^ |
