Skip to content

Qualified paths like libc::c_int should be globally qualified like ::libc::c_int to avoid name clashes #447

@kkysen

Description

@kkysen

Right now, most paths that c2rust transpile generates are fully-qualified, like libc::c_int. This can be ambiguous, however, when there is another item named libc, which would shadow the libc crate. To fix this, we should make the qualified paths global, i.e., prefix them with a :: like ::libc::c_int, which causes the lookup to be only within crates, not within all in-scope items, which is what we want.

This can cause practical issues, like in the tests/longdouble test. When I added a typedef long double f128 to the C code, then the generated Rust code included a pub type f128 = f128::f128. That is, the f128 type alias clashed with the f128 crate. If pub type f128 = ::f128::f128 was generated, it would work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions