Skip to content

Commit

Permalink
diag message migration, can't fix backtick repeat
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyJado committed Feb 23, 2024
1 parent 397937d commit 38c9970
Show file tree
Hide file tree
Showing 11 changed files with 1,347 additions and 294 deletions.
364 changes: 356 additions & 8 deletions compiler/rustc_borrowck/messages.ftl

Large diffs are not rendered by default.

384 changes: 222 additions & 162 deletions compiler/rustc_borrowck/src/borrowck_errors.rs

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1917,6 +1917,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
/// cannot borrow `a.u` (via `a.u.z.c`) as immutable because it is also borrowed as
/// mutable (via `a.u.s.b`) [E0502]
/// ```
// FIXME(#100717): In the return value, the first three strings can contain untranslated text.
pub(crate) fn describe_place_for_conflicting_borrow(
&self,
first_borrowed_place: Place<'tcx>,
Expand Down
23 changes: 20 additions & 3 deletions compiler/rustc_borrowck/src/diagnostics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::session_diagnostics::{
CaptureVarKind, CaptureVarPathUseCause, OnClosureNote,
};
use itertools::Itertools;
use rustc_errors::{Applicability, DiagnosticBuilder};
use rustc_errors::{Applicability, DiagnosticArgValue, DiagnosticBuilder, IntoDiagnosticArg};
use rustc_hir as hir;
use rustc_hir::def::{CtorKind, Namespace};
use rustc_hir::CoroutineKind;
Expand Down Expand Up @@ -48,7 +48,7 @@ mod region_errors;

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

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

#[derive(Debug)]
pub(super) struct DescribedPlace(pub(super) Option<String>);

impl IntoDiagnosticArg for DescribedPlace {
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
match self.0 {
Some(descr) => descr.into_diagnostic_arg(),
None => "value".into_diagnostic_arg(),
}
}
}

impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
/// Adds a suggestion when a closure is invoked twice with a moved variable or when a closure
/// is moved after being invoked.
Expand Down Expand Up @@ -175,6 +187,10 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
}
}

pub(super) fn describe_place_typed(&self, place_ref: PlaceRef<'tcx>) -> DescribedPlace {
DescribedPlace(self.describe_place(place_ref))
}

/// End-user visible description of `place` if one can be found.
/// If the place is a temporary for instance, `None` will be returned.
pub(super) fn describe_place(&self, place_ref: PlaceRef<'tcx>) -> Option<String> {
Expand Down Expand Up @@ -699,6 +715,7 @@ impl UseSpans<'_> {
}
}

#[derive(Clone, Copy, Debug)]
pub(super) enum BorrowedContentSource<'tcx> {
DerefRawPointer,
DerefMutableRef,
Expand Down Expand Up @@ -750,7 +767,7 @@ impl<'tcx> BorrowedContentSource<'tcx> {
_ => None,
})
.unwrap_or_else(|| format!("dereference of `{ty}`")),
BorrowedContentSource::OverloadedIndex(ty) => format!("an index of `{ty}`"),
BorrowedContentSource::OverloadedIndex(ty) => format!("`{ty}`"),
}
}

Expand Down
10 changes: 4 additions & 6 deletions compiler/rustc_borrowck/src/diagnostics/move_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use rustc_span::{BytePos, ExpnKind, MacroKind, Span};
use crate::diagnostics::CapturedMessageOpt;
use crate::diagnostics::{DescribePlaceOpt, UseSpans};
use crate::prefixes::PrefixSet;
use crate::session_diagnostics::AddMoveErr;
use crate::MirBorrowckCtxt;

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

if j == 0 {
err.span_label(binding_span, "data moved here");
err.subdiagnostic(self.dcx(), AddMoveErr::Here { binding_span });
} else {
err.span_label(binding_span, "...and here");
err.subdiagnostic(self.dcx(), AddMoveErr::AndHere { binding_span });
}

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

if binds_to.len() > 1 {
err.note(
"move occurs because these variables have types that don't implement the `Copy` \
trait",
);
err.subdiagnostic(self.dcx(), AddMoveErr::MovedNotCopy);
}
}

Expand Down
Loading

0 comments on commit 38c9970

Please sign in to comment.