Auto merge of #13442 - Alexendoo:no-rustfix-reasons, r=Jarcho

Add reasons for or remove some `//@no-rustfix` annotations

changelog: none
This commit is contained in:
bors 2024-09-25 02:00:26 +00:00
commit f01dfed99f
14 changed files with 242 additions and 38 deletions

View File

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

132
tests/ui/borrow_box.fixed Normal file
View File

@ -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();
}

View File

@ -5,7 +5,6 @@
clippy::disallowed_names, clippy::disallowed_names,
clippy::needless_pass_by_ref_mut clippy::needless_pass_by_ref_mut
)] )]
//@no-rustfix
use std::fmt::Display; use std::fmt::Display;
@ -36,12 +35,6 @@ trait Test4 {
//~^ ERROR: you seem to be trying to use `&Box<T>`. Consider using just `&T` //~^ 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; use std::any::Any;
pub fn test5(foo: &mut Box<dyn 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)>) {} pub fn test20(_display: &Box<(dyn Display + Send)>) {}
//~^ ERROR: you seem to be trying to use `&Box<T>`. Consider using just `&T` //~^ 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() { fn main() {
test1(&mut Box::new(false)); test1(&mut Box::new(false));
test2(); test2();

View File

@ -1,5 +1,5 @@
error: you seem to be trying to use `&Box<T>`. Consider using just `&T` 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>; LL | let foo: &Box<bool>;
| ^^^^^^^^^^ help: try: `&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` 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>, LL | foo: &'a Box<bool>,
| ^^^^^^^^^^^^^ help: try: `&'a bool` | ^^^^^^^^^^^^^ help: try: `&'a bool`
error: you seem to be trying to use `&Box<T>`. Consider using just `&T` 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>); LL | fn test4(a: &Box<bool>);
| ^^^^^^^^^^ help: try: `&bool` | ^^^^^^^^^^ help: try: `&bool`
error: you seem to be trying to use `&Box<T>`. Consider using just `&T` 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>) {} LL | pub fn test14(_display: &Box<dyn Display>) {}
| ^^^^^^^^^^^^^^^^^ help: try: `&dyn Display` | ^^^^^^^^^^^^^^^^^ help: try: `&dyn Display`
error: you seem to be trying to use `&Box<T>`. Consider using just `&T` 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>) {} LL | pub fn test15(_display: &Box<dyn Display + Send>) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&(dyn Display + Send)` | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&(dyn Display + Send)`
error: you seem to be trying to use `&Box<T>`. Consider using just `&T` 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>) {} LL | pub fn test16<'a>(_display: &'a Box<dyn Display + 'a>) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&'a (dyn Display + 'a)` | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&'a (dyn Display + 'a)`
error: you seem to be trying to use `&Box<T>`. Consider using just `&T` 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>) {} LL | pub fn test17(_display: &Box<impl Display>) {}
| ^^^^^^^^^^^^^^^^^^ help: try: `&impl Display` | ^^^^^^^^^^^^^^^^^^ help: try: `&impl Display`
error: you seem to be trying to use `&Box<T>`. Consider using just `&T` 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>) {} LL | pub fn test18(_display: &Box<impl Display + Send>) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&(impl Display + Send)` | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&(impl Display + Send)`
error: you seem to be trying to use `&Box<T>`. Consider using just `&T` 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>) {} LL | pub fn test19<'a>(_display: &'a Box<impl Display + 'a>) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&'a (impl Display + 'a)` | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&'a (impl Display + 'a)`
error: you seem to be trying to use `&Box<T>`. Consider using just `&T` 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)>) {} LL | pub fn test20(_display: &Box<(dyn Display + Send)>) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&(dyn Display + Send)` | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&(dyn Display + Send)`

View File

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

View File

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

View File

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

View File

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

View File

@ -1,5 +1,5 @@
error: strict comparison of `f32` or `f64` constant 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; LL | 1f32 == ONE;
| ^^^^^^^^^^^ help: consider comparing them within some margin of error: `(1f32 - ONE).abs() < error_margin` | ^^^^^^^^^^^ 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)]` = help: to override `-D warnings` add `#[allow(clippy::float_cmp_const)]`
error: strict comparison of `f32` or `f64` constant 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; LL | TWO == ONE;
| ^^^^^^^^^^ help: consider comparing them within some margin of error: `(TWO - ONE).abs() < error_margin` | ^^^^^^^^^^ help: consider comparing them within some margin of error: `(TWO - ONE).abs() < error_margin`
error: strict comparison of `f32` or `f64` constant 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; LL | TWO != ONE;
| ^^^^^^^^^^ help: consider comparing them within some margin of error: `(TWO - ONE).abs() > error_margin` | ^^^^^^^^^^ help: consider comparing them within some margin of error: `(TWO - ONE).abs() > error_margin`
error: strict comparison of `f32` or `f64` constant 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; LL | ONE + ONE == TWO;
| ^^^^^^^^^^^^^^^^ help: consider comparing them within some margin of error: `(ONE + ONE - TWO).abs() < error_margin` | ^^^^^^^^^^^^^^^^ help: consider comparing them within some margin of error: `(ONE + ONE - TWO).abs() < error_margin`
error: strict comparison of `f32` or `f64` constant 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; LL | x as f32 == ONE;
| ^^^^^^^^^^^^^^^ help: consider comparing them within some margin of error: `(x as f32 - ONE).abs() < error_margin` | ^^^^^^^^^^^^^^^ help: consider comparing them within some margin of error: `(x as f32 - ONE).abs() < error_margin`
error: strict comparison of `f32` or `f64` constant 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; LL | v == ONE;
| ^^^^^^^^ help: consider comparing them within some margin of error: `(v - ONE).abs() < error_margin` | ^^^^^^^^ help: consider comparing them within some margin of error: `(v - ONE).abs() < error_margin`
error: strict comparison of `f32` or `f64` constant 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; LL | v != ONE;
| ^^^^^^^^ help: consider comparing them within some margin of error: `(v - ONE).abs() > error_margin` | ^^^^^^^^ help: consider comparing them within some margin of error: `(v - ONE).abs() > error_margin`
error: strict comparison of `f32` or `f64` constant arrays 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; LL | NON_ZERO_ARRAY == NON_ZERO_ARRAY2;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -1,5 +1,5 @@
#![warn(clippy::float_equality_without_abs)] #![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 // FIXME(f16_f128): add tests for these types when abs is available

View File

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

View File

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

View File

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

View File

@ -1,5 +1,5 @@
error: format specifiers have no effect on `format_args!()` 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!("")); LL | println!("{:5}.", format_args!(""));
| ^^^^ | ^^^^
@ -17,7 +17,7 @@ LL + println!("{}.", format_args!(""));
| |
error: format specifiers have no effect on `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")); LL | println!("{:.3}", format_args!("abcde"));
| ^^^^^ | ^^^^^
@ -33,7 +33,7 @@ LL + println!("{}", format_args!("abcde"));
| |
error: format specifiers have no effect on `format_args!()` 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!()); 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!()` 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}"); LL | println!("{args:5}");
| ^^^^^^^^ | ^^^^^^^^