@@ -3,42 +3,44 @@ use clippy_utils::source::snippet_with_applicability;
3
3
use clippy_utils:: { path_def_id, qpath_generic_tys} ;
4
4
use rustc_errors:: Applicability ;
5
5
use rustc_hir:: def_id:: DefId ;
6
- use rustc_hir:: { self as hir , QPath , TyKind } ;
6
+ use rustc_hir:: { QPath , Ty , TyKind } ;
7
7
use rustc_lint:: LateContext ;
8
8
use rustc_span:: symbol:: sym;
9
9
use std:: borrow:: Cow ;
10
10
11
11
use super :: RC_BUFFER ;
12
12
13
- pub ( super ) fn check ( cx : & LateContext < ' _ > , hir_ty : & hir :: Ty < ' _ > , qpath : & QPath < ' _ > , def_id : DefId ) -> bool {
13
+ pub ( super ) fn check ( cx : & LateContext < ' _ > , hir_ty : & Ty < ' _ > , qpath : & QPath < ' _ > , def_id : DefId ) -> bool {
14
14
let mut app = Applicability :: Unspecified ;
15
15
let name = cx. tcx . get_diagnostic_name ( def_id) ;
16
16
if name == Some ( sym:: Rc ) {
17
- if let Some ( alternate) = match_buffer_type ( cx, qpath, & mut app) {
18
- #[ expect( clippy:: collapsible_span_lint_calls, reason = "rust-clippy#7797" ) ]
17
+ if let Some ( ty) = qpath_generic_tys ( qpath) . next ( )
18
+ && let Some ( alternate) = match_buffer_type ( cx, ty, & mut app)
19
+ {
19
20
span_lint_and_then (
20
21
cx,
21
22
RC_BUFFER ,
22
23
hir_ty. span ,
23
24
"usage of `Rc<T>` when `T` is a buffer type" ,
24
25
|diag| {
25
- diag. span_suggestion ( hir_ty . span , "try" , format ! ( "Rc<{ alternate}>" ) , app) ;
26
+ diag. span_suggestion_verbose ( ty . span , "try" , alternate, app) ;
26
27
} ,
27
28
) ;
28
29
true
29
30
} else {
30
31
false
31
32
}
32
33
} else if name == Some ( sym:: Arc ) {
33
- if let Some ( alternate) = match_buffer_type ( cx, qpath, & mut app) {
34
- #[ expect( clippy:: collapsible_span_lint_calls, reason = "rust-clippy#7797" ) ]
34
+ if let Some ( ty) = qpath_generic_tys ( qpath) . next ( )
35
+ && let Some ( alternate) = match_buffer_type ( cx, ty, & mut app)
36
+ {
35
37
span_lint_and_then (
36
38
cx,
37
39
RC_BUFFER ,
38
40
hir_ty. span ,
39
41
"usage of `Arc<T>` when `T` is a buffer type" ,
40
42
|diag| {
41
- diag. span_suggestion ( hir_ty . span , "try" , format ! ( "Arc<{ alternate}>" ) , app) ;
43
+ diag. span_suggestion_verbose ( ty . span , "try" , alternate, app) ;
42
44
} ,
43
45
) ;
44
46
true
@@ -52,10 +54,9 @@ pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, qpath: &QPath<'_
52
54
53
55
fn match_buffer_type (
54
56
cx : & LateContext < ' _ > ,
55
- qpath : & QPath < ' _ > ,
57
+ ty : & Ty < ' _ > ,
56
58
applicability : & mut Applicability ,
57
59
) -> Option < Cow < ' static , str > > {
58
- let ty = qpath_generic_tys ( qpath) . next ( ) ?;
59
60
let id = path_def_id ( cx, ty) ?;
60
61
let path = match cx. tcx . get_diagnostic_name ( id) {
61
62
Some ( sym:: OsString ) => "std::ffi::OsStr" . into ( ) ,
0 commit comments