Skip to content

Incorrect type resolving for differently scoped types of same name #199

Closed

Description

@regexident

A minimalistic crate like this …

Details
// lib.rs

pub mod foo {
    pub struct Foobar<T> { pub field: T }
}

pub mod bar {
    pub struct Foobar { pub field: u8 }

    #[no_mangle]
    pub unsafe extern "C" fn placebo(_foobar: &Foobar) {}
}

… generates a header like this …

Details
// lib.h

#include <cstdint>
#include <cstdlib>

template<typename T>
struct Foobar;

extern "C" {

void placebo(const Foobar *_foobar);

} // extern "C"

… while it should generate something like this instead:

#include <cstdint>
#include <cstdlib>

struct Foobar;

extern "C" {

void placebo(const Foobar *_foobar);

} // extern "C"

What's wrong:

  1. Foobar<T> is not used in any exported fn and hence shouldn't be generated.
  2. Foobar however is used in an exported fn and hence should be generated.

Observations:

  1. Changing the order of mod foo and mod bar makes it behave correctly.
  2. Adding #[repr(C)] to bar::Foobar makes it behave correctly, strangely enough.
  3. The <T> doesn't seem to be strictly necessary for triggering this bug, but makes things easier to spot in the generated header.

Looks like there's a name collision in the type registration. Probably by using their local instead of fully qualified names for lookup?

Activity

  1. eqrion commented on Aug 21, 2018

    @eqrion
    Collaborator

    This is a duplicate of the root issue of #7. Essentially cbindgen doesn't understand fully qualified names, and it doesn't understand imports and aliases. This is a longstanding issue, unfortunately.

    I'll close this here. If you'd provide some of these details in that issue, I'd greatly appreciate that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions