Skip to content

Commit 487e71f

Browse files
committed
Auto merge of #59670 - Centril:rollup-bqa1xeq, r=Centril
Rollup of 5 pull requests Successful merges: - #59076 (Include trailing comma in multiline Debug representation) - #59619 (wasi: Implement more of the standard library) - #59639 (Never return uninhabited values at all) - #59643 (std: Upgrade `compiler_builtins` to fix wasi linkage) - #59664 (Updated the documentation of spin_loop and spin_loop_hint) Failed merges: r? @ghost
2 parents f8673e0 + f985f24 commit 487e71f

File tree

53 files changed

+1521
-590
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1521
-590
lines changed

Cargo.lock

+16-16
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ dependencies = [
1717
name = "alloc"
1818
version = "0.0.0"
1919
dependencies = [
20-
"compiler_builtins 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
20+
"compiler_builtins 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
2121
"core 0.0.0",
2222
"rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
2323
"rand_xorshift 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -107,7 +107,7 @@ version = "0.1.27"
107107
source = "registry+https://github.com/rust-lang/crates.io-index"
108108
dependencies = [
109109
"cc 1.0.28 (registry+https://github.com/rust-lang/crates.io-index)",
110-
"compiler_builtins 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
110+
"compiler_builtins 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
111111
"libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)",
112112
"rustc-std-workspace-core 1.0.0",
113113
]
@@ -465,7 +465,7 @@ dependencies = [
465465

466466
[[package]]
467467
name = "compiler_builtins"
468-
version = "0.1.8"
468+
version = "0.1.9"
469469
source = "registry+https://github.com/rust-lang/crates.io-index"
470470
dependencies = [
471471
"cc 1.0.28 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -751,7 +751,7 @@ name = "dlmalloc"
751751
version = "0.1.3"
752752
source = "registry+https://github.com/rust-lang/crates.io-index"
753753
dependencies = [
754-
"compiler_builtins 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
754+
"compiler_builtins 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
755755
"libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)",
756756
"rustc-std-workspace-core 1.0.0",
757757
]
@@ -917,7 +917,7 @@ name = "fortanix-sgx-abi"
917917
version = "0.3.2"
918918
source = "registry+https://github.com/rust-lang/crates.io-index"
919919
dependencies = [
920-
"compiler_builtins 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
920+
"compiler_builtins 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
921921
"rustc-std-workspace-core 1.0.0",
922922
]
923923

@@ -1769,7 +1769,7 @@ dependencies = [
17691769
name = "panic_abort"
17701770
version = "0.0.0"
17711771
dependencies = [
1772-
"compiler_builtins 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
1772+
"compiler_builtins 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
17731773
"core 0.0.0",
17741774
"libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)",
17751775
]
@@ -1779,7 +1779,7 @@ name = "panic_unwind"
17791779
version = "0.0.0"
17801780
dependencies = [
17811781
"alloc 0.0.0",
1782-
"compiler_builtins 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
1782+
"compiler_builtins 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
17831783
"core 0.0.0",
17841784
"libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)",
17851785
"unwind 0.0.0",
@@ -1964,7 +1964,7 @@ name = "profiler_builtins"
19641964
version = "0.0.0"
19651965
dependencies = [
19661966
"cc 1.0.28 (registry+https://github.com/rust-lang/crates.io-index)",
1967-
"compiler_builtins 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
1967+
"compiler_builtins 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
19681968
"core 0.0.0",
19691969
]
19701970

@@ -2499,7 +2499,7 @@ name = "rustc-demangle"
24992499
version = "0.1.10"
25002500
source = "registry+https://github.com/rust-lang/crates.io-index"
25012501
dependencies = [
2502-
"compiler_builtins 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
2502+
"compiler_builtins 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
25032503
"rustc-std-workspace-core 1.0.0",
25042504
]
25052505

@@ -2599,7 +2599,7 @@ dependencies = [
25992599
"alloc 0.0.0",
26002600
"build_helper 0.1.0",
26012601
"cmake 0.1.33 (registry+https://github.com/rust-lang/crates.io-index)",
2602-
"compiler_builtins 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
2602+
"compiler_builtins 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
26032603
"core 0.0.0",
26042604
]
26052605

@@ -2826,7 +2826,7 @@ dependencies = [
28262826
"alloc 0.0.0",
28272827
"build_helper 0.1.0",
28282828
"cmake 0.1.33 (registry+https://github.com/rust-lang/crates.io-index)",
2829-
"compiler_builtins 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
2829+
"compiler_builtins 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
28302830
"core 0.0.0",
28312831
]
28322832

@@ -2888,7 +2888,7 @@ dependencies = [
28882888
"alloc 0.0.0",
28892889
"build_helper 0.1.0",
28902890
"cmake 0.1.33 (registry+https://github.com/rust-lang/crates.io-index)",
2891-
"compiler_builtins 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
2891+
"compiler_builtins 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
28922892
"core 0.0.0",
28932893
]
28942894

@@ -3009,7 +3009,7 @@ dependencies = [
30093009
"alloc 0.0.0",
30103010
"build_helper 0.1.0",
30113011
"cmake 0.1.33 (registry+https://github.com/rust-lang/crates.io-index)",
3012-
"compiler_builtins 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
3012+
"compiler_builtins 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
30133013
"core 0.0.0",
30143014
]
30153015

@@ -3276,7 +3276,7 @@ dependencies = [
32763276
"alloc 0.0.0",
32773277
"backtrace-sys 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)",
32783278
"cc 1.0.28 (registry+https://github.com/rust-lang/crates.io-index)",
3279-
"compiler_builtins 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
3279+
"compiler_builtins 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
32803280
"core 0.0.0",
32813281
"dlmalloc 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
32823282
"fortanix-sgx-abi 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -3849,7 +3849,7 @@ dependencies = [
38493849
name = "unwind"
38503850
version = "0.0.0"
38513851
dependencies = [
3852-
"compiler_builtins 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
3852+
"compiler_builtins 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
38533853
"core 0.0.0",
38543854
"libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)",
38553855
]
@@ -4045,7 +4045,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
40454045
"checksum colored 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b0aa3473e85a3161b59845d6096b289bb577874cafeaf75ea1b1beaa6572c7fc"
40464046
"checksum commoncrypto 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d056a8586ba25a1e4d61cb090900e495952c7886786fc55f909ab2f819b69007"
40474047
"checksum commoncrypto-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1fed34f46747aa73dfaa578069fd8279d2818ade2b55f38f22a9401c7f4083e2"
4048-
"checksum compiler_builtins 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "a28c3898d0c57b26fa6f92de141ba665fa5ac5179f795db06db408be84302395"
4048+
"checksum compiler_builtins 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "d7de11892d9f9f1bc76d43011c8233d27d58300d629dc9dfb51b6626ef7f6077"
40494049
"checksum compiletest_rs 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)" = "56c799b1f7142badf3b047b4c1f2074cc96b6b784fb2432f2ed9c87da0a03749"
40504050
"checksum constant_time_eq 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8ff012e225ce166d4422e0e78419d901719760f62ae2b7969ca6b564d1b54a9e"
40514051
"checksum core-foundation 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4e2640d6d0bf22e82bed1b73c6aef8d5dd31e5abe6666c57e6d45e2649f4f887"

src/libcore/fmt/builders.rs

+32-58
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ impl<'a> PadAdapter<'a> {
1111
fmt.wrap_buf(move |buf| {
1212
*slot = Some(PadAdapter {
1313
buf,
14-
on_newline: false,
14+
on_newline: true,
1515
});
1616
slot.as_mut().unwrap()
1717
})
@@ -128,22 +128,21 @@ impl<'a, 'b: 'a> DebugStruct<'a, 'b> {
128128
#[stable(feature = "debug_builders", since = "1.2.0")]
129129
pub fn field(&mut self, name: &str, value: &dyn fmt::Debug) -> &mut DebugStruct<'a, 'b> {
130130
self.result = self.result.and_then(|_| {
131-
let prefix = if self.has_fields {
132-
","
133-
} else {
134-
" {"
135-
};
136-
137131
if self.is_pretty() {
132+
if !self.has_fields {
133+
self.fmt.write_str(" {\n")?;
134+
}
138135
let mut slot = None;
139136
let mut writer = PadAdapter::wrap(&mut self.fmt, &mut slot);
140-
writer.write_str(prefix)?;
141-
writer.write_str("\n")?;
142137
writer.write_str(name)?;
143138
writer.write_str(": ")?;
144-
value.fmt(&mut writer)
139+
value.fmt(&mut writer)?;
140+
writer.write_str(",\n")
145141
} else {
146-
write!(self.fmt, "{} {}: ", prefix, name)?;
142+
let prefix = if self.has_fields { ", " } else { " { " };
143+
self.fmt.write_str(prefix)?;
144+
self.fmt.write_str(name)?;
145+
self.fmt.write_str(": ")?;
147146
value.fmt(self.fmt)
148147
}
149148
});
@@ -184,7 +183,7 @@ impl<'a, 'b: 'a> DebugStruct<'a, 'b> {
184183
if self.has_fields {
185184
self.result = self.result.and_then(|_| {
186185
if self.is_pretty() {
187-
self.fmt.write_str("\n}")
186+
self.fmt.write_str("}")
188187
} else {
189188
self.fmt.write_str(" }")
190189
}
@@ -275,21 +274,17 @@ impl<'a, 'b: 'a> DebugTuple<'a, 'b> {
275274
#[stable(feature = "debug_builders", since = "1.2.0")]
276275
pub fn field(&mut self, value: &dyn fmt::Debug) -> &mut DebugTuple<'a, 'b> {
277276
self.result = self.result.and_then(|_| {
278-
let (prefix, space) = if self.fields > 0 {
279-
(",", " ")
280-
} else {
281-
("(", "")
282-
};
283-
284277
if self.is_pretty() {
278+
if self.fields == 0 {
279+
self.fmt.write_str("(\n")?;
280+
}
285281
let mut slot = None;
286282
let mut writer = PadAdapter::wrap(&mut self.fmt, &mut slot);
287-
writer.write_str(prefix)?;
288-
writer.write_str("\n")?;
289-
value.fmt(&mut writer)
283+
value.fmt(&mut writer)?;
284+
writer.write_str(",\n")
290285
} else {
286+
let prefix = if self.fields == 0 { "(" } else { ", " };
291287
self.fmt.write_str(prefix)?;
292-
self.fmt.write_str(space)?;
293288
value.fmt(self.fmt)
294289
}
295290
});
@@ -326,10 +321,7 @@ impl<'a, 'b: 'a> DebugTuple<'a, 'b> {
326321
pub fn finish(&mut self) -> fmt::Result {
327322
if self.fields > 0 {
328323
self.result = self.result.and_then(|_| {
329-
if self.is_pretty() {
330-
self.fmt.write_str("\n")?;
331-
}
332-
if self.fields == 1 && self.empty_name {
324+
if self.fields == 1 && self.empty_name && !self.is_pretty() {
333325
self.fmt.write_str(",")?;
334326
}
335327
self.fmt.write_str(")")
@@ -353,14 +345,13 @@ impl<'a, 'b: 'a> DebugInner<'a, 'b> {
353345
fn entry(&mut self, entry: &dyn fmt::Debug) {
354346
self.result = self.result.and_then(|_| {
355347
if self.is_pretty() {
348+
if !self.has_fields {
349+
self.fmt.write_str("\n")?;
350+
}
356351
let mut slot = None;
357352
let mut writer = PadAdapter::wrap(&mut self.fmt, &mut slot);
358-
writer.write_str(if self.has_fields {
359-
",\n"
360-
} else {
361-
"\n"
362-
})?;
363-
entry.fmt(&mut writer)
353+
entry.fmt(&mut writer)?;
354+
writer.write_str(",\n")
364355
} else {
365356
if self.has_fields {
366357
self.fmt.write_str(", ")?
@@ -372,15 +363,6 @@ impl<'a, 'b: 'a> DebugInner<'a, 'b> {
372363
self.has_fields = true;
373364
}
374365

375-
pub fn finish(&mut self) {
376-
let prefix = if self.is_pretty() && self.has_fields {
377-
"\n"
378-
} else {
379-
""
380-
};
381-
self.result = self.result.and_then(|_| self.fmt.write_str(prefix));
382-
}
383-
384366
fn is_pretty(&self) -> bool {
385367
self.fmt.alternate()
386368
}
@@ -421,7 +403,7 @@ pub struct DebugSet<'a, 'b: 'a> {
421403
}
422404

423405
pub fn debug_set_new<'a, 'b>(fmt: &'a mut fmt::Formatter<'b>) -> DebugSet<'a, 'b> {
424-
let result = write!(fmt, "{{");
406+
let result = fmt.write_str("{");
425407
DebugSet {
426408
inner: DebugInner {
427409
fmt,
@@ -519,7 +501,6 @@ impl<'a, 'b: 'a> DebugSet<'a, 'b> {
519501
/// ```
520502
#[stable(feature = "debug_builders", since = "1.2.0")]
521503
pub fn finish(&mut self) -> fmt::Result {
522-
self.inner.finish();
523504
self.inner.result.and_then(|_| self.inner.fmt.write_str("}"))
524505
}
525506
}
@@ -559,7 +540,7 @@ pub struct DebugList<'a, 'b: 'a> {
559540
}
560541

561542
pub fn debug_list_new<'a, 'b>(fmt: &'a mut fmt::Formatter<'b>) -> DebugList<'a, 'b> {
562-
let result = write!(fmt, "[");
543+
let result = fmt.write_str("[");
563544
DebugList {
564545
inner: DebugInner {
565546
fmt,
@@ -657,7 +638,6 @@ impl<'a, 'b: 'a> DebugList<'a, 'b> {
657638
/// ```
658639
#[stable(feature = "debug_builders", since = "1.2.0")]
659640
pub fn finish(&mut self) -> fmt::Result {
660-
self.inner.finish();
661641
self.inner.result.and_then(|_| self.inner.fmt.write_str("]"))
662642
}
663643
}
@@ -699,7 +679,7 @@ pub struct DebugMap<'a, 'b: 'a> {
699679
}
700680

701681
pub fn debug_map_new<'a, 'b>(fmt: &'a mut fmt::Formatter<'b>) -> DebugMap<'a, 'b> {
702-
let result = write!(fmt, "{{");
682+
let result = fmt.write_str("{");
703683
DebugMap {
704684
fmt,
705685
result,
@@ -734,16 +714,15 @@ impl<'a, 'b: 'a> DebugMap<'a, 'b> {
734714
pub fn entry(&mut self, key: &dyn fmt::Debug, value: &dyn fmt::Debug) -> &mut DebugMap<'a, 'b> {
735715
self.result = self.result.and_then(|_| {
736716
if self.is_pretty() {
717+
if !self.has_fields {
718+
self.fmt.write_str("\n")?;
719+
}
737720
let mut slot = None;
738721
let mut writer = PadAdapter::wrap(&mut self.fmt, &mut slot);
739-
writer.write_str(if self.has_fields {
740-
",\n"
741-
} else {
742-
"\n"
743-
})?;
744722
key.fmt(&mut writer)?;
745723
writer.write_str(": ")?;
746-
value.fmt(&mut writer)
724+
value.fmt(&mut writer)?;
725+
writer.write_str(",\n")
747726
} else {
748727
if self.has_fields {
749728
self.fmt.write_str(", ")?
@@ -818,12 +797,7 @@ impl<'a, 'b: 'a> DebugMap<'a, 'b> {
818797
/// ```
819798
#[stable(feature = "debug_builders", since = "1.2.0")]
820799
pub fn finish(&mut self) -> fmt::Result {
821-
let prefix = if self.is_pretty() && self.has_fields {
822-
"\n"
823-
} else {
824-
""
825-
};
826-
self.result.and_then(|_| write!(self.fmt, "{}}}", prefix))
800+
self.result.and_then(|_| self.fmt.write_str("}"))
827801
}
828802

829803
fn is_pretty(&self) -> bool {

src/libcore/hint.rs

+20-7
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,28 @@ pub unsafe fn unreachable_unchecked() -> ! {
5050
intrinsics::unreachable()
5151
}
5252

53-
/// Save power or switch hyperthreads in a busy-wait spin-loop.
53+
/// Signals the processor that it is entering a busy-wait spin-loop.
5454
///
55-
/// This function is deliberately more primitive than
56-
/// [`std::thread::yield_now`](../../std/thread/fn.yield_now.html) and
57-
/// does not directly yield to the system's scheduler.
58-
/// In some cases it might be useful to use a combination of both functions.
59-
/// Careful benchmarking is advised.
55+
/// Upon receiving spin-loop signal the processor can optimize its behavior by, for example, saving
56+
/// power or switching hyper-threads.
6057
///
61-
/// On some platforms this function may not do anything at all.
58+
/// This function is different than [`std::thread::yield_now`] which directly yields to the
59+
/// system's scheduler, whereas `spin_loop` only signals the processor that it is entering a
60+
/// busy-wait spin-loop without yielding control to the system's scheduler.
61+
///
62+
/// Using a busy-wait spin-loop with `spin_loop` is ideally used in situations where a
63+
/// contended lock is held by another thread executed on a different CPU and where the waiting
64+
/// times are relatively small. Because entering busy-wait spin-loop does not trigger the system's
65+
/// scheduler, no overhead for switching threads occurs. However, if the thread holding the
66+
/// contended lock is running on the same CPU, the spin-loop is likely to occupy an entire CPU slice
67+
/// before switching to the thread that holds the lock. If the contending lock is held by a thread
68+
/// on the same CPU or if the waiting times for acquiring the lock are longer, it is often better to
69+
/// use [`std::thread::yield_now`].
70+
///
71+
/// **Note**: On platforms that do not support receiving spin-loop hints this function does not
72+
/// do anything at all.
73+
///
74+
/// [`std::thread::yield_now`]: ../../std/thread/fn.yield_now.html
6275
#[inline]
6376
#[unstable(feature = "renamed_spin_loop", issue = "55002")]
6477
pub fn spin_loop() {

0 commit comments

Comments
 (0)