Skip to content

Commit da5eeb3

Browse files
committed
Auto merge of #3980 - rust-lang:rustup-2024-10-20, r=RalfJung
Automatic Rustup
2 parents 4636ddc + 76600be commit da5eeb3

File tree

9 files changed

+76
-17
lines changed

9 files changed

+76
-17
lines changed

rust-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
dd5127615ad626741a1116d022cf784637ac05df
1+
54791efd8235805dcfbdad3b8788e08f2142c50b

src/borrow_tracker/stacked_borrows/diagnostics.rs

Lines changed: 9 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,11 @@ 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(
428+
&self,
429+
item: &Item,
430+
kind: ProtectorKind,
431+
) -> InterpErrorKind<'tcx> {
428432
let protected = match kind {
429433
ProtectorKind::WeakProtector => "weakly protected",
430434
ProtectorKind::StrongProtector => "strongly protected",
@@ -445,7 +449,7 @@ impl<'history, 'ecx, 'tcx> DiagnosticCx<'history, 'ecx, 'tcx> {
445449
}
446450

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

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

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)