0

I've got this crate in/src/lib.rs which I'm trying to run tests on:

#![crate_type = "lib"]
#![crate_name = "mycrate"]

pub mod mycrate {
    pub struct Struct {
        field: i32,
    }

    impl Struct {
        pub fn new(n: i32) -> Struct {
            Struct { field: n }
        }
    }
}

The test file at /tests/test.rs:

extern crate mycrate;

use mycrate::*;

#[test]
fn test() {
    ...
}

Running cargo test gives this error:

tests/test.rs:3:5: 3:16 error: import `mycrate` conflicts with imported crate in this module (maybe you meant `use mycrate::*`?) [E0254]
tests/test.rs:3 use mycrate::*;
                     ^~~~~~~~~

What am I doing wrong here?

andrey
  • 1,515
  • 5
  • 23
  • 39

1 Answers1

2

A crate is also automatically a module of its own name. So you do not need to specify a sub-module. Since you imported everything in the mycrate crate, you also imported the mycrate::mycrate module, which caused the naming conflict.

Simply change the contents of your src/lib.rs to

pub struct Struct {
    field: i32,
}

impl Struct {
    pub fn new(n: i32) -> Struct {
        Struct { field: n }
    }
}

There's also no need for the crate_name and crate_type attributes.

oli_obk
  • 28,729
  • 6
  • 82
  • 98