Skip to content

#[test] visibility changes can produce conflicts and type errors with glob use. #52557

Closed
@djrenren

Description

@djrenren

Because #[test] marks tests as public so that they can be reexported (avoiding E0364), they can cause namespace pollutions that only occur in test builds.

Minimal repro:

mod A {
    #[test]
    fn foo() {}
}

mod B {
    pub fn foo() -> bool {
        true
    }
}

use B::foo;
use A::*;

fn conflict() {
    let x: bool = foo();
}

In a normal build, the only foo in scope is B::foo, but in a test build A::foo will shadow it. And produce the following error:

error[E0308]: mismatched types
  --> ./test.rs:20:19
   |
20 |     let x: bool = foo();
   |                   ^^^^^ expected bool, found ()
   |
   = note: expected type `bool`
              found type `()`

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-libtestArea: `#[test]` / the `test` libraryT-dev-toolsRelevant to the dev-tools subteam, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions