rust-lang / rust-lang/rust-clippy

`permissions_set_readonly_false` false positive on Windows

Open
#10,477 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug I-false-positive
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

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://github.com/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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the permissions_set_readonly_false lint entry point and reproduce the diagnostic from the Windows-gated perms.set_readonly(false) call in src\uu\shred\src/shred.rs. Check the lint's platform handling and existing tests; done means this Windows case no longer produces a false positive while the Unix warning remains covered.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.