Skip to content

Commit c23c274

Browse files
committed
redundant_allocation: use span_lint_and_note
1 parent 5e10fdd commit c23c274

5 files changed

+44
-44
lines changed

clippy_lints/src/types/redundant_allocation.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use clippy_utils::diagnostics::{span_lint_and_help, span_lint_and_sugg};
1+
use clippy_utils::diagnostics::{span_lint_and_note, span_lint_and_sugg};
22
use clippy_utils::source::snippet_with_applicability;
33
use clippy_utils::{get_qpath_generic_tys, is_ty_param_diagnostic_item, is_ty_param_lang_item};
44
use rustc_errors::Applicability;
@@ -67,7 +67,7 @@ pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, qpath: &QPath<'_
6767
applicability,
6868
);
6969
} else {
70-
span_lint_and_help(
70+
span_lint_and_note(
7171
cx,
7272
REDUNDANT_ALLOCATION,
7373
hir_ty.span,

tests/ui/redundant_allocation.stderr

+30-30
Original file line numberDiff line numberDiff line change
@@ -1,123 +1,123 @@
1-
error: you seem to be trying to use `Box<Rc<T>>`. Consider using just `Box<T>` of `Rc<T>`
1+
error: you seem to be trying to use `Box<Rc<T>>`. Consider using just `Box<T>` or `Rc<T>`
22
--> $DIR/redundant_allocation.rs:25:30
33
|
44
LL | pub fn box_test6<T>(foo: Box<Rc<T>>) {}
55
| ^^^^^^^^^^
66
|
77
= note: `-D clippy::redundant-allocation` implied by `-D warnings`
8-
= help: `Rc<T>` is already on the heap, `Box<Rc<T>>` makes an extra allocation
8+
= note: `Rc<T>` is already on the heap, `Box<Rc<T>>` makes an extra allocation
99

10-
error: you seem to be trying to use `Box<Arc<T>>`. Consider using just `Box<T>` of `Arc<T>`
10+
error: you seem to be trying to use `Box<Arc<T>>`. Consider using just `Box<T>` or `Arc<T>`
1111
--> $DIR/redundant_allocation.rs:27:30
1212
|
1313
LL | pub fn box_test7<T>(foo: Box<Arc<T>>) {}
1414
| ^^^^^^^^^^^
1515
|
16-
= help: `Arc<T>` is already on the heap, `Box<Arc<T>>` makes an extra allocation
16+
= note: `Arc<T>` is already on the heap, `Box<Arc<T>>` makes an extra allocation
1717

18-
error: you seem to be trying to use `Box<Rc<T>>`. Consider using just `Box<T>` of `Rc<T>`
18+
error: you seem to be trying to use `Box<Rc<T>>`. Consider using just `Box<T>` or `Rc<T>`
1919
--> $DIR/redundant_allocation.rs:29:27
2020
|
2121
LL | pub fn box_test8() -> Box<Rc<SubT<usize>>> {
2222
| ^^^^^^^^^^^^^^^^^^^^
2323
|
24-
= help: `Rc<T>` is already on the heap, `Box<Rc<T>>` makes an extra allocation
24+
= note: `Rc<T>` is already on the heap, `Box<Rc<T>>` makes an extra allocation
2525

26-
error: you seem to be trying to use `Box<Arc<T>>`. Consider using just `Box<T>` of `Arc<T>`
26+
error: you seem to be trying to use `Box<Arc<T>>`. Consider using just `Box<T>` or `Arc<T>`
2727
--> $DIR/redundant_allocation.rs:33:30
2828
|
2929
LL | pub fn box_test9<T>(foo: Box<Arc<T>>) -> Box<Arc<SubT<T>>> {
3030
| ^^^^^^^^^^^
3131
|
32-
= help: `Arc<T>` is already on the heap, `Box<Arc<T>>` makes an extra allocation
32+
= note: `Arc<T>` is already on the heap, `Box<Arc<T>>` makes an extra allocation
3333

34-
error: you seem to be trying to use `Box<Arc<T>>`. Consider using just `Box<T>` of `Arc<T>`
34+
error: you seem to be trying to use `Box<Arc<T>>`. Consider using just `Box<T>` or `Arc<T>`
3535
--> $DIR/redundant_allocation.rs:33:46
3636
|
3737
LL | pub fn box_test9<T>(foo: Box<Arc<T>>) -> Box<Arc<SubT<T>>> {
3838
| ^^^^^^^^^^^^^^^^^
3939
|
40-
= help: `Arc<T>` is already on the heap, `Box<Arc<T>>` makes an extra allocation
40+
= note: `Arc<T>` is already on the heap, `Box<Arc<T>>` makes an extra allocation
4141

42-
error: you seem to be trying to use `Rc<Box<T>>`. Consider using just `Rc<T>` of `Box<T>`
42+
error: you seem to be trying to use `Rc<Box<T>>`. Consider using just `Rc<T>` or `Box<T>`
4343
--> $DIR/redundant_allocation.rs:46:24
4444
|
4545
LL | pub fn rc_test5(a: Rc<Box<bool>>) {}
4646
| ^^^^^^^^^^^^^
4747
|
48-
= help: `Box<T>` is already on the heap, `Rc<Box<T>>` makes an extra allocation
48+
= note: `Box<T>` is already on the heap, `Rc<Box<T>>` makes an extra allocation
4949

50-
error: you seem to be trying to use `Rc<Arc<T>>`. Consider using just `Rc<T>` of `Arc<T>`
50+
error: you seem to be trying to use `Rc<Arc<T>>`. Consider using just `Rc<T>` or `Arc<T>`
5151
--> $DIR/redundant_allocation.rs:48:24
5252
|
5353
LL | pub fn rc_test7(a: Rc<Arc<bool>>) {}
5454
| ^^^^^^^^^^^^^
5555
|
56-
= help: `Arc<T>` is already on the heap, `Rc<Arc<T>>` makes an extra allocation
56+
= note: `Arc<T>` is already on the heap, `Rc<Arc<T>>` makes an extra allocation
5757

58-
error: you seem to be trying to use `Rc<Box<T>>`. Consider using just `Rc<T>` of `Box<T>`
58+
error: you seem to be trying to use `Rc<Box<T>>`. Consider using just `Rc<T>` or `Box<T>`
5959
--> $DIR/redundant_allocation.rs:50:26
6060
|
6161
LL | pub fn rc_test8() -> Rc<Box<SubT<usize>>> {
6262
| ^^^^^^^^^^^^^^^^^^^^
6363
|
64-
= help: `Box<T>` is already on the heap, `Rc<Box<T>>` makes an extra allocation
64+
= note: `Box<T>` is already on the heap, `Rc<Box<T>>` makes an extra allocation
6565

66-
error: you seem to be trying to use `Rc<Arc<T>>`. Consider using just `Rc<T>` of `Arc<T>`
66+
error: you seem to be trying to use `Rc<Arc<T>>`. Consider using just `Rc<T>` or `Arc<T>`
6767
--> $DIR/redundant_allocation.rs:54:29
6868
|
6969
LL | pub fn rc_test9<T>(foo: Rc<Arc<T>>) -> Rc<Arc<SubT<T>>> {
7070
| ^^^^^^^^^^
7171
|
72-
= help: `Arc<T>` is already on the heap, `Rc<Arc<T>>` makes an extra allocation
72+
= note: `Arc<T>` is already on the heap, `Rc<Arc<T>>` makes an extra allocation
7373

74-
error: you seem to be trying to use `Rc<Arc<T>>`. Consider using just `Rc<T>` of `Arc<T>`
74+
error: you seem to be trying to use `Rc<Arc<T>>`. Consider using just `Rc<T>` or `Arc<T>`
7575
--> $DIR/redundant_allocation.rs:54:44
7676
|
7777
LL | pub fn rc_test9<T>(foo: Rc<Arc<T>>) -> Rc<Arc<SubT<T>>> {
7878
| ^^^^^^^^^^^^^^^^
7979
|
80-
= help: `Arc<T>` is already on the heap, `Rc<Arc<T>>` makes an extra allocation
80+
= note: `Arc<T>` is already on the heap, `Rc<Arc<T>>` makes an extra allocation
8181

82-
error: you seem to be trying to use `Arc<Box<T>>`. Consider using just `Arc<T>` of `Box<T>`
82+
error: you seem to be trying to use `Arc<Box<T>>`. Consider using just `Arc<T>` or `Box<T>`
8383
--> $DIR/redundant_allocation.rs:67:25
8484
|
8585
LL | pub fn arc_test5(a: Arc<Box<bool>>) {}
8686
| ^^^^^^^^^^^^^^
8787
|
88-
= help: `Box<T>` is already on the heap, `Arc<Box<T>>` makes an extra allocation
88+
= note: `Box<T>` is already on the heap, `Arc<Box<T>>` makes an extra allocation
8989

90-
error: you seem to be trying to use `Arc<Rc<T>>`. Consider using just `Arc<T>` of `Rc<T>`
90+
error: you seem to be trying to use `Arc<Rc<T>>`. Consider using just `Arc<T>` or `Rc<T>`
9191
--> $DIR/redundant_allocation.rs:69:25
9292
|
9393
LL | pub fn arc_test6(a: Arc<Rc<bool>>) {}
9494
| ^^^^^^^^^^^^^
9595
|
96-
= help: `Rc<T>` is already on the heap, `Arc<Rc<T>>` makes an extra allocation
96+
= note: `Rc<T>` is already on the heap, `Arc<Rc<T>>` makes an extra allocation
9797

98-
error: you seem to be trying to use `Arc<Box<T>>`. Consider using just `Arc<T>` of `Box<T>`
98+
error: you seem to be trying to use `Arc<Box<T>>`. Consider using just `Arc<T>` or `Box<T>`
9999
--> $DIR/redundant_allocation.rs:71:27
100100
|
101101
LL | pub fn arc_test8() -> Arc<Box<SubT<usize>>> {
102102
| ^^^^^^^^^^^^^^^^^^^^^
103103
|
104-
= help: `Box<T>` is already on the heap, `Arc<Box<T>>` makes an extra allocation
104+
= note: `Box<T>` is already on the heap, `Arc<Box<T>>` makes an extra allocation
105105

106-
error: you seem to be trying to use `Arc<Rc<T>>`. Consider using just `Arc<T>` of `Rc<T>`
106+
error: you seem to be trying to use `Arc<Rc<T>>`. Consider using just `Arc<T>` or `Rc<T>`
107107
--> $DIR/redundant_allocation.rs:75:30
108108
|
109109
LL | pub fn arc_test9<T>(foo: Arc<Rc<T>>) -> Arc<Rc<SubT<T>>> {
110110
| ^^^^^^^^^^
111111
|
112-
= help: `Rc<T>` is already on the heap, `Arc<Rc<T>>` makes an extra allocation
112+
= note: `Rc<T>` is already on the heap, `Arc<Rc<T>>` makes an extra allocation
113113

114-
error: you seem to be trying to use `Arc<Rc<T>>`. Consider using just `Arc<T>` of `Rc<T>`
114+
error: you seem to be trying to use `Arc<Rc<T>>`. Consider using just `Arc<T>` or `Rc<T>`
115115
--> $DIR/redundant_allocation.rs:75:45
116116
|
117117
LL | pub fn arc_test9<T>(foo: Arc<Rc<T>>) -> Arc<Rc<SubT<T>>> {
118118
| ^^^^^^^^^^^^^^^^
119119
|
120-
= help: `Rc<T>` is already on the heap, `Arc<Rc<T>>` makes an extra allocation
120+
= note: `Rc<T>` is already on the heap, `Arc<Rc<T>>` makes an extra allocation
121121

122122
error: aborting due to 15 previous errors
123123

tests/ui/redundant_allocation_fixed.stderr renamed to tests/ui/redundant_allocation_fixable.stderr

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,73 @@
11
error: usage of `Box<&T>`
2-
--> $DIR/redundant_allocation_fixed.rs:26:30
2+
--> $DIR/redundant_allocation_fixable.rs:26:30
33
|
44
LL | pub fn box_test1<T>(foo: Box<&T>) {}
55
| ^^^^^^^ help: try: `&T`
66
|
77
= note: `-D clippy::redundant-allocation` implied by `-D warnings`
88

99
error: usage of `Box<&T>`
10-
--> $DIR/redundant_allocation_fixed.rs:28:27
10+
--> $DIR/redundant_allocation_fixable.rs:28:27
1111
|
1212
LL | pub fn box_test2(foo: Box<&MyStruct>) {}
1313
| ^^^^^^^^^^^^^^ help: try: `&MyStruct`
1414

1515
error: usage of `Box<&T>`
16-
--> $DIR/redundant_allocation_fixed.rs:30:27
16+
--> $DIR/redundant_allocation_fixable.rs:30:27
1717
|
1818
LL | pub fn box_test3(foo: Box<&MyEnum>) {}
1919
| ^^^^^^^^^^^^ help: try: `&MyEnum`
2020

2121
error: usage of `Box<Box<T>>`
22-
--> $DIR/redundant_allocation_fixed.rs:34:30
22+
--> $DIR/redundant_allocation_fixable.rs:34:30
2323
|
2424
LL | pub fn box_test5<T>(foo: Box<Box<T>>) {}
2525
| ^^^^^^^^^^^ help: try: `Box<T>`
2626

2727
error: usage of `Rc<&T>`
28-
--> $DIR/redundant_allocation_fixed.rs:45:29
28+
--> $DIR/redundant_allocation_fixable.rs:45:29
2929
|
3030
LL | pub fn rc_test1<T>(foo: Rc<&T>) {}
3131
| ^^^^^^ help: try: `&T`
3232

3333
error: usage of `Rc<&T>`
34-
--> $DIR/redundant_allocation_fixed.rs:47:26
34+
--> $DIR/redundant_allocation_fixable.rs:47:26
3535
|
3636
LL | pub fn rc_test2(foo: Rc<&MyStruct>) {}
3737
| ^^^^^^^^^^^^^ help: try: `&MyStruct`
3838

3939
error: usage of `Rc<&T>`
40-
--> $DIR/redundant_allocation_fixed.rs:49:26
40+
--> $DIR/redundant_allocation_fixable.rs:49:26
4141
|
4242
LL | pub fn rc_test3(foo: Rc<&MyEnum>) {}
4343
| ^^^^^^^^^^^ help: try: `&MyEnum`
4444

4545
error: usage of `Rc<Rc<T>>`
46-
--> $DIR/redundant_allocation_fixed.rs:53:24
46+
--> $DIR/redundant_allocation_fixable.rs:53:24
4747
|
4848
LL | pub fn rc_test6(a: Rc<Rc<bool>>) {}
4949
| ^^^^^^^^^^^^ help: try: `Rc<bool>`
5050

5151
error: usage of `Arc<&T>`
52-
--> $DIR/redundant_allocation_fixed.rs:64:30
52+
--> $DIR/redundant_allocation_fixable.rs:64:30
5353
|
5454
LL | pub fn arc_test1<T>(foo: Arc<&T>) {}
5555
| ^^^^^^^ help: try: `&T`
5656

5757
error: usage of `Arc<&T>`
58-
--> $DIR/redundant_allocation_fixed.rs:66:27
58+
--> $DIR/redundant_allocation_fixable.rs:66:27
5959
|
6060
LL | pub fn arc_test2(foo: Arc<&MyStruct>) {}
6161
| ^^^^^^^^^^^^^^ help: try: `&MyStruct`
6262

6363
error: usage of `Arc<&T>`
64-
--> $DIR/redundant_allocation_fixed.rs:68:27
64+
--> $DIR/redundant_allocation_fixable.rs:68:27
6565
|
6666
LL | pub fn arc_test3(foo: Arc<&MyEnum>) {}
6767
| ^^^^^^^^^^^^ help: try: `&MyEnum`
6868

6969
error: usage of `Arc<Arc<T>>`
70-
--> $DIR/redundant_allocation_fixed.rs:72:25
70+
--> $DIR/redundant_allocation_fixable.rs:72:25
7171
|
7272
LL | pub fn arc_test7(a: Arc<Arc<bool>>) {}
7373
| ^^^^^^^^^^^^^^ help: try: `Arc<bool>`

0 commit comments

Comments
 (0)