microsoft / microsoft/windows-rs

`windows-bindgen` _Impl trait should use `unsafe fn` if any of its parameters are pointers

Open
#1,506 12 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

question
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

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 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.