11use clippy_utils:: diagnostics:: span_lint_and_sugg;
2- use clippy_utils:: get_parent_expr;
32use clippy_utils:: msrvs:: { self , Msrv } ;
43use clippy_utils:: source:: snippet;
4+ use clippy_utils:: { get_parent_expr, sym} ;
55use rustc_ast:: { LitKind , StrStyle } ;
66use rustc_errors:: Applicability ;
77use rustc_hir:: { Expr , ExprKind , Node , QPath , TyKind } ;
88use rustc_lint:: LateContext ;
99use rustc_span:: edition:: Edition :: Edition2021 ;
10- use rustc_span:: { Span , Symbol , sym } ;
10+ use rustc_span:: { Span , Symbol } ;
1111
1212use super :: MANUAL_C_STR_LITERALS ;
1313
@@ -71,15 +71,15 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, func: &Expr<'_>, args
7171 && cx. tcx . sess . edition ( ) >= Edition2021
7272 && msrv. meets ( cx, msrvs:: C_STR_LITERALS )
7373 {
74- match fn_name. as_str ( ) {
75- name @ ( " from_bytes_with_nul" | " from_bytes_with_nul_unchecked" )
74+ match fn_name {
75+ sym :: from_bytes_with_nul | sym :: from_bytes_with_nul_unchecked
7676 if !arg. span . from_expansion ( )
7777 && let ExprKind :: Lit ( lit) = arg. kind
7878 && let LitKind :: ByteStr ( _, StrStyle :: Cooked ) | LitKind :: Str ( _, StrStyle :: Cooked ) = lit. node =>
7979 {
80- check_from_bytes ( cx, expr, arg, name ) ;
80+ check_from_bytes ( cx, expr, arg, fn_name ) ;
8181 } ,
82- " from_ptr" => check_from_ptr ( cx, expr, arg) ,
82+ sym :: from_ptr => check_from_ptr ( cx, expr, arg) ,
8383 _ => { } ,
8484 }
8585 }
@@ -106,13 +106,13 @@ fn check_from_ptr(cx: &LateContext<'_>, expr: &Expr<'_>, arg: &Expr<'_>) {
106106 }
107107}
108108/// Checks `CStr::from_bytes_with_nul(b"foo\0")`
109- fn check_from_bytes ( cx : & LateContext < ' _ > , expr : & Expr < ' _ > , arg : & Expr < ' _ > , method : & str ) {
109+ fn check_from_bytes ( cx : & LateContext < ' _ > , expr : & Expr < ' _ > , arg : & Expr < ' _ > , method : Symbol ) {
110110 let ( span, applicability) = if let Some ( parent) = get_parent_expr ( cx, expr)
111111 && let ExprKind :: MethodCall ( method, ..) = parent. kind
112112 && [ sym:: unwrap, sym:: expect] . contains ( & method. ident . name )
113113 {
114114 ( parent. span , Applicability :: MachineApplicable )
115- } else if method == " from_bytes_with_nul_unchecked" {
115+ } else if method == sym :: from_bytes_with_nul_unchecked {
116116 // `*_unchecked` returns `&CStr` directly, nothing needs to be changed
117117 ( expr. span , Applicability :: MachineApplicable )
118118 } else {
0 commit comments