microsoft / microsoft/windows-rs
`windows-bindgen` _Impl trait should use `unsafe fn` if any of its parameters are pointers
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 12.8k
- Forks
- 665
- Avg merge
- 7h 9m
- Merged PRs (30d)
- 70
Description
### Which crate is this about?
windows
### Crate version
0.32.0
### Summary
```rust
#[implement(Windows::Win32::Graphics::Imaging::IWICBitmapFrameDecode)]
pub struct Foo {}
impl IWICBitmapSource_Impl for Foo {
fn GetSize(&mut self, puiwidth: *mut u32, puiheight: *mut u32) -> windows::core::Result<()> {
unsafe {
*puiwidth = 0u32;
*puiheight = 0u32;
}
Ok(())
}
/* ... */
}
```
### Expected behavior
It should be an `unsafe fn` as the implementation is expected to dereference the pointer parameters.
### Actual behavior
Everything is just a safe `fn`.
### Additional comments
`cargo clippy` is unsatisfied:
```
error: this public function might dereference a raw pointer but is not marked `unsafe`
--> src\lib.rs:149:14
|
149 | *puiwidth = self.decoded.borrow().basic_info.xsize;
| ^^^^^^^^
|
= note: `#[deny(clippy::not_unsafe_ptr_arg_deref)]` on by default
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#not_unsafe_ptr_arg_deref
```
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 in the windows-bindgen code that generates _Impl trait method signatures, using the GetSize example as the target case. Check how pointer parameters are represented, then run cargo clippy on an implementation that dereferences them; done means the generated method is unsafe and the not_unsafe_ptr_arg_deref warning is resolved.
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
- 35/100