Skip to content

Commit f01dfed

Browse files
committed
Auto merge of #13442 - Alexendoo:no-rustfix-reasons, r=Jarcho
Add reasons for or remove some `//@no-rustfix` annotations changelog: none
2 parents cbe294c + 6e387c9 commit f01dfed

14 files changed

+242
-38
lines changed

tests/ui/as_ptr_cast_mut.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![allow(unused)]
22
#![warn(clippy::as_ptr_cast_mut)]
33
#![allow(clippy::wrong_self_convention, clippy::unnecessary_cast)]
4-
//@no-rustfix
4+
//@no-rustfix: incorrect suggestion
55

66
struct MutPtrWrapper(Vec<u8>);
77
impl MutPtrWrapper {

tests/ui/borrow_box.fixed

+132
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
#![deny(clippy::borrowed_box)]
2+
#![allow(dead_code, unused_variables)]
3+
#![allow(
4+
clippy::uninlined_format_args,
5+
clippy::disallowed_names,
6+
clippy::needless_pass_by_ref_mut
7+
)]
8+
9+
use std::fmt::Display;
10+
11+
pub fn test1(foo: &mut Box<bool>) {
12+
// Although this function could be changed to "&mut bool",
13+
// avoiding the Box, mutable references to boxes are not
14+
// flagged by this lint.
15+
//
16+
// This omission is intentional: By passing a mutable Box,
17+
// the memory location of the pointed-to object could be
18+
// modified. By passing a mutable reference, the contents
19+
// could change, but not the location.
20+
println!("{:?}", foo)
21+
}
22+
23+
pub fn test2() {
24+
let foo: &bool;
25+
//~^ ERROR: you seem to be trying to use `&Box<T>`. Consider using just `&T`
26+
}
27+
28+
struct Test3<'a> {
29+
foo: &'a bool,
30+
//~^ ERROR: you seem to be trying to use `&Box<T>`. Consider using just `&T`
31+
}
32+
33+
trait Test4 {
34+
fn test4(a: &bool);
35+
//~^ ERROR: you seem to be trying to use `&Box<T>`. Consider using just `&T`
36+
}
37+
38+
use std::any::Any;
39+
40+
pub fn test5(foo: &mut Box<dyn Any>) {
41+
println!("{:?}", foo)
42+
}
43+
44+
pub fn test6() {
45+
let foo: &Box<dyn Any>;
46+
}
47+
48+
struct Test7<'a> {
49+
foo: &'a Box<dyn Any>,
50+
}
51+
52+
trait Test8 {
53+
fn test8(a: &Box<dyn Any>);
54+
}
55+
56+
impl<'a> Test8 for Test7<'a> {
57+
fn test8(a: &Box<dyn Any>) {
58+
unimplemented!();
59+
}
60+
}
61+
62+
pub fn test9(foo: &mut Box<dyn Any + Send + Sync>) {
63+
let _ = foo;
64+
}
65+
66+
pub fn test10() {
67+
let foo: &Box<dyn Any + Send + 'static>;
68+
}
69+
70+
struct Test11<'a> {
71+
foo: &'a Box<dyn Any + Send>,
72+
}
73+
74+
trait Test12 {
75+
fn test4(a: &Box<dyn Any + 'static>);
76+
}
77+
78+
impl<'a> Test12 for Test11<'a> {
79+
fn test4(a: &Box<dyn Any + 'static>) {
80+
unimplemented!();
81+
}
82+
}
83+
84+
pub fn test13(boxed_slice: &mut Box<[i32]>) {
85+
// Unconditionally replaces the box pointer.
86+
//
87+
// This cannot be accomplished if "&mut [i32]" is passed,
88+
// and provides a test case where passing a reference to
89+
// a Box is valid.
90+
let mut data = vec![12];
91+
*boxed_slice = data.into_boxed_slice();
92+
}
93+
94+
// The suggestion should include proper parentheses to avoid a syntax error.
95+
pub fn test14(_display: &dyn Display) {}
96+
//~^ ERROR: you seem to be trying to use `&Box<T>`. Consider using just `&T`
97+
pub fn test15(_display: &(dyn Display + Send)) {}
98+
//~^ ERROR: you seem to be trying to use `&Box<T>`. Consider using just `&T`
99+
pub fn test16<'a>(_display: &'a (dyn Display + 'a)) {}
100+
//~^ ERROR: you seem to be trying to use `&Box<T>`. Consider using just `&T`
101+
102+
pub fn test17(_display: &impl Display) {}
103+
//~^ ERROR: you seem to be trying to use `&Box<T>`. Consider using just `&T`
104+
pub fn test18(_display: &(impl Display + Send)) {}
105+
//~^ ERROR: you seem to be trying to use `&Box<T>`. Consider using just `&T`
106+
pub fn test19<'a>(_display: &'a (impl Display + 'a)) {}
107+
//~^ ERROR: you seem to be trying to use `&Box<T>`. Consider using just `&T`
108+
109+
// This exists only to check what happens when parentheses are already present.
110+
// Even though the current implementation doesn't put extra parentheses,
111+
// it's fine that unnecessary parentheses appear in the future for some reason.
112+
pub fn test20(_display: &(dyn Display + Send)) {}
113+
//~^ ERROR: you seem to be trying to use `&Box<T>`. Consider using just `&T`
114+
115+
#[allow(clippy::borrowed_box)]
116+
trait Trait {
117+
fn f(b: &Box<bool>);
118+
}
119+
120+
// Trait impls are not linted
121+
impl Trait for () {
122+
fn f(_: &Box<bool>) {}
123+
}
124+
125+
fn main() {
126+
test1(&mut Box::new(false));
127+
test2();
128+
test5(&mut (Box::new(false) as Box<dyn Any>));
129+
test6();
130+
test9(&mut (Box::new(false) as Box<dyn Any + Send + Sync>));
131+
test10();
132+
}

tests/ui/borrow_box.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
clippy::disallowed_names,
66
clippy::needless_pass_by_ref_mut
77
)]
8-
//@no-rustfix
98

109
use std::fmt::Display;
1110

@@ -36,12 +35,6 @@ trait Test4 {
3635
//~^ ERROR: you seem to be trying to use `&Box<T>`. Consider using just `&T`
3736
}
3837

39-
impl<'a> Test4 for Test3<'a> {
40-
fn test4(a: &Box<bool>) {
41-
unimplemented!();
42-
}
43-
}
44-
4538
use std::any::Any;
4639

4740
pub fn test5(foo: &mut Box<dyn Any>) {
@@ -119,6 +112,16 @@ pub fn test19<'a>(_display: &'a Box<impl Display + 'a>) {}
119112
pub fn test20(_display: &Box<(dyn Display + Send)>) {}
120113
//~^ ERROR: you seem to be trying to use `&Box<T>`. Consider using just `&T`
121114

115+
#[allow(clippy::borrowed_box)]
116+
trait Trait {
117+
fn f(b: &Box<bool>);
118+
}
119+
120+
// Trait impls are not linted
121+
impl Trait for () {
122+
fn f(_: &Box<bool>) {}
123+
}
124+
122125
fn main() {
123126
test1(&mut Box::new(false));
124127
test2();

tests/ui/borrow_box.stderr

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: you seem to be trying to use `&Box<T>`. Consider using just `&T`
2-
--> tests/ui/borrow_box.rs:25:14
2+
--> tests/ui/borrow_box.rs:24:14
33
|
44
LL | let foo: &Box<bool>;
55
| ^^^^^^^^^^ help: try: `&bool`
@@ -11,55 +11,55 @@ LL | #![deny(clippy::borrowed_box)]
1111
| ^^^^^^^^^^^^^^^^^^^^
1212

1313
error: you seem to be trying to use `&Box<T>`. Consider using just `&T`
14-
--> tests/ui/borrow_box.rs:30:10
14+
--> tests/ui/borrow_box.rs:29:10
1515
|
1616
LL | foo: &'a Box<bool>,
1717
| ^^^^^^^^^^^^^ help: try: `&'a bool`
1818

1919
error: you seem to be trying to use `&Box<T>`. Consider using just `&T`
20-
--> tests/ui/borrow_box.rs:35:17
20+
--> tests/ui/borrow_box.rs:34:17
2121
|
2222
LL | fn test4(a: &Box<bool>);
2323
| ^^^^^^^^^^ help: try: `&bool`
2424

2525
error: you seem to be trying to use `&Box<T>`. Consider using just `&T`
26-
--> tests/ui/borrow_box.rs:102:25
26+
--> tests/ui/borrow_box.rs:95:25
2727
|
2828
LL | pub fn test14(_display: &Box<dyn Display>) {}
2929
| ^^^^^^^^^^^^^^^^^ help: try: `&dyn Display`
3030

3131
error: you seem to be trying to use `&Box<T>`. Consider using just `&T`
32-
--> tests/ui/borrow_box.rs:104:25
32+
--> tests/ui/borrow_box.rs:97:25
3333
|
3434
LL | pub fn test15(_display: &Box<dyn Display + Send>) {}
3535
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&(dyn Display + Send)`
3636

3737
error: you seem to be trying to use `&Box<T>`. Consider using just `&T`
38-
--> tests/ui/borrow_box.rs:106:29
38+
--> tests/ui/borrow_box.rs:99:29
3939
|
4040
LL | pub fn test16<'a>(_display: &'a Box<dyn Display + 'a>) {}
4141
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&'a (dyn Display + 'a)`
4242

4343
error: you seem to be trying to use `&Box<T>`. Consider using just `&T`
44-
--> tests/ui/borrow_box.rs:109:25
44+
--> tests/ui/borrow_box.rs:102:25
4545
|
4646
LL | pub fn test17(_display: &Box<impl Display>) {}
4747
| ^^^^^^^^^^^^^^^^^^ help: try: `&impl Display`
4848

4949
error: you seem to be trying to use `&Box<T>`. Consider using just `&T`
50-
--> tests/ui/borrow_box.rs:111:25
50+
--> tests/ui/borrow_box.rs:104:25
5151
|
5252
LL | pub fn test18(_display: &Box<impl Display + Send>) {}
5353
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&(impl Display + Send)`
5454

5555
error: you seem to be trying to use `&Box<T>`. Consider using just `&T`
56-
--> tests/ui/borrow_box.rs:113:29
56+
--> tests/ui/borrow_box.rs:106:29
5757
|
5858
LL | pub fn test19<'a>(_display: &'a Box<impl Display + 'a>) {}
5959
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&'a (impl Display + 'a)`
6060

6161
error: you seem to be trying to use `&Box<T>`. Consider using just `&T`
62-
--> tests/ui/borrow_box.rs:119:25
62+
--> tests/ui/borrow_box.rs:112:25
6363
|
6464
LL | pub fn test20(_display: &Box<(dyn Display + Send)>) {}
6565
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&(dyn Display + Send)`

tests/ui/bytecount.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//@no-rustfix
1+
//@no-rustfix: suggests external crate
22

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

tests/ui/deref_addrof_double_trigger.rs

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

tests/ui/float_cmp.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
clippy::unnecessary_operation,
99
clippy::cast_lossless
1010
)]
11-
//@no-rustfix
11+
//@no-rustfix: suggestions have an error margin placeholder
1212
use std::ops::Add;
1313

1414
const ZERO: f32 = 0.0;

tests/ui/float_cmp_const.rs

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

tests/ui/float_cmp_const.stderr

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: strict comparison of `f32` or `f64` constant
2-
--> tests/ui/float_cmp_const.rs:16:5
2+
--> tests/ui/float_cmp_const.rs:15:5
33
|
44
LL | 1f32 == ONE;
55
| ^^^^^^^^^^^ help: consider comparing them within some margin of error: `(1f32 - ONE).abs() < error_margin`
@@ -8,43 +8,43 @@ LL | 1f32 == ONE;
88
= help: to override `-D warnings` add `#[allow(clippy::float_cmp_const)]`
99

1010
error: strict comparison of `f32` or `f64` constant
11-
--> tests/ui/float_cmp_const.rs:18:5
11+
--> tests/ui/float_cmp_const.rs:17:5
1212
|
1313
LL | TWO == ONE;
1414
| ^^^^^^^^^^ help: consider comparing them within some margin of error: `(TWO - ONE).abs() < error_margin`
1515

1616
error: strict comparison of `f32` or `f64` constant
17-
--> tests/ui/float_cmp_const.rs:20:5
17+
--> tests/ui/float_cmp_const.rs:19:5
1818
|
1919
LL | TWO != ONE;
2020
| ^^^^^^^^^^ help: consider comparing them within some margin of error: `(TWO - ONE).abs() > error_margin`
2121

2222
error: strict comparison of `f32` or `f64` constant
23-
--> tests/ui/float_cmp_const.rs:22:5
23+
--> tests/ui/float_cmp_const.rs:21:5
2424
|
2525
LL | ONE + ONE == TWO;
2626
| ^^^^^^^^^^^^^^^^ help: consider comparing them within some margin of error: `(ONE + ONE - TWO).abs() < error_margin`
2727

2828
error: strict comparison of `f32` or `f64` constant
29-
--> tests/ui/float_cmp_const.rs:25:5
29+
--> tests/ui/float_cmp_const.rs:24:5
3030
|
3131
LL | x as f32 == ONE;
3232
| ^^^^^^^^^^^^^^^ help: consider comparing them within some margin of error: `(x as f32 - ONE).abs() < error_margin`
3333

3434
error: strict comparison of `f32` or `f64` constant
35-
--> tests/ui/float_cmp_const.rs:29:5
35+
--> tests/ui/float_cmp_const.rs:28:5
3636
|
3737
LL | v == ONE;
3838
| ^^^^^^^^ help: consider comparing them within some margin of error: `(v - ONE).abs() < error_margin`
3939

4040
error: strict comparison of `f32` or `f64` constant
41-
--> tests/ui/float_cmp_const.rs:31:5
41+
--> tests/ui/float_cmp_const.rs:30:5
4242
|
4343
LL | v != ONE;
4444
| ^^^^^^^^ help: consider comparing them within some margin of error: `(v - ONE).abs() > error_margin`
4545

4646
error: strict comparison of `f32` or `f64` constant arrays
47-
--> tests/ui/float_cmp_const.rs:64:5
47+
--> tests/ui/float_cmp_const.rs:63:5
4848
|
4949
LL | NON_ZERO_ARRAY == NON_ZERO_ARRAY2;
5050
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

tests/ui/float_equality_without_abs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![warn(clippy::float_equality_without_abs)]
2-
//@no-rustfix
2+
//@no-rustfix: suggestions cause type ambiguity
33

44
// FIXME(f16_f128): add tests for these types when abs is available
55

tests/ui/unused_format_specs.1.fixed

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#![warn(clippy::unused_format_specs)]
2+
#![allow(unused)]
3+
4+
macro_rules! format_args_from_macro {
5+
() => {
6+
format_args!("from macro")
7+
};
8+
}
9+
10+
fn main() {
11+
// prints `.`, not ` .`
12+
println!("{:5}.", format!(""));
13+
//~^ ERROR: format specifiers have no effect on `format_args!()`
14+
//~| NOTE: `-D clippy::unused-format-specs` implied by `-D warnings`
15+
//prints `abcde`, not `abc`
16+
println!("{:.3}", format!("abcde"));
17+
//~^ ERROR: format specifiers have no effect on `format_args!()`
18+
19+
println!("{}.", format_args_from_macro!());
20+
//~^ ERROR: format specifiers have no effect on `format_args!()`
21+
22+
let args = format_args!("");
23+
println!("{args}");
24+
//~^ ERROR: format specifiers have no effect on `format_args!()`
25+
}
26+
27+
fn should_not_lint() {
28+
println!("{}", format_args!(""));
29+
// Technically the same as `{}`, but the `format_args` docs specifically mention that you can use
30+
// debug formatting so allow it
31+
println!("{:?}", format_args!(""));
32+
33+
let args = format_args!("");
34+
println!("{args}");
35+
}

0 commit comments

Comments
 (0)