1- use clippy_utils:: diagnostics:: span_lint_and_sugg ;
1+ use clippy_utils:: diagnostics:: span_lint_and_then ;
22use clippy_utils:: source:: snippet_with_applicability;
33use clippy_utils:: { path_def_id, qpath_generic_tys} ;
44use rustc_errors:: Applicability ;
@@ -13,14 +13,15 @@ pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, qpath: &QPath<'_
1313 let app = Applicability :: Unspecified ;
1414 if cx. tcx . is_diagnostic_item ( sym:: Rc , def_id) {
1515 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 (
1718 cx,
1819 RC_BUFFER ,
1920 hir_ty. span ,
2021 "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+ } ,
2425 ) ;
2526 } else {
2627 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<'_
3536 Some ( ty) => ty. span ,
3637 None => return false ,
3738 } ;
38- let mut applicability = app;
39- span_lint_and_sugg (
39+ span_lint_and_then (
4040 cx,
4141 RC_BUFFER ,
4242 hir_ty. span ,
4343 "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+ } ,
5056 ) ;
5157 return true ;
5258 }
5359 } else if cx. tcx . is_diagnostic_item ( sym:: Arc , def_id) {
5460 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 (
5663 cx,
5764 RC_BUFFER ,
5865 hir_ty. span ,
5966 "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+ } ,
6370 ) ;
6471 } else if let Some ( ty) = qpath_generic_tys ( qpath) . next ( ) {
6572 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<'_
7178 Some ( ty) => ty. span ,
7279 None => return false ,
7380 } ;
74- let mut applicability = app;
75- span_lint_and_sugg (
81+ span_lint_and_then (
7682 cx,
7783 RC_BUFFER ,
7884 hir_ty. span ,
7985 "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+ } ,
8698 ) ;
8799 return true ;
88100 }
0 commit comments