4
4
use std:: cell:: RefCell ;
5
5
use std:: collections:: { HashMap , HashSet } ;
6
6
use std:: fmt;
7
- use std:: fmt:: Write ;
8
7
use std:: num:: NonZeroU64 ;
9
8
use std:: rc:: Rc ;
10
9
@@ -279,13 +278,10 @@ impl<'tcx> Stack {
279
278
if let Some ( call) = item. protector {
280
279
if global. is_active ( call) {
281
280
if let Some ( tag) = tag {
282
- return Err ( err_ub_experimental (
283
- tag,
284
- format ! (
285
- "not granting access to tag {:?} because incompatible item is protected: {:?}" ,
286
- tag, item
287
- ) ,
288
- ) ) ;
281
+ throw_ub ! ( UbExperimental ( format!(
282
+ "not granting access to tag {:?} because incompatible item is protected: {:?}" ,
283
+ tag, item
284
+ ) ) ) ;
289
285
} else {
290
286
throw_ub ! ( UbExperimental ( format!(
291
287
"deallocating while item is protected: {:?}" ,
@@ -303,12 +299,9 @@ impl<'tcx> Stack {
303
299
// Two main steps: Find granting item, remove incompatible items above.
304
300
305
301
// Step 1: Find granting item.
306
- let granting_idx = self . find_granting ( access, tag) . ok_or_else ( || {
307
- err_ub_experimental (
308
- tag,
309
- format ! ( "no item granting {} to tag {:?} found in borrow stack." , access, tag) ,
310
- )
311
- } ) ?;
302
+ let granting_idx = self . find_granting ( access, tag) . ok_or_else ( || err_ub ! ( UbExperimental (
303
+ format!( "no item granting {} to tag {:?} found in borrow stack." , access, tag) ,
304
+ ) ) ) ?;
312
305
313
306
// Step 2: Remove incompatible items above them. Make sure we do not remove protected
314
307
// items. Behavior differs for reads and writes.
@@ -347,13 +340,10 @@ impl<'tcx> Stack {
347
340
/// active protectors at all because we will remove all items.
348
341
fn dealloc ( & mut self , tag : Tag , global : & GlobalState ) -> InterpResult < ' tcx > {
349
342
// Step 1: Find granting item.
350
- self . find_granting ( AccessKind :: Write , tag) . ok_or_else ( || {
351
- err_ub_experimental (
352
- tag, format ! (
353
- "no item granting write access for deallocation to tag {:?} found in borrow stack" ,
354
- tag,
355
- ) )
356
- } ) ?;
343
+ self . find_granting ( AccessKind :: Write , tag) . ok_or_else ( || err_ub ! ( UbExperimental ( format!(
344
+ "no item granting write access for deallocation to tag {:?} found in borrow stack" ,
345
+ tag,
346
+ ) ) ) ) ?;
357
347
358
348
// Step 2: Remove all items. Also checks for protectors.
359
349
for item in self . borrows . drain ( ..) . rev ( ) {
@@ -374,14 +364,10 @@ impl<'tcx> Stack {
374
364
// Now we figure out which item grants our parent (`derived_from`) this kind of access.
375
365
// We use that to determine where to put the new item.
376
366
let granting_idx = self . find_granting ( access, derived_from)
377
- . ok_or_else ( ||
378
- err_ub_experimental (
379
- derived_from,
380
- format ! (
381
- "trying to reborrow for {:?}, but parent tag {:?} does not have an appropriate item in the borrow stack" ,
382
- new. perm, derived_from,
383
- ) ,
384
- ) ) ?;
367
+ . ok_or_else ( || err_ub ! ( UbExperimental ( format!(
368
+ "trying to reborrow for {:?}, but parent tag {:?} does not have an appropriate item in the borrow stack" ,
369
+ new. perm, derived_from,
370
+ ) ) ) ) ?;
385
371
386
372
// Compute where to put the new item.
387
373
// Either way, we ensure that we insert the new item in a way such that between
@@ -647,10 +633,3 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
647
633
}
648
634
}
649
635
650
- fn err_ub_experimental ( tag : Tag , mut msg : String ) -> InterpErrorInfo < ' static > {
651
- if let Tag :: Tagged ( id) = tag {
652
- // FIXME: do not add this message when the flag is already set
653
- write ! ( msg, " Rerun with `-Zmiri-track-pointer-tag={}` for more information" , id) . unwrap ( ) ;
654
- }
655
- err_ub ! ( UbExperimental ( msg) ) . into ( )
656
- }
0 commit comments