1
1
use clippy_utils:: diagnostics:: span_lint_and_sugg;
2
- use clippy_utils:: numeric_literal:: { NumericLiteral , Radix } ;
3
2
use clippy_utils:: source:: { snippet_opt, snippet_with_applicability} ;
4
3
use clippy_utils:: { match_def_path, paths} ;
5
- use rustc_ast:: LitKind ;
6
4
use rustc_errors:: Applicability ;
7
5
use rustc_hir:: { Expr , ExprKind } ;
8
6
use rustc_lint:: { LateContext , LateLintPass } ;
@@ -41,29 +39,6 @@ declare_clippy_lint! {
41
39
42
40
declare_lint_pass ! ( NonOctalUnixPermissions => [ NON_OCTAL_UNIX_PERMISSIONS ] ) ;
43
41
44
- fn check_binary_unix_permissions ( lit_kind : & LitKind , snip : & str ) -> bool {
45
- // support binary unix permissions
46
- if let Some ( num_lit) = NumericLiteral :: from_lit_kind ( snip, lit_kind) {
47
- if num_lit. radix != Radix :: Binary {
48
- return false ;
49
- }
50
-
51
- let group_sizes: Vec < usize > = num_lit. integer . split ( '_' ) . map ( str:: len) . collect ( ) ;
52
- // check whether is binary format unix permissions
53
- if group_sizes. len ( ) == 1 && ( num_lit. integer . len ( ) == 9 || num_lit. integer . len ( ) == 12 ) {
54
- // 0bxxxxxxxxx or 0bxxxxxxxxxxxx
55
- true
56
- } else if group_sizes. len ( ) == 3 || group_sizes. len ( ) == 4 {
57
- // 0bxxx_xxx_xxx or 0bxxx_xxx_xxx_xxx
58
- group_sizes. iter ( ) . all ( |len| * len == 3 )
59
- } else {
60
- false
61
- }
62
- } else {
63
- false
64
- }
65
- }
66
-
67
42
impl < ' tcx > LateLintPass < ' tcx > for NonOctalUnixPermissions {
68
43
fn check_expr ( & mut self , cx : & LateContext < ' tcx > , expr : & ' tcx Expr < ' tcx > ) {
69
44
match & expr. kind {
@@ -76,10 +51,10 @@ impl<'tcx> LateLintPass<'tcx> for NonOctalUnixPermissions {
76
51
) )
77
52
|| ( path. ident . name == sym ! ( set_mode)
78
53
&& cx. tcx . is_diagnostic_item ( sym:: FsPermissions , adt. did ( ) ) ) )
79
- && let ExprKind :: Lit ( lit_kind ) = param. kind
54
+ && let ExprKind :: Lit ( _ ) = param. kind
80
55
&& param. span . eq_ctxt ( expr. span )
81
56
&& let Some ( snip) = snippet_opt ( cx, param. span )
82
- && !( snip. starts_with ( "0o" ) || check_binary_unix_permissions ( & lit_kind . node , & snip) )
57
+ && !( snip. starts_with ( "0o" ) || snip. starts_with ( "0b" ) )
83
58
{
84
59
show_error ( cx, param) ;
85
60
}
@@ -88,10 +63,10 @@ impl<'tcx> LateLintPass<'tcx> for NonOctalUnixPermissions {
88
63
if let ExprKind :: Path ( ref path) = func. kind
89
64
&& let Some ( def_id) = cx. qpath_res ( path, func. hir_id ) . opt_def_id ( )
90
65
&& match_def_path ( cx, def_id, & paths:: PERMISSIONS_FROM_MODE )
91
- && let ExprKind :: Lit ( lit_kind ) = param. kind
66
+ && let ExprKind :: Lit ( _ ) = param. kind
92
67
&& param. span . eq_ctxt ( expr. span )
93
68
&& let Some ( snip) = snippet_opt ( cx, param. span )
94
- && !( snip. starts_with ( "0o" ) || check_binary_unix_permissions ( & lit_kind . node , & snip) )
69
+ && !( snip. starts_with ( "0o" ) || snip. starts_with ( "0b" ) )
95
70
{
96
71
show_error ( cx, param) ;
97
72
}
0 commit comments