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