Skip to content

Unresolved import: extern crate ignored in submodules #17056

@gavinb

Description

@gavinb

Given a module lib.rs:

pub mod foo;

and a submodule foo.rs:

extern crate libc;
use libc::size_t;
fn test() {
    let sz: size_t = 1024;
}

Compiling it with:

$ rustc --crate-type=rlib lib.rs

gives the following error:

foo.rs:4:5: 4:9 error: unresolved import `libc::size_t`. Did you mean `self::libc`?
foo.rs:4 use libc::size_t;
             ^~~~
error: aborting due to previous error

The extern crate line in foo.rs is ignored without any message, and compilation only succeeds if this line is moved to lib.rs. This behaviour is quite confusing as the error message doesn't lead you to the correct solution.

It would be nice if you could have extern crate declarations in all modules, but failing that, at least there should be a diagnostic that it is ignored in the submodule and required in the top level module of the crate.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions