mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-23 21:23:56 +00:00
Auto merge of #12049 - cocodery:fix/issue#11243, r=Alexendoo
fix/issue#11243: allow 3-digit-grouped binary in non_octal_unix_permissions fixes [Issue#11243](https://github.com/rust-lang/rust-clippy/issues/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
This commit is contained in:
commit
3b8323d790
4 changed files with 13 additions and 9 deletions
|
@ -53,14 +53,10 @@ impl<'tcx> LateLintPass<'tcx> for NonOctalUnixPermissions {
|
|||
&& cx.tcx.is_diagnostic_item(sym::FsPermissions, adt.did())))
|
||||
&& let ExprKind::Lit(_) = param.kind
|
||||
&& param.span.eq_ctxt(expr.span)
|
||||
&& let Some(snip) = snippet_opt(cx, param.span)
|
||||
&& !(snip.starts_with("0o") || snip.starts_with("0b"))
|
||||
{
|
||||
let Some(snip) = snippet_opt(cx, param.span) else {
|
||||
return;
|
||||
};
|
||||
|
||||
if !snip.starts_with("0o") {
|
||||
show_error(cx, param);
|
||||
}
|
||||
show_error(cx, param);
|
||||
}
|
||||
},
|
||||
ExprKind::Call(func, [param]) => {
|
||||
|
@ -70,7 +66,7 @@ impl<'tcx> LateLintPass<'tcx> for NonOctalUnixPermissions {
|
|||
&& let ExprKind::Lit(_) = param.kind
|
||||
&& param.span.eq_ctxt(expr.span)
|
||||
&& let Some(snip) = snippet_opt(cx, param.span)
|
||||
&& !snip.starts_with("0o")
|
||||
&& !(snip.starts_with("0o") || snip.starts_with("0b"))
|
||||
{
|
||||
show_error(cx, param);
|
||||
}
|
||||
|
|
|
@ -25,9 +25,13 @@ fn main() {
|
|||
|
||||
permissions.set_mode(0o644);
|
||||
permissions.set_mode(0o704);
|
||||
// no error
|
||||
permissions.set_mode(0b111_000_100);
|
||||
|
||||
// DirBuilderExt::mode
|
||||
let mut builder = DirBuilder::new();
|
||||
builder.mode(0o755);
|
||||
builder.mode(0o406);
|
||||
// no error
|
||||
permissions.set_mode(0b111000100);
|
||||
}
|
||||
|
|
|
@ -25,9 +25,13 @@ fn main() {
|
|||
|
||||
permissions.set_mode(644);
|
||||
permissions.set_mode(0o704);
|
||||
// no error
|
||||
permissions.set_mode(0b111_000_100);
|
||||
|
||||
// DirBuilderExt::mode
|
||||
let mut builder = DirBuilder::new();
|
||||
builder.mode(755);
|
||||
builder.mode(0o406);
|
||||
// no error
|
||||
permissions.set_mode(0b111000100);
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ LL | permissions.set_mode(644);
|
|||
| ^^^ help: consider using an octal literal instead: `0o644`
|
||||
|
||||
error: using a non-octal value to set unix file permissions
|
||||
--> $DIR/non_octal_unix_permissions.rs:31:18
|
||||
--> $DIR/non_octal_unix_permissions.rs:33:18
|
||||
|
|
||||
LL | builder.mode(755);
|
||||
| ^^^ help: consider using an octal literal instead: `0o755`
|
||||
|
|
Loading…
Reference in a new issue