Skip to content

Commit 1d37ed6

Browse files
committed
Auto merge of #101611 - GuillaumeGomez:rollup-yw3qtug, r=GuillaumeGomez
Rollup of 5 pull requests Successful merges: - #101475 (Use futex-based locks and thread parker on Hermit) - #101492 (Suggest adding array lengths to references to arrays if possible) - #101495 (Compile spin_loop_hint as pause on x86 even without sse2 enabled) - #101529 (Fix the example code and doctest for Formatter::sign_plus) - #101600 (rustdoc: simplify the codeblock tooltip) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 98f3001 + 2e258ce commit 1d37ed6

File tree

21 files changed

+244
-580
lines changed

21 files changed

+244
-580
lines changed

Diff for: Cargo.lock

+4-3
Original file line numberDiff line numberDiff line change
@@ -1656,12 +1656,13 @@ dependencies = [
16561656

16571657
[[package]]
16581658
name = "hermit-abi"
1659-
version = "0.2.0"
1659+
version = "0.2.6"
16601660
source = "registry+https://github.com/rust-lang/crates.io-index"
1661-
checksum = "1ab7905ea95c6d9af62940f9d7dd9596d54c334ae2c15300c482051292d5637f"
1661+
checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7"
16621662
dependencies = [
16631663
"compiler_builtins",
16641664
"libc",
1665+
"rustc-std-workspace-alloc",
16651666
"rustc-std-workspace-core",
16661667
]
16671668

@@ -4608,7 +4609,7 @@ dependencies = [
46084609
"dlmalloc",
46094610
"fortanix-sgx-abi",
46104611
"hashbrown",
4611-
"hermit-abi 0.2.0",
4612+
"hermit-abi 0.2.6",
46124613
"libc",
46134614
"miniz_oxide 0.4.0",
46144615
"object 0.26.2",

Diff for: compiler/rustc_hir/src/hir.rs

+8
Original file line numberDiff line numberDiff line change
@@ -2401,6 +2401,14 @@ impl<'hir> Ty<'hir> {
24012401
_ => None,
24022402
}
24032403
}
2404+
2405+
pub fn peel_refs(&self) -> &Self {
2406+
let mut final_ty = self;
2407+
while let TyKind::Rptr(_, MutTy { ty, .. }) = &final_ty.kind {
2408+
final_ty = &ty;
2409+
}
2410+
final_ty
2411+
}
24042412
}
24052413

24062414
/// Not represented directly in the AST; referred to by name through a `ty_path`.

Diff for: compiler/rustc_typeck/src/check/expr.rs

+23-24
Original file line numberDiff line numberDiff line change
@@ -1305,31 +1305,30 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
13051305
}
13061306

