Skip to content

Commit 1350eea

Browse files
committed
Auto merge of #131887 - jieyouxu:rollup-ftik4ni, r=jieyouxu
Rollup of 9 pull requests Successful merges: - #130136 (Partially stabilize const_pin) - #131755 (Regression test for AVR `rjmp` offset) - #131774 (Add getentropy for RTEMS) - #131802 (Dont ICE when computing coverage of synthetic async closure body) - #131809 (Fix predicate signatures in retain_mut docs) - #131858 (Remove outdated documentation for `repeat_n`) - #131866 (Avoid use imports in `thread_local_inner!`) - #131874 (Default to the medium code model on OpenHarmony LoongArch target) - #131877 (checktools.sh: add link to issue for more context about disabled Miri tests) r? `@ghost` `@rustbot` modify labels: rollup
2 parents acfdb8d + 80a8f7b commit 1350eea

File tree

26 files changed

+287
-60
lines changed

26 files changed

+287
-60
lines changed

compiler/rustc_middle/src/query/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,7 @@ rustc_queries! {
570570
/// either `#[coverage(on)]` or no coverage attribute was found.
571571
query coverage_attr_on(key: LocalDefId) -> bool {
572572
desc { |tcx| "checking for `#[coverage(..)]` on `{}`", tcx.def_path_str(key) }
573+
feedable
573574
}
574575

575576
/// Summarizes coverage IDs inserted by the `InstrumentCoverage` MIR pass

compiler/rustc_mir_transform/src/coroutine/by_move_body.rs

+1
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ pub(crate) fn coroutine_by_move_body_def_id<'tcx>(
223223

224224
// Inherited from the by-ref coroutine.
225225
body_def.codegen_fn_attrs(tcx.codegen_fn_attrs(coroutine_def_id).clone());
226+
body_def.coverage_attr_on(tcx.coverage_attr_on(coroutine_def_id));
226227
body_def.constness(tcx.constness(coroutine_def_id));
227228
body_def.coroutine_kind(tcx.coroutine_kind(coroutine_def_id));
228229
body_def.def_ident_span(tcx.def_ident_span(coroutine_def_id));

compiler/rustc_mir_transform/src/coverage/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,11 @@ fn extract_hir_info<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> ExtractedHir
524524
// FIXME(#79625): Consider improving MIR to provide the information needed, to avoid going back
525525
// to HIR for it.
526526

527+
// HACK: For synthetic MIR bodies (async closures), use the def id of the HIR body.
528+
if tcx.is_synthetic_mir(def_id) {
529+
return extract_hir_info(tcx, tcx.local_parent(def_id));
530+
}
531+
527532
let hir_node = tcx.hir_node_by_def_id(def_id);
528533
let fn_body_id = hir_node.body_id().expect("HIR node is a function with body");
529534
let hir_body = tcx.hir().body(fn_body_id);

compiler/rustc_target/src/spec/targets/loongarch64_unknown_linux_ohos.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::spec::{SanitizerSet, Target, TargetOptions, base};
1+
use crate::spec::{CodeModel, SanitizerSet, Target, TargetOptions, base};
22

33
pub(crate) fn target() -> Target {
44
Target {
@@ -13,6 +13,7 @@ pub(crate) fn target() -> Target {
1313
data_layout: "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128".into(),
1414
arch: "loongarch64".into(),
1515
options: TargetOptions {
16+
code_model: Some(CodeModel::Medium),
1617
cpu: "generic".into(),
1718
features: "+f,+d".into(),
1819
llvm_abiname: "lp64d".into(),

library/alloc/src/collections/linked_list.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1082,7 +1082,7 @@ impl<T, A: Allocator> LinkedList<T, A> {
10821082

10831083
/// Retains only the elements specified by the predicate.
10841084
///
1085-
/// In other words, remove all elements `e` for which `f(&e)` returns false.
1085+
/// In other words, remove all elements `e` for which `f(&mut e)` returns false.
10861086
/// This method operates in place, visiting each element exactly once in the
10871087
/// original order, and preserves the order of the retained elements.
10881088
///

library/alloc/src/collections/vec_deque/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2122,7 +2122,7 @@ impl<T, A: Allocator> VecDeque<T, A> {
21222122

21232123
/// Retains only the elements specified by the predicate.
21242124
///
2125-
/// In other words, remove all elements `e` for which `f(&e)` returns false.
2125+
/// In other words, remove all elements `e` for which `f(&mut e)` returns false.
21262126
/// This method operates in place, visiting each element exactly once in the
21272127
/// original order, and preserves the order of the retained elements.
21282128
///

library/alloc/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@
112112
#![feature(const_eval_select)]
113113
#![feature(const_heap)]
114114
#![feature(const_maybe_uninit_write)]
115-
#![feature(const_pin)]
116115
#![feature(const_size_of_val)]
117116
#![feature(const_vec_string_slice)]
118117
#![feature(core_intrinsics)]

library/core/src/iter/sources/repeat_n.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ use crate::num::NonZero;
88
/// The `repeat_n()` function repeats a single value exactly `n` times.
99
///
1010
/// This is very similar to using [`repeat()`] with [`Iterator::take()`],
11-
/// but there are two differences:
12-
/// - `repeat_n()` can return the original value, rather than always cloning.
13-
/// - `repeat_n()` produces an [`ExactSizeIterator`].
11+
/// but `repeat_n()` can return the original value, rather than always cloning.
1412
///
1513
/// [`repeat()`]: crate::iter::repeat
1614
///

library/core/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@
129129
#![feature(const_nonnull_new)]
130130
#![feature(const_num_midpoint)]
131131
#![feature(const_option_ext)]
132-
#![feature(const_pin)]
132+
#![feature(const_pin_2)]
133133
#![feature(const_pointer_is_aligned)]
134134
#![feature(const_ptr_is_null)]
135135
#![feature(const_ptr_sub_ptr)]

library/core/src/pin.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -1186,7 +1186,7 @@ impl<Ptr: Deref<Target: Unpin>> Pin<Ptr> {
11861186
/// let mut pinned: Pin<&mut u8> = Pin::new(&mut val);
11871187
/// ```
11881188
#[inline(always)]
1189-
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
1189+
#[rustc_const_stable(feature = "const_pin", since = "CURRENT_RUSTC_VERSION")]
11901190
#[stable(feature = "pin", since = "1.33.0")]
11911191
pub const fn new(pointer: Ptr) -> Pin<Ptr> {
11921192
// SAFETY: the value pointed to is `Unpin`, and so has no requirements
@@ -1214,7 +1214,7 @@ impl<Ptr: Deref<Target: Unpin>> Pin<Ptr> {
12141214
/// assert_eq!(*r, 5);
12151215
/// ```
12161216
#[inline(always)]
1217-
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
1217+
#[rustc_const_unstable(feature = "const_pin_2", issue = "76654")]
12181218
#[stable(feature = "pin_into_inner", since = "1.39.0")]
12191219
pub const fn into_inner(pin: Pin<Ptr>) -> Ptr {
12201220
pin.__pointer
@@ -1351,7 +1351,7 @@ impl<Ptr: Deref> Pin<Ptr> {
13511351
/// [`pin` module docs]: self
13521352
#[lang = "new_unchecked"]
13531353
#[inline(always)]
1354-
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
1354+
#[rustc_const_stable(feature = "const_pin", since = "CURRENT_RUSTC_VERSION")]
13551355
#[stable(feature = "pin", since = "1.33.0")]
13561356
pub const unsafe fn new_unchecked(pointer: Ptr) -> Pin<Ptr> {
13571357
Pin { __pointer: pointer }
@@ -1503,7 +1503,7 @@ impl<Ptr: Deref> Pin<Ptr> {
15031503
/// If the underlying data is [`Unpin`], [`Pin::into_inner`] should be used
15041504
/// instead.
15051505
#[inline(always)]
1506-
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
1506+
#[rustc_const_unstable(feature = "const_pin_2", issue = "76654")]
15071507
#[stable(feature = "pin_into_inner", since = "1.39.0")]
15081508
pub const unsafe fn into_inner_unchecked(pin: Pin<Ptr>) -> Ptr {
15091509
pin.__pointer
@@ -1559,7 +1559,7 @@ impl<'a, T: ?Sized> Pin<&'a T> {
15591559
/// ["pinning projections"]: self#projections-and-structural-pinning
15601560
#[inline(always)]
15611561
#[must_use]
1562-
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
1562+
#[rustc_const_stable(feature = "const_pin", since = "CURRENT_RUSTC_VERSION")]
15631563
#[stable(feature = "pin", since = "1.33.0")]
15641564
pub const fn get_ref(self) -> &'a T {
15651565
self.__pointer
@@ -1570,7 +1570,7 @@ impl<'a, T: ?Sized> Pin<&'a mut T> {
15701570
/// Converts this `Pin<&mut T>` into a `Pin<&T>` with the same lifetime.
15711571
#[inline(always)]
15721572
#[must_use = "`self` will be dropped if the result is not used"]
1573-
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
1573+
#[rustc_const_stable(feature = "const_pin", since = "CURRENT_RUSTC_VERSION")]
15741574
#[stable(feature = "pin", since = "1.33.0")]
15751575
pub const fn into_ref(self) -> Pin<&'a T> {
15761576
Pin { __pointer: self.__pointer }
@@ -1588,7 +1588,7 @@ impl<'a, T: ?Sized> Pin<&'a mut T> {
15881588
#[inline(always)]
15891589
#[must_use = "`self` will be dropped if the result is not used"]
15901590
#[stable(feature = "pin", since = "1.33.0")]
1591-
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
1591+
#[rustc_const_stable(feature = "const_pin", since = "CURRENT_RUSTC_VERSION")]
15921592
pub const fn get_mut(self) -> &'a mut T
15931593
where
15941594
T: Unpin,
@@ -1609,7 +1609,7 @@ impl<'a, T: ?Sized> Pin<&'a mut T> {
16091609
#[inline(always)]
16101610
#[must_use = "`self` will be dropped if the result is not used"]
16111611
#[stable(feature = "pin", since = "1.33.0")]
1612-
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
1612+
#[rustc_const_stable(feature = "const_pin", since = "CURRENT_RUSTC_VERSION")]
16131613
pub const unsafe fn get_unchecked_mut(self) -> &'a mut T {
16141614
self.__pointer
16151615
}
@@ -1652,7 +1652,7 @@ impl<T: ?Sized> Pin<&'static T> {
16521652
/// This is safe because `T` is borrowed immutably for the `'static` lifetime, which
16531653
/// never ends.
16541654
#[stable(feature = "pin_static_ref", since = "1.61.0")]
1655-
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
1655+
#[rustc_const_stable(feature = "const_pin", since = "CURRENT_RUSTC_VERSION")]
16561656
pub const fn static_ref(r: &'static T) -> Pin<&'static T> {
16571657
// SAFETY: The 'static borrow guarantees the data will not be
16581658
// moved/invalidated until it gets dropped (which is never).
@@ -1666,7 +1666,7 @@ impl<T: ?Sized> Pin<&'static mut T> {
16661666
/// This is safe because `T` is borrowed for the `'static` lifetime, which
16671667
/// never ends.
16681668
#[stable(feature = "pin_static_ref", since = "1.61.0")]
1669-
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
1669+
#[rustc_const_stable(feature = "const_pin", since = "CURRENT_RUSTC_VERSION")]
16701670
pub const fn static_mut(r: &'static mut T) -> Pin<&'static mut T> {
16711671
// SAFETY: The 'static borrow guarantees the data will not be
16721672
// moved/invalidated until it gets dropped (which is never).

library/core/tests/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#![feature(const_likely)]
2222
#![feature(const_nonnull_new)]
2323
#![feature(const_option_ext)]
24-
#![feature(const_pin)]
24+
#![feature(const_pin_2)]
2525
#![feature(const_pointer_is_aligned)]
2626
#![feature(const_three_way_compare)]
2727
#![feature(const_trait_impl)]

library/core/tests/pin.rs

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ fn pin_const() {
1919
const REF: &'static usize = PINNED.get_ref();
2020
assert_eq!(REF, POINTER);
2121

22+
const INT: u8 = 42;
23+
const STATIC_REF: Pin<&'static u8> = Pin::static_ref(&INT);
24+
assert_eq!(*STATIC_REF, INT);
25+
2226
// Note: `pin_mut_const` tests that the methods of `Pin<&mut T>` are usable in a const context.
2327
// A const fn is used because `&mut` is not (yet) usable in constants.
2428
const fn pin_mut_const() {

library/std/src/random.rs

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ use crate::sys::random as sys;
4040
/// Horizon | `getrandom` shim
4141
/// Hurd, L4Re, QNX | `/dev/urandom`
4242
/// Redox | `/scheme/rand`
43+
/// RTEMS | [`arc4random_buf`](https://docs.rtems.org/branches/master/bsp-howto/getentropy.html)
4344
/// SGX | [`rdrand`](https://en.wikipedia.org/wiki/RDRAND)
4445
/// SOLID | `SOLID_RNG_SampleRandomBytes`
4546
/// TEEOS | `TEE_GenerateRandom`

library/std/src/sys/random/arc4random.rs

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#[cfg(not(any(
1313
target_os = "haiku",
1414
target_os = "illumos",
15+
target_os = "rtems",
1516
target_os = "solaris",
1617
target_os = "vita",
1718
)))]
@@ -21,6 +22,7 @@ use libc::arc4random_buf;
2122
#[cfg(any(
2223
target_os = "haiku", // See https://git.haiku-os.org/haiku/tree/headers/compatibility/bsd/stdlib.h
2324
target_os = "illumos", // See https://www.illumos.org/man/3C/arc4random
25+
target_os = "rtems", // See https://docs.rtems.org/branches/master/bsp-howto/getentropy.html
2426
target_os = "solaris", // See https://docs.oracle.com/cd/E88353_01/html/E37843/arc4random-3c.html
2527
target_os = "vita", // See https://github.com/vitasdk/newlib/blob/b89e5bc183b516945f9ee07eef483ecb916e45ff/newlib/libc/include/stdlib.h#L74
2628
))]

library/std/src/sys/random/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ cfg_if::cfg_if! {
1717
target_os = "illumos",
1818
target_os = "netbsd",
1919
target_os = "openbsd",
20+
target_os = "rtems",
2021
target_os = "solaris",
2122
target_os = "vita",
2223
))] {

library/std/src/sys/thread_local/native/mod.rs

+15-16
Original file line numberDiff line numberDiff line change
@@ -49,20 +49,21 @@ pub use lazy::Storage as LazyStorage;
4949
#[unstable(feature = "thread_local_internals", issue = "none")]
5050
#[rustc_macro_transparency = "semitransparent"]
5151
pub macro thread_local_inner {
52-
// used to generate the `LocalKey` value for const-initialized thread locals
52+
// NOTE: we cannot import `LocalKey`, `LazyStorage` or `EagerStorage` with a `use` because that
53+
// can shadow user provided type or type alias with a matching name. Please update the shadowing
54+
// test in `tests/thread.rs` if these types are renamed.
55+
56+
// Used to generate the `LocalKey` value for const-initialized thread locals.
5357
(@key $t:ty, const $init:expr) => {{
5458
const __INIT: $t = $init;
5559

5660
unsafe {
57-
use $crate::mem::needs_drop;
58-
use $crate::thread::LocalKey;
59-
use $crate::thread::local_impl::EagerStorage;
60-
61-
LocalKey::new(const {
62-
if needs_drop::<$t>() {
61+
$crate::thread::LocalKey::new(const {
62+
if $crate::mem::needs_drop::<$t>() {
6363
|_| {
6464
#[thread_local]
65-
static VAL: EagerStorage<$t> = EagerStorage::new(__INIT);
65+
static VAL: $crate::thread::local_impl::EagerStorage<$t>
66+
= $crate::thread::local_impl::EagerStorage::new(__INIT);
6667
VAL.get()
6768
}
6869
} else {
@@ -84,21 +85,19 @@ pub macro thread_local_inner {
8485
}
8586

8687
unsafe {
87-
use $crate::mem::needs_drop;
88-
use $crate::thread::LocalKey;
89-
use $crate::thread::local_impl::LazyStorage;
90-
91-
LocalKey::new(const {
92-
if needs_drop::<$t>() {
88+
$crate::thread::LocalKey::new(const {
89+
if $crate::mem::needs_drop::<$t>() {
9390
|init| {
9491
#[thread_local]
95-
static VAL: LazyStorage<$t, ()> = LazyStorage::new();
92+
static VAL: $crate::thread::local_impl::LazyStorage<$t, ()>
93+
= $crate::thread::local_impl::LazyStorage::new();
9694
VAL.get_or_init(init, __init)
9795
}
9896
} else {
9997
|init| {
10098
#[thread_local]
101-
static VAL: LazyStorage<$t, !> = LazyStorage::new();
99+
static VAL: $crate::thread::local_impl::LazyStorage<$t, !>
100+
= $crate::thread::local_impl::LazyStorage::new();
102101
VAL.get_or_init(init, __init)
103102
}
104103
}

library/std/src/sys/thread_local/os.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,24 @@ pub macro thread_local_inner {
1515
$crate::thread::local_impl::thread_local_inner!(@key $t, { const INIT_EXPR: $t = $init; INIT_EXPR })
1616
},
1717

18-
// used to generate the `LocalKey` value for `thread_local!`
18+
// NOTE: we cannot import `Storage` or `LocalKey` with a `use` because that can shadow user
19+
// provided type or type alias with a matching name. Please update the shadowing test in
20+
// `tests/thread.rs` if these types are renamed.
21+
22+
// used to generate the `LocalKey` value for `thread_local!`.
1923
(@key $t:ty, $init:expr) => {{
2024
#[inline]
2125
fn __init() -> $t { $init }
2226

27+
// NOTE: this cannot import `LocalKey` or `Storage` with a `use` because that can shadow
28+
// user provided type or type alias with a matching name. Please update the shadowing test
29+
// in `tests/thread.rs` if these types are renamed.
2330
unsafe {
24-
use $crate::thread::LocalKey;
25-
use $crate::thread::local_impl::Storage;
26-
2731
// Inlining does not work on windows-gnu due to linking errors around
2832
// dllimports. See https://github.com/rust-lang/rust/issues/109797.
29-
LocalKey::new(#[cfg_attr(windows, inline(never))] |init| {
30-
static VAL: Storage<$t> = Storage::new();
33+
$crate::thread::LocalKey::new(#[cfg_attr(windows, inline(never))] |init| {
34+
static VAL: $crate::thread::local_impl::Storage<$t>
35+
= $crate::thread::local_impl::Storage::new();
3136
VAL.get(init, __init)
3237
})
3338
}

library/std/tests/thread.rs

+23
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,29 @@ fn thread_local_containing_const_statements() {
3838
assert_eq!(REFCELL.take(), 1);
3939
}
4040

41+
#[test]
42+
fn thread_local_hygeiene() {
43+
// Previously `thread_local_inner!` had use imports for `LocalKey`, `Storage`, `EagerStorage`
44+
// and `LazyStorage`. The use imports will shadow a user-provided type or type alias if the
45+
// user-provided type or type alias has the same name. Make sure that this does not happen. See
46+
// <https://github.com/rust-lang/rust/issues/131863>.
47+
//
48+
// NOTE: if the internal implementation details change (i.e. get renamed), this test should be
49+
// updated.
50+
51+
#![allow(dead_code)]
52+
type LocalKey = ();
53+
type Storage = ();
54+
type LazyStorage = ();
55+
type EagerStorage = ();
56+
thread_local! {
57+
static A: LocalKey = const { () };
58+
static B: Storage = const { () };
59+
static C: LazyStorage = const { () };
60+
static D: EagerStorage = const { () };
61+
}
62+
}
63+
4164
#[test]
4265
// Include an ignore list on purpose, so that new platforms don't miss it
4366
#[cfg_attr(

src/ci/docker/host-x86_64/x86_64-gnu-tools/checktools.sh

+2
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ case $HOST_TARGET in
5959
# "error: cannot produce cdylib for ... as the target ... does not support these crate types".
6060
# Only run "pass" tests, which is quite a bit faster.
6161
#FIXME: Re-enable this once CI issues are fixed
62+
# See <https://github.com/rust-lang/rust/issues/127883>
63+
# For now, these tests are moved to `x86_64-msvc-ext2` in `src/ci/github-actions/jobs.yml`.
6264
#python3 "$X_PY" test --stage 2 src/tools/miri --target aarch64-apple-darwin --test-args pass
6365
#python3 "$X_PY" test --stage 2 src/tools/miri --target i686-pc-windows-gnu --test-args pass
6466
;;

src/ci/github-actions/jobs.yml

+2
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,8 @@ auto:
386386
<<: *job-windows-8c
387387

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

0 commit comments

Comments
 (0)