Skip to content

Commit

Permalink
Add reasons for or remove some //@no-rustfix annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexendoo committed Sep 23, 2024
1 parent 59bac6a commit 6e387c9
Show file tree
Hide file tree
Showing 14 changed files with 242 additions and 38 deletions.
2 changes: 1 addition & 1 deletion tests/ui/as_ptr_cast_mut.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
132 changes: 132 additions & 0 deletions tests/ui/borrow_box.fixed
Original file line number Diff line number Diff line change
@@ -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();
}
17 changes: 10 additions & 7 deletions tests/ui/borrow_box.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
clippy::disallowed_names,
clippy::needless_pass_by_ref_mut
)]
//@no-rustfix

use std::fmt::Display;

Expand Down Expand Up @@ -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>) {
Expand Down Expand Up @@ -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();
Expand Down
20 changes: 10 additions & 10 deletions tests/ui/borrow_box.stderr
Original file line number Diff line number Diff line change
@@ -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`
Expand All @@ -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)`
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/bytecount.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@no-rustfix
//@no-rustfix: suggests external crate

#![allow(clippy::needless_borrow, clippy::useless_vec)]

Expand Down
4 changes: 2 additions & 2 deletions tests/ui/deref_addrof_double_trigger.rs
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/float_cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions tests/ui/float_cmp_const.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down
16 changes: 8 additions & 8 deletions tests/ui/float_cmp_const.stderr
Original file line number Diff line number Diff line change
@@ -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`
Expand All @@ -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;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/float_equality_without_abs.rs
Original file line number Diff line number Diff line change
@@ -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

Expand Down
35 changes: 35 additions & 0 deletions tests/ui/unused_format_specs.1.fixed
Original file line number Diff line number Diff line change
@@ -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}");
}
Loading

0 comments on commit 6e387c9

Please sign in to comment.