about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--tests/ui/as_ptr_cast_mut.rs2
-rw-r--r--tests/ui/borrow_box.fixed132
-rw-r--r--tests/ui/borrow_box.rs17
-rw-r--r--tests/ui/borrow_box.stderr20
-rw-r--r--tests/ui/bytecount.rs2
-rw-r--r--tests/ui/deref_addrof_double_trigger.rs4
-rw-r--r--tests/ui/float_cmp.rs2
-rw-r--r--tests/ui/float_cmp_const.rs3
-rw-r--r--tests/ui/float_cmp_const.stderr16
-rw-r--r--tests/ui/float_equality_without_abs.rs2
-rw-r--r--tests/ui/unused_format_specs.1.fixed35
-rw-r--r--tests/ui/unused_format_specs.2.fixed35
-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
14 files changed, 242 insertions, 38 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/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/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}");
    |               ^^^^^^^^