Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: Allow 3-digit-grouped binary in non_octal_unix_permissions #11243

Closed
SabrinaJewson opened this issue Jul 27, 2023 · 3 comments · Fixed by #12049
Closed

Proposal: Allow 3-digit-grouped binary in non_octal_unix_permissions #11243

SabrinaJewson opened this issue Jul 27, 2023 · 3 comments · Fixed by #12049
Assignees
Labels
C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages

Comments

@SabrinaJewson
Copy link
Contributor

SabrinaJewson commented Jul 27, 2023

Description

I personally much prefer to write Unix permissions in binary rather than octal. For comparison:

Format Representation
ls(1) rwxr-xr--
Binary 0b111_101_100
Octal 0o754
chmod(1) ugo+rwx,go-w,o-x or u+rwx,g+rx-w,o+r-wx

The 3-group binary format is more readable than octal in my opinion, because it lines up very neatly with the ls(1) rwxrwxrwx format, and does not require any binary conversion or lookup tables in one’s head.

Currently Clippy disallows the following code:

fn main() {
    std::fs::Permissions::from_mode(0b111_101_100);
}
use std::os::unix::prelude::PermissionsExt as _;

To support this pattern, Clippy should include an exception in the non_octal_unix_permissions and unusual_byte_groupings lints, to specifically allow binary literals of the exact format 0b[XXX_]XXX_XXX_XXX.

Version

rustc 1.71.0 (8ede3aae2 2023-07-12)
binary: rustc
commit-hash: 8ede3aae28fe6e4d52b38157d7bfe0d3bceef225
commit-date: 2023-07-12
host: x86_64-unknown-linux-gnu
release: 1.71.0
LLVM version: 16.0.5

Additional Labels

@rustbot label +C-enhancement

@rustbot rustbot added the C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages label Jul 27, 2023
@Alexendoo
Copy link
Member

It would be reasonable to plain allow binary literals in general

@Centri3
Copy link
Member

Centri3 commented Jul 28, 2023

I agree, in the case of bitflags of any kind it's much easier to understand using binary

@cocodery
Copy link
Contributor

@rustbot claim

bors added a commit that referenced this issue Jan 8, 2024
fix/issue#11243: allow 3-digit-grouped binary in non_octal_unix_permissions

fixes [Issue#11243](#11243)

Issue#11243 suggest lint `non_octal_unix_permissions` should not report binary format literal unix permissions as an error, and we think binary format is a good way to understand these permissions.

To solve this problem, we need to add check for binary literal, which is written in function `check_binary_unix_permissions` , only `binary, 3 groups and each group length equals to 3` is a legal format.

changelog: [`non_octal_unix_permissions`]: Add check for binary format literal unix permissions like 0b111_111_111
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants