Remove cfg(test) from library/core by saethlin · Pull Request #129592 · rust-lang/rust (original) (raw)

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: <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>T</mi><mo>=</mo></mrow><annotation encoding="application/x-tex">T = </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6833em;"></span><span class="mord mathnormal" style="margin-right:0.13889em;">T</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span></span></span></span>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?