@@ -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 , Diag } ;
8
+ use rustc_errors:: { Applicability , Diag , DiagArgValue , 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 ) -> DiagArgValue {
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.
@@ -76,7 +88,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
76
88
/// LL | for (key, value) in dict {
77
89
/// | ^^^^
78
90
/// ```
79
- #[ allow( rustc:: diagnostic_outside_of_impl) ] // FIXME
80
91
pub ( super ) fn add_moved_or_invoked_closure_note (
81
92
& self ,
82
93
location : Location ,
@@ -176,6 +187,10 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
176
187
}
177
188
}
178
189
190
+ pub ( super ) fn describe_place_typed ( & self , place_ref : PlaceRef < ' tcx > ) -> DescribedPlace {
191
+ DescribedPlace ( self . describe_place ( place_ref) )
192
+ }
193
+
179
194
/// End-user visible description of `place` if one can be found.
180
195
/// If the place is a temporary for instance, `None` will be returned.
181
196
pub ( super ) fn describe_place ( & self , place_ref : PlaceRef < ' tcx > ) -> Option < String > {
@@ -586,7 +601,6 @@ impl UseSpans<'_> {
586
601
}
587
602
588
603
/// Add a span label to the arguments of the closure, if it exists.
589
- #[ allow( rustc:: diagnostic_outside_of_impl) ]
590
604
pub ( super ) fn args_subdiag (
591
605
self ,
592
606
dcx : & rustc_errors:: DiagCtxt ,
@@ -600,7 +614,6 @@ impl UseSpans<'_> {
600
614
601
615
/// Add a span label to the use of the captured variable, if it exists.
602
616
/// only adds label to the `path_span`
603
- #[ allow( rustc:: diagnostic_outside_of_impl) ]
604
617
pub ( super ) fn var_path_only_subdiag (
605
618
self ,
606
619
dcx : & rustc_errors:: DiagCtxt ,
@@ -638,7 +651,6 @@ impl UseSpans<'_> {
638
651
}
639
652
640
653
/// Add a subdiagnostic to the use of the captured variable, if it exists.
641
- #[ allow( rustc:: diagnostic_outside_of_impl) ]
642
654
pub ( super ) fn var_subdiag (
643
655
self ,
644
656
dcx : & rustc_errors:: DiagCtxt ,
@@ -703,6 +715,7 @@ impl UseSpans<'_> {
703
715
}
704
716
}
705
717
718
+ #[ derive( Clone , Copy , Debug ) ]
706
719
pub ( super ) enum BorrowedContentSource < ' tcx > {
707
720
DerefRawPointer ,
708
721
DerefMutableRef ,
@@ -754,7 +767,7 @@ impl<'tcx> BorrowedContentSource<'tcx> {
754
767
_ => None ,
755
768
} )
756
769
. unwrap_or_else ( || format ! ( "dereference of `{ty}`" ) ) ,
757
- BorrowedContentSource :: OverloadedIndex ( ty) => format ! ( "an index of `{ty}`" ) ,
770
+ BorrowedContentSource :: OverloadedIndex ( ty) => format ! ( "`{ty}`" ) ,
758
771
}
759
772
}
760
773
@@ -1012,8 +1025,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
1012
1025
self . borrow_spans ( span, borrow. reserve_location )
1013
1026
}
1014
1027
1015
- #[ allow( rustc:: diagnostic_outside_of_impl) ]
1016
- #[ allow( rustc:: untranslatable_diagnostic) ] // FIXME: make this translatable
1017
1028
fn explain_captures (
1018
1029
& mut self ,
1019
1030
err : & mut Diag < ' _ > ,
0 commit comments