Skip to content

Commit 5eb3e23

Browse files
committed
diag message migration, can't fix backtick repeat
1 parent 397937d commit 5eb3e23

11 files changed

+1359
-304
lines changed

compiler/rustc_borrowck/messages.ftl

+356-8
Large diffs are not rendered by default.

compiler/rustc_borrowck/src/borrowck_errors.rs

+222-162
Large diffs are not rendered by default.

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1917,6 +1917,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
19171917
/// cannot borrow `a.u` (via `a.u.z.c`) as immutable because it is also borrowed as
19181918
/// mutable (via `a.u.s.b`) [E0502]
19191919
/// ```
1920+
// FIXME(#100717): In the return value, the first three strings can contain untranslated text.
19201921
pub(crate) fn describe_place_for_conflicting_borrow(
19211922
&self,
19221923
first_borrowed_place: Place<'tcx>,

compiler/rustc_borrowck/src/diagnostics/mod.rs

+20-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::session_diagnostics::{
55
CaptureVarKind, CaptureVarPathUseCause, OnClosureNote,
66
};
77
use itertools::Itertools;
8-
use rustc_errors::{Applicability, DiagnosticBuilder};
8+
use rustc_errors::{Applicability, DiagnosticArgValue, DiagnosticBuilder, IntoDiagnosticArg};
99
use rustc_hir as hir;
1010
use rustc_hir::def::{CtorKind, Namespace};
1111
use rustc_hir::CoroutineKind;
@@ -48,7 +48,7 @@ mod region_errors;
4848

4949
pub(crate) use bound_region_errors::{ToUniverseInfo, UniverseInfo};
5050
pub(crate) use move_errors::{IllegalMoveOriginKind, MoveError};
51-
pub(crate) use mutability_errors::AccessKind;
51+
pub(crate) use mutability_errors::{AccessKind, PlaceAndReason};
5252
pub(crate) use outlives_suggestion::OutlivesSuggestionBuilder;
5353
pub(crate) use region_errors::{ErrorConstraintInfo, RegionErrorKind, RegionErrors};
5454
pub(crate) use region_name::{RegionName, RegionNameSource};
@@ -64,6 +64,18 @@ pub(super) struct DescribePlaceOpt {
6464

6565
pub(super) struct IncludingTupleField(pub(super) bool);
6666

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+
6779
impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
6880
/// Adds a suggestion when a closure is invoked twice with a moved variable or when a closure
6981
/// is moved after being invoked.
@@ -175,6 +187,10 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
175187
}
176188
}
177189

190+
pub(super) fn describe_place_typed(&self, place_ref: PlaceRef<'tcx>) -> DescribedPlace {
191+
DescribedPlace(self.describe_place(place_ref))
192+
}
193+
178194
/// End-user visible description of `place` if one can be found.
179195
/// If the place is a temporary for instance, `None` will be returned.
180196
pub(super) fn describe_place(&self, place_ref: PlaceRef<'tcx>) -> Option<String> {
@@ -699,6 +715,7 @@ impl UseSpans<'_> {
699715
}
700716
}
701717

718+
#[derive(Clone, Copy, Debug)]
702719
pub(super) enum BorrowedContentSource<'tcx> {
703720
DerefRawPointer,
704721
DerefMutableRef,
@@ -750,7 +767,7 @@ impl<'tcx> BorrowedContentSource<'tcx> {
750767
_ => None,
751768
})
752769
.unwrap_or_else(|| format!("dereference of `{ty}`")),
753-
BorrowedContentSource::OverloadedIndex(ty) => format!("an index of `{ty}`"),
770+
BorrowedContentSource::OverloadedIndex(ty) => format!("`{ty}`"),
754771
}
755772
}
756773

compiler/rustc_borrowck/src/diagnostics/move_errors.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use rustc_span::{BytePos, ExpnKind, MacroKind, Span};
1010
use crate::diagnostics::CapturedMessageOpt;
1111
use crate::diagnostics::{DescribePlaceOpt, UseSpans};
1212
use crate::prefixes::PrefixSet;
13+
use crate::session_diagnostics::AddMoveErr;
1314
use crate::MirBorrowckCtxt;
1415

1516
#[derive(Debug)]
@@ -584,9 +585,9 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
584585
let binding_span = bind_to.source_info.span;
585586

586587
if j == 0 {
587-
err.span_label(binding_span, "data moved here");
588+
err.subdiagnostic(self.dcx(), AddMoveErr::Here { binding_span });
588589
} else {
589-
err.span_label(binding_span, "...and here");
590+
err.subdiagnostic(self.dcx(), AddMoveErr::AndHere { binding_span });
590591
}
591592

592593
if binds_to.len() == 1 {
@@ -604,10 +605,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
604605
}
605606

606607
if binds_to.len() > 1 {
607-
err.note(
608-
"move occurs because these variables have types that don't implement the `Copy` \
609-
trait",
610-
);
608+
err.subdiagnostic(self.dcx(), AddMoveErr::MovedNotCopy);
611609
}
612610
}
613611

0 commit comments

Comments
 (0)