Skip to content
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

Rollup of 7 pull requests #131881

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
24810b0
Partially stabilize const_pin
GKFX Sep 9, 2024
3ed5d55
Fix predicate signatures in retain_mut docs
collinoc Oct 17, 2024
cdacdae
remove outdated documentation for `repeat_n`
AnthonyMikh Oct 17, 2024
7b2320c
Avoid shadowing user provided types or type aliases in `thread_local!`
jieyouxu Oct 18, 2024
21a0208
Consolidate test collection state in one place
Zalathar Oct 18, 2024
932e9f0
Store test collection context/state in two structs
Zalathar Oct 18, 2024
c4c62a5
Rename `inputs` to `common_inputs_stamp`
Zalathar Oct 18, 2024
3f8d87b
Rename `found_paths` to `found_path_stems`
Zalathar Oct 18, 2024
5540976
Rename `stamp` to `stamp_file_path`
Zalathar Oct 18, 2024
275ec06
Default to the medium code model on OpenHarmony LoongArch target
heiher Oct 18, 2024
cc5fd6a
Store path stems in a BTreeSet
Zalathar Oct 18, 2024
4277160
checktools.sh: add link to issue for more context about disabled Miri…
RalfJung Oct 18, 2024
421ce58
Rollup merge of #130136 - GKFX:stabilize-const-pin, r=dtolnay
jhpratt Oct 18, 2024
c3fcc0d
Rollup merge of #131809 - collinoc:fix-retain-mut-docs, r=jhpratt
jhpratt Oct 18, 2024
c4edbb2
Rollup merge of #131858 - AnthonyMikh:AnthonyMikh/repeat_n-is-not-tha…
jhpratt Oct 18, 2024
a9d80cb
Rollup merge of #131866 - jieyouxu:thread_local, r=jhpratt
jhpratt Oct 18, 2024
bf05fa6
Rollup merge of #131870 - Zalathar:test-collector, r=jieyouxu
jhpratt Oct 18, 2024
85fe025
Rollup merge of #131874 - heiher:loong-ohos-medium, r=jieyouxu
jhpratt Oct 18, 2024
79e763a
Rollup merge of #131877 - RalfJung:checktools-comment, r=ChrisDenton
jhpratt Oct 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::spec::{SanitizerSet, Target, TargetOptions, base};
use crate::spec::{CodeModel, SanitizerSet, Target, TargetOptions, base};