13071307
fn suggest_array_len(&self, expr: &'tcx hir::Expr<'tcx>, array_len: u64) {
1308-
if let Some(parent_hir_id) = self.tcx.hir().find_parent_node(expr.hir_id) {
1309-
let ty = match self.tcx.hir().find(parent_hir_id) {
1310-
Some(
1311-
hir::Node::Local(hir::Local { ty: Some(ty), .. })
1312-
| hir::Node::Item(hir::Item { kind: hir::ItemKind::Const(ty, _), .. }),
1313-
) => Some(ty),
1314-
_ => None,
1315-
};
1316-
if let Some(ty) = ty
1317-
&& let hir::TyKind::Array(_, length) = ty.kind
1318-
&& let hir::ArrayLen::Body(hir::AnonConst { hir_id, .. }) = length
1319-
&& let Some(span) = self.tcx.hir().opt_span(hir_id)
1320-
{
1321-
match self.tcx.sess.diagnostic().steal_diagnostic(span, StashKey::UnderscoreForArrayLengths) {
1322-
Some(mut err) => {
1323-
err.span_suggestion(
1324-
span,
1325-
"consider specifying the array length",
1326-
array_len,
1327-
Applicability::MaybeIncorrect,
1328-
);
1329-
err.emit();
1330-
}
1331-
None => ()
1308+
let parent_node = self.tcx.hir().parent_iter(expr.hir_id).find(|(_, node)| {
1309+
!matches!(node, hir::Node::Expr(hir::Expr { kind: hir::ExprKind::AddrOf(..), .. }))
1310+
});
1311+
let Some((_,
1312+
hir::Node::Local(hir::Local { ty: Some(ty), .. })
1313+
| hir::Node::Item(hir::Item { kind: hir::ItemKind::Const(ty, _), .. }))
1314+
) = parent_node else {
1315+
return
1316+
};
1317+
if let hir::TyKind::Array(_, length) = ty.peel_refs().kind
1318+
&& let hir::ArrayLen::Body(hir::AnonConst { hir_id, .. }) = length
1319+
&& let Some(span) = self.tcx.hir().opt_span(hir_id)
1320+
{
1321+
match self.tcx.sess.diagnostic().steal_diagnostic(span, StashKey::UnderscoreForArrayLengths) {
1322+
Some(mut err) => {
1323+
err.span_suggestion(
1324+
span,
1325+
"consider specifying the array length",
1326+
array_len,
1327+
Applicability::MaybeIncorrect,
1328+
);
1329+
err.emit();
13321330
}
1331+
None => ()
13331332
}
13341333
}
13351334
}

Diff for: library/core/src/fmt/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1819,14 +1819,15 @@ impl<'a> Formatter<'a> {
18191819
/// write!(formatter,
18201820
/// "Foo({}{})",
18211821
/// if self.0 < 0 { '-' } else { '+' },
1822-
/// self.0)
1822+
/// self.0.abs())
18231823
/// } else {
18241824
/// write!(formatter, "Foo({})", self.0)
18251825
/// }
18261826
/// }
18271827
/// }
18281828
///
18291829
/// assert_eq!(&format!("{:+}", Foo(23)), "Foo(+23)");
1830+
/// assert_eq!(&format!("{:+}", Foo(-23)), "Foo(-23)");
18301831
/// assert_eq!(&format!("{}", Foo(23)), "Foo(23)");
18311832
/// ```
18321833
#[must_use]

Diff for: library/core/src/hint.rs

+8-11
Original file line numberDiff line numberDiff line change
@@ -160,19 +160,16 @@ pub const unsafe fn unreachable_unchecked() -> ! {
160160
#[inline]
161161
#[stable(feature = "renamed_spin_loop", since = "1.49.0")]
162162
pub fn spin_loop() {
163-
#[cfg(all(any(target_arch = "x86", target_arch = "x86_64"), target_feature = "sse2"))]
163+
#[cfg(target_arch = "x86")]
164164
{
165-
#[cfg(target_arch = "x86")]
166-
{
167-
// SAFETY: the `cfg` attr ensures that we only execute this on x86 targets.
168-
unsafe { crate::arch::x86::_mm_pause() };
169-
}
165+
// SAFETY: the `cfg` attr ensures that we only execute this on x86 targets.
166+
unsafe { crate::arch::x86::_mm_pause() };
167+
}
170168

171-
#[cfg(target_arch = "x86_64")]
172-
{
173-
// SAFETY: the `cfg` attr ensures that we only execute this on x86_64 targets.
174-
unsafe { crate::arch::x86_64::_mm_pause() };
175-
}
169+
#[cfg(target_arch = "x86_64")]
170+
{
171+
// SAFETY: the `cfg` attr ensures that we only execute this on x86_64 targets.
172+
unsafe { crate::arch::x86_64::_mm_pause() };
176173
}
177174

178175
// RISC-V platform spin loop hint implementation

Diff for: library/std/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ dlmalloc = { version = "0.2.3", features = ['rustc-dep-of-std'] }
4242
fortanix-sgx-abi = { version = "0.5.0", features = ['rustc-dep-of-std'] }
4343

4444
[target.'cfg(target_os = "hermit")'.dependencies]
45-
hermit-abi = { version = "0.2.0", features = ['rustc-dep-of-std'] }
45+
hermit-abi = { version = "0.2.6", features = ['rustc-dep-of-std'] }
4646

4747
[target.wasm32-wasi.dependencies]
4848
wasi = { version = "0.11.0", features = ['rustc-dep-of-std'], default-features = false }

Diff for: library/std/src/sys/hermit/condvar.rs

-90
This file was deleted.

Diff for: library/std/src/sys/hermit/futex.rs

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
use super::abi;
2+
use crate::ptr::null;
3+
use crate::sync::atomic::AtomicU32;
4+
use crate::time::Duration;
5+
6+
pub fn futex_wait(futex: &AtomicU32, expected: u32, timeout: Option<Duration>) -> bool {
7+
// Calculate the timeout as a relative timespec.
8+
//
9+
// Overflows are rounded up to an infinite timeout (None).
10+
let timespec = timeout.and_then(|dur| {
11+
Some(abi::timespec {
12+
tv_sec: dur.as_secs().try_into().ok()?,
13+
tv_nsec: dur.subsec_nanos().into(),
14+
})
15+
});
16+
17+
let r = unsafe {
18+
abi::futex_wait(
19+
futex.as_mut_ptr(),
20+
expected,
21+
timespec.as_ref().map_or(null(), |t| t as *const abi::timespec),
22+
abi::FUTEX_RELATIVE_TIMEOUT,
23+
)
24+
};
25+
26+
r != -abi::errno::ETIMEDOUT
27+
}
28+
29+
#[inline]
30+
pub fn futex_wake(futex: &AtomicU32) -> bool {
31+
unsafe { abi::futex_wake(futex.as_mut_ptr(), 1) > 0 }
32+
}
33+
34+
#[inline]
35+
pub fn futex_wake_all(futex: &AtomicU32) {
36+
unsafe {
37+
abi::futex_wake(futex.as_mut_ptr(), i32::MAX);
38+
}
39+
}

Diff for: library/std/src/sys/hermit/mod.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pub mod cmath;
2525
pub mod env;
2626
pub mod fd;
2727
pub mod fs;
28+
pub mod futex;
2829
#[path = "../unsupported/io.rs"]
2930
pub mod io;
3031
pub mod memchr;
@@ -45,14 +46,14 @@ pub mod thread_local_dtor;
4546
pub mod thread_local_key;
4647
pub mod time;
4748

48-
mod condvar;
49-
mod mutex;
50-
mod rwlock;
51-
49+
#[path = "../unix/locks"]
5250
pub mod locks {
53-
pub use super::condvar::*;
54-
pub use super::mutex::*;
55-
pub use super::rwlock::*;
51+
mod futex_condvar;
52+
mod futex_mutex;
53+
mod futex_rwlock;
54+
pub(crate) use futex_condvar::MovableCondvar;
55+
pub(crate) use futex_mutex::{MovableMutex, Mutex};
56+
pub(crate) use futex_rwlock::{MovableRwLock, RwLock};
5657
}
5758

5859
use crate::io::ErrorKind;

0 commit comments

Comments
 (0)