@@ -2,7 +2,7 @@ use smallvec::SmallVec;
22use std:: fmt;
33
44use rustc_middle:: mir:: interpret:: { alloc_range, AllocId , AllocRange } ;
5- use rustc_span:: { Span , SpanData } ;
5+ use rustc_span:: { Span , SpanData , DUMMY_SP } ;
66use rustc_target:: abi:: Size ;
77
88use crate :: helpers:: CurrentSpan ;
@@ -91,6 +91,7 @@ impl fmt::Display for InvalidationCause {
9191
9292#[ derive( Clone , Debug ) ]
9393struct Protection {
94+ /// The parent tag from which this protected tag was derived.
9495 orig_tag : ProvenanceExtra ,
9596 tag : SbTag ,
9697 span : Span ,
@@ -342,32 +343,39 @@ impl<'span, 'history, 'ecx, 'mir, 'tcx> DiagnosticCx<'span, 'history, 'ecx, 'mir
342343
343344 let protected = protector_tag
344345 . and_then ( |protector| {
345- self . history . protectors . iter ( ) . find_map ( |protection| {
346- if protection. tag == protector {
347- Some ( ( protection. orig_tag , protection. span . data ( ) ) )
348- } else {
349- None
350- }
346+ self . history . protectors . iter ( ) . find ( |protection| {
347+ protection. tag == protector
351348 } )
352349 } )
353- . and_then ( |( tag , call_span ) | {
350+ . and_then ( |protection | {
354351 self . history . creations . iter ( ) . rev ( ) . find_map ( |event| {
355- if ProvenanceExtra :: Concrete ( event. retag . new_tag ) == tag {
356- Some ( ( event . retag . orig_tag , event. span . data ( ) , call_span ) )
352+ if ProvenanceExtra :: Concrete ( event. retag . new_tag ) == protection . orig_tag {
353+ Some ( ( protection , event) )
357354 } else {
358355 None
359356 }
360357 } )
361358 } )
362- . map ( |( protecting_tag, protecting_tag_span, protection_span) | {
359+ . map ( |( protection, protection_parent) | {
360+ let protected_tag = protection. tag ;
363361 [
364362 (
365363 format ! (
366- "{tag:?} was protected due to {protecting_tag :?} which was created here"
364+ "{tag:?} cannot be used for memory access because that would remove protected tag {protected_tag :?}, protected by this function call" ,
367365 ) ,
368- protecting_tag_span ,
366+ protection . span . data ( ) ,
369367 ) ,
370- ( format ! ( "this protector is live for this call" ) , protection_span) ,
368+ if protection_parent. retag . new_tag == tag {
369+ ( format ! ( "{protected_tag:?} was derived from {tag:?}, the tag used for this memory access" ) , DUMMY_SP . data ( ) )
370+ } else {
371+ (
372+ format ! (
373+ "{protected_tag:?} was derived from {protected_parent_tag:?}, which in turn was created here" ,
374+ protected_parent_tag = protection_parent. retag. new_tag,
375+ ) ,
376+ protection_parent. span . data ( )
377+ )
378+ }
371379 ]
372380 } ) ;
373381
0 commit comments