Skip to content

the name std is defined multiple times #59243

Closed
@Riateche

Description

@Riateche

The error happens on latest stable and nightly.
Steps to reproduce: cargo new --lib lib1;
src/lib.rs:

pub mod std {
}

tests/test1.rs:

use lib1;
fn main() {
}

cargo test returns error:

error[E0260]: the name `std` is defined multiple times
  |
  = note: `std` must be defined only once in the type namespace of this module

The error only happens if the module is named std (for instance, core and alloc work without error). The error is not produced if test1.rs doesn't use lib1 in any way. If test1.rs doesn't contain imports but uses the library directly (e.g. ::lib1::x()), the error is produced. cargo build always succeeds.

I don't know if this is supposed to be forbidden but the error message seems to be misleading.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-metadataArea: Crate metadataA-resolveArea: Name/path resolution done by `rustc_resolve` specifically

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions