Skip to content

Commit e084680

Browse files
authored
Rollup merge of #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 199e714 + 638b226 commit e084680

34 files changed

+90
-127
lines changed

compiler/rustc_codegen_cranelift/patches/0027-stdlib-128bit-atomic-operations.patch

+11-13
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
From ad7ffe71baba46865f2e65266ab025920dfdc20b Mon Sep 17 00:00:00 2001
1+
From 5d7c709608b01301d4628d2159265936d4440b67 Mon Sep 17 00:00:00 2001
22
From: bjorn3 <[email protected]>
33
Date: Thu, 18 Feb 2021 18:45:28 +0100
44
Subject: [PATCH] Disable 128bit atomic operations
@@ -7,11 +7,10 @@ Cranelift doesn't support them yet
77
---
88
library/core/src/panic/unwind_safe.rs | 6 -----
99
library/core/src/sync/atomic.rs | 38 ---------------------------
10-
library/core/tests/atomic.rs | 4 ---
11-
4 files changed, 4 insertions(+), 50 deletions(-)
10+
2 files changed, 44 deletions(-)
1211

1312
diff --git a/library/core/src/panic/unwind_safe.rs b/library/core/src/panic/unwind_safe.rs
14-
index 092b7cf..158cf71 100644
13+
index a60f0799c0e..af056fbf41f 100644
1514
--- a/library/core/src/panic/unwind_safe.rs
1615
+++ b/library/core/src/panic/unwind_safe.rs
1716
@@ -216,9 +216,6 @@ impl RefUnwindSafe for crate::sync::atomic::AtomicI32 {}
@@ -21,7 +20,7 @@ index 092b7cf..158cf71 100644
2120
-#[cfg(target_has_atomic_load_store = "128")]
2221
-#[unstable(feature = "integer_atomics", issue = "99069")]
2322
-impl RefUnwindSafe for crate::sync::atomic::AtomicI128 {}
24-
23+
2524
#[cfg(target_has_atomic_load_store = "ptr")]
2625
#[stable(feature = "unwind_safe_atomic_refs", since = "1.14.0")]
2726
@@ -235,9 +232,6 @@ impl RefUnwindSafe for crate::sync::atomic::AtomicU32 {}
@@ -31,14 +30,14 @@ index 092b7cf..158cf71 100644
3130
-#[cfg(target_has_atomic_load_store = "128")]
3231
-#[unstable(feature = "integer_atomics", issue = "99069")]
3332
-impl RefUnwindSafe for crate::sync::atomic::AtomicU128 {}
34-
33+
3534
#[cfg(target_has_atomic_load_store = "8")]
3635
#[stable(feature = "unwind_safe_atomic_refs", since = "1.14.0")]
3736
diff --git a/library/core/src/sync/atomic.rs b/library/core/src/sync/atomic.rs
38-
index d9de37e..8293fce 100644
37+
index bf2b6d59f88..d5ccce03bbf 100644
3938
--- a/library/core/src/sync/atomic.rs
4039
+++ b/library/core/src/sync/atomic.rs
41-
@@ -2996,44 +2996,6 @@ atomic_int! {
40+
@@ -3585,44 +3585,6 @@ pub const fn as_ptr(&self) -> *mut $int_type {
4241
8,
4342
u64 AtomicU64
4443
}
@@ -54,7 +53,7 @@ index d9de37e..8293fce 100644
5453
- unstable(feature = "integer_atomics", issue = "99069"),
5554
- rustc_const_unstable(feature = "integer_atomics", issue = "99069"),
5655
- rustc_const_unstable(feature = "integer_atomics", issue = "99069"),
57-
- cfg_attr(not(test), rustc_diagnostic_item = "AtomicI128"),
56+
- rustc_diagnostic_item = "AtomicI128",
5857
- "i128",
5958
- "#![feature(integer_atomics)]\n\n",
6059
- atomic_min, atomic_max,
@@ -73,7 +72,7 @@ index d9de37e..8293fce 100644
7372
- unstable(feature = "integer_atomics", issue = "99069"),
7473
- rustc_const_unstable(feature = "integer_atomics", issue = "99069"),
7574
- rustc_const_unstable(feature = "integer_atomics", issue = "99069"),
76-
- cfg_attr(not(test), rustc_diagnostic_item = "AtomicU128"),
75+
- rustc_diagnostic_item = "AtomicU128",
7776
- "u128",
7877
- "#![feature(integer_atomics)]\n\n",
7978
- atomic_umin, atomic_umax,
@@ -83,7 +82,6 @@ index d9de37e..8293fce 100644
8382

8483
#[cfg(target_has_atomic_load_store = "ptr")]
8584
macro_rules! atomic_int_ptr_sized {
86-
( $($target_pointer_width:literal $align:literal)* ) => { $(
87-
--
88-
2.26.2.7.g19db9cfb68
85+
--
86+
2.48.1
8987

library/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
///

library/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.

library/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 }

library/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>,

library/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

library/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
}

library/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")]

library/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 {

library/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 {

library/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 {

library/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,

library/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
}

library/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
///

library/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>,

library/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 {

0 commit comments

Comments
 (0)