@@ -6,7 +6,7 @@ use rustc_span::{Span, SpanData};
6
6
use rustc_target:: abi:: Size ;
7
7
8
8
use crate :: helpers:: CurrentSpan ;
9
- use crate :: stacked_borrows:: { err_sb_ub, AccessKind , GlobalStateInner , Permission } ;
9
+ use crate :: stacked_borrows:: { err_sb_ub, AccessKind , GlobalStateInner , Permission , ProtectorKind } ;
10
10
use crate :: * ;
11
11
12
12
use rustc_middle:: mir:: interpret:: InterpError ;
@@ -288,7 +288,11 @@ impl<'span, 'history, 'ecx, 'mir, 'tcx> DiagnosticCx<'span, 'history, 'ecx, 'mir
288
288
}
289
289
Operation :: Access ( AccessOp { kind, range, .. } ) =>
290
290
( * range, InvalidationCause :: Access ( * kind) ) ,
291
- _ => unreachable ! ( "Tags can only be invalidated during a retag or access" ) ,
291
+ Operation :: Dealloc ( _) => {
292
+ // This can be reached, but never be relevant later since the entire allocation is
293
+ // gone now.
294
+ return ;
295
+ }
292
296
} ;
293
297
self . history . invalidations . push ( Invalidation { tag, range, span, cause } ) ;
294
298
}
@@ -369,7 +373,7 @@ impl<'span, 'history, 'ecx, 'mir, 'tcx> DiagnosticCx<'span, 'history, 'ecx, 'mir
369
373
370
374
/// Report a descriptive error when `new` could not be granted from `derived_from`.
371
375
#[ inline( never) ] // This is only called on fatal code paths
372
- pub fn grant_error ( & self , perm : Permission , stack : & Stack ) -> InterpError < ' tcx > {
376
+ pub ( super ) fn grant_error ( & self , perm : Permission , stack : & Stack ) -> InterpError < ' tcx > {
373
377
let Operation :: Retag ( op) = & self . operation else {
374
378
unreachable ! ( "grant_error should only be called during a retag" )
375
379
} ;
@@ -389,7 +393,7 @@ impl<'span, 'history, 'ecx, 'mir, 'tcx> DiagnosticCx<'span, 'history, 'ecx, 'mir
389
393
390
394
/// Report a descriptive error when `access` is not permitted based on `tag`.
391
395
#[ inline( never) ] // This is only called on fatal code paths
392
- pub fn access_error ( & self , stack : & Stack ) -> InterpError < ' tcx > {
396
+ pub ( super ) fn access_error ( & self , stack : & Stack ) -> InterpError < ' tcx > {
393
397
let Operation :: Access ( op) = & self . operation else {
394
398
unreachable ! ( "access_error should only be called during an access" )
395
399
} ;
@@ -408,7 +412,11 @@ impl<'span, 'history, 'ecx, 'mir, 'tcx> DiagnosticCx<'span, 'history, 'ecx, 'mir
408
412
}
409
413
410
414
#[ inline( never) ] // This is only called on fatal code paths
411
- pub fn protector_error ( & self , item : & Item ) -> InterpError < ' tcx > {
415
+ pub ( super ) fn protector_error ( & self , item : & Item , kind : ProtectorKind ) -> InterpError < ' tcx > {
416
+ let protected = match kind {
417
+ ProtectorKind :: WeakProtector => "weakly protected" ,
418
+ ProtectorKind :: StrongProtector => "strongly protected" ,
419
+ } ;
412
420
let call_id = self
413
421
. threads
414
422
. all_stacks ( )
@@ -422,19 +430,15 @@ impl<'span, 'history, 'ecx, 'mir, 'tcx> DiagnosticCx<'span, 'history, 'ecx, 'mir
422
430
match self . operation {
423
431
Operation :: Dealloc ( _) =>
424
432
err_sb_ub (
425
- format ! (
426
- "deallocating while item {:?} is protected by call {:?}" ,
427
- item, call_id
428
- ) ,
433
+ format ! ( "deallocating while item {item:?} is {protected} by call {call_id:?}" , ) ,
429
434
None ,
430
435
None ,
431
436
) ,
432
437
Operation :: Retag ( RetagOp { orig_tag : tag, .. } )
433
438
| Operation :: Access ( AccessOp { tag, .. } ) =>
434
439
err_sb_ub (
435
440
format ! (
436
- "not granting access to tag {:?} because that would remove {:?} which is protected because it is an argument of call {:?}" ,
437
- tag, item, call_id
441
+ "not granting access to tag {tag:?} because that would remove {item:?} which is {protected} because it is an argument of call {call_id:?}" ,
438
442
) ,
439
443
None ,
440
444
tag. and_then ( |tag| self . get_logs_relevant_to ( tag, Some ( item. tag ( ) ) ) ) ,
0 commit comments