Fix bug: allow no- '_'-split binary format string, add test
This commit is contained in:
parent
79e70ccf6f
commit
60c647b262
@ -50,10 +50,15 @@ fn check_binary_unix_permissions(lit_kind: &LitKind, snip: &str) -> bool {
|
||||
|
||||
let group_sizes: Vec<usize> = num_lit.integer.split('_').map(str::len).collect();
|
||||
// check whether is binary format unix permissions
|
||||
if group_sizes.len() != 3 && group_sizes.len() != 4 {
|
||||
return false;
|
||||
if group_sizes.len() == 1 && (num_lit.integer.len() == 9 || num_lit.integer.len() == 12) {
|
||||
// 0bxxxxxxxxx or 0bxxxxxxxxxxxx
|
||||
true
|
||||
} else if group_sizes.len() == 3 || group_sizes.len() == 4 {
|
||||
// 0bxxx_xxx_xxx or 0bxxx_xxx_xxx_xxx
|
||||
group_sizes.iter().all(|len| *len == 3)
|
||||
} else {
|
||||
false
|
||||
}
|
||||
group_sizes.iter().all(|len| *len == 3)
|
||||
} else {
|
||||
false
|
||||
}
|
||||
|
@ -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 New Issue
Block a user