44use std:: cell:: RefCell ;
55use std:: collections:: { HashMap , HashSet } ;
66use std:: fmt;
7- use std:: fmt:: Write ;
87use std:: num:: NonZeroU64 ;
98use std:: rc:: Rc ;
109
@@ -279,13 +278,10 @@ impl<'tcx> Stack {
279278 if let Some ( call) = item. protector {
280279 if global. is_active ( call) {
281280 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+ ) ) ) ;
289285 } else {
290286 throw_ub ! ( UbExperimental ( format!(
291287 "deallocating while item is protected: {:?}" ,
@@ -303,12 +299,9 @@ impl<'tcx> Stack {
303299 // Two main steps: Find granting item, remove incompatible items above.
304300
305301 // 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+ ) ) ) ?;
312305
313306 // Step 2: Remove incompatible items above them. Make sure we do not remove protected
314307 // items. Behavior differs for reads and writes.
@@ -347,13 +340,10 @@ impl<'tcx> Stack {
347340 /// active protectors at all because we will remove all items.
348341 fn dealloc ( & mut self , tag : Tag , global : & GlobalState ) -> InterpResult < ' tcx > {
349342 // 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+ ) ) ) ) ?;
357347
358348 // Step 2: Remove all items. Also checks for protectors.
359349 for item in self . borrows . drain ( ..) . rev ( ) {
@@ -374,14 +364,10 @@ impl<'tcx> Stack {
374364 // Now we figure out which item grants our parent (`derived_from`) this kind of access.
375365 // We use that to determine where to put the new item.
376366 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+ ) ) ) ) ?;
385371
386372 // Compute where to put the new item.
387373 // 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
647633 }
648634}
649635
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