1
- use clippy_utils:: diagnostics:: span_lint_and_sugg ;
1
+ use clippy_utils:: diagnostics:: span_lint_and_then ;
2
2
use clippy_utils:: source:: snippet_with_applicability;
3
3
use clippy_utils:: { path_def_id, qpath_generic_tys} ;
4
4
use rustc_errors:: Applicability ;
@@ -13,14 +13,15 @@ pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, qpath: &QPath<'_
13
13
let app = Applicability :: Unspecified ;
14
14
if cx. tcx . is_diagnostic_item ( sym:: Rc , def_id) {
15
15
if let Some ( alternate) = match_buffer_type ( cx, qpath) {
16
- span_lint_and_sugg (
16
+ #[ expect( clippy:: collapsible_span_lint_calls, reason = "rust-clippy#7797" ) ]
17
+ span_lint_and_then (
17
18
cx,
18
19
RC_BUFFER ,
19
20
hir_ty. span ,
20
21
"usage of `Rc<T>` when T is a buffer type" ,
21
- "try" ,
22
- format ! ( "Rc<{alternate}>" ) ,
23
- app ,
22
+ |diag| {
23
+ diag . span_suggestion ( hir_ty . span , "try" , format ! ( "Rc<{alternate}>" ) , app ) ;
24
+ } ,
24
25
) ;
25
26
} else {
26
27
let Some ( ty) = qpath_generic_tys ( qpath) . next ( ) else {
@@ -35,31 +36,37 @@ pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, qpath: &QPath<'_
35
36
Some ( ty) => ty. span ,
36
37
None => return false ,
37
38
} ;
38
- let mut applicability = app;
39
- span_lint_and_sugg (
39
+ span_lint_and_then (
40
40
cx,
41
41
RC_BUFFER ,
42
42
hir_ty. span ,
43
43
"usage of `Rc<T>` when T is a buffer type" ,
44
- "try" ,
45
- format ! (
46
- "Rc<[{}]>" ,
47
- snippet_with_applicability( cx, inner_span, ".." , & mut applicability)
48
- ) ,
49
- app,
44
+ |diag| {
45
+ let mut applicability = app;
46
+ diag. span_suggestion (
47
+ hir_ty. span ,
48
+ "try" ,
49
+ format ! (
50
+ "Rc<[{}]>" ,
51
+ snippet_with_applicability( cx, inner_span, ".." , & mut applicability)
52
+ ) ,
53
+ app,
54
+ ) ;
55
+ } ,
50
56
) ;
51
57
return true ;
52
58
}
53
59
} else if cx. tcx . is_diagnostic_item ( sym:: Arc , def_id) {
54
60
if let Some ( alternate) = match_buffer_type ( cx, qpath) {
55
- span_lint_and_sugg (
61
+ #[ expect( clippy:: collapsible_span_lint_calls, reason = "rust-clippy#7797" ) ]
62
+ span_lint_and_then (
56
63
cx,
57
64
RC_BUFFER ,
58
65
hir_ty. span ,
59
66
"usage of `Arc<T>` when T is a buffer type" ,
60
- "try" ,
61
- format ! ( "Arc<{alternate}>" ) ,
62
- app ,
67
+ |diag| {
68
+ diag . span_suggestion ( hir_ty . span , "try" , format ! ( "Arc<{alternate}>" ) , app ) ;
69
+ } ,
63
70
) ;
64
71
} else if let Some ( ty) = qpath_generic_tys ( qpath) . next ( ) {
65
72
let Some ( id) = path_def_id ( cx, ty) else { return false } ;
@@ -71,18 +78,23 @@ pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, qpath: &QPath<'_
71
78
Some ( ty) => ty. span ,
72
79
None => return false ,
73
80
} ;
74
- let mut applicability = app;
75
- span_lint_and_sugg (
81
+ span_lint_and_then (
76
82
cx,
77
83
RC_BUFFER ,
78
84
hir_ty. span ,
79
85
"usage of `Arc<T>` when T is a buffer type" ,
80
- "try" ,
81
- format ! (
82
- "Arc<[{}]>" ,
83
- snippet_with_applicability( cx, inner_span, ".." , & mut applicability)
84
- ) ,
85
- app,
86
+ |diag| {
87
+ let mut applicability = app;
88
+ diag. span_suggestion (
89
+ hir_ty. span ,
90
+ "try" ,
91
+ format ! (
92
+ "Arc<[{}]>" ,
93
+ snippet_with_applicability( cx, inner_span, ".." , & mut applicability)
94
+ ) ,
95
+ app,
96
+ ) ;
97
+ } ,
86
98
) ;
87
99
return true ;
88
100
}
0 commit comments