Skip to content

Import renames à la use Foo as Bar; are not resolved properly #200

Closed

Description

@regexident

A minimalistic crate like this …

Details
// lib.rs

pub struct Foo { pub field: bool }

use Foo as Bar;

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

… generates a header like this …

Details
// lib.h

#include <cstdint>
#include <cstdlib>

extern "C" {

void placebo(const Bar *_bar);

} // extern "C"

… emitting the following warning:

WARN: Can't find Bar. This usually means that this type was incompatible or not found.

… while it should generate something like this instead:

// lib.h

#include <cstdint>
#include <cstdlib>

struct Foo;

extern "C" {

void placebo(const Foo *_bar);

} // extern "C"

What's wrong:

  1. cbindgen doesn't recognize that Foo is used in an exported fn thus does not generate it.
  2. _bar: &Bar is not properly resolved to _bar: &Foo in the function argument.

Observations:

  1. This appears to be related to Incorrect type resolving for differently scoped types of same name #199.

Looks like cbindgen does not resolve scoped renames (i.e. use Foo as Bar;) of items.

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