Rollup merge of #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.
This commit is contained in:
Matthias Krüger 2024-08-26 17:25:33 +02:00 committed by GitHub
commit b9dfb4d6f8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 697 additions and 707 deletions

View File

@ -1,9 +1,6 @@
#![doc = include_str!("error.md")] #![doc = include_str!("error.md")]
#![stable(feature = "error_in_core", since = "1.81.0")] #![stable(feature = "error_in_core", since = "1.81.0")]
#[cfg(test)]
mod tests;
use crate::any::TypeId; use crate::any::TypeId;
use crate::fmt::{Debug, Display, Formatter, Result}; use crate::fmt::{Debug, Display, Formatter, Result};

View File

@ -141,7 +141,6 @@ mod intrinsics;
mod io; mod io;
mod iter; mod iter;
mod lazy; mod lazy;
#[cfg(test)]
mod macros; mod macros;
mod manually_drop; mod manually_drop;
mod mem; mod mem;

View File

@ -1,7 +1,5 @@
macro_rules! int_module { macro_rules! int_module {
($T:ident) => { ($T:ident) => {
#[cfg(test)]
mod tests {
use core::ops::{BitAnd, BitOr, BitXor, Not, Shl, Shr}; use core::ops::{BitAnd, BitOr, BitXor, Not, Shl, Shr};
use core::$T::*; use core::$T::*;
@ -422,6 +420,5 @@ macro_rules! int_module {
assert_eq!(<$T>::midpoint(<$T>::MAX, 6), <$T>::MAX / 2 + 3); assert_eq!(<$T>::midpoint(<$T>::MAX, 6), <$T>::MAX / 2 + 3);
assert_eq!(<$T>::midpoint(6, <$T>::MAX), <$T>::MAX / 2 + 3); assert_eq!(<$T>::midpoint(6, <$T>::MAX), <$T>::MAX / 2 + 3);
} }
}
}; };
} }

View File

@ -178,7 +178,7 @@ fn test_can_not_overflow() {
// Check u128 separately: // Check u128 separately:
for base in 2..=36 { for base in 2..=36 {
let num = u128::MAX as u128; let num = <u128>::MAX;
let max_len_string = format_radix(num, base as u128); let max_len_string = format_radix(num, base as u128);
// base 16 fits perfectly for u128 and won't overflow: // base 16 fits perfectly for u128 and won't overflow:
assert_eq!(can_overflow::<u128>(base, &max_len_string), base != 16); assert_eq!(can_overflow::<u128>(base, &max_len_string), base != 16);

View File

@ -1,7 +1,5 @@
macro_rules! uint_module { macro_rules! uint_module {
($T:ident) => { ($T:ident) => {
#[cfg(test)]
mod tests {
use core::ops::{BitAnd, BitOr, BitXor, Not, Shl, Shr}; use core::ops::{BitAnd, BitOr, BitXor, Not, Shl, Shr};
use core::$T::*; use core::$T::*;
use std::str::FromStr; use std::str::FromStr;
@ -315,6 +313,5 @@ macro_rules! uint_module {
assert_eq!(<$T>::midpoint(<$T>::MAX, 6), (<$T>::MAX - <$T>::MIN) / 2 + 3); assert_eq!(<$T>::midpoint(<$T>::MAX, 6), (<$T>::MAX - <$T>::MIN) / 2 + 3);
assert_eq!(<$T>::midpoint(6, <$T>::MAX), (<$T>::MAX - <$T>::MIN) / 2 + 3); assert_eq!(<$T>::midpoint(6, <$T>::MAX), (<$T>::MAX - <$T>::MIN) / 2 + 3);
} }
}
}; };
} }