@@ -46,7 +46,7 @@ mod mutability_errors;
4646mod region_errors;
4747
4848pub ( crate ) use bound_region_errors:: { ToUniverseInfo , UniverseInfo } ;
49- pub ( crate ) use mutability_errors:: AccessKind ;
49+ pub ( crate ) use mutability_errors:: { AccessKind , PlaceAndReason } ;
5050pub ( crate ) use outlives_suggestion:: OutlivesSuggestionBuilder ;
5151pub ( crate ) use region_errors:: { ErrorConstraintInfo , RegionErrorKind , RegionErrors } ;
5252pub ( crate ) use region_name:: { RegionName , RegionNameSource } ;
@@ -678,6 +678,7 @@ impl UseSpans<'_> {
678678 }
679679}
680680
681+ #[ derive( Clone , Copy , Debug ) ]
681682pub ( super ) enum BorrowedContentSource < ' tcx > {
682683 DerefRawPointer ,
683684 DerefMutableRef ,
@@ -715,21 +716,22 @@ impl<'tcx> BorrowedContentSource<'tcx> {
715716 }
716717 }
717718
718- pub ( super ) fn describe_for_immutable_place ( & self , tcx : TyCtxt < ' _ > ) -> String {
719+ // ready to remove
720+ pub ( super ) fn describe_for_immutable_place ( & self , tcx : TyCtxt < ' _ > ) -> Option < String > {
719721 match * self {
720- BorrowedContentSource :: DerefRawPointer => "a `*const` pointer" . to_string ( ) ,
721- BorrowedContentSource :: DerefSharedRef => "a `&` reference" . to_string ( ) ,
722+ BorrowedContentSource :: DerefRawPointer => None ,
723+ BorrowedContentSource :: DerefSharedRef => None ,
722724 BorrowedContentSource :: DerefMutableRef => {
723725 bug ! ( "describe_for_immutable_place: DerefMutableRef isn't immutable" )
724726 }
725727 BorrowedContentSource :: OverloadedDeref ( ty) => ty
726728 . ty_adt_def ( )
727729 . and_then ( |adt| match tcx. get_diagnostic_name ( adt. did ( ) ) ? {
728- name @ ( sym:: Rc | sym:: Arc ) => Some ( format ! ( "an `{name}`" ) ) ,
730+ name @ ( sym:: Rc | sym:: Arc ) => Some ( Some ( format ! ( "an `{name}`" ) ) ) ,
729731 _ => None ,
730732 } )
731- . unwrap_or_else ( || format ! ( "dereference of `{ty}`" ) ) ,
732- BorrowedContentSource :: OverloadedIndex ( ty) => format ! ( "an index of `{ty}`" ) ,
733+ . unwrap_or_else ( || Some ( format ! ( "dereference of `{ty}`" ) ) ) ,
734+ BorrowedContentSource :: OverloadedIndex ( ty) => Some ( format ! ( "`{ty}`" ) ) ,
733735 }
734736 }
735737
0 commit comments