Skip to content

Inconsistent opaque type representation #1194

Open
@jsgf

Description

@jsgf

Input C/C++ Header

template <class a> class Range { a b, c; };
typedef Range<const char *> StringPiece;
typedef Range<char> MutableStringPiece;
Range<char const *> d() {}

Bindgen Invocation

$ bindgen input.h --whitelist-type '(Mutable)?StringPiece'     --generate=types     --opaque-type '(Mutable)?StringPiece'     --no-layout-tests -- -x c++ -std=gnu++14

Actual Results

/* automatically generated by rust-bindgen */

pub type StringPiece = [u64; 2usize];
pub type MutableStringPiece = u8;

Expected Results

pub type StringPiece = [u64; 2usize];
pub type MutableStringPiece = [u64; 2usize];

StringPiece has a Rust type which correctly reflects its representation: [u64; 2size], which allows the Rust version of the type to be moved around etc. The MutableStringPiece is misrepresented by u8, which results in runtime errors because only the first byte is moved.

It looks like the d() function is what makes the difference; if I remove this then both StringPiece and MutableStringPiece get the same incorrect u8 representation.

This seems to be a regression introduced about 0.31, but I haven't checked specifically.

cc @kulshrax

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions