-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Remove cfg(test) from library/core #129592
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
CI passed. Phew. I was afraid these were somehow used for some complicated setup CI uses. |
library/core/tests/num/mod.rs
Outdated
@@ -178,7 +178,7 @@ fn test_can_not_overflow() { | |||
|
|||
// Check u128 separately: | |||
for base in 2..=36 { | |||
let num = u128::MAX as u128; | |||
let num = core::u128::MAX as u128; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this change needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The last paragraph of the PR description was my attempt at a short summary. Here's a bigger one.
Without this part of the PR, removing the mod tests {
wrapper module generates this error:
error[E0603]: constant import `MAX` is private
--> core/tests/num/mod.rs:181:25
|
181 | let num = u128::MAX as u128;
| ^^^ private constant import
|
note: the constant import `MAX` is defined here...
--> core/tests/num/uint_macros.rs:4:13
|
1 | / macro_rules! uint_module {
2 | | ($T:ident) => {
3 | | use core::ops::{BitAnd, BitOr, BitXor, Not, Shl, Shr};
4 | | use core::$T::*;
| | ^^^^^^^^^^^
... |
316 | | };
317 | | }
| |_- in this expansion of `uint_module!`
|
::: core/tests/num/u128.rs:1:1
|
1 | uint_module!(u128);
| ------------------ in this macro invocation
note: ...and refers to the constant `MAX` which is defined here
--> /home/ben/rust/library/core/src/num/shells/int_macros.rs:44:9
|
3 | / macro_rules! int_module {
4 | | ($T:ident) => (int_module!($T, #[stable(feature = "rust1", since = "1.0.0")]););
5 | | ($T:ident, #[$attr:meta]) => (
6 | | #[doc = concat!(
... |
44 | | pub const MAX: $T = $T::MAX;
| | ^^^^^^^^^^^^^^^^^ you could import this directly
45 | | )
46 | | }
| |_- in this expansion of `int_module!`
|
::: /home/ben/rust/library/core/src/num/shells/u128.rs:11:1
|
11 | int_module! { u128, #[stable(feature = "i128", since="1.26.0")] }
| ----------------------------------------------------------------- in this macro invocation
help: consider importing this constant instead
|
181 | let num = std::u128::MAX as u128;
| ~~~~~~~~~~~~~~
Before this PR, name resolution must be concluding that u128::MAX
cannot refer to the local u128
module because it doesn't contain an item called MAX
. But with the other changes in this PR the local u128
module does contain an item MAX
(which was previously at the path u128::tests::MAX
)... except that the item is private. And name resolution doesn't recover from that state and try the other u128::MAX
possibility?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh duh yeah I should read better
checks "hide whitespace" in the GH diff view lgtm. r=me with one comment
I thought I noticed that yesterday when trying to figure out https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/Unit.20tests.20in.20core. I wonder if we could have check-cfg explicitly forbid |
Ah! Yes your Zulip thread is exactly why I was thinking about this. |
@bors r+ |
69acb67
to
4f3ef2a
Compare
Little race condition. While re-reading the code I realized why the macro above doesn't need special treatment: It does |
@bors r=tgross35 |
…iaskrgr Rollup of 7 pull requests Successful merges: - rust-lang#129190 (Add f16 and f128 to tests/ui/consts/const-float-bits-conv.rs) - rust-lang#129377 (Add implementations for `unbounded_shl`/`unbounded_shr`) - rust-lang#129539 (link to Future::poll from the Poll docs) - rust-lang#129588 (pal/hermit: correctly round up microseconds in `Thread::sleep`) - rust-lang#129592 (Remove cfg(test) from library/core) - rust-lang#129597 (mv `build_reduced_graph_for_external_crate_res` into Resolver) - rust-lang#129600 (Tie `impl_trait_overcaptures` lint to Rust 2024) r? `@ghost` `@rustbot` modify labels: rollup
…iaskrgr Rollup of 7 pull requests Successful merges: - rust-lang#129190 (Add f16 and f128 to tests/ui/consts/const-float-bits-conv.rs) - rust-lang#129377 (Add implementations for `unbounded_shl`/`unbounded_shr`) - rust-lang#129539 (link to Future::poll from the Poll docs) - rust-lang#129588 (pal/hermit: correctly round up microseconds in `Thread::sleep`) - rust-lang#129592 (Remove cfg(test) from library/core) - rust-lang#129597 (mv `build_reduced_graph_for_external_crate_res` into Resolver) - rust-lang#129600 (Tie `impl_trait_overcaptures` lint to Rust 2024) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#129592 - saethlin:core-cfg-test, r=tgross35 Remove cfg(test) from library/core The diff here is very small with the ignore whitespace option. `core` doesn't/can't have unit tests. All of its tests are just modules under `tests/`, so it has no use for `cfg(test)`, because the entire contents of `library/core/src` are only ever compiled with that cfg off, and the entire contents of `library/core/tests` are only ever compiled with that cfg on. You can tell this is what's happening because we had `#[cfg(test)]` on a module declaration that has no source file. I also deleted the extra `mod tests {` layer of nesting; there's no need to mention again in the module path that this is a module of tests. This exposes a name collision between the `u128` module of tests and `core::u128`. Fixed that by using `<u128>::MAX` like is done in the `check!` macro, which is what avoids this name ambiguity for the other types.
The diff here is very small with the ignore whitespace option.
core
doesn't/can't have unit tests. All of its tests are just modules undertests/
, so it has no use forcfg(test)
, because the entire contents oflibrary/core/src
are only ever compiled with that cfg off, and the entire contents oflibrary/core/tests
are only ever compiled with that cfg on.You can tell this is what's happening because we had
#[cfg(test)]
on a module declaration that has no source file.I also deleted the extra
mod tests {
layer of nesting; there's no need to mention again in the module path that this is a module of tests. This exposes a name collision between theu128
module of tests andcore::u128
. Fixed that by using<u128>::MAX
like is done in thecheck!
macro, which is what avoids this name ambiguity for the other types.