Skip to content

Commit 0e61dbc

Browse files
authored
Rollup merge of rust-lang#138082 - thaliaarchi:slice-cfg-not-test, r=thomcc
Remove `#[cfg(not(test))]` gates in `core` These gates are unnecessary now that unit tests for `core` are in a separate package, `coretests`, instead of in the same files as the source code. They previously prevented the two `core` versions from conflicting with each other.
2 parents b65e296 + 01ab9ca commit 0e61dbc

33 files changed

+79
-114
lines changed

core/src/any.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ use crate::{fmt, hash, intrinsics};
109109
// unsafe traits and unsafe methods (i.e., `type_id` would still be safe to call,
110110
// but we would likely want to indicate as such in documentation).
111111
#[stable(feature = "rust1", since = "1.0.0")]
112-
#[cfg_attr(not(test), rustc_diagnostic_item = "Any")]
112+
#[rustc_diagnostic_item = "Any"]
113113
pub trait Any: 'static {
114114
/// Gets the `TypeId` of `self`.
115115
///

core/src/array/ascii.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::ascii;
22

3-
#[cfg(not(test))]
43
impl<const N: usize> [u8; N] {
54
/// Converts this array of bytes into an array of ASCII characters,
65
/// or returns `None` if any of the characters is non-ASCII.

core/src/bool.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ impl bool {
5656
/// ```
5757
#[doc(alias = "then_with")]
5858
#[stable(feature = "lazy_bool_to_option", since = "1.50.0")]
59-
#[cfg_attr(not(test), rustc_diagnostic_item = "bool_then")]
59+
#[rustc_diagnostic_item = "bool_then"]
6060
#[inline]
6161
pub fn then<T, F: FnOnce() -> T>(self, f: F) -> Option<T> {
6262
if self { Some(f()) } else { None }

core/src/cell.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ pub use once::OnceCell;
304304
/// ```
305305
///
306306
/// See the [module-level documentation](self) for more.
307-
#[cfg_attr(not(test), rustc_diagnostic_item = "Cell")]
307+
#[rustc_diagnostic_item = "Cell"]
308308
#[stable(feature = "rust1", since = "1.0.0")]
309309
#[repr(transparent)]
310310
#[rustc_pub_transparent]
@@ -725,7 +725,7 @@ impl<T, const N: usize> Cell<[T; N]> {
725725
/// A mutable memory location with dynamically checked borrow rules
726726
///
727727
/// See the [module-level documentation](self) for more.
728-
#[cfg_attr(not(test), rustc_diagnostic_item = "RefCell")]
728+
#[rustc_diagnostic_item = "RefCell"]
729729
#[stable(feature = "rust1", since = "1.0.0")]
730730
pub struct RefCell<T: ?Sized> {
731731
borrow: Cell<BorrowFlag>,

core/src/char/methods.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1178,7 +1178,7 @@ impl char {
11781178
#[must_use]
11791179
#[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")]
11801180
#[rustc_const_stable(feature = "const_char_is_ascii", since = "1.32.0")]
1181-
#[cfg_attr(not(test), rustc_diagnostic_item = "char_is_ascii")]
1181+
#[rustc_diagnostic_item = "char_is_ascii"]
11821182
#[inline]
11831183
pub const fn is_ascii(&self) -> bool {
11841184
*self as u32 <= 0x7F

core/src/cmp.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1481,7 +1481,7 @@ pub macro PartialOrd($item:item) {
14811481
#[inline]
14821482
#[must_use]
14831483
#[stable(feature = "rust1", since = "1.0.0")]
1484-
#[cfg_attr(not(test), rustc_diagnostic_item = "cmp_min")]
1484+
#[rustc_diagnostic_item = "cmp_min"]
14851485
pub fn min<T: Ord>(v1: T, v2: T) -> T {
14861486
v1.min(v2)
14871487
}
@@ -1573,7 +1573,7 @@ pub fn min_by_key<T, F: FnMut(&T) -> K, K: Ord>(v1: T, v2: T, mut f: F) -> T {
15731573
#[inline]
15741574
#[must_use]
15751575
#[stable(feature = "rust1", since = "1.0.0")]
1576-
#[cfg_attr(not(test), rustc_diagnostic_item = "cmp_max")]
1576+
#[rustc_diagnostic_item = "cmp_max"]
15771577
pub fn max<T: Ord>(v1: T, v2: T) -> T {
15781578
v1.max(v2)
15791579
}

core/src/convert/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ pub const fn identity<T>(x: T) -> T {
214214
/// is_hello(s);
215215
/// ```
216216
#[stable(feature = "rust1", since = "1.0.0")]
217-
#[cfg_attr(not(test), rustc_diagnostic_item = "AsRef")]
217+
#[rustc_diagnostic_item = "AsRef"]
218218
pub trait AsRef<T: ?Sized> {
219219
/// Converts this type into a shared reference of the (usually inferred) input type.
220220
#[stable(feature = "rust1", since = "1.0.0")]
@@ -365,7 +365,7 @@ pub trait AsRef<T: ?Sized> {
365365
/// Note, however, that APIs don't need to be generic. In many cases taking a `&mut [u8]` or
366366
/// `&mut Vec<u8>`, for example, is the better choice (callers need to pass the correct type then).
367367
#[stable(feature = "rust1", since = "1.0.0")]
368-
#[cfg_attr(not(test), rustc_diagnostic_item = "AsMut")]
368+
#[rustc_diagnostic_item = "AsMut"]
369369
pub trait AsMut<T: ?Sized> {
370370
/// Converts this type into a mutable reference of the (usually inferred) input type.
371371
#[stable(feature = "rust1", since = "1.0.0")]

core/src/default.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ use crate::ascii::Char as AsciiChar;
101101
/// bar: f32,
102102
/// }
103103
/// ```
104-
#[cfg_attr(not(test), rustc_diagnostic_item = "Default")]
104+
#[rustc_diagnostic_item = "Default"]
105105
#[stable(feature = "rust1", since = "1.0.0")]
106106
#[rustc_trivial_field_reads]
107107
pub trait Default: Sized {

core/src/error.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ use crate::fmt::{self, Debug, Display, Formatter};
4747
/// impl Error for ReadConfigError {}
4848
/// ```
4949
#[stable(feature = "rust1", since = "1.0.0")]
50-
#[cfg_attr(not(test), rustc_diagnostic_item = "Error")]
50+
#[rustc_diagnostic_item = "Error"]
5151
#[rustc_has_incoherent_inherent_impls]
5252
#[allow(multiple_supertrait_upcastable)]
5353
pub trait Error: Debug + Display {

core/src/fmt/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ mod num;
1818
mod rt;
1919

2020
#[stable(feature = "fmt_flags_align", since = "1.28.0")]
21-
#[cfg_attr(not(test), rustc_diagnostic_item = "Alignment")]
21+
#[rustc_diagnostic_item = "Alignment"]
2222
/// Possible alignments returned by `Formatter::align`
2323
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
2424
pub enum Alignment {

core/src/iter/adapters/enumerate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::ops::Try;
1414
#[derive(Clone, Debug)]
1515
#[must_use = "iterators are lazy and do nothing unless consumed"]
1616
#[stable(feature = "rust1", since = "1.0.0")]
17-
#[cfg_attr(not(test), rustc_diagnostic_item = "Enumerate")]
17+
#[rustc_diagnostic_item = "Enumerate"]
1818
pub struct Enumerate<I> {
1919
iter: I,
2020
count: usize,

core/src/iter/sources/repeat.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ use crate::num::NonZero;
5656
/// ```
5757
#[inline]
5858
#[stable(feature = "rust1", since = "1.0.0")]
59-
#[cfg_attr(not(test), rustc_diagnostic_item = "iter_repeat")]
59+
#[rustc_diagnostic_item = "iter_repeat"]
6060
pub fn repeat<T: Clone>(elt: T) -> Repeat<T> {
6161
Repeat { element: elt }
6262
}

core/src/iter/traits/double_ended.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use crate::ops::{ControlFlow, Try};
3737
/// assert_eq!(None, iter.next_back());
3838
/// ```
3939
#[stable(feature = "rust1", since = "1.0.0")]
40-
#[cfg_attr(not(test), rustc_diagnostic_item = "DoubleEndedIterator")]
40+
#[rustc_diagnostic_item = "DoubleEndedIterator"]
4141
pub trait DoubleEndedIterator: Iterator {
4242
/// Removes and returns an element from the end of the iterator.
4343
///

core/src/iter/traits/iterator.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,7 @@ pub trait Iterator {
862862
/// Note that `iter.filter(f).next()` is equivalent to `iter.find(f)`.
863863
#[inline]
864864
#[stable(feature = "rust1", since = "1.0.0")]
865-
#[cfg_attr(not(test), rustc_diagnostic_item = "iter_filter")]
865+
#[rustc_diagnostic_item = "iter_filter"]
866866
fn filter<P>(self, predicate: P) -> Filter<Self, P>
867867
where
868868
Self: Sized,
@@ -954,7 +954,7 @@ pub trait Iterator {
954954
/// ```
955955
#[inline]
956956
#[stable(feature = "rust1", since = "1.0.0")]
957-
#[cfg_attr(not(test), rustc_diagnostic_item = "enumerate_method")]
957+
#[rustc_diagnostic_item = "enumerate_method"]
958958
fn enumerate(self) -> Enumerate<Self>
959959
where
960960
Self: Sized,
@@ -1972,7 +1972,7 @@ pub trait Iterator {
19721972
#[inline]
19731973
#[stable(feature = "rust1", since = "1.0.0")]
19741974
#[must_use = "if you really need to exhaust the iterator, consider `.for_each(drop)` instead"]
1975-
#[cfg_attr(not(test), rustc_diagnostic_item = "iterator_collect_fn")]
1975+
#[rustc_diagnostic_item = "iterator_collect_fn"]
19761976
fn collect<B: FromIterator<Self::Item>>(self) -> B
19771977
where
19781978
Self: Sized,
@@ -3367,7 +3367,7 @@ pub trait Iterator {
33673367
/// assert_eq!(v_map, vec![1, 2, 3]);
33683368
/// ```
33693369
#[stable(feature = "iter_copied", since = "1.36.0")]
3370-
#[cfg_attr(not(test), rustc_diagnostic_item = "iter_copied")]
3370+
#[rustc_diagnostic_item = "iter_copied"]
33713371
fn copied<'a, T: 'a>(self) -> Copied<Self>
33723372
where
33733373
Self: Sized + Iterator<Item = &'a T>,
@@ -3415,7 +3415,7 @@ pub trait Iterator {
34153415
/// assert_eq!(&[vec![23]], &faster[..]);
34163416
/// ```
34173417
#[stable(feature = "rust1", since = "1.0.0")]
3418-
#[cfg_attr(not(test), rustc_diagnostic_item = "iter_cloned")]
3418+
#[rustc_diagnostic_item = "iter_cloned"]
34193419
fn cloned<'a, T: 'a>(self) -> Cloned<Self>
34203420
where
34213421
Self: Sized + Iterator<Item = &'a T>,

core/src/lib.rs

-17
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,6 @@
4343
//! which do not trigger a panic can be assured that this function is never
4444
//! called. The `lang` attribute is called `eh_personality`.
4545
46-
// Since core defines many fundamental lang items, all tests live in a
47-
// separate crate, coretests (library/coretests), to avoid bizarre issues.
48-
//
49-
// Here we explicitly #[cfg]-out this whole crate when testing. If we don't do
50-
// this, both the generated test artifact and the linked libtest (which
51-
// transitively includes core) will both define the same set of lang items,
52-
// and this will cause the E0152 "found duplicate lang item" error. See
53-
// discussion in #50466 for details.
54-
//
55-
// This cfg won't affect doc tests.
56-
#![cfg(not(test))]
57-
//
5846
#![stable(feature = "core", since = "1.6.0")]
5947
#![doc(
6048
html_playground_url = "https://play.rust-lang.org/",
@@ -64,7 +52,6 @@
6452
)]
6553
#![doc(rust_logo)]
6654
#![doc(cfg_hide(
67-
not(test),
6855
no_fp_fmt_parse,
6956
target_pointer_width = "16",
7057
target_pointer_width = "32",
@@ -228,13 +215,9 @@ extern crate self as core;
228215
#[allow(unused)]
229216
use prelude::rust_2024::*;
230217

231-
#[cfg(not(test))] // See #65860
232218
#[macro_use]
233219
mod macros;
234220

235-
// We don't export this through #[macro_export] for now, to avoid breakage.
236-
// See https://github.com/rust-lang/rust/issues/82913
237-
#[cfg(not(test))]
238221
#[unstable(feature = "assert_matches", issue = "82775")]
239222
/// Unstable module containing the unstable `assert_matches` macro.
240223
pub mod assert_matches {

core/src/macros/mod.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ macro_rules! panic {
3737
/// ```
3838
#[macro_export]
3939
#[stable(feature = "rust1", since = "1.0.0")]
40-
#[cfg_attr(not(test), rustc_diagnostic_item = "assert_eq_macro")]
40+
#[rustc_diagnostic_item = "assert_eq_macro"]
4141
#[allow_internal_unstable(panic_internals)]
4242
macro_rules! assert_eq {
4343
($left:expr, $right:expr $(,)?) => {
@@ -93,7 +93,7 @@ macro_rules! assert_eq {
9393
/// ```
9494
#[macro_export]
9595
#[stable(feature = "assert_ne", since = "1.13.0")]
96-
#[cfg_attr(not(test), rustc_diagnostic_item = "assert_ne_macro")]
96+
#[rustc_diagnostic_item = "assert_ne_macro"]
9797
#[allow_internal_unstable(panic_internals)]
9898
macro_rules! assert_ne {
9999
($left:expr, $right:expr $(,)?) => {
@@ -331,7 +331,7 @@ macro_rules! debug_assert {
331331
/// ```
332332
#[macro_export]
333333
#[stable(feature = "rust1", since = "1.0.0")]
334-
#[cfg_attr(not(test), rustc_diagnostic_item = "debug_assert_eq_macro")]
334+
#[rustc_diagnostic_item = "debug_assert_eq_macro"]
335335
macro_rules! debug_assert_eq {
336336
($($arg:tt)*) => {
337337
if $crate::cfg!(debug_assertions) {
@@ -361,7 +361,7 @@ macro_rules! debug_assert_eq {
361361
/// ```
362362
#[macro_export]
363363
#[stable(feature = "assert_ne", since = "1.13.0")]
364-
#[cfg_attr(not(test), rustc_diagnostic_item = "debug_assert_ne_macro")]
364+
#[rustc_diagnostic_item = "debug_assert_ne_macro"]
365365
macro_rules! debug_assert_ne {
366366
($($arg:tt)*) => {
367367
if $crate::cfg!(debug_assertions) {
@@ -442,7 +442,7 @@ pub macro debug_assert_matches($($arg:tt)*) {
442442
/// ```
443443
#[macro_export]
444444
#[stable(feature = "matches_macro", since = "1.42.0")]
445-
#[cfg_attr(not(test), rustc_diagnostic_item = "matches_macro")]
445+
#[rustc_diagnostic_item = "matches_macro"]
446446
macro_rules! matches {
447447
($expression:expr, $pattern:pat $(if $guard:expr)? $(,)?) => {
448448
match $expression {
@@ -617,7 +617,7 @@ macro_rules! r#try {
617617
/// ```
618618
#[macro_export]
619619
#[stable(feature = "rust1", since = "1.0.0")]
620-
#[cfg_attr(not(test), rustc_diagnostic_item = "write_macro")]
620+
#[rustc_diagnostic_item = "write_macro"]
621621
macro_rules! write {
622622
($dst:expr, $($arg:tt)*) => {
623623
$dst.write_fmt($crate::format_args!($($arg)*))
@@ -651,7 +651,7 @@ macro_rules! write {
651651
/// ```
652652
#[macro_export]
653653
#[stable(feature = "rust1", since = "1.0.0")]
654-
#[cfg_attr(not(test), rustc_diagnostic_item = "writeln_macro")]
654+
#[rustc_diagnostic_item = "writeln_macro"]
655655
#[allow_internal_unstable(format_args_nl)]
656656
macro_rules! writeln {
657657
($dst:expr $(,)?) => {
@@ -718,7 +718,7 @@ macro_rules! writeln {
718718
#[rustc_builtin_macro(unreachable)]
719719
#[allow_internal_unstable(edition_panic)]
720720
#[stable(feature = "rust1", since = "1.0.0")]
721-
#[cfg_attr(not(test), rustc_diagnostic_item = "unreachable_macro")]
721+
#[rustc_diagnostic_item = "unreachable_macro"]
722722
macro_rules! unreachable {
723723
// Expands to either `$crate::panic::unreachable_2015` or `$crate::panic::unreachable_2021`
724724
// depending on the edition of the caller.
@@ -803,7 +803,7 @@ macro_rules! unreachable {
803803
/// ```
804804
#[macro_export]
805805
#[stable(feature = "rust1", since = "1.0.0")]
806-
#[cfg_attr(not(test), rustc_diagnostic_item = "unimplemented_macro")]
806+
#[rustc_diagnostic_item = "unimplemented_macro"]
807807
#[allow_internal_unstable(panic_internals)]
808808
macro_rules! unimplemented {
809809
() => {
@@ -883,7 +883,7 @@ macro_rules! unimplemented {
883883
/// ```
884884
#[macro_export]
885885
#[stable(feature = "todo_macro", since = "1.40.0")]
886-
#[cfg_attr(not(test), rustc_diagnostic_item = "todo_macro")]
886+
#[rustc_diagnostic_item = "todo_macro"]
887887
#[allow_internal_unstable(panic_internals)]
888888
macro_rules! todo {
889889
() => {
@@ -995,7 +995,7 @@ pub(crate) mod builtin {
995995
/// and cannot be stored for later use.
996996
/// This is a known limitation, see [#92698](https://github.com/rust-lang/rust/issues/92698).
997997
#[stable(feature = "rust1", since = "1.0.0")]
998-
#[cfg_attr(not(test), rustc_diagnostic_item = "format_args_macro")]
998+
#[rustc_diagnostic_item = "format_args_macro"]
999999
#[allow_internal_unsafe]
10001000
#[allow_internal_unstable(fmt_internals)]
10011001
#[rustc_builtin_macro]
@@ -1342,7 +1342,7 @@ pub(crate) mod builtin {
13421342
#[stable(feature = "rust1", since = "1.0.0")]
13431343
#[rustc_builtin_macro]
13441344
#[macro_export]
1345-
#[cfg_attr(not(test), rustc_diagnostic_item = "include_str_macro")]
1345+
#[rustc_diagnostic_item = "include_str_macro"]
13461346
macro_rules! include_str {
13471347
($file:expr $(,)?) => {{ /* compiler built-in */ }};
13481348
}
@@ -1382,7 +1382,7 @@ pub(crate) mod builtin {
13821382
#[stable(feature = "rust1", since = "1.0.0")]
13831383
#[rustc_builtin_macro]
13841384
#[macro_export]
1385-
#[cfg_attr(not(test), rustc_diagnostic_item = "include_bytes_macro")]
1385+
#[rustc_diagnostic_item = "include_bytes_macro"]
13861386
macro_rules! include_bytes {
13871387
($file:expr $(,)?) => {{ /* compiler built-in */ }};
13881388
}

core/src/marker.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ macro marker_impls {
8282
/// [arc]: ../../std/sync/struct.Arc.html
8383
/// [ub]: ../../reference/behavior-considered-undefined.html
8484
#[stable(feature = "rust1", since = "1.0.0")]
85-
#[cfg_attr(not(test), rustc_diagnostic_item = "Send")]
85+
#[rustc_diagnostic_item = "Send"]
8686
#[diagnostic::on_unimplemented(
8787
message = "`{Self}` cannot be sent between threads safely",
8888
label = "`{Self}` cannot be sent between threads safely"
@@ -545,7 +545,7 @@ pub trait BikeshedGuaranteedNoDrop {}
545545
/// [transmute]: crate::mem::transmute
546546
/// [nomicon-send-and-sync]: ../../nomicon/send-and-sync.html
547547
#[stable(feature = "rust1", since = "1.0.0")]
548-
#[cfg_attr(not(test), rustc_diagnostic_item = "Sync")]
548+
#[rustc_diagnostic_item = "Sync"]
549549
#[lang = "sync"]
550550
#[rustc_on_unimplemented(
551551
on(
@@ -1305,7 +1305,7 @@ pub trait FnPtr: Copy + Clone {
13051305
/// ```
13061306
#[rustc_builtin_macro(CoercePointee, attributes(pointee))]
13071307
#[allow_internal_unstable(dispatch_from_dyn, coerce_unsized, unsize, coerce_pointee_validated)]
1308-
#[cfg_attr(not(test), rustc_diagnostic_item = "CoercePointee")]
1308+
#[rustc_diagnostic_item = "CoercePointee"]
13091309
#[unstable(feature = "derive_coerce_pointee", issue = "123430")]
13101310
pub macro CoercePointee($item:item) {
13111311
/* compiler built-in */

0 commit comments

Comments
 (0)