@@ -346,7 +346,7 @@ impl<'tcx> Stack {
346346 // Step 1: Find granting item.
347347 let granting_idx = self . find_granting ( access, tag) . ok_or_else ( || {
348348 err_sb_ub ( format ! (
349- "no item granting {} to tag {:?} over {}[{:#x}..{:#x}] found in borrow stack ." ,
349+ "no item granting {} to tag {:?} exists in the borrow stack for memory range {}[{:#x}..{:#x}]." ,
350350 access,
351351 tag,
352352 alloc_id,
@@ -485,23 +485,33 @@ impl<'tcx> Stack {
485485 alloc_range. start. bytes( ) ,
486486 alloc_range. end( ) . bytes( )
487487 ) ;
488- if derived_from == SbTag :: Untagged {
488+ // Find all permissions that this tag grants. When we are not doing raw pointer tagging,
489+ // there may be many untagged items in the borrow stack, and we want to report the most
490+ // permissions that the tag grants.
491+ let mut available_permissions = self
492+ . borrows
493+ . iter ( )
494+ . filter_map ( |item| ( item. tag == derived_from) . then ( || item. perm ) )
495+ . filter ( |perm| * perm != Permission :: Disabled ) // Dont't want to say "parent tag grants Disabled"
496+ . collect :: < Vec < _ > > ( ) ;
497+ available_permissions. sort_by_key ( |perm| {
498+ match perm {
499+ Permission :: Unique => 0 ,
500+ Permission :: SharedReadWrite => 1 ,
501+ Permission :: SharedReadOnly => 2 ,
502+ Permission :: Disabled => unreachable ! ( ) ,
503+ }
504+ } ) ;
505+ if let Some ( max_granted) = available_permissions. get ( 0 ) {
489506 err_sb_ub ( format ! (
490- "{}, but parent tag {:?} does not grant the required permission over memory range " ,
491- action, derived_from
507+ "{}, but parent tag {:?} grants insufficient permission: {:?} " ,
508+ action, derived_from, max_granted
492509 ) )
493510 } else {
494- if let Some ( parent) = self . borrows . iter ( ) . rev ( ) . find ( |item| derived_from == item. tag ) {
495- err_sb_ub ( format ! (
496- "{}, but parent tag {:?} grants insufficient permission: {:?}" ,
497- action, derived_from, parent. perm
498- ) )
499- } else {
500- err_sb_ub ( format ! (
501- "{}, but parent tag {:?} does not exist in the borrow stack for this memory range" ,
502- action, derived_from
503- ) )
504- }
511+ err_sb_ub ( format ! (
512+ "{}, but parent tag {:?} does not exist in the borrow stack for this memory range" ,
513+ action, derived_from
514+ ) )
505515 }
506516 }
507517}
0 commit comments