Skip to content

Commit 9558cda

Browse files
committed
Auto merge of rust-lang#115263 - matthiaskrgr:rollup-taqu2h0, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - rust-lang#114924 (coverage: Tidy up `run-coverage` tests in several small ways) - rust-lang#114927 (CI: add more debug logging to Docker caching) - rust-lang#114957 (tests: Fix tests for LoongArch64) - rust-lang#115007 (Correct and expand documentation of `handle_alloc_error` and `set_alloc_error_hook`.) - rust-lang#115098 (rust-gdbgui: remove excessive quotes) - rust-lang#115111 (compile rust-anaylzer with `x check` if it's enabled) r? `@ghost` `@rustbot` modify labels: rollup
2 parents d1fb175 + ab1123b commit 9558cda

Some content is hidden

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

51 files changed

+163
-145
lines changed

Diff for: library/alloc/src/alloc.rs

+19-6
Original file line numberDiff line numberDiff line change
@@ -343,18 +343,31 @@ extern "Rust" {
343343
fn __rust_alloc_error_handler(size: usize, align: usize) -> !;
344344
}
345345

346-
/// Abort on memory allocation error or failure.
346+
/// Signal a memory allocation error.
347347
///
348-
/// Callers of memory allocation APIs wishing to abort computation
348+
/// Callers of memory allocation APIs wishing to cease execution
349349
/// in response to an allocation error are encouraged to call this function,
350-
/// rather than directly invoking `panic!` or similar.
350+
/// rather than directly invoking [`panic!`] or similar.
351351
///
352-
/// The default behavior of this function is to print a message to standard error
353-
/// and abort the process.
354-
/// It can be replaced with [`set_alloc_error_hook`] and [`take_alloc_error_hook`].
352+
/// This function is guaranteed to diverge (not return normally with a value), but depending on
353+
/// global configuration, it may either panic (resulting in unwinding or aborting as per
354+
/// configuration for all panics), or abort the process (with no unwinding).
355+
///
356+
/// The default behavior is:
357+
///
358+
/// * If the binary links against `std` (typically the case), then
359+
/// print a message to standard error and abort the process.
360+
/// This behavior can be replaced with [`set_alloc_error_hook`] and [`take_alloc_error_hook`].
361+
/// Future versions of Rust may panic by default instead.
362+
///
363+
/// * If the binary does not link against `std` (all of its crates are marked
364+
/// [`#![no_std]`][no_std]), then call [`panic!`] with a message.
365+
/// [The panic handler] applies as to any panic.
355366
///
356367
/// [`set_alloc_error_hook`]: ../../std/alloc/fn.set_alloc_error_hook.html
357368
/// [`take_alloc_error_hook`]: ../../std/alloc/fn.take_alloc_error_hook.html
369+
/// [The panic handler]: https://doc.rust-lang.org/reference/runtime.html#the-panic_handler-attribute
370+
/// [no_std]: https://doc.rust-lang.org/reference/names/preludes.html#the-no_std-attribute
358371
#[stable(feature = "global_alloc", since = "1.28.0")]
359372
#[rustc_const_unstable(feature = "const_alloc_error", issue = "92523")]
360373
#[cfg(all(not(no_global_oom_handling), not(test)))]

Diff for: library/std/src/alloc.rs

+20-6
Original file line numberDiff line numberDiff line change
@@ -290,15 +290,29 @@ static HOOK: AtomicPtr<()> = AtomicPtr::new(ptr::null_mut());
290290

291291
/// Registers a custom allocation error hook, replacing any that was previously registered.
292292
///
293-
/// The allocation error hook is invoked when an infallible memory allocation fails, before
294-
/// the runtime aborts. The default hook prints a message to standard error,
295-
/// but this behavior can be customized with the [`set_alloc_error_hook`] and
296-
/// [`take_alloc_error_hook`] functions.
293+
/// The allocation error hook is invoked when an infallible memory allocation fails — that is,
294+
/// as a consequence of calling [`handle_alloc_error`] — before the runtime aborts.
297295
///
298-
/// The hook is provided with a `Layout` struct which contains information
296+
/// The allocation error hook is a global resource. [`take_alloc_error_hook`] may be used to
297+
/// retrieve a previously registered hook and wrap or discard it.
298+
///
299+
/// # What the provided `hook` function should expect
300+
///
301+
/// The hook function is provided with a [`Layout`] struct which contains information
299302
/// about the allocation that failed.
300303
///
301-
/// The allocation error hook is a global resource.
304+
/// The hook function may choose to panic or abort; in the event that it returns normally, this
305+
/// will cause an immediate abort.
306+
///
307+
/// Since [`take_alloc_error_hook`] is a safe function that allows retrieving the hook, the hook
308+
/// function must be _sound_ to call even if no memory allocations were attempted.
309+
///
310+
/// # The default hook
311+
///
312+
/// The default hook, used if [`set_alloc_error_hook`] is never called, prints a message to
313+
/// standard error (and then returns, causing the runtime to abort the process).
314+
/// Compiler options may cause it to panic instead, and the default behavior may be changed
315+
/// to panicking in future versions of Rust.
302316
///
303317
/// # Examples
304318
///

