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

permissions_set_readonly_false false positive on Windows #10477

Open
miles170 opened this issue Mar 10, 2023 · 3 comments
Open

permissions_set_readonly_false false positive on Windows #10477

miles170 opened this issue Mar 10, 2023 · 3 comments
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@miles170
Copy link

miles170 commented Mar 10, 2023

Summary

permissions_set_readonly_false false positive when running Clippy on Windows.

Lint Name

permissions_set_readonly_false

Reproducer

I tried this code on Windows

let metadata = fs::metadata(path).map_err_context(String::new)?;
let mut perms = metadata.permissions();
#[cfg(not(unix))]
perms.set_readonly(false);

I saw this happen:

error: call to `set_readonly` with argument `false`
   --> src\uu\shred\src/shred.rs:475:9
    |
475 |         perms.set_readonly(false);
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: on Unix platforms this results in the file being world writable
    = help: you can set the desired permissions using `PermissionsExt`. For more information, see
            https://doc.rust-lang.org/std/os/unix/fs/trait.PermissionsExt.html
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#permissions_set_readonly_false
    = note: `-D clippy::permissions-set-readonly-false` implied by `-D warnings`

I expected to see no error.

See https:/uutils/coreutils/actions/runs/4383223472/jobs/7673213723

Version

rustc 1.68.0 (2c8cc3432 2023-03-06)
binary: rustc
commit-hash: 2c8cc343237b8f7d5a3c3703e3a87f2eb2c54a74
commit-date: 2023-03-06
host: x86_64-unknown-linux-gnu
release: 1.68.0
LLVM version: 15.0.6

Additional Labels

No response

@miles170 miles170 added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Mar 10, 2023
@Jarcho
Copy link
Contributor

Jarcho commented Mar 11, 2023

Checking the repo, it looks like there's nothing in the code to say it's only compiled for Windows. This means that there's no way for clippy to know that there's only one target.

Even with that, I don't think the lint does anything to check if the function call is within a cfg block. This would be a good extension for the lint.

Edit: Looks like you're reporting about the pr, not the current master.

@miles170
Copy link
Author

Checking the repo, it looks like there's nothing in the code to say it's only compiled for Windows. This means that there's no way for clippy to know that there's only one target.

Even with that, I don't think the lint does anything to check if the function call is within a cfg block. This would be a good extension for the lint.

Edit: Looks like you're reporting about the pr, not the current master.

Sorry for the incomplete information. I'm indeed reporting about the PR.

I have updated the code where perms.set_readonly(false) is inside the #[cfg(not(unix))] block.

@sylvestre
Copy link
Contributor

it is this PR:
uutils/coreutils#4488

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

No branches or pull requests

3 participants