rust-lang / rust-lang/rust-clippy
Warn for use of RawFd or AsRawFd in public interfaces
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
What it does
RFC 3128 adds AsFd, OwnedFd and BorrowedFd, which are much safer ways to handle file access than AsRawFd and RawFd. They're what Rust ideally would've done from the start. And now that they're in stable Rust there is little reason to use RawFd anymore. I suggest that Clippy warn when safe functions, especially public ones, use RawFd or AsRawFd in their signatures.
https://rust-lang.github.io/rfcs/3128-io-safety.html
Lint Name
rawfd_interface
Category
suspicious
Advantage
Prevents bugs caused by invalid file descriptors and use-after-close.
Drawbacks
- Requires a recent MSRV (1.63.0)
- For crates in the middle of the application stack, it may not be possible to convert them to use I/O Safety before lower-level crates do.
Example
pub fn do_some_io<FD: AsRawFd>(input: &FD) -> io::Result<()> {
some_syscall(input.as_raw_fd())
}
Could be written as:
pub fn do_some_io<FD: AsFd>(input: &FD) -> io::Result<()> {
some_syscall(input.as_fd())
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with RFC 3128 and the issue's RawFd/AsRawFd example. Define the rawfd_interface lint so safe function signatures, especially public ones, warn when they use RawFd or AsRawFd, while recognizing the stated MSRV and migration constraints. Done when the lint behavior and its replacement guidance are covered for the proposed cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100