rust-lang / rust-lang/rust-clippy
Lint to warn about str::as_ptr() usage in ffi call
Open
@fpdotmonkey is already working on this.
Since Jul 10, 2026.
A-lint
good first issue
L-correctness
T-middle
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Hello.
It would be nice to have a warning when using str::as_ptr() in a ffi call instead of using CStr.
For instance, in the following code:
unsafe { printf("Hello".as_ptr() as *const _) };
should give a warning and propose something like:
let cstring = CString::new("Hello".as_bytes()).unwrap();
unsafe { printf(cstring.as_ptr()) };
Thanks to add this lint.
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.
Assessment
This issue has not been assessed yet.