rust-lang / rust-lang/rust-clippy
Check that ffi functions override libc or other global namespace C functions
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
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=11155e0af04128f0e867045b28b688ed
In example above, close() function is never called in the code. However, test fails, because this function overrides libc close function and cargo uses it instead of normal close function.
Linter should check extern "C" functions names and signatures on possible collision with existing c functions.
Lint Name
Global-C-Function-Collide
Category
correctness, suspicious
Advantage
- Removes possible undefined behaviour when exposing a C interface
Drawbacks
- Override might be deliberate
Example
struct Dummy{}
impl Dummy {
#[no_mangle]
pub extern "C" fn close(_: *mut Self) {
assert_eq!(0,1);
}
}
#[cfg(test)]
mod tests {
#[test]
fn test() {}
}
The linter should say something like: line 5: exposed function overrides existing function (suggested fix: change function name).
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
Reproduce the collision with the linked Rust Playground example and confirm that the unused close function affects the test. The issue names no repository files or tests, so identify the Clippy lint entry point and testing location before defining how libc and other global C functions are checked; done means the example emits the proposed diagnostic without incorrectly rejecting deliberate overrides.
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
- Needs clarification
- Newbie friendliness
- 35/100