@@ -31,8 +31,8 @@ declare_lint_pass!(ByteCharSlice => [BYTE_CHAR_SLICES]);
3131
3232impl EarlyLintPass for ByteCharSlice {
3333 fn check_expr ( & mut self , cx : & EarlyContext < ' _ > , expr : & Expr ) {
34- if let Some ( slice ) = is_byte_char_slices ( expr)
35- && !expr . span . from_expansion ( )
34+ if ! expr. span . from_expansion ( )
35+ && let Some ( slice ) = is_byte_char_slices ( expr )
3636 {
3737 span_lint_and_sugg (
3838 cx,
@@ -47,33 +47,28 @@ impl EarlyLintPass for ByteCharSlice {
4747 }
4848}
4949
50+ /// Checks whether the slice is that of byte chars, and if so, builds a byte-string out of it
5051fn is_byte_char_slices ( expr : & Expr ) -> Option < String > {
51- if let ExprKind :: AddrOf ( BorrowKind :: Ref , Mutability :: Not , expr) = & expr. kind {
52- match & expr. kind {
53- ExprKind :: Array ( members) => {
54- if members. is_empty ( ) {
55- return None ;
56- }
57-
58- members
59- . iter ( )
60- . map ( |member| match & member. kind {
61- ExprKind :: Lit ( Lit {
62- kind : LitKind :: Byte ,
63- symbol,
64- ..
65- } ) => Some ( symbol. as_str ( ) ) ,
66- _ => None ,
67- } )
68- . map ( |maybe_quote| match maybe_quote {
69- Some ( "\" " ) => Some ( "\\ \" " ) ,
70- Some ( "\\ '" ) => Some ( "'" ) ,
71- other => other,
72- } )
73- . collect :: < Option < String > > ( )
74- } ,
75- _ => None ,
76- }
52+ if let ExprKind :: AddrOf ( BorrowKind :: Ref , Mutability :: Not , expr) = & expr. kind
53+ && let ExprKind :: Array ( members) = & expr. kind
54+ && !members. is_empty ( )
55+ {
56+ members
57+ . iter ( )
58+ . map ( |member| match & member. kind {
59+ ExprKind :: Lit ( Lit {
60+ kind : LitKind :: Byte ,
61+ symbol,
62+ ..
63+ } ) => Some ( symbol. as_str ( ) ) ,
64+ _ => None ,
65+ } )
66+ . map ( |maybe_quote| match maybe_quote {
67+ Some ( "\" " ) => Some ( "\\ \" " ) ,
68+ Some ( "\\ '" ) => Some ( "'" ) ,
69+ other => other,
70+ } )
71+ . collect :: < Option < String > > ( )
7772 } else {
7873 None
7974 }
0 commit comments