Skip to content

Commit 8ebc364

Browse files
committed
borrow_ck some diagnostic msg migration
E0596 & E0594 diagnose migration sort ftl messages alphabetically a153 patch 141c patch squash
1 parent 46455dc commit 8ebc364

File tree

11 files changed

+1346
-303
lines changed

11 files changed

+1346
-303
lines changed

compiler/rustc_borrowck/messages.ftl

Lines changed: 368 additions & 8 deletions
Large diffs are not rendered by default.

compiler/rustc_borrowck/src/borrowck_errors.rs

Lines changed: 237 additions & 164 deletions
Large diffs are not rendered by default.

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1795,6 +1795,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
17951795
/// cannot borrow `a.u` (via `a.u.z.c`) as immutable because it is also borrowed as
17961796
/// mutable (via `a.u.s.b`) [E0502]
17971797
/// ```
1798+
// FIXME: first 3 out of 4 can contain English word value, note for diagnostic migration
17981799
pub(crate) fn describe_place_for_conflicting_borrow(
17991800
&self,
18001801
first_borrowed_place: Place<'tcx>,

compiler/rustc_borrowck/src/diagnostics/mod.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ mod region_errors;
4747

4848
pub(crate) use bound_region_errors::{ToUniverseInfo, UniverseInfo};
4949
pub(crate) use move_errors::{IllegalMoveOriginKind, MoveError};
50-
pub(crate) use mutability_errors::AccessKind;
50+
pub(crate) use mutability_errors::{AccessKind, PlaceAndReason};
5151
pub(crate) use outlives_suggestion::OutlivesSuggestionBuilder;
5252
pub(crate) use region_errors::{ErrorConstraintInfo, RegionErrorKind, RegionErrors};
5353
pub(crate) use region_name::{RegionName, RegionNameSource};
@@ -681,6 +681,7 @@ impl UseSpans<'_> {
681681
}
682682
}
683683

684+
#[derive(Clone, Copy, Debug)]
684685
pub(super) enum BorrowedContentSource<'tcx> {
685686
DerefRawPointer,
686687
DerefMutableRef,
@@ -718,21 +719,22 @@ impl<'tcx> BorrowedContentSource<'tcx> {
718719
}
719720
}
720721

721-
pub(super) fn describe_for_immutable_place(&self, tcx: TyCtxt<'_>) -> String {
722+
// ready to remove
723+
pub(super) fn describe_for_immutable_place(&self, tcx: TyCtxt<'_>) -> Option<String> {
722724
match *self {
723-
BorrowedContentSource::DerefRawPointer => "a `*const` pointer".to_string(),
724-
BorrowedContentSource::DerefSharedRef => "a `&` reference".to_string(),
725+
BorrowedContentSource::DerefRawPointer => None,
726+
BorrowedContentSource::DerefSharedRef => None,
725727
BorrowedContentSource::DerefMutableRef => {
726728
bug!("describe_for_immutable_place: DerefMutableRef isn't immutable")
727729
}
728730
BorrowedContentSource::OverloadedDeref(ty) => ty
729731
.ty_adt_def()
730732
.and_then(|adt| match tcx.get_diagnostic_name(adt.did())? {
731-
name @ (sym::Rc | sym::Arc) => Some(format!("an `{name}`")),
733+
name @ (sym::Rc | sym::Arc) => Some(Some(format!("an `{name}`"))),
732734
_ => None,
733735
})
734-
.unwrap_or_else(|| format!("dereference of `{ty}`")),
735-
BorrowedContentSource::OverloadedIndex(ty) => format!("an index of `{ty}`"),
736+
.unwrap_or_else(|| Some(format!("dereference of `{ty}`"))),
737+
BorrowedContentSource::OverloadedIndex(ty) => Some(format!("`{ty}`")),
736738
}
737739
}
738740

compiler/rustc_borrowck/src/diagnostics/move_errors.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use rustc_span::{BytePos, Span};
77
use crate::diagnostics::CapturedMessageOpt;
88
use crate::diagnostics::{DescribePlaceOpt, UseSpans};
99
use crate::prefixes::PrefixSet;
10+
use crate::session_diagnostics::AddMoveErr;
1011
use crate::MirBorrowckCtxt;
1112

1213
#[derive(Debug)]
@@ -571,9 +572,9 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
571572
let binding_span = bind_to.source_info.span;
572573

573574
if j == 0 {
574-
err.span_label(binding_span, "data moved here");
575+
err.subdiagnostic(AddMoveErr::Here { binding_span });
575576
} else {
576-
err.span_label(binding_span, "...and here");
577+
err.subdiagnostic(AddMoveErr::AndHere { binding_span });
577578
}
578579

579580
if binds_to.len() == 1 {
@@ -588,10 +589,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
588589
}
589590

590591
if binds_to.len() > 1 {
591-
err.note(
592-
"move occurs because these variables have types that don't implement the `Copy` \
593-
trait",
594-
);
592+
err.subdiagnostic(AddMoveErr::MovedNotCopy);
595593
}
596594
}
597595
}

0 commit comments

Comments
 (0)