Skip to content

Commit

Permalink
More consistency in diagnostics
Browse files Browse the repository at this point in the history
  • Loading branch information
saethlin committed Mar 8, 2022
1 parent 2ff395e commit 99c7a03
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions src/stacked_borrows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ impl<'tcx> Stack {
// Step 1: Find granting item.
let granting_idx = self.find_granting(access, tag).ok_or_else(|| {
err_sb_ub(format!(
"no item granting {} to tag {:?} over {}[{:#x}..{:#x}] found in borrow stack.",
"no item granting {} to tag {:?} exists in the borrow stack for memory range {}[{:#x}..{:#x}].",
access,
tag,
alloc_id,
Expand Down Expand Up @@ -485,23 +485,33 @@ impl<'tcx> Stack {
alloc_range.start.bytes(),
alloc_range.end().bytes()
);
if derived_from == SbTag::Untagged {
// Find all permissions that this tag grants. When we are not doing raw pointer tagging,
// there may be many untagged items in the borrow stack, and we want to report the most
// permissions that the tag grants.
let mut available_permissions = self
.borrows
.iter()
.filter_map(|item| (item.tag == derived_from).then(|| item.perm))
.filter(|perm| *perm != Permission::Disabled) // Dont't want to say "parent tag grants Disabled"
.collect::<Vec<_>>();
available_permissions.sort_by_key(|perm| {
match perm {
Permission::Unique => 0,
Permission::SharedReadWrite => 1,
Permission::SharedReadOnly => 2,
Permission::Disabled => unreachable!(),
}
});
if let Some(max_granted) = available_permissions.get(0) {
err_sb_ub(format!(
"{}, but parent tag {:?} does not grant the required permission over memory range",
action, derived_from
"{}, but parent tag {:?} grants insufficient permission: {:?}",
action, derived_from, max_granted
))
} else {
if let Some(parent) = self.borrows.iter().rev().find(|item| derived_from == item.tag) {
err_sb_ub(format!(
"{}, but parent tag {:?} grants insufficient permission: {:?}",
action, derived_from, parent.perm
))
} else {
err_sb_ub(format!(
"{}, but parent tag {:?} does not exist in the borrow stack for this memory range",
action, derived_from
))
}
err_sb_ub(format!(
"{}, but parent tag {:?} does not exist in the borrow stack for this memory range",
action, derived_from
))
}
}
}
Expand Down

0 comments on commit 99c7a03

Please sign in to comment.