Repository navigation
#[test] visibility changes can produce conflicts and type errors with glob use. #52557
Description
Activity
I propose that instead of expanding:
#[test] fn foo() {}
to:
pub fn foo(){} pub mod __test_reexports { pub use super::foo; }
we expand to:
pub mod __test_reexports { use super::*; pub fn foo() {...} }
This is a breaking change but only for the semi-pathological case where you have test functions referencing each other. It also brings test into line with standard builds in that
#[test]are not referenceable. (in debug/release due to removal, and in test due to a gensymed module).- addedT-dev-toolsRelevant to the dev-tools subteam, which will review and decide on the PR/issue.Relevant to the dev-tools subteam, which will review and decide on the PR/issue.A-libtestArea: `#[test]` / the `test` libraryArea: `#[test]` / the `test` library
on Jul 20, 2018 the semi-pathological case where you have test functions referencing each other
I bet that's not uncommon enough to make a breaking change. However, I would expect test functions that reference each other to do so via relative paths, and this would only be breaking if absolute paths were used (iiuc). In any case we should probably just fix this and do a Crater run.
cc @petrochenkov and @rust-lang/compiler
We might be able to hack something in name resolution? Perhaps glob imports don't treat test functions as public? Or we give them some weird hygiene marker or something?
Actually if we did:
use __test_reexports::*; pub mod __test_reexports { use super::*; pub fn foo() {...} }
I think we'd be compatible and safe
Well, technically we should
useorpub useeach test in accordance with its visibilityI much better prefer rust-lang/rfcs#2471 (comment) as a solution to all our testing woes. I'll maybe try to prototype it soon.
- added a commit that references this issue
on Aug 2, 2018 Fixed by #52890
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:
In a normal build, the only
fooin scope isB::foo, but in a test buildA::foowill shadow it. And produce the following error: