1
1
use clippy_utils:: diagnostics:: span_lint_and_sugg;
2
- use clippy_utils:: get_parent_expr;
3
2
use clippy_utils:: msrvs:: { self , Msrv } ;
4
3
use clippy_utils:: source:: snippet;
4
+ use clippy_utils:: { get_parent_expr, sym} ;
5
5
use rustc_ast:: { LitKind , StrStyle } ;
6
6
use rustc_errors:: Applicability ;
7
7
use rustc_hir:: { Expr , ExprKind , Node , QPath , TyKind } ;
8
8
use rustc_lint:: LateContext ;
9
9
use rustc_span:: edition:: Edition :: Edition2021 ;
10
- use rustc_span:: { Span , Symbol , sym } ;
10
+ use rustc_span:: { Span , Symbol } ;
11
11
12
12
use super :: MANUAL_C_STR_LITERALS ;
13
13
@@ -71,15 +71,15 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, func: &Expr<'_>, args
71
71
&& cx. tcx . sess . edition ( ) >= Edition2021
72
72
&& msrv. meets ( cx, msrvs:: C_STR_LITERALS )
73
73
{
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
76
76
if !arg. span . from_expansion ( )
77
77
&& let ExprKind :: Lit ( lit) = arg. kind
78
78
&& let LitKind :: ByteStr ( _, StrStyle :: Cooked ) | LitKind :: Str ( _, StrStyle :: Cooked ) = lit. node =>
79
79
{
80
- check_from_bytes ( cx, expr, arg, name ) ;
80
+ check_from_bytes ( cx, expr, arg, fn_name ) ;
81
81
} ,
82
- " from_ptr" => check_from_ptr ( cx, expr, arg) ,
82
+ sym :: from_ptr => check_from_ptr ( cx, expr, arg) ,
83
83
_ => { } ,
84
84
}
85
85
}
@@ -106,13 +106,13 @@ fn check_from_ptr(cx: &LateContext<'_>, expr: &Expr<'_>, arg: &Expr<'_>) {
106
106
}
107
107
}
108
108
/// 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 ) {
110
110
let ( span, applicability) = if let Some ( parent) = get_parent_expr ( cx, expr)
111
111
&& let ExprKind :: MethodCall ( method, ..) = parent. kind
112
112
&& [ sym:: unwrap, sym:: expect] . contains ( & method. ident . name )
113
113
{
114
114
( parent. span , Applicability :: MachineApplicable )
115
- } else if method == " from_bytes_with_nul_unchecked" {
115
+ } else if method == sym :: from_bytes_with_nul_unchecked {
116
116
// `*_unchecked` returns `&CStr` directly, nothing needs to be changed
117
117
( expr. span , Applicability :: MachineApplicable )
118
118
} else {
0 commit comments