@@ -5,7 +5,7 @@ use crate::session_diagnostics::{
5
5
CaptureVarKind , CaptureVarPathUseCause , OnClosureNote ,
6
6
} ;
7
7
use itertools:: Itertools ;
8
- use rustc_errors:: { Applicability , DiagnosticBuilder } ;
8
+ use rustc_errors:: { Applicability , DiagnosticArgValue , DiagnosticBuilder , IntoDiagnosticArg } ;
9
9
use rustc_hir as hir;
10
10
use rustc_hir:: def:: { CtorKind , Namespace } ;
11
11
use rustc_hir:: CoroutineKind ;
@@ -48,7 +48,7 @@ mod region_errors;
48
48
49
49
pub ( crate ) use bound_region_errors:: { ToUniverseInfo , UniverseInfo } ;
50
50
pub ( crate ) use move_errors:: { IllegalMoveOriginKind , MoveError } ;
51
- pub ( crate ) use mutability_errors:: AccessKind ;
51
+ pub ( crate ) use mutability_errors:: { AccessKind , PlaceAndReason } ;
52
52
pub ( crate ) use outlives_suggestion:: OutlivesSuggestionBuilder ;
53
53
pub ( crate ) use region_errors:: { ErrorConstraintInfo , RegionErrorKind , RegionErrors } ;
54
54
pub ( crate ) use region_name:: { RegionName , RegionNameSource } ;
@@ -64,6 +64,18 @@ pub(super) struct DescribePlaceOpt {
64
64
65
65
pub ( super ) struct IncludingTupleField ( pub ( super ) bool ) ;
66
66
67
+ #[ derive( Debug ) ]
68
+ pub ( super ) struct DescribedPlace ( pub ( super ) Option < String > ) ;
69
+
70
+ impl IntoDiagnosticArg for DescribedPlace {
71
+ fn into_diagnostic_arg ( self ) -> DiagnosticArgValue {
72
+ match self . 0 {
73
+ Some ( descr) => descr. into_diagnostic_arg ( ) ,
74
+ None => "value" . into_diagnostic_arg ( ) ,
75
+ }
76
+ }
77
+ }
78
+
67
79
impl < ' cx , ' tcx > MirBorrowckCtxt < ' cx , ' tcx > {
68
80
/// Adds a suggestion when a closure is invoked twice with a moved variable or when a closure
69
81
/// is moved after being invoked.
@@ -175,6 +187,10 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
175
187
}
176
188
}
177
189
190
+ pub ( super ) fn describe_place_typed ( & self , place_ref : PlaceRef < ' tcx > ) -> DescribedPlace {
191
+ DescribedPlace ( self . describe_place ( place_ref) )
192
+ }
193
+
178
194
/// End-user visible description of `place` if one can be found.
179
195
/// If the place is a temporary for instance, `None` will be returned.
180
196
pub ( super ) fn describe_place ( & self , place_ref : PlaceRef < ' tcx > ) -> Option < String > {
@@ -699,6 +715,7 @@ impl UseSpans<'_> {
699
715
}
700
716
}
701
717
718
+ #[ derive( Clone , Copy , Debug ) ]
702
719
pub ( super ) enum BorrowedContentSource < ' tcx > {
703
720
DerefRawPointer ,
704
721
DerefMutableRef ,
@@ -750,7 +767,7 @@ impl<'tcx> BorrowedContentSource<'tcx> {
750
767
_ => None ,
751
768
} )
752
769
. unwrap_or_else ( || format ! ( "dereference of `{ty}`" ) ) ,
753
- BorrowedContentSource :: OverloadedIndex ( ty) => format ! ( "an index of `{ty}`" ) ,
770
+ BorrowedContentSource :: OverloadedIndex ( ty) => format ! ( "`{ty}`" ) ,
754
771
}
755
772
}
756
773
0 commit comments