@@ -400,6 +400,9 @@ impl<'tcx> Stack {
400
400
// Either way, we ensure that we insert the new item in a way that between
401
401
// `derived_from` and the new one, there are only items *compatible with* `derived_from`.
402
402
let new_idx = if weak {
403
+ // A weak SharedReadOnly reborrow might be added below other items, violating the
404
+ // invariant that only SharedReadOnly can sit on top of SharedReadOnly.
405
+ assert ! ( new. perm != Permission :: SharedReadOnly , "Weak SharedReadOnly reborrows don't work" ) ;
403
406
// A very liberal reborrow because the new pointer does not expect any kind of aliasing guarantee.
404
407
// Just insert new permission as child of old permission, and maintain everything else.
405
408
// This inserts "as far down as possible", which is good because it makes this pointer as
@@ -581,8 +584,8 @@ trait EvalContextPrivExt<'a, 'mir, 'tcx: 'a+'mir>: crate::MiriEvalContextExt<'a,
581
584
// We need a frozen-sensitive reborrow.
582
585
return this. visit_freeze_sensitive ( place, size, |cur_ptr, size, frozen| {
583
586
// We are only ever `SharedReadOnly` inside the frozen bits.
584
- let weak = !frozen || kind != RefKind :: Shared ; // `RefKind::Raw` is always weak, as is `SharedReadWrite`.
585
587
let perm = if frozen { Permission :: SharedReadOnly } else { Permission :: SharedReadWrite } ;
588
+ let weak = perm == Permission :: SharedReadWrite ;
586
589
let item = Item { perm, tag : new_tag, protector } ;
587
590
alloc. extra . for_each ( cur_ptr, size, |stack, global| {
588
591
stack. reborrow ( cur_ptr. tag , force_weak || weak, item, global)
0 commit comments