rust-lang / rust-lang/rust-bindgen

`Copy` is not being derived when referring to a blocklisted type

Open
#3,436 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
5.3k
Forks
829
Avg merge
1d 1h
Merged PRs (30d)
15

Description

I am using blocklist_file to control which items go into which generated binding files, and I manually add the imports so everything compiles fine.
The issue is that when a struct references another type that has been blocklisted it doesn't add a #[derive(Copy)] to that type.

An example:

// This works fine:
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct xcb_input_device_key_state_notify_event_t {
    pub response_type: u8,
    pub device_id: u8,
    pub sequence: u16,
    pub keys: [u8; 28usize],
}

// This doesn't:
#[repr(C)]
pub struct xcb_input_change_device_notify_event_t {
    pub response_type: u8,
    pub device_id: u8,
    pub sequence: u16,
    pub time: xcb_timestamp_t, // this is a type alias to u32 which is defined in a header that has been block-listed while generating the bindings for that file
    pub request: u8,
    pub pad0: [u8; 23usize],
}

Is this intended behavior? Is there a workaround?

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 by reproducing the blocklist_file case with the two structs shown, then trace how bindgen decides whether generated structs receive Copy and Clone derives when a referenced type is blocklisted. Done means the affected struct derives Copy consistently, with a regression test covering the blocklisted type alias scenario.

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
Active
Clarity
Mostly clear
Newbie friendliness
62/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.