diff --git a/rust-version b/rust-version index f54537d33b9..94c6f5e4b8c 100644 --- a/rust-version +++ b/rust-version @@ -1 +1 @@ -8e917f48382c6afaf50568263b89d35fba5d98e4 +a45743345659c775b01484574af2818c46a2cb03 diff --git a/src/eval.rs b/src/eval.rs index 837757c1ad3..bc9d97b0280 100644 --- a/src/eval.rs +++ b/src/eval.rs @@ -41,10 +41,9 @@ pub fn create_ecx<'mir, 'tcx: 'mir>( let main_mir = ecx.load_mir(main_instance.def)?; if !main_mir.return_ty().is_unit() || main_mir.arg_count != 0 { - throw_unsup!(Unimplemented( + throw_unsup_format!( "miri does not support main functions without `fn()` type signatures" - .to_owned(), - )); + ); } let start_id = tcx.lang_items().start_fn().unwrap(); @@ -60,10 +59,10 @@ pub fn create_ecx<'mir, 'tcx: 'mir>( let start_mir = ecx.load_mir(start_instance.def)?; if start_mir.arg_count != 3 { - throw_unsup!(AbiViolation(format!( + bug!( "'start' lang item should have three arguments, but has {}", start_mir.arg_count - ))); + ); } // Return value (in static memory so that it does not count as leak). diff --git a/src/machine.rs b/src/machine.rs index 7fa79d822c3..30f3231308a 100644 --- a/src/machine.rs +++ b/src/machine.rs @@ -247,9 +247,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'tcx> { let data = vec![0; size.bytes() as usize]; Allocation::from_bytes(&data, tcx.data_layout.pointer_align.abi) } - _ => throw_unsup!(Unimplemented( - format!("can't access foreign static: {}", link_name), - )), + _ => throw_unsup_format!("can't access foreign static: {}", link_name), }; Ok(Cow::Owned(alloc)) } diff --git a/src/shims/dlsym.rs b/src/shims/dlsym.rs index 00549309624..b859a801902 100644 --- a/src/shims/dlsym.rs +++ b/src/shims/dlsym.rs @@ -16,9 +16,7 @@ impl Dlsym { "getentropy" => Some(GetEntropy), "__pthread_get_minstack" => None, _ => - throw_unsup!(Unimplemented(format!( - "Unsupported dlsym: {}", name - ))), + throw_unsup_format!("Unsupported dlsym: {}", name), }) } } diff --git a/src/shims/foreign_items.rs b/src/shims/foreign_items.rs index 12baa79916a..5561231edf0 100644 --- a/src/shims/foreign_items.rs +++ b/src/shims/foreign_items.rs @@ -141,7 +141,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx // First: functions that diverge. match link_name { "__rust_start_panic" | "panic_impl" => { - throw_unsup!(MachineError("the evaluated program panicked".to_string())); + throw_unsup_format!("the evaluated program panicked"); } "exit" | "ExitProcess" => { // it's really u32 for ExitProcess, but we have to put it into the `Exit` error variant anyway @@ -149,9 +149,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx return Err(InterpError::Exit(code).into()); } _ => if dest.is_none() { - throw_unsup!(Unimplemented( - format!("can't call diverging foreign function: {}", link_name), - )); + throw_unsup_format!("can't call (diverging) foreign function: {}", link_name); } } @@ -183,10 +181,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx FIXME: This check is disabled because rustc violates it. See . if align < this.pointer_size().bytes() { - throw_unsup!(MachineError(format!( + throw_ub_format!( "posix_memalign: alignment must be at least the size of a pointer, but is {}", align, - ))); + ); } */ if size == 0 { @@ -309,9 +307,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx this.write_scalar(Scalar::from_uint(len, dest.layout.size), dest)?; } id => { - throw_unsup!(Unimplemented( - format!("miri does not support syscall ID {}", id), - )) + throw_unsup_format!("miri does not support syscall ID {}", id) } } } @@ -359,12 +355,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx )?; let mut args = this.frame().body.args_iter(); - let arg_local = args.next().ok_or_else(|| - err_unsup!(AbiViolation( - "Argument to __rust_maybe_catch_panic does not take enough arguments." - .to_owned(), - )), - )?; + let arg_local = args.next() + .expect("Argument to __rust_maybe_catch_panic does not take enough arguments."); let arg_dest = this.local_place(arg_local)?; this.write_scalar(data, arg_dest)?; @@ -632,9 +624,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx if let Some(result) = result { this.write_scalar(result, dest)?; } else { - throw_unsup!(Unimplemented( - format!("Unimplemented sysconf name: {}", name), - )); + throw_unsup_format!("Unimplemented sysconf name: {}", name) } } @@ -661,9 +651,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx // This is `libc::pthread_key_t`. let key_type = args[0].layout.ty .builtin_deref(true) - .ok_or_else(|| err_unsup!( - AbiViolation("wrong signature used for `pthread_key_create`: first argument must be a raw pointer.".to_owned()) - ))? + .ok_or_else(|| err_ub!(Ub(format!( + "wrong signature used for `pthread_key_create`: first argument must be a raw pointer." + ))))? .ty; let key_layout = this.layout_of(key_type)?; @@ -729,7 +719,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx // We don't support threading. (Also for Windows.) "pthread_create" | "CreateThread" => { - throw_unsup!(Unimplemented(format!("Miri does not support threading"))); + throw_unsup_format!("Miri does not support threading"); } // Stub out calls for condvar, mutex and rwlock, to just return `0`. @@ -948,9 +938,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx // We can't execute anything else. _ => { - throw_unsup!(Unimplemented( - format!("can't call foreign function: {}", link_name), - )); + throw_unsup_format!("can't call foreign function: {}", link_name) } } diff --git a/src/shims/intrinsics.rs b/src/shims/intrinsics.rs index 7a213a80599..5c3ff139c02 100644 --- a/src/shims/intrinsics.rs +++ b/src/shims/intrinsics.rs @@ -133,7 +133,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx "atomic_xsub_relaxed" => { let ptr = this.deref_operand(args[0])?; if !ptr.layout.ty.is_integral() { - throw_unsup!(Unimplemented(format!("Atomic arithmetic operations only work on integer types"))); + bug!("Atomic arithmetic operations only work on integer types"); } let rhs = this.read_immediate(args[1])?; let old = this.read_immediate(ptr.into())?; @@ -279,9 +279,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx // Check if `b` is -1, which is the "min_value / -1" case. let minus1 = Scalar::from_int(-1, dest.layout.size); return Err(if b.to_scalar().unwrap() == minus1 { - err_unsup!(Intrinsic(format!("exact_div: result of dividing MIN by -1 cannot be represented"))) + err_ub!(Ub(format!("exact_div: result of dividing MIN by -1 cannot be represented"))) } else { - err_unsup!(Intrinsic(format!("exact_div: {:?} cannot be divided by {:?} without remainder", *a, *b))) + err_ub!(Ub(format!("exact_div: {:?} cannot be divided by {:?} without remainder", *a, *b))) }.into()); } this.binop_ignore_overflow(mir::BinOp::Div, a, b, dest)?; @@ -350,7 +350,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx let ty = substs.type_at(0); let layout = this.layout_of(ty)?; if layout.abi.is_uninhabited() { - throw_unsup!(Intrinsic(format!("Trying to instantiate uninhabited type {}", ty))) + throw_ub_format!("Trying to instantiate uninhabited type {}", ty) } } @@ -444,7 +444,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx let r = this.read_immediate(args[1])?; let rval = r.to_scalar()?.to_bits(args[1].layout.size)?; if rval == 0 { - throw_unsup!(Intrinsic(format!("Division by 0 in unchecked_div"))); + throw_ub_format!("Division by 0 in unchecked_div"); } this.binop_ignore_overflow( mir::BinOp::Div, @@ -459,7 +459,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx let r = this.read_immediate(args[1])?; let rval = r.to_scalar()?.to_bits(args[1].layout.size)?; if rval == 0 { - throw_unsup!(Intrinsic(format!("Division by 0 in unchecked_rem"))); + throw_ub_format!("Division by 0 in unchecked_rem"); } this.binop_ignore_overflow( mir::BinOp::Rem, @@ -480,7 +480,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx }; let (res, overflowed) = this.binary_op(op, l, r)?; if overflowed { - throw_unsup!(Intrinsic(format!("Overflowing arithmetic in {}", intrinsic_name.get()))); + throw_ub_format!("Overflowing arithmetic in {}", intrinsic_name.get()); } this.write_scalar(res, dest)?; } @@ -504,7 +504,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx } } - name => throw_unsup!(Unimplemented(format!("unimplemented intrinsic: {}", name))), + name => throw_unsup_format!("unimplemented intrinsic: {}", name), } Ok(()) diff --git a/src/shims/tls.rs b/src/shims/tls.rs index 145d2b3e789..05b8dc15da6 100644 --- a/src/shims/tls.rs +++ b/src/shims/tls.rs @@ -158,7 +158,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx StackPopCleanup::None { cleanup: true }, )?; let arg_local = this.frame().body.args_iter().next().ok_or_else( - || err_unsup!(AbiViolation("TLS dtor does not take enough arguments.".to_owned())), + || err_ub!(Ub(format!("TLS dtor does not take enough arguments."))), )?; let dest = this.local_place(arg_local)?; this.write_scalar(ptr, dest)?; diff --git a/src/stacked_borrows.rs b/src/stacked_borrows.rs index 5ef934b9922..0fbc3e1ac28 100644 --- a/src/stacked_borrows.rs +++ b/src/stacked_borrows.rs @@ -273,14 +273,14 @@ impl<'tcx> Stack { if let Some(call) = item.protector { if global.is_active(call) { if let Some(tag) = tag { - throw_unsup!(MachineError(format!( + throw_ub_format!( "not granting access to tag {:?} because incompatible item is protected: {:?}", tag, item - ))); + ); } else { - throw_unsup!(MachineError(format!( + throw_ub_format!( "deallocating while item is protected: {:?}", item - ))); + ); } } } @@ -299,7 +299,7 @@ impl<'tcx> Stack { // Step 1: Find granting item. let granting_idx = self.find_granting(access, tag) - .ok_or_else(|| err_unsup!(MachineError(format!( + .ok_or_else(|| err_ub!(Ub(format!( "no item granting {} to tag {:?} found in borrow stack", access, tag, ))))?; @@ -346,7 +346,7 @@ impl<'tcx> Stack { ) -> InterpResult<'tcx> { // Step 1: Find granting item. self.find_granting(AccessKind::Write, tag) - .ok_or_else(|| err_unsup!(MachineError(format!( + .ok_or_else(|| err_ub!(Ub(format!( "no item granting write access for deallocation to tag {:?} found in borrow stack", tag, ))))?; @@ -378,7 +378,7 @@ impl<'tcx> Stack { // Now we figure out which item grants our parent (`derived_from`) this kind of access. // We use that to determine where to put the new item. let granting_idx = self.find_granting(access, derived_from) - .ok_or_else(|| err_unsup!(MachineError(format!( + .ok_or_else(|| err_ub!(Ub(format!( "trying to reborrow for {:?}, but parent tag {:?} does not have an appropriate item in the borrow stack", new.perm, derived_from, ))))?;