Skip to content

Rollup of 6 pull requests #115263

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

Merged
merged 14 commits into from
Aug 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
25 changes: 19 additions & 6 deletions library/alloc/src/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,18 +343,31 @@ extern "Rust" {
fn __rust_alloc_error_handler(size: usize, align: usize) -> !;
}

/// Abort on memory allocation error or failure.
/// Signal a memory allocation error.
///
/// Callers of memory allocation APIs wishing to abort computation
/// Callers of memory allocation APIs wishing to cease execution
/// in response to an allocation error are encouraged to call this function,
/// rather than directly invoking `panic!` or similar.
/// rather than directly invoking [`panic!`] or similar.
///
/// The default behavior of this function is to print a message to standard error
/// and abort the process.
/// It can be replaced with [`set_alloc_error_hook`] and [`take_alloc_error_hook`].
/// This function is guaranteed to diverge (not return normally with a value), but depending on
/// global configuration, it may either panic (resulting in unwinding or aborting as per
/// configuration for all panics), or abort the process (with no unwinding).
///
/// The default behavior is:
///
/// * If the binary links against `std` (typically the case), then
/// print a message to standard error and abort the process.
/// This behavior can be replaced with [`set_alloc_error_hook`] and [`take_alloc_error_hook`].
/// Future versions of Rust may panic by default instead.
///
/// * If the binary does not link against `std` (all of its crates are marked
/// [`#![no_std]`][no_std]), then call [`panic!`] with a message.
/// [The panic handler] applies as to any panic.
///
/// [`set_alloc_error_hook`]: ../../std/alloc/fn.set_alloc_error_hook.html
/// [`take_alloc_error_hook`]: ../../std/alloc/fn.take_alloc_error_hook.html
/// [The panic handler]: https://doc.rust-lang.org/reference/runtime.html#the-panic_handler-attribute
/// [no_std]: https://doc.rust-lang.org/reference/names/preludes.html#the-no_std-attribute
#[stable(feature = "global_alloc", since = "1.28.0")]
#[rustc_const_unstable(feature = "const_alloc_error", issue = "92523")]
#[cfg(all(not(no_global_oom_handling), not(test)))]
Expand Down
26 changes: 20 additions & 6 deletions library/std/src/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,15 +290,29 @@ static HOOK: AtomicPtr<()> = AtomicPtr::new(ptr::null_mut());

