rust-bindgen icon indicating copy to clipboard operation
rust-bindgen copied to clipboard

Replacement types possibly confuse `used_template_params` somehow

Open adetaylor opened this issue 9 months ago • 0 comments

Reproduction:

C++:

/**
* <div rustbindgen="true" replaces="std::unique_ptr">
*/
template<typename T> class UniquePtr {
    T* ptr;
};

#include <memory>

template <typename at> class au {
std::unique_ptr<at> aw;
};
class bb;
using bc = au<bb>;

Command-line: cargo run -- test.hpp --no-layout-tests --enable-cxx-namespaces --allowlist-type bc -- -std=c++14

Rust output:

/* automatically generated by rust-bindgen 0.71.1 */

#[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)]
pub mod root {
    #[allow(unused_imports)]
    use self::super::root;
    pub mod std {
        #[allow(unused_imports)]
        use self::super::super::root;
        #[doc = " <div rustbindgen=\"true\" replaces=\"std::unique_ptr\">"]
        #[repr(C)]
        #[derive(Debug, Copy, Clone)]
        pub struct unique_ptr<T> {
            pub _phantom_0:
                ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>,
            pub ptr: *mut T,
        }
    }
    #[repr(C)]
    #[derive(Debug, Copy, Clone)]
    pub struct au {
        pub aw: root::std::unique_ptr<T>,
    }
    #[repr(C)]
    #[derive(Debug, Copy, Clone)]
    pub struct bb {
        _unused: [u8; 0],
    }
    pub type bc = root::au;
}

Note this bit:

    pub struct au {
        pub aw: root::std::unique_ptr<T>,
    }

... we're depending on a template parameter which doesn't exist in the outer struct.

Bindgen version 20aa65a0b9edfd5f8ab3e038197da5cb2c52ff18, today's HEAD.

adetaylor avatar Feb 26 '25 12:02 adetaylor