pub(crate) fn target() -> Target {
Target {
Expand All @@ -13,6 +13,7 @@ pub(crate) fn target() -> Target {
data_layout: "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128".into(),
arch: "loongarch64".into(),
options: TargetOptions {
code_model: Some(CodeModel::Medium),
cpu: "generic".into(),
features: "+f,+d".into(),
llvm_abiname: "lp64d".into(),
Expand Down
2 changes: 1 addition & 1 deletion library/alloc/src/collections/linked_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1082,7 +1082,7 @@ impl<T, A: Allocator> LinkedList<T, A> {

/// Retains only the elements specified by the predicate.
///
/// In other words, remove all elements `e` for which `f(&e)` returns false.
/// In other words, remove all elements `e` for which `f(&mut e)` returns false.
/// This method operates in place, visiting each element exactly once in the
/// original order, and preserves the order of the retained elements.
///
Expand Down
2 changes: 1 addition & 1 deletion library/alloc/src/collections/vec_deque/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2122,7 +2122,7 @@ impl<T, A: Allocator> VecDeque<T, A> {

/// Retains only the elements specified by the predicate.
///
/// In other words, remove all elements `e` for which `f(&e)` returns false.
/// In other words, remove all elements `e` for which `f(&mut e)` returns false.
/// This method operates in place, visiting each element exactly once in the
/// original order, and preserves the order of the retained elements.
///
Expand Down
1 change: 0 additions & 1 deletion library/alloc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@
#![feature(const_eval_select)]
#![feature(const_heap)]
#![feature(const_maybe_uninit_write)]
#![feature(const_pin)]
#![feature(const_size_of_val)]
#![feature(const_vec_string_slice)]
#![feature(core_intrinsics)]
Expand Down
4 changes: 1 addition & 3 deletions library/core/src/iter/sources/repeat_n.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ use crate::num::NonZero;
/// The `repeat_n()` function repeats a single value exactly `n` times.
///
/// This is very similar to using [`repeat()`] with [`Iterator::take()`],
/// but there are two differences:
/// - `repeat_n()` can return the original value, rather than always cloning.
/// - `repeat_n()` produces an [`ExactSizeIterator`].
/// but `repeat_n()` can return the original value, rather than always cloning.
///
/// [`repeat()`]: crate::iter::repeat
///
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
#![feature(const_nonnull_new)]
#![feature(const_num_midpoint)]
#![feature(const_option_ext)]
#![feature(const_pin)]
#![feature(const_pin_2)]
#![feature(const_pointer_is_aligned)]
#![feature(const_ptr_is_null)]
#![feature(const_ptr_sub_ptr)]
Expand Down
20 changes: 10 additions & 10 deletions library/core/src/pin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1186,7 +1186,7 @@ impl<Ptr: Deref<Target: Unpin>> Pin<Ptr> {
/// let mut pinned: Pin<&mut u8> = Pin::new(&mut val);
/// ```
#[inline(always)]
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
#[rustc_const_stable(feature = "const_pin", since = "CURRENT_RUSTC_VERSION")]
#[stable(feature = "pin", since = "1.33.0")]
pub const fn new(pointer: Ptr) -> Pin<Ptr> {
// SAFETY: the value pointed to is `Unpin`, and so has no requirements
Expand Down Expand Up @@ -1214,7 +1214,7 @@ impl<Ptr: Deref<Target: Unpin>> Pin<Ptr> {
/// assert_eq!(*r, 5);
/// ```
#[inline(always)]
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
#[rustc_const_unstable(feature = "const_pin_2", issue = "76654")]
#[stable(feature = "pin_into_inner", since = "1.39.0")]
pub const fn into_inner(pin: Pin<Ptr>) -> Ptr {
pin.__pointer
Expand Down Expand Up @@ -1351,7 +1351,7 @@ impl<Ptr: Deref> Pin<Ptr> {
/// [`pin` module docs]: self
#[lang = "new_unchecked"]
#[inline(always)]
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
#[rustc_const_stable(feature = "const_pin", since = "CURRENT_RUSTC_VERSION")]
#[stable(feature = "pin", since = "1.33.0")]
pub const unsafe fn new_unchecked(pointer: Ptr) -> Pin<Ptr> {
Pin { __pointer: pointer }
Expand Down Expand Up @@ -1503,7 +1503,7 @@ impl<Ptr: Deref> Pin<Ptr> {
/// If the underlying data is [`Unpin`], [`Pin::into_inner`] should be used
/// instead.
#[inline(always)]
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
#[rustc_const_unstable(feature = "const_pin_2", issue = "76654")]
#[stable(feature = "pin_into_inner", since = "1.39.0")]
pub const unsafe fn into_inner_unchecked(pin: Pin<Ptr>) -> Ptr {
pin.__pointer
Expand Down Expand Up @@ -1559,7 +1559,7 @@ impl<'a, T: ?Sized> Pin<&'a T> {
/// ["pinning projections"]: self#projections-and-structural-pinning
#[inline(always)]
#[must_use]
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
#[rustc_const_stable(feature = "const_pin", since = "CURRENT_RUSTC_VERSION")]
#[stable(feature = "pin", since = "1.33.0")]
pub const fn get_ref(self) -> &'a T {
self.__pointer
Expand All @@ -1570,7 +1570,7 @@ impl<'a, T: ?Sized> Pin<&'a mut T> {
/// Converts this `Pin<&mut T>` into a `Pin<&T>` with the same lifetime.
#[inline(always)]
#[must_use = "`self` will be dropped if the result is not used"]
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
#[rustc_const_stable(feature = "const_pin", since = "CURRENT_RUSTC_VERSION")]
#[stable(feature = "pin", since = "1.33.0")]
pub const fn into_ref(self) -> Pin<&'a T> {
Pin { __pointer: self.__pointer }
Expand All @@ -1588,7 +1588,7 @@ impl<'a, T: ?Sized> Pin<&'a mut T> {
#[inline(always)]
#[must_use = "`self` will be dropped if the result is not used"]
#[stable(feature = "pin", since = "1.33.0")]
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
#[rustc_const_stable(feature = "const_pin", since = "CURRENT_RUSTC_VERSION")]
pub const fn get_mut(self) -> &'a mut T
where
T: Unpin,
Expand All @@ -1609,7 +1609,7 @@ impl<'a, T: ?Sized> Pin<&'a mut T> {
#[inline(always)]
#[must_use = "`self` will be dropped if the result is not used"]
#[stable(feature = "pin", since = "1.33.0")]
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
#[rustc_const_stable(feature = "const_pin", since = "CURRENT_RUSTC_VERSION")]
pub const unsafe fn get_unchecked_mut(self) -> &'a mut T {
self.__pointer
}
Expand Down Expand Up @@ -1652,7 +1652,7 @@ impl<T: ?Sized> Pin<&'static T> {
/// This is safe because `T` is borrowed immutably for the `'static` lifetime, which
/// never ends.
#[stable(feature = "pin_static_ref", since = "1.61.0")]
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
#[rustc_const_stable(feature = "const_pin", since = "CURRENT_RUSTC_VERSION")]
pub const fn static_ref(r: &'static T) -> Pin<&'static T> {
// SAFETY: The 'static borrow guarantees the data will not be
// moved/invalidated until it gets dropped (which is never).
Expand All @@ -1666,7 +1666,7 @@ impl<T: ?Sized> Pin<&'static mut T> {
/// This is safe because `T` is borrowed for the `'static` lifetime, which
/// never ends.
#[stable(feature = "pin_static_ref", since = "1.61.0")]
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
#[rustc_const_stable(feature = "const_pin", since = "CURRENT_RUSTC_VERSION")]
pub const fn static_mut(r: &'static mut T) -> Pin<&'static mut T> {
// SAFETY: The 'static borrow guarantees the data will not be
// moved/invalidated until it gets dropped (which is never).
Expand Down
2 changes: 1 addition & 1 deletion library/core/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#![feature(const_likely)]
#![feature(const_nonnull_new)]
#![feature(const_option_ext)]
#![feature(const_pin)]
#![feature(const_pin_2)]
#![feature(const_pointer_is_aligned)]
#![feature(const_three_way_compare)]
#![feature(const_trait_impl)]
Expand Down
4 changes: 4 additions & 0 deletions library/core/tests/pin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ fn pin_const() {
const REF: &'static usize = PINNED.get_ref();
assert_eq!(REF, POINTER);

const INT: u8 = 42;
const STATIC_REF: Pin<&'static u8> = Pin::static_ref(&INT);
assert_eq!(*STATIC_REF, INT);

// Note: `pin_mut_const` tests that the methods of `Pin<&mut T>` are usable in a const context.
// A const fn is used because `&mut` is not (yet) usable in constants.
const fn pin_mut_const() {
Expand Down
31 changes: 15 additions & 16 deletions library/std/src/sys/thread_local/native/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,21 @@ pub use lazy::Storage as LazyStorage;
#[unstable(feature = "thread_local_internals", issue = "none")]
#[rustc_macro_transparency = "semitransparent"]
pub macro thread_local_inner {
// used to generate the `LocalKey` value for const-initialized thread locals
// NOTE: we cannot import `LocalKey`, `LazyStorage` or `EagerStorage` with a `use` because that
// can shadow user provided type or type alias with a matching name. Please update the shadowing
// test in `tests/thread.rs` if these types are renamed.

// Used to generate the `LocalKey` value for const-initialized thread locals.
(@key $t:ty, const $init:expr) => {{
const __INIT: $t = $init;

unsafe {
use $crate::mem::needs_drop;
use $crate::thread::LocalKey;
use $crate::thread::local_impl::EagerStorage;

LocalKey::new(const {
if needs_drop::<$t>() {
$crate::thread::LocalKey::new(const {
if $crate::mem::needs_drop::<$t>() {
|_| {
#[thread_local]
static VAL: EagerStorage<$t> = EagerStorage::new(__INIT);
static VAL: $crate::thread::local_impl::EagerStorage<$t>
= $crate::thread::local_impl::EagerStorage::new(__INIT);
VAL.get()
}
} else {
Expand All @@ -84,21 +85,19 @@ pub macro thread_local_inner {
}

unsafe {
use $crate::mem::needs_drop;
use $crate::thread::LocalKey;
use $crate::thread::local_impl::LazyStorage;

LocalKey::new(const {
if needs_drop::<$t>() {
$crate::thread::LocalKey::new(const {
if $crate::mem::needs_drop::<$t>() {
|init| {
#[thread_local]
static VAL: LazyStorage<$t, ()> = LazyStorage::new();
static VAL: $crate::thread::local_impl::LazyStorage<$t, ()>
= $crate::thread::local_impl::LazyStorage::new();
VAL.get_or_init(init, __init)
}
} else {
|init| {
#[thread_local]
static VAL: LazyStorage<$t, !> = LazyStorage::new();
static VAL: $crate::thread::local_impl::LazyStorage<$t, !>
= $crate::thread::local_impl::LazyStorage::new();
VAL.get_or_init(init, __init)
}
}
Expand Down
17 changes: 11 additions & 6 deletions library/std/src/sys/thread_local/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,24 @@ pub macro thread_local_inner {
$crate::thread::local_impl::thread_local_inner!(@key $t, { const INIT_EXPR: $t = $init; INIT_EXPR })
},

// used to generate the `LocalKey` value for `thread_local!`
// NOTE: we cannot import `Storage` or `LocalKey` with a `use` because that can shadow user
// provided type or type alias with a matching name. Please update the shadowing test in
// `tests/thread.rs` if these types are renamed.

// used to generate the `LocalKey` value for `thread_local!`.
(@key $t:ty, $init:expr) => {{
#[inline]
fn __init() -> $t { $init }

// NOTE: this cannot import `LocalKey` or `Storage` with a `use` because that can shadow
// user provided type or type alias with a matching name. Please update the shadowing test
// in `tests/thread.rs` if these types are renamed.
unsafe {
use $crate::thread::LocalKey;
use $crate::thread::local_impl::Storage;

// Inlining does not work on windows-gnu due to linking errors around
// dllimports. See https://github.com/rust-lang/rust/issues/109797.
LocalKey::new(#[cfg_attr(windows, inline(never))] |init| {
static VAL: Storage<$t> = Storage::new();
$crate::thread::LocalKey::new(#[cfg_attr(windows, inline(never))] |init| {
static VAL: $crate::thread::local_impl::Storage<$t>
= $crate::thread::local_impl::Storage::new();
VAL.get(init, __init)
})
}
Expand Down
23 changes: 23 additions & 0 deletions library/std/tests/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,29 @@ fn thread_local_containing_const_statements() {
assert_eq!(REFCELL.take(), 1);
}

#[test]
fn thread_local_hygeiene() {
// Previously `thread_local_inner!` had use imports for `LocalKey`, `Storage`, `EagerStorage`
// and `LazyStorage`. The use imports will shadow a user-provided type or type alias if the
// user-provided type or type alias has the same name. Make sure that this does not happen. See
// <https://github.com/rust-lang/rust/issues/131863>.
//
// NOTE: if the internal implementation details change (i.e. get renamed), this test should be
// updated.

#![allow(dead_code)]
type LocalKey = ();
type Storage = ();
type LazyStorage = ();
type EagerStorage = ();
thread_local! {
static A: LocalKey = const { () };
static B: Storage = const { () };
static C: LazyStorage = const { () };
static D: EagerStorage = const { () };
}
}

#[test]
// Include an ignore list on purpose, so that new platforms don't miss it
#[cfg_attr(
Expand Down
2 changes: 2 additions & 0 deletions src/ci/docker/host-x86_64/x86_64-gnu-tools/checktools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ case $HOST_TARGET in
# "error: cannot produce cdylib for ... as the target ... does not support these crate types".
# Only run "pass" tests, which is quite a bit faster.
#FIXME: Re-enable this once CI issues are fixed
# See <https://github.com/rust-lang/rust/issues/127883>
# For now, these tests are moved to `x86_64-msvc-ext2` in `src/ci/github-actions/jobs.yml`.
#python3 "$X_PY" test --stage 2 src/tools/miri --target aarch64-apple-darwin --test-args pass
#python3 "$X_PY" test --stage 2 src/tools/miri --target i686-pc-windows-gnu --test-args pass
;;
Expand Down
2 changes: 2 additions & 0 deletions src/ci/github-actions/jobs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,8 @@ auto:
<<: *job-windows-8c

# Temporary builder to workaround CI issues
# See <https://github.com/rust-lang/rust/issues/127883>
#FIXME: Remove this, and re-enable the same tests in `checktools.sh`, once CI issues are fixed.
- image: x86_64-msvc-ext2
env:
SCRIPT: >
Expand Down
Loading
Loading