/// Registers a custom allocation error hook, replacing any that was previously registered.
///
/// The allocation error hook is invoked when an infallible memory allocation fails, before
/// the runtime aborts. The default hook prints a message to standard error,
/// but this behavior can be customized with the [`set_alloc_error_hook`] and
/// [`take_alloc_error_hook`] functions.
/// The allocation error hook is invoked when an infallible memory allocation fails — that is,
/// as a consequence of calling [`handle_alloc_error`] — before the runtime aborts.
///
/// The hook is provided with a `Layout` struct which contains information
/// The allocation error hook is a global resource. [`take_alloc_error_hook`] may be used to
/// retrieve a previously registered hook and wrap or discard it.
///
/// # What the provided `hook` function should expect
///
/// The hook function is provided with a [`Layout`] struct which contains information
/// about the allocation that failed.
///
/// The allocation error hook is a global resource.
/// The hook function may choose to panic or abort; in the event that it returns normally, this
/// will cause an immediate abort.
///
/// Since [`take_alloc_error_hook`] is a safe function that allows retrieving the hook, the hook
/// function must be _sound_ to call even if no memory allocations were attempted.
///
/// # The default hook
///
/// The default hook, used if [`set_alloc_error_hook`] is never called, prints a message to
/// standard error (and then returns, causing the runtime to abort the process).
/// Compiler options may cause it to panic instead, and the default behavior may be changed
/// to panicking in future versions of Rust.
///
/// # Examples
///
Expand Down
11 changes: 9 additions & 2 deletions src/bootstrap/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,10 +353,17 @@ pub struct RustAnalyzer {
impl Step for RustAnalyzer {
type Output = ();
const ONLY_HOSTS: bool = true;
const DEFAULT: bool = false;
const DEFAULT: bool = true;

fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
run.path("src/tools/rust-analyzer")
let builder = run.builder;
run.path("src/tools/rust-analyzer").default_condition(
builder
.config
.tools
.as_ref()
.map_or(true, |tools| tools.iter().any(|tool| tool == "rust-analyzer")),
)
}

fn make_run(run: RunConfig<'_>) {
Expand Down
14 changes: 10 additions & 4 deletions src/ci/docker/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,8 @@ if [ -f "$docker_dir/$image/Dockerfile" ]; then

docker --version >> $hash_key

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

cksum=$(sha512sum $hash_key | \
awk '{print $1}')
Expand All @@ -78,6 +77,10 @@ if [ -f "$docker_dir/$image/Dockerfile" ]; then
set +e
retry curl --max-time 600 -y 30 -Y 10 --connect-timeout 30 -f -L -C - \
-o /tmp/rustci_docker_cache "$url"

docker_archive_hash=$(sha512sum /tmp/rustci_docker_cache | awk '{print $1}')
echo "Downloaded archive hash: ${docker_archive_hash}"

echo "Loading images into docker"
# docker load sometimes hangs in the CI, so time out after 10 minutes with TERM,
# KILL after 12 minutes
Expand Down Expand Up @@ -115,8 +118,10 @@ if [ -f "$docker_dir/$image/Dockerfile" ]; then
digest=$(docker inspect rust-ci --format '{{.Id}}')
echo "Built container $digest"
if ! grep -q "$digest" <(echo "$loaded_images"); then
echo "Uploading finished image to $url"
echo "Uploading finished image $digest to $url"
set +e
# Print image history for easier debugging of layer SHAs
docker history rust-ci
docker history -q rust-ci | \
grep -v missing | \
xargs docker save | \
Expand All @@ -131,6 +136,7 @@ if [ -f "$docker_dir/$image/Dockerfile" ]; then
mkdir -p "$dist"
echo "$url" >"$info"
echo "$digest" >>"$info"
cat "$info"
fi
elif [ -f "$docker_dir/disabled/$image/Dockerfile" ]; then
if isCI; then
Expand Down
6 changes: 3 additions & 3 deletions src/etc/rust-gdbgui
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ RUST_GDBGUI="${RUST_GDBGUI:-gdbgui}"

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

# Finally we execute gdbgui.
PYTHONPATH="$PYTHONPATH:$GDB_PYTHON_MODULE_DIRECTORY" \
Expand Down
4 changes: 2 additions & 2 deletions tests/codegen/loongarch-abi/loongarch64-lp64d-abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,11 @@ pub struct IntDoubleInt {
c: i32,
}

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

// CHECK: define void @f_ret_int_double_int_s(ptr noalias nocapture noundef sret(%IntDoubleInt) dereferenceable(24) %0)
// CHECK: define void @f_ret_int_double_int_s(ptr noalias nocapture noundef sret(%IntDoubleInt) align 8 dereferenceable(24) %_0)
#[no_mangle]
pub extern "C" fn f_ret_int_double_int_s() -> IntDoubleInt {
IntDoubleInt { a: 1, b: 2., c: 3 }
Expand Down
4 changes: 3 additions & 1 deletion tests/run-coverage-rustdoc/doctest.coverage
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ $DIR/auxiliary/doctest_crate.rs:
LL| 3|}

$DIR/doctest.rs:
LL| |// aux-build:doctest_crate.rs
LL| |
LL| |//! This test ensures that code from doctests is properly re-mapped.
LL| |//! See <https://github.com/rust-lang/rust/issues/79417> for more info.
LL| |//!
Expand Down Expand Up @@ -78,7 +80,7 @@ $DIR/doctest.rs:
LL| |//! doctest_main()
LL| |//! }
LL| |//! ```
LL| |// aux-build:doctest_crate.rs
LL| |
LL| |/// doctest attached to fn testing external code:
LL| |/// ```
LL| 1|/// extern crate doctest_crate;
Expand Down
4 changes: 3 additions & 1 deletion tests/run-coverage-rustdoc/doctest.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// aux-build:doctest_crate.rs

//! This test ensures that code from doctests is properly re-mapped.
//! See <https://github.com/rust-lang/rust/issues/79417> for more info.
//!
Expand Down Expand Up @@ -63,7 +65,7 @@
//! doctest_main()
//! }
//! ```
// aux-build:doctest_crate.rs

/// doctest attached to fn testing external code:
/// ```
/// extern crate doctest_crate;
Expand Down
2 changes: 1 addition & 1 deletion tests/run-coverage/assert.coverage
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
^1
LL| 3|}
LL| |
LL| 1|fn main() -> Result<(),u8> {
LL| 1|fn main() -> Result<(), u8> {
LL| 1| let mut countdown = 10;
LL| 11| while countdown > 0 {
LL| 11| if countdown == 1 {
Expand Down
2 changes: 1 addition & 1 deletion tests/run-coverage/assert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ fn might_fail_assert(one_plus_one: u32) {
assert_eq!(1 + 1, one_plus_one, "the argument was wrong");
}

fn main() -> Result<(),u8> {
fn main() -> Result<(), u8> {
let mut countdown = 10;
while countdown > 0 {
if countdown == 1 {
Expand Down
12 changes: 0 additions & 12 deletions tests/run-coverage/async2.coverage
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
LL| |// compile-flags: --edition=2018
LL| |
LL| |use core::{
LL| | future::Future,
LL| | marker::Send,
LL| | pin::Pin,
LL| |};
LL| |
LL| 1|fn non_async_func() {
LL| 1| println!("non_async_func was covered");
LL| 1| let b = true;
Expand All @@ -15,9 +9,6 @@
^0
LL| 1|}
LL| |
LL| |
LL| |
LL| |
LL| 1|async fn async_func() {
LL| 1| println!("async_func was covered");
LL| 1| let b = true;
Expand All @@ -27,9 +18,6 @@
^0
LL| 1|}
LL| |
LL| |
LL| |
LL| |
LL| 1|async fn async_func_just_println() {
LL| 1| println!("async_func_just_println was covered");
LL| 1|}
Expand Down
12 changes: 0 additions & 12 deletions tests/run-coverage/async2.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
// compile-flags: --edition=2018

use core::{
future::Future,
marker::Send,
pin::Pin,
};

fn non_async_func() {
println!("non_async_func was covered");
let b = true;
Expand All @@ -14,9 +8,6 @@ fn non_async_func() {
}
}




async fn async_func() {
println!("async_func was covered");
let b = true;
Expand All @@ -25,9 +16,6 @@ async fn async_func() {
}
}




async fn async_func_just_println() {
println!("async_func_just_println was covered");
}
Expand Down
4 changes: 2 additions & 2 deletions tests/run-coverage/auxiliary/inline_always_with_dead_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

mod foo {
#[inline(always)]
pub fn called() { }
pub fn called() {}

fn uncalled() { }
fn uncalled() {}
}

pub mod bar {
Expand Down
1 change: 1 addition & 0 deletions tests/run-coverage/auxiliary/unused_mod_helper.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[allow(dead_code)]
pub fn never_called_function() {
println!("I am never called");
}
5 changes: 4 additions & 1 deletion tests/run-coverage/auxiliary/used_crate.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#![allow(unused_assignments, unused_variables)]
// Verify that coverage works with optimizations:
// compile-flags: -C opt-level=3
use std::fmt::Debug; // ^^ validates coverage now works with optimizations

use std::fmt::Debug;

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

#[allow(dead_code)]
fn unused_private_function() {
let is_true = std::env::args().len() == 1;
let mut countdown = 2;
Expand Down
11 changes: 3 additions & 8 deletions tests/run-coverage/auxiliary/used_inline_crate.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![allow(unused_assignments, unused_variables)]

// Verify that coverage works with optimizations:
// compile-flags: -C opt-level=3
// ^^ validates coverage now works with optimizations

use std::fmt::Debug;

pub fn used_function() {
Expand Down Expand Up @@ -29,12 +29,6 @@ pub fn used_inline_function() {
use_this_lib_crate();
}







#[inline(always)]
pub fn used_only_from_bin_crate_generic_function<T: Debug>(arg: T) {
println!("used_only_from_bin_crate_generic_function with {:?}", arg);
Expand Down Expand Up @@ -71,6 +65,7 @@ pub fn unused_function() {
}

#[inline(always)]
#[allow(dead_code)]
fn unused_private_function() {
let is_true = std::env::args().len() == 1;
let mut countdown = 2;
Expand Down
9 changes: 7 additions & 2 deletions tests/run-coverage/closure.coverage
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
LL| |#![allow(unused_assignments, unused_variables)]
LL| |// compile-flags: -C opt-level=2
LL| 1|fn main() { // ^^ fix described in rustc_middle/mir/mono.rs
LL| |
LL| |// This test used to be sensitive to certain coverage-specific hacks in
LL| |// `rustc_middle/mir/mono.rs`, but those hacks were later cleaned up by
LL| |// <https://github.com/rust-lang/rust/pull/83666>.
LL| |
LL| 1|fn main() {
LL| 1| // Initialize test constants in a way that cannot be determined at compile time, to ensure
LL| 1| // rustc and LLVM cannot optimize out statements (or coverage counters) downstream from
LL| 1| // dependent conditions.
LL| 1| let is_true = std::env::args().len() == 1;
LL| 1| let is_false = ! is_true;
LL| 1| let is_false = !is_true;
LL| 1|
LL| 1| let mut some_string = Some(String::from("the string content"));
LL| 1| println!(
Expand Down
9 changes: 7 additions & 2 deletions tests/run-coverage/closure.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
#![allow(unused_assignments, unused_variables)]
// compile-flags: -C opt-level=2
fn main() { // ^^ fix described in rustc_middle/mir/mono.rs

// This test used to be sensitive to certain coverage-specific hacks in
// `rustc_middle/mir/mono.rs`, but those hacks were later cleaned up by
// <https://github.com/rust-lang/rust/pull/83666>.

fn main() {
// Initialize test constants in a way that cannot be determined at compile time, to ensure
// rustc and LLVM cannot optimize out statements (or coverage counters) downstream from
// dependent conditions.
let is_true = std::env::args().len() == 1;
let is_false = ! is_true;
let is_false = !is_true;

let mut some_string = Some(String::from("the string content"));
println!(
Expand Down
Loading