Skip to content

Commit

Permalink
Auto merge of rust-lang#134878 - Zalathar:rollup-ebqmxw7, r=Zalathar
Browse files Browse the repository at this point in the history
Rollup of 4 pull requests

Successful merges:

 - rust-lang#122565 (Try to write the panic message with a single `write_all` call)
 - rust-lang#133460 (Use `check-run-results` for `run-fail` test stderr)
 - rust-lang#134627 (Avoid ICE in borrowck)
 - rust-lang#134799 (nits: Cleanups in `librustdoc::clean`)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Dec 29, 2024
2 parents 480eec0 + 68d06b4 commit 4a7bd52
Show file tree
Hide file tree
Showing 451 changed files with 1,083 additions and 254 deletions.
10 changes: 8 additions & 2 deletions compiler/rustc_borrowck/src/region_infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1950,8 +1950,14 @@ impl<'tcx> RegionInferenceContext<'tcx> {
target_test: impl Fn(RegionVid) -> bool,
) -> (BlameConstraint<'tcx>, Vec<ExtraConstraintInfo>) {
// Find all paths
let (path, target_region) =
self.find_constraint_paths_between_regions(from_region, target_test).unwrap();
let (path, target_region) = self
.find_constraint_paths_between_regions(from_region, target_test)
.or_else(|| {
self.find_constraint_paths_between_regions(from_region, |r| {
self.cannot_name_placeholder(from_region, r)
})
})
.unwrap();
debug!(
"path={:#?}",
path.iter()
Expand Down
18 changes: 17 additions & 1 deletion library/std/src/panicking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,23 @@ fn default_hook(info: &PanicHookInfo<'_>) {
// Use a lock to prevent mixed output in multithreading context.
// Some platforms also require it when printing a backtrace, like `SymFromAddr` on Windows.
let mut lock = backtrace::lock();
let _ = writeln!(err, "thread '{name}' panicked at {location}:\n{msg}");
// Try to write the panic message to a buffer first to prevent other concurrent outputs
// interleaving with it.
let mut buffer = [0u8; 512];
let mut cursor = crate::io::Cursor::new(&mut buffer[..]);

let write_msg = |dst: &mut dyn crate::io::Write| {
// We add a newline to ensure the panic message appears at the start of a line.
writeln!(dst, "\nthread '{name}' panicked at {location}:\n{msg}")
};

if write_msg(&mut cursor).is_ok() {
let pos = cursor.position() as usize;
let _ = err.write_all(&buffer[0..pos]);
} else {
// The message did not fit into the buffer, write it directly instead.
let _ = write_msg(err);
};

static FIRST_PANIC: AtomicBool = AtomicBool::new(true);

Expand Down
22 changes: 10 additions & 12 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ fn clean_poly_trait_ref_with_constraints<'tcx>(
)
}

fn clean_lifetime(lifetime: &hir::Lifetime, cx: &mut DocContext<'_>) -> Lifetime {
fn clean_lifetime(lifetime: &hir::Lifetime, cx: &DocContext<'_>) -> Lifetime {
if let Some(
rbv::ResolvedArg::EarlyBound(did)
| rbv::ResolvedArg::LateBound(_, _, did)
Expand Down Expand Up @@ -362,9 +362,9 @@ pub(crate) fn clean_predicate<'tcx>(
let bound_predicate = predicate.kind();
match bound_predicate.skip_binder() {
ty::ClauseKind::Trait(pred) => clean_poly_trait_predicate(bound_predicate.rebind(pred), cx),
ty::ClauseKind::RegionOutlives(pred) => clean_region_outlives_predicate(pred),
ty::ClauseKind::RegionOutlives(pred) => Some(clean_region_outlives_predicate(pred)),
ty::ClauseKind::TypeOutlives(pred) => {
clean_type_outlives_predicate(bound_predicate.rebind(pred), cx)
Some(clean_type_outlives_predicate(bound_predicate.rebind(pred), cx))
}
ty::ClauseKind::Projection(pred) => {
Some(clean_projection_predicate(bound_predicate.rebind(pred), cx))
Expand Down Expand Up @@ -396,32 +396,30 @@ fn clean_poly_trait_predicate<'tcx>(
})
}

fn clean_region_outlives_predicate(
pred: ty::RegionOutlivesPredicate<'_>,
) -> Option<WherePredicate> {
fn clean_region_outlives_predicate(pred: ty::RegionOutlivesPredicate<'_>) -> WherePredicate {
let ty::OutlivesPredicate(a, b) = pred;

Some(WherePredicate::RegionPredicate {
WherePredicate::RegionPredicate {
lifetime: clean_middle_region(a).expect("failed to clean lifetime"),
bounds: vec![GenericBound::Outlives(
clean_middle_region(b).expect("failed to clean bounds"),
)],
})
}
}

fn clean_type_outlives_predicate<'tcx>(
pred: ty::Binder<'tcx, ty::TypeOutlivesPredicate<'tcx>>,
cx: &mut DocContext<'tcx>,
) -> Option<WherePredicate> {
) -> WherePredicate {
let ty::OutlivesPredicate(ty, lt) = pred.skip_binder();

Some(WherePredicate::BoundPredicate {
WherePredicate::BoundPredicate {
ty: clean_middle_ty(pred.rebind(ty), cx, None, None),
bounds: vec![GenericBound::Outlives(
clean_middle_region(lt).expect("failed to clean lifetimes"),
)],
bound_params: Vec::new(),
})
}
}

fn clean_middle_term<'tcx>(
Expand Down Expand Up @@ -1860,7 +1858,7 @@ pub(crate) fn clean_ty<'tcx>(ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> T

/// Returns `None` if the type could not be normalized
fn normalize<'tcx>(
cx: &mut DocContext<'tcx>,
cx: &DocContext<'tcx>,
ty: ty::Binder<'tcx, Ty<'tcx>>,
) -> Option<ty::Binder<'tcx, Ty<'tcx>>> {
// HACK: low-churn fix for #79459 while we wait for a trait normalization fix
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

thread 'main' panicked at tests/fail/function_calls/exported_symbol_bad_unwind1.rs:LL:CC:
explicit panic
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@

thread 'main' panicked at tests/fail/function_calls/exported_symbol_bad_unwind2.rs:LL:CC:
explicit panic
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
note: in Miri, you may have to set `MIRIFLAGS=-Zmiri-env-forward=RUST_BACKTRACE` for the environment variable to have an effect

thread 'main' panicked at RUSTLIB/core/src/panicking.rs:LL:CC:
panic in a function that cannot unwind
stack backtrace:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@

thread 'main' panicked at tests/fail/function_calls/exported_symbol_bad_unwind2.rs:LL:CC:
explicit panic
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
note: in Miri, you may have to set `MIRIFLAGS=-Zmiri-env-forward=RUST_BACKTRACE` for the environment variable to have an effect

thread 'main' panicked at RUSTLIB/core/src/panicking.rs:LL:CC:
panic in a function that cannot unwind
stack backtrace:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

thread 'main' panicked at tests/fail/function_calls/exported_symbol_bad_unwind2.rs:LL:CC:
explicit panic
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

thread 'main' panicked at tests/fail/function_calls/return_pointer_on_unwind.rs:LL:CC:
explicit panic
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

thread 'main' panicked at RUSTLIB/core/src/panicking.rs:LL:CC:
aborted execution: attempted to instantiate uninhabited type `!`
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Expand Down
1 change: 1 addition & 0 deletions src/tools/miri/tests/fail/intrinsics/zero_fn_ptr.stderr
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

thread 'main' panicked at RUSTLIB/core/src/panicking.rs:LL:CC:
aborted execution: attempted to zero-initialize type `fn()`, which is invalid
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Expand Down
2 changes: 2 additions & 0 deletions src/tools/miri/tests/fail/panic/abort_unwind.stderr
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@

thread 'main' panicked at tests/fail/panic/abort_unwind.rs:LL:CC:
PANIC!!!
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
note: in Miri, you may have to set `MIRIFLAGS=-Zmiri-env-forward=RUST_BACKTRACE` for the environment variable to have an effect

thread 'main' panicked at RUSTLIB/core/src/panicking.rs:LL:CC:
panic in a function that cannot unwind
stack backtrace:
Expand Down
1 change: 1 addition & 0 deletions src/tools/miri/tests/fail/panic/bad_unwind.stderr
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

thread 'main' panicked at tests/fail/panic/bad_unwind.rs:LL:CC:
explicit panic
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Expand Down
3 changes: 3 additions & 0 deletions src/tools/miri/tests/fail/panic/double_panic.stderr
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@

thread 'main' panicked at tests/fail/panic/double_panic.rs:LL:CC:
first
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
note: in Miri, you may have to set `MIRIFLAGS=-Zmiri-env-forward=RUST_BACKTRACE` for the environment variable to have an effect

thread 'main' panicked at tests/fail/panic/double_panic.rs:LL:CC:
second
stack backtrace:

thread 'main' panicked at RUSTLIB/core/src/panicking.rs:LL:CC:
panic in a destructor during cleanup
thread caused non-unwinding panic. aborting.
Expand Down
1 change: 1 addition & 0 deletions src/tools/miri/tests/fail/panic/panic_abort1.stderr
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

thread 'main' panicked at tests/fail/panic/panic_abort1.rs:LL:CC:
panicking from libstd
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Expand Down
1 change: 1 addition & 0 deletions src/tools/miri/tests/fail/panic/panic_abort2.stderr
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

thread 'main' panicked at tests/fail/panic/panic_abort2.rs:LL:CC:
42-panicking from libstd
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Expand Down
1 change: 1 addition & 0 deletions src/tools/miri/tests/fail/panic/panic_abort3.stderr
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

thread 'main' panicked at tests/fail/panic/panic_abort3.rs:LL:CC:
panicking from libcore
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Expand Down
1 change: 1 addition & 0 deletions src/tools/miri/tests/fail/panic/panic_abort4.stderr
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

thread 'main' panicked at tests/fail/panic/panic_abort4.rs:LL:CC:
42-panicking from libcore
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

thread $NAME panicked at tests/fail/panic/tls_macro_const_drop_panic.rs:LL:CC:
ow
fatal runtime error: thread local panicked on drop
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

thread $NAME panicked at tests/fail/panic/tls_macro_drop_panic.rs:LL:CC:
ow
fatal runtime error: thread local panicked on drop
Expand Down
2 changes: 2 additions & 0 deletions src/tools/miri/tests/fail/terminate-terminator.stderr
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
warning: You have explicitly enabled MIR optimizations, overriding Miri's default which is to completely disable them. Any optimizations may hide UB that Miri would otherwise detect, and it is not necessarily possible to predict what kind of UB will be missed. If you are enabling optimizations to make Miri run faster, we advise using cfg(miri) to shrink your workload instead. The performance benefit of enabling MIR optimizations is usually marginal at best.


thread 'main' panicked at tests/fail/terminate-terminator.rs:LL:CC:
explicit panic
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
note: in Miri, you may have to set `MIRIFLAGS=-Zmiri-env-forward=RUST_BACKTRACE` for the environment variable to have an effect

thread 'main' panicked at RUSTLIB/core/src/panicking.rs:LL:CC:
panic in a function that cannot unwind
stack backtrace:
Expand Down
2 changes: 2 additions & 0 deletions src/tools/miri/tests/fail/unwind-action-terminate.stderr
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@

thread 'main' panicked at tests/fail/unwind-action-terminate.rs:LL:CC:
explicit panic
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
note: in Miri, you may have to set `MIRIFLAGS=-Zmiri-env-forward=RUST_BACKTRACE` for the environment variable to have an effect

thread 'main' panicked at RUSTLIB/core/src/panicking.rs:LL:CC:
panic in a function that cannot unwind
stack backtrace:
Expand Down
1 change: 1 addition & 0 deletions src/tools/miri/tests/panic/alloc_error_handler_hook.stderr
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

thread 'main' panicked at tests/panic/alloc_error_handler_hook.rs:LL:CC:
alloc error hook called
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

thread 'main' panicked at RUSTLIB/std/src/alloc.rs:LL:CC:
memory allocation of 4 bytes failed
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Expand Down
1 change: 1 addition & 0 deletions src/tools/miri/tests/panic/div-by-zero-2.stderr
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

thread 'main' panicked at tests/panic/div-by-zero-2.rs:LL:CC:
attempt to divide by zero
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@

thread 'main' panicked at tests/panic/function_calls/exported_symbol_good_unwind.rs:LL:CC:
explicit panic
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
note: in Miri, you may have to set `MIRIFLAGS=-Zmiri-env-forward=RUST_BACKTRACE` for the environment variable to have an effect

thread 'main' panicked at tests/panic/function_calls/exported_symbol_good_unwind.rs:LL:CC:
explicit panic

thread 'main' panicked at tests/panic/function_calls/exported_symbol_good_unwind.rs:LL:CC:
explicit panic
1 change: 1 addition & 0 deletions src/tools/miri/tests/panic/mir-validation.stderr
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

thread 'rustc' panicked at compiler/rustc_mir_transform/src/validate.rs:LL:CC:
broken MIR in Item(DefId) (after phase change to runtime-optimized) at bb0[1]:
place (*(_2.0: *mut i32)) has deref as a later projection (it is only permitted as the first projection)
Expand Down
1 change: 1 addition & 0 deletions src/tools/miri/tests/panic/oob_subslice.stderr
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

thread 'main' panicked at tests/panic/oob_subslice.rs:LL:CC:
range end index 5 out of range for slice of length 4
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Expand Down
1 change: 1 addition & 0 deletions src/tools/miri/tests/panic/overflowing-lsh-neg.stderr
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

thread 'main' panicked at tests/panic/overflowing-lsh-neg.rs:LL:CC:
attempt to shift left with overflow
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Expand Down
1 change: 1 addition & 0 deletions src/tools/miri/tests/panic/overflowing-rsh-1.stderr
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

thread 'main' panicked at tests/panic/overflowing-rsh-1.rs:LL:CC:
attempt to shift right with overflow
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Expand Down
1 change: 1 addition & 0 deletions src/tools/miri/tests/panic/overflowing-rsh-2.stderr
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

thread 'main' panicked at tests/panic/overflowing-rsh-2.rs:LL:CC:
attempt to shift right with overflow
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Expand Down
1 change: 1 addition & 0 deletions src/tools/miri/tests/panic/panic1.stderr
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

thread 'main' panicked at tests/panic/panic1.rs:LL:CC:
panicking from libstd
stack backtrace:
Expand Down
1 change: 1 addition & 0 deletions src/tools/miri/tests/panic/panic2.stderr
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

thread 'main' panicked at tests/panic/panic2.rs:LL:CC:
42-panicking from libstd
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Expand Down
1 change: 1 addition & 0 deletions src/tools/miri/tests/panic/panic3.stderr
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

thread 'main' panicked at tests/panic/panic3.rs:LL:CC:
panicking from libcore
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Expand Down
1 change: 1 addition & 0 deletions src/tools/miri/tests/panic/panic4.stderr
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

thread 'main' panicked at tests/panic/panic4.rs:LL:CC:
42-panicking from libcore
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Expand Down
1 change: 1 addition & 0 deletions src/tools/miri/tests/panic/transmute_fat2.stderr
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

thread 'main' panicked at tests/panic/transmute_fat2.rs:LL:CC:
index out of bounds: the len is 0 but the index is 0
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Expand Down
11 changes: 11 additions & 0 deletions src/tools/miri/tests/pass/panic/catch_panic.stderr
Original file line number Diff line number Diff line change
@@ -1,35 +1,46 @@

thread 'main' panicked at tests/pass/panic/catch_panic.rs:LL:CC:
Hello from std::panic
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
note: in Miri, you may have to set `MIRIFLAGS=-Zmiri-env-forward=RUST_BACKTRACE` for the environment variable to have an effect
Caught panic message (&str): Hello from std::panic

thread 'main' panicked at tests/pass/panic/catch_panic.rs:LL:CC:
Hello from std::panic: 1
Caught panic message (String): Hello from std::panic: 1

thread 'main' panicked at tests/pass/panic/catch_panic.rs:LL:CC:
Hello from std::panic_any: 2
Caught panic message (String): Hello from std::panic_any: 2

thread 'main' panicked at tests/pass/panic/catch_panic.rs:LL:CC:
Box<dyn Any>
Failed to get caught panic message.

thread 'main' panicked at tests/pass/panic/catch_panic.rs:LL:CC:
Hello from core::panic
Caught panic message (&str): Hello from core::panic

thread 'main' panicked at tests/pass/panic/catch_panic.rs:LL:CC:
Hello from core::panic: 5
Caught panic message (String): Hello from core::panic: 5

thread 'main' panicked at tests/pass/panic/catch_panic.rs:LL:CC:
index out of bounds: the len is 3 but the index is 4
Caught panic message (String): index out of bounds: the len is 3 but the index is 4

thread 'main' panicked at tests/pass/panic/catch_panic.rs:LL:CC:
attempt to divide by zero
Caught panic message (&str): attempt to divide by zero

thread 'main' panicked at RUSTLIB/core/src/ptr/const_ptr.rs:LL:CC:
align_offset: align is not a power-of-two
Caught panic message (&str): align_offset: align is not a power-of-two

thread 'main' panicked at tests/pass/panic/catch_panic.rs:LL:CC:
assertion failed: false
Caught panic message (&str): assertion failed: false

thread 'main' panicked at tests/pass/panic/catch_panic.rs:LL:CC:
assertion failed: false
Caught panic message (&str): assertion failed: false
Expand Down
2 changes: 2 additions & 0 deletions src/tools/miri/tests/pass/panic/concurrent-panic.stderr
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
Thread 1 starting, will block on mutex
Thread 1 reported it has started

thread '<unnamed>' panicked at tests/pass/panic/concurrent-panic.rs:LL:CC:
panic in thread 2
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
note: in Miri, you may have to set `MIRIFLAGS=-Zmiri-env-forward=RUST_BACKTRACE` for the environment variable to have an effect
Thread 2 blocking on thread 1
Thread 2 reported it has started
Unlocking mutex

thread '<unnamed>' panicked at tests/pass/panic/concurrent-panic.rs:LL:CC:
panic in thread 1
Thread 1 has exited
Expand Down
2 changes: 2 additions & 0 deletions src/tools/miri/tests/pass/panic/nested_panic_caught.stderr
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@

thread 'main' panicked at tests/pass/panic/nested_panic_caught.rs:LL:CC:
once
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
note: in Miri, you may have to set `MIRIFLAGS=-Zmiri-env-forward=RUST_BACKTRACE` for the environment variable to have an effect

thread 'main' panicked at tests/pass/panic/nested_panic_caught.rs:LL:CC:
twice
stack backtrace:
2 changes: 2 additions & 0 deletions src/tools/miri/tests/pass/panic/thread_panic.stderr
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

thread '<unnamed>' panicked at tests/pass/panic/thread_panic.rs:LL:CC:
Hello!
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
note: in Miri, you may have to set `MIRIFLAGS=-Zmiri-env-forward=RUST_BACKTRACE` for the environment variable to have an effect

thread 'childthread' panicked at tests/pass/panic/thread_panic.rs:LL:CC:
Hello, world!
Loading

0 comments on commit 4a7bd52

Please sign in to comment.