Diff for: src/bootstrap/check.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -353,10 +353,17 @@ pub struct RustAnalyzer {
353353
impl Step for RustAnalyzer {
354354
type Output = ();
355355
const ONLY_HOSTS: bool = true;
356-
const DEFAULT: bool = false;
356+
const DEFAULT: bool = true;
357357

358358
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
359-
run.path("src/tools/rust-analyzer")
359+
let builder = run.builder;
360+
run.path("src/tools/rust-analyzer").default_condition(
361+
builder
362+
.config
363+
.tools
364+
.as_ref()
365+
.map_or(true, |tools| tools.iter().any(|tool| tool == "rust-analyzer")),
366+
)
360367
}
361368

362369
fn make_run(run: RunConfig<'_>) {

Diff for: src/ci/docker/run.sh

+10-4
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,8 @@ if [ -f "$docker_dir/$image/Dockerfile" ]; then
6464

6565
docker --version >> $hash_key
6666

67-
# Include cache version. Currently it is needed to bust Docker
68-
# cache key after opting in into the old Docker build backend.
69-
echo "1" >> $hash_key
67+
# Include cache version. Can be used to manually bust the Docker cache.
68+
echo "2" >> $hash_key
7069

7170
cksum=$(sha512sum $hash_key | \
7271
awk '{print $1}')
@@ -78,6 +77,10 @@ if [ -f "$docker_dir/$image/Dockerfile" ]; then
7877
set +e
7978
retry curl --max-time 600 -y 30 -Y 10 --connect-timeout 30 -f -L -C - \
8079
-o /tmp/rustci_docker_cache "$url"
80+
81+
docker_archive_hash=$(sha512sum /tmp/rustci_docker_cache | awk '{print $1}')
82+
echo "Downloaded archive hash: ${docker_archive_hash}"
83+
8184
echo "Loading images into docker"
8285
# docker load sometimes hangs in the CI, so time out after 10 minutes with TERM,
8386
# KILL after 12 minutes
@@ -115,8 +118,10 @@ if [ -f "$docker_dir/$image/Dockerfile" ]; then
115118
digest=$(docker inspect rust-ci --format '{{.Id}}')
116119
echo "Built container $digest"
117120
if ! grep -q "$digest" <(echo "$loaded_images"); then
118-
echo "Uploading finished image to $url"
121+
echo "Uploading finished image $digest to $url"
119122
set +e
123+
# Print image history for easier debugging of layer SHAs
124+
docker history rust-ci
120125
docker history -q rust-ci | \
121126
grep -v missing | \
122127
xargs docker save | \
@@ -131,6 +136,7 @@ if [ -f "$docker_dir/$image/Dockerfile" ]; then
131136
mkdir -p "$dist"
132137
echo "$url" >"$info"
133138
echo "$digest" >>"$info"
139+
cat "$info"
134140
fi
135141
elif [ -f "$docker_dir/disabled/$image/Dockerfile" ]; then
136142
if isCI; then

Diff for: src/etc/rust-gdbgui

+3-3
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ RUST_GDBGUI="${RUST_GDBGUI:-gdbgui}"
5555

5656
# These arguments get passed through to GDB and make it load the
5757
# Rust pretty printers.
58-
GDB_ARGS="--directory=\"$GDB_PYTHON_MODULE_DIRECTORY\"" \
59-
"-iex \"add-auto-load-safe-path $GDB_PYTHON_MODULE_DIRECTORY\"" \
60-
"-iex \"set substitute-path /rustc/$RUSTC_COMMIT_HASH $RUSTC_SYSROOT/lib/rustlib/src/rust\""
58+
GDB_ARGS="--directory=\"$GDB_PYTHON_MODULE_DIRECTORY\" \
59+
-iex \"add-auto-load-safe-path $GDB_PYTHON_MODULE_DIRECTORY\" \
60+
-iex \"set substitute-path /rustc/$RUSTC_COMMIT_HASH $RUSTC_SYSROOT/lib/rustlib/src/rust\""
6161

6262
# Finally we execute gdbgui.
6363
PYTHONPATH="$PYTHONPATH:$GDB_PYTHON_MODULE_DIRECTORY" \

Diff for: tests/codegen/loongarch-abi/loongarch64-lp64d-abi.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -250,11 +250,11 @@ pub struct IntDoubleInt {
250250
c: i32,
251251
}
252252

253-
// CHECK: define void @f_int_double_int_s_arg(ptr noalias nocapture noundef dereferenceable(24) %a)
253+
// CHECK: define void @f_int_double_int_s_arg(ptr noalias nocapture noundef align 8 dereferenceable(24) %a)
254254
#[no_mangle]
255255
pub extern "C" fn f_int_double_int_s_arg(a: IntDoubleInt) {}
256256

257-
// CHECK: define void @f_ret_int_double_int_s(ptr noalias nocapture noundef sret(%IntDoubleInt) dereferenceable(24) %0)
257+
// CHECK: define void @f_ret_int_double_int_s(ptr noalias nocapture noundef sret(%IntDoubleInt) align 8 dereferenceable(24) %_0)
258258
#[no_mangle]
259259
pub extern "C" fn f_ret_int_double_int_s() -> IntDoubleInt {
260260
IntDoubleInt { a: 1, b: 2., c: 3 }

Diff for: tests/run-coverage-rustdoc/doctest.coverage

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ $DIR/auxiliary/doctest_crate.rs:
1010
LL| 3|}
1111

1212
$DIR/doctest.rs:
13+
LL| |// aux-build:doctest_crate.rs
14+
LL| |
1315
LL| |//! This test ensures that code from doctests is properly re-mapped.
1416
LL| |//! See <https://github.com/rust-lang/rust/issues/79417> for more info.
1517
LL| |//!
@@ -78,7 +80,7 @@ $DIR/doctest.rs:
7880
LL| |//! doctest_main()
7981
LL| |//! }
8082
LL| |//! ```
81-
LL| |// aux-build:doctest_crate.rs
83+
LL| |
8284
LL| |/// doctest attached to fn testing external code:
8385
LL| |/// ```
8486
LL| 1|/// extern crate doctest_crate;

Diff for: tests/run-coverage-rustdoc/doctest.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// aux-build:doctest_crate.rs
2+
13
//! This test ensures that code from doctests is properly re-mapped.
24
//! See <https://github.com/rust-lang/rust/issues/79417> for more info.
35
//!
@@ -63,7 +65,7 @@
6365
//! doctest_main()
6466
//! }
6567
//! ```
66-
// aux-build:doctest_crate.rs
68+
6769
/// doctest attached to fn testing external code:
6870
/// ```
6971
/// extern crate doctest_crate;

Diff for: tests/run-coverage/assert.coverage

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
^1
88
LL| 3|}
99
LL| |
10-
LL| 1|fn main() -> Result<(),u8> {
10+
LL| 1|fn main() -> Result<(), u8> {
1111
LL| 1| let mut countdown = 10;
1212
LL| 11| while countdown > 0 {
1313
LL| 11| if countdown == 1 {

Diff for: tests/run-coverage/assert.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ fn might_fail_assert(one_plus_one: u32) {
66
assert_eq!(1 + 1, one_plus_one, "the argument was wrong");
77
}
88

9-
fn main() -> Result<(),u8> {
9+
fn main() -> Result<(), u8> {
1010
let mut countdown = 10;
1111
while countdown > 0 {
1212
if countdown == 1 {

Diff for: tests/run-coverage/async2.coverage

-12
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
LL| |// compile-flags: --edition=2018
22
LL| |
3-
LL| |use core::{
4-
LL| | future::Future,
5-
LL| | marker::Send,
6-
LL| | pin::Pin,
7-
LL| |};
8-
LL| |
93
LL| 1|fn non_async_func() {
104
LL| 1| println!("non_async_func was covered");
115
LL| 1| let b = true;
@@ -15,9 +9,6 @@
159
^0
1610
LL| 1|}
1711
LL| |
18-
LL| |
19-
LL| |
20-
LL| |
2112
LL| 1|async fn async_func() {
2213
LL| 1| println!("async_func was covered");
2314
LL| 1| let b = true;
@@ -27,9 +18,6 @@
2718
^0
2819
LL| 1|}
2920
LL| |
30-
LL| |
31-
LL| |
32-
LL| |
3321
LL| 1|async fn async_func_just_println() {
3422
LL| 1| println!("async_func_just_println was covered");
3523
LL| 1|}

Diff for: tests/run-coverage/async2.rs

-12
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
// compile-flags: --edition=2018
22

3-
use core::{
4-
future::Future,
5-
marker::Send,
6-
pin::Pin,
7-
};
8-
93
fn non_async_func() {
104
println!("non_async_func was covered");
115
let b = true;
@@ -14,9 +8,6 @@ fn non_async_func() {
148
}
159
}
1610

17-
18-
19-
2011
async fn async_func() {
2112
println!("async_func was covered");
2213
let b = true;
@@ -25,9 +16,6 @@ async fn async_func() {
2516
}
2617
}
2718

28-
29-
30-
3119
async fn async_func_just_println() {
3220
println!("async_func_just_println was covered");
3321
}

Diff for: tests/run-coverage/auxiliary/inline_always_with_dead_code.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
mod foo {
66
#[inline(always)]
7-
pub fn called() { }
7+
pub fn called() {}
88

9-
fn uncalled() { }
9+
fn uncalled() {}
1010
}
1111

1212
pub mod bar {

Diff for: tests/run-coverage/auxiliary/unused_mod_helper.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#[allow(dead_code)]
12
pub fn never_called_function() {
23
println!("I am never called");
34
}

Diff for: tests/run-coverage/auxiliary/used_crate.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#![allow(unused_assignments, unused_variables)]
2+
// Verify that coverage works with optimizations:
23
// compile-flags: -C opt-level=3
3-
use std::fmt::Debug; // ^^ validates coverage now works with optimizations
4+
5+
use std::fmt::Debug;
46

57
pub fn used_function() {
68
// Initialize test constants in a way that cannot be determined at compile time, to ensure
@@ -42,6 +44,7 @@ pub fn unused_function() {
4244
}
4345
}
4446

47+
#[allow(dead_code)]
4548
fn unused_private_function() {
4649
let is_true = std::env::args().len() == 1;
4750
let mut countdown = 2;

Diff for: tests/run-coverage/auxiliary/used_inline_crate.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![allow(unused_assignments, unused_variables)]
2-
2+
// Verify that coverage works with optimizations:
33
// compile-flags: -C opt-level=3
4-
// ^^ validates coverage now works with optimizations
4+
55
use std::fmt::Debug;
66

77
pub fn used_function() {
@@ -29,12 +29,6 @@ pub fn used_inline_function() {
2929
use_this_lib_crate();
3030
}
3131

32-
33-
34-
35-
36-
37-
3832
#[inline(always)]
3933
pub fn used_only_from_bin_crate_generic_function<T: Debug>(arg: T) {
4034
println!("used_only_from_bin_crate_generic_function with {:?}", arg);
@@ -71,6 +65,7 @@ pub fn unused_function() {
7165
}
7266

7367
#[inline(always)]
68+
#[allow(dead_code)]
7469
fn unused_private_function() {
7570
let is_true = std::env::args().len() == 1;
7671
let mut countdown = 2;

Diff for: tests/run-coverage/closure.coverage

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
LL| |#![allow(unused_assignments, unused_variables)]
22
LL| |// compile-flags: -C opt-level=2
3-
LL| 1|fn main() { // ^^ fix described in rustc_middle/mir/mono.rs
3+
LL| |
4+
LL| |// This test used to be sensitive to certain coverage-specific hacks in
5+
LL| |// `rustc_middle/mir/mono.rs`, but those hacks were later cleaned up by
6+
LL| |// <https://github.com/rust-lang/rust/pull/83666>.
7+
LL| |
8+
LL| 1|fn main() {
49
LL| 1| // Initialize test constants in a way that cannot be determined at compile time, to ensure
510
LL| 1| // rustc and LLVM cannot optimize out statements (or coverage counters) downstream from
611
LL| 1| // dependent conditions.
712
LL| 1| let is_true = std::env::args().len() == 1;
8-
LL| 1| let is_false = ! is_true;
13+
LL| 1| let is_false = !is_true;
914
LL| 1|
1015
LL| 1| let mut some_string = Some(String::from("the string content"));
1116
LL| 1| println!(

Diff for: tests/run-coverage/closure.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
#![allow(unused_assignments, unused_variables)]
22
// compile-flags: -C opt-level=2
3-
fn main() { // ^^ fix described in rustc_middle/mir/mono.rs
3+
4+
// This test used to be sensitive to certain coverage-specific hacks in
5+
// `rustc_middle/mir/mono.rs`, but those hacks were later cleaned up by
6+
// <https://github.com/rust-lang/rust/pull/83666>.
7+
8+
fn main() {
49
// Initialize test constants in a way that cannot be determined at compile time, to ensure
510
// rustc and LLVM cannot optimize out statements (or coverage counters) downstream from
611
// dependent conditions.
712
let is_true = std::env::args().len() == 1;
8-
let is_false = ! is_true;
13+
let is_false = !is_true;
914

1015
let mut some_string = Some(String::from("the string content"));
1116
println!(

0 commit comments

Comments
 (0)