Skip to content

Opaque types do not honor no-* flags #1238

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
osialr opened this issue Jan 28, 2018 · 1 comment
Closed

Opaque types do not honor no-* flags #1238

osialr opened this issue Jan 28, 2018 · 1 comment
Labels

Comments

@osialr
Copy link
Contributor

osialr commented Jan 28, 2018

To preface, I'm just starting with bindgen so this could be me simply not thinking about the problem the right way in rust.

I have an allocator function that returns an opaque type MyTypeT. I would like the type to not have the Copy trait so that it's a move-only type.

Neither the --no-derive-copy nor --no-copy flags affected the output of bindgen on the type.

Input C/C++ Header

typedef struct MyType MyTypeT;

Bindgen Invocation

$ bindgen --no-derive-copy --no-copy '.*' test.h -o out.rs

Actual Results

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct MyType {
    _unused: [u8; 0],
}
pub type MyTypeT = MyType;

Expected Results

#[repr(C)]
#[derive(Debug)]
pub struct MyType {
    _unused: [u8; 0],
}
pub type MyTypeT = MyType;
@emilio
Copy link
Contributor

emilio commented Jan 29, 2018

Yeah, I don't think these should be copy. Thanks for the report :)

@emilio emilio added the bug label Jan 29, 2018
emilio added a commit to emilio/rust-bindgen that referenced this issue Jan 29, 2018
emilio added a commit to emilio/rust-bindgen that referenced this issue Jan 29, 2018
Instead of special-casing.

This allows to use the normal flags to control what can be or not derived for
them.

Arguably deriving Copy / Clone is kind of busted for those, but changing this by
default broke tests (RefPtr<ForwardDeclaredType> stopped working for example).

So I think this is a good compromise.

Fixes rust-lang#1238
bors-servo pushed a commit that referenced this issue Jan 29, 2018
codegen: Make forward declarations go through the more generic path.

Instead of special-casing.

This allows to use the normal flags to control what can be or not derived for
them.

Arguably deriving Copy / Clone is kind of busted for those, but changing this by
default broke tests (RefPtr<ForwardDeclaredType> stopped working for example).

So I think this is a good compromise.

Fixes #1238
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants