Skip to content

Commit 4c8e867

Browse files
author
The Miri Cronjob Bot
committed
Merge from rustc
2 parents f9c1c86 + dabc82e commit 4c8e867

File tree

8 files changed

+70
-16
lines changed

8 files changed

+70
-16
lines changed

src/borrow_tracker/stacked_borrows/diagnostics.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ fn err_sb_ub<'tcx>(
1313
msg: String,
1414
help: Vec<String>,
1515
history: Option<TagHistory>,
16-
) -> InterpError<'tcx> {
16+
) -> InterpErrorKind<'tcx> {
1717
err_machine_stop!(TerminationInfo::StackedBorrowsUb { msg, help, history })
1818
}
1919

@@ -376,7 +376,7 @@ impl<'history, 'ecx, 'tcx> DiagnosticCx<'history, 'ecx, 'tcx> {
376376

377377
/// Report a descriptive error when `new` could not be granted from `derived_from`.
378378
#[inline(never)] // This is only called on fatal code paths
379-
pub(super) fn grant_error(&self, stack: &Stack) -> InterpError<'tcx> {
379+
pub(super) fn grant_error(&self, stack: &Stack) -> InterpErrorKind<'tcx> {
380380
let Operation::Retag(op) = &self.operation else {
381381
unreachable!("grant_error should only be called during a retag")
382382
};
@@ -402,7 +402,7 @@ impl<'history, 'ecx, 'tcx> DiagnosticCx<'history, 'ecx, 'tcx> {
402402

403403
/// Report a descriptive error when `access` is not permitted based on `tag`.
404404
#[inline(never)] // This is only called on fatal code paths
405-
pub(super) fn access_error(&self, stack: &Stack) -> InterpError<'tcx> {
405+
pub(super) fn access_error(&self, stack: &Stack) -> InterpErrorKind<'tcx> {
406406
// Deallocation and retagging also do an access as part of their thing, so handle that here, too.
407407
let op = match &self.operation {
408408
Operation::Access(op) => op,
@@ -424,7 +424,7 @@ impl<'history, 'ecx, 'tcx> DiagnosticCx<'history, 'ecx, 'tcx> {
424424
}
425425

426426
#[inline(never)] // This is only called on fatal code paths
427-
pub(super) fn protector_error(&self, item: &Item, kind: ProtectorKind) -> InterpError<'tcx> {
427+
pub(super) fn protector_error(&self, item: &Item, kind: ProtectorKind) -> InterpErrorKind<'tcx> {
428428
let protected = match kind {
429429
ProtectorKind::WeakProtector => "weakly protected",
430430
ProtectorKind::StrongProtector => "strongly protected",
@@ -445,7 +445,7 @@ impl<'history, 'ecx, 'tcx> DiagnosticCx<'history, 'ecx, 'tcx> {
445445
}
446446

447447
#[inline(never)] // This is only called on fatal code paths
448-
pub fn dealloc_error(&self, stack: &Stack) -> InterpError<'tcx> {
448+
pub fn dealloc_error(&self, stack: &Stack) -> InterpErrorKind<'tcx> {
449449
let Operation::Dealloc(op) = &self.operation else {
450450
unreachable!("dealloc_error should only be called during a deallocation")
451451
};

src/borrow_tracker/tree_borrows/diagnostics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ pub(super) struct TbError<'node> {
298298

299299
impl TbError<'_> {
300300
/// Produce a UB error.
301-
pub fn build<'tcx>(self) -> InterpError<'tcx> {
301+
pub fn build<'tcx>(self) -> InterpErrorKind<'tcx> {
302302
use TransitionError::*;
303303
let cause = self.access_cause;
304304
let accessed = self.accessed_info;

src/borrow_tracker/tree_borrows/tree.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ impl<'tcx> Tree {
674674
Ok(())
675675
}
676676
},
677-
|args: ErrHandlerArgs<'_, TransitionError>| -> InterpError<'tcx> {
677+
|args: ErrHandlerArgs<'_, TransitionError>| -> InterpErrorKind<'tcx> {
678678
let ErrHandlerArgs { error_kind, conflicting_info, accessed_info } = args;
679679
TbError {
680680
conflicting_info,
@@ -772,7 +772,7 @@ impl<'tcx> Tree {
772772
let err_handler = |perms_range: Range<u64>,
773773
access_cause: diagnostics::AccessCause,
774774
args: ErrHandlerArgs<'_, TransitionError>|
775-
-> InterpError<'tcx> {
775+
-> InterpErrorKind<'tcx> {
776776
let ErrHandlerArgs { error_kind, conflicting_info, accessed_info } = args;
777777
TbError {
778778
conflicting_info,

src/diagnostics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ pub fn report_error<'tcx>(
214214
ecx: &InterpCx<'tcx, MiriMachine<'tcx>>,
215215
e: InterpErrorInfo<'tcx>,
216216
) -> Option<(i64, bool)> {
217-
use InterpError::*;
217+
use InterpErrorKind::*;
218218
use UndefinedBehaviorInfo::*;
219219

220220
let mut msg = vec![];

src/intrinsics/simd.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -245,17 +245,17 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
245245
let val = match which {
246246
Op::MirOp(mir_op) => {
247247
// This does NaN adjustments.
248-
let val = this.binary_op(mir_op, &left, &right).map_err(|err| {
249-
match err.kind() {
250-
&InterpError::UndefinedBehavior(UndefinedBehaviorInfo::ShiftOverflow { shift_amount, .. }) => {
248+
let val = this.binary_op(mir_op, &left, &right).map_err_kind(|kind| {
249+
match kind {
250+
InterpErrorKind::UndefinedBehavior(UndefinedBehaviorInfo::ShiftOverflow { shift_amount, .. }) => {
251251
// This resets the interpreter backtrace, but it's not worth avoiding that.
252252
let shift_amount = match shift_amount {
253253
Either::Left(v) => v.to_string(),
254254
Either::Right(v) => v.to_string(),
255255
};
256-
err_ub_format!("overflowing shift by {shift_amount} in `simd_{intrinsic_name}` in lane {i}").into()
256+
err_ub_format!("overflowing shift by {shift_amount} in `simd_{intrinsic_name}` in lane {i}")
257257
}
258-
_ => err
258+
kind => kind
259259
}
260260
})?;
261261
if matches!(mir_op, BinOp::Eq | BinOp::Ne | BinOp::Lt | BinOp::Le | BinOp::Gt | BinOp::Ge) {

src/shims/foreign_items.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,11 +289,10 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
289289
"miri_get_alloc_id" => {
290290
let [ptr] = this.check_shim(abi, Abi::Rust, link_name, args)?;
291291
let ptr = this.read_pointer(ptr)?;
292-
let (alloc_id, _, _) = this.ptr_get_alloc_id(ptr, 0).map_err(|_e| {
292+
let (alloc_id, _, _) = this.ptr_get_alloc_id(ptr, 0).map_err_kind(|_e| {
293293
err_machine_stop!(TerminationInfo::Abort(format!(
294294
"pointer passed to `miri_get_alloc_id` must not be dangling, got {ptr:?}"
295295
)))
296-
.into()
297296
})?;
298297
this.write_scalar(Scalar::from_u64(alloc_id.0.get()), dest)?;
299298
}

tests/pass/dyn-upcast.rs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ fn main() {
99
struct_();
1010
replace_vptr();
1111
vtable_nop_cast();
12+
drop_principal();
1213
}
1314

1415
fn vtable_nop_cast() {
@@ -430,3 +431,53 @@ fn replace_vptr() {
430431
let s = S(42);
431432
invoke_outer(&s);
432433
}
434+
435+
fn drop_principal() {
436+
use std::{alloc::Layout, any::Any};
437+
438+
const fn yeet_principal(x: Box<dyn Any + Send>) -> Box<dyn Send> {
439+
x
440+
}
441+
442+
trait Bar: Send + Sync {}
443+
444+
impl<T: Send + Sync> Bar for T {}
445+
446+
const fn yeet_principal_2(x: Box<dyn Bar>) -> Box<dyn Send> {
447+
x
448+
}
449+
450+
struct CallMe<F: FnOnce()>(Option<F>);
451+
452+
impl<F: FnOnce()> CallMe<F> {
453+
fn new(f: F) -> Self {
454+
CallMe(Some(f))
455+
}
456+
}
457+
458+
impl<F: FnOnce()> Drop for CallMe<F> {
459+
fn drop(&mut self) {
460+
(self.0.take().unwrap())();
461+
}
462+
}
463+
464+
fn goodbye() {
465+
println!("goodbye");
466+
}
467+
468+
let x = Box::new(CallMe::new(goodbye)) as Box<dyn Any + Send>;
469+
let x_layout = Layout::for_value(&*x);
470+
let y = yeet_principal(x);
471+
let y_layout = Layout::for_value(&*y);
472+
assert_eq!(x_layout, y_layout);
473+
println!("before");
474+
drop(y);
475+
476+
let x = Box::new(CallMe::new(goodbye)) as Box<dyn Bar>;
477+
let x_layout = Layout::for_value(&*x);
478+
let y = yeet_principal_2(x);
479+
let y_layout = Layout::for_value(&*y);
480+
assert_eq!(x_layout, y_layout);
481+
println!("before");
482+
drop(y);
483+
}

tests/pass/dyn-upcast.stdout

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
before
2+
goodbye
3+
before
4+
goodbye

0 commit comments

Comments
 (0)