11//! Checks for usage of `&Vec[_]` and `&String`.
22
33use 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 ;
55use clippy_utils:: ty:: expr_sig;
66use clippy_utils:: visitors:: contains_unsafe_block;
77use 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 {
243243 . chain ( result. replacements . iter ( ) . map ( |r| {
244244 (
245245 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) ,
247247 )
248248 } ) )
249249 . collect ( ) ,
@@ -372,7 +372,7 @@ impl fmt::Display for DerefTyDisplay<'_, '_> {
372372 DerefTy :: Path => f. write_str ( "Path" ) ,
373373 DerefTy :: Slice ( hir_ty, ty) => {
374374 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 ) ) {
376376 Some ( s) => f. write_str ( & s) ?,
377377 None => ty. fmt ( f) ?,
378378 }
@@ -413,6 +413,7 @@ impl<'tcx> DerefTy<'tcx> {
413413 }
414414}
415415
416+ #[ expect( clippy:: too_many_lines) ]
416417fn check_fn_args < ' cx , ' tcx : ' cx > (
417418 cx : & ' cx LateContext < ' tcx > ,
418419 fn_sig : ty:: FnSig < ' tcx > ,
@@ -488,8 +489,6 @@ fn check_fn_args<'cx, 'tcx: 'cx>(
488489 return None ;
489490 }
490491
491- let ty_name = snippet_opt ( cx, ty. span ( ) ) . unwrap_or_else ( || args. type_at ( 1 ) . to_string ( ) ) ;
492-
493492 span_lint_hir_and_then (
494493 cx,
495494 PTR_ARG ,
@@ -500,7 +499,10 @@ fn check_fn_args<'cx, 'tcx: 'cx>(
500499 diag. span_suggestion (
501500 hir_ty. span ,
502501 "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+ } ,
504506 Applicability :: Unspecified ,
505507 ) ;
506508 } ,
0 commit comments