1
1
//! Checks for usage of `&Vec[_]` and `&String`.
2
2
3
3
use clippy_utils:: diagnostics:: { span_lint, span_lint_and_sugg, span_lint_and_then, span_lint_hir_and_then} ;
4
- use clippy_utils:: source:: snippet_opt ;
4
+ use clippy_utils:: source:: SpanRangeExt ;
5
5
use clippy_utils:: ty:: expr_sig;
6
6
use clippy_utils:: visitors:: contains_unsafe_block;
7
7
use clippy_utils:: { get_expr_use_or_unification_node, is_lint_allowed, path_def_id, path_to_local} ;
@@ -243,7 +243,7 @@ impl<'tcx> LateLintPass<'tcx> for Ptr {
243
243
. chain ( result. replacements . iter ( ) . map ( |r| {
244
244
(
245
245
r. expr_span ,
246
- format ! ( "{}{}" , snippet_opt ( cx , r. self_span) . unwrap( ) , r. replacement) ,
246
+ format ! ( "{}{}" , r. self_span. get_source_text ( cx ) . unwrap( ) , r. replacement) ,
247
247
)
248
248
} ) )
249
249
. collect ( ) ,
@@ -372,7 +372,7 @@ impl fmt::Display for DerefTyDisplay<'_, '_> {
372
372
DerefTy :: Path => f. write_str ( "Path" ) ,
373
373
DerefTy :: Slice ( hir_ty, ty) => {
374
374
f. write_char ( '[' ) ?;
375
- match hir_ty. and_then ( |s| snippet_opt ( self . 0 , s ) ) {
375
+ match hir_ty. and_then ( |s| s . get_source_text ( self . 0 ) ) {
376
376
Some ( s) => f. write_str ( & s) ?,
377
377
None => ty. fmt ( f) ?,
378
378
}
@@ -413,6 +413,7 @@ impl<'tcx> DerefTy<'tcx> {
413
413
}
414
414
}
415
415
416
+ #[ expect( clippy:: too_many_lines) ]
416
417
fn check_fn_args < ' cx , ' tcx : ' cx > (
417
418
cx : & ' cx LateContext < ' tcx > ,
418
419
fn_sig : ty:: FnSig < ' tcx > ,
@@ -488,8 +489,6 @@ fn check_fn_args<'cx, 'tcx: 'cx>(
488
489
return None ;
489
490
}
490
491
491
- let ty_name = snippet_opt ( cx, ty. span ( ) ) . unwrap_or_else ( || args. type_at ( 1 ) . to_string ( ) ) ;
492
-
493
492
span_lint_hir_and_then (
494
493
cx,
495
494
PTR_ARG ,
@@ -500,7 +499,10 @@ fn check_fn_args<'cx, 'tcx: 'cx>(
500
499
diag. span_suggestion (
501
500
hir_ty. span ,
502
501
"change this to" ,
503
- format ! ( "&{}{ty_name}" , mutability. prefix_str( ) ) ,
502
+ match ty. span ( ) . get_source_text ( cx) {
503
+ Some ( s) => format ! ( "&{}{s}" , mutability. prefix_str( ) ) ,
504
+ None => format ! ( "&{}{}" , mutability. prefix_str( ) , args. type_at( 1 ) ) ,
505
+ } ,
504
506
Applicability :: Unspecified ,
505
507
) ;
506
508
} ,
0 commit comments