Skip to content

Commit

Permalink
Remove MirBorrowckCtxt methods that duplicate DiagCtxt methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
nnethercote committed Dec 20, 2023
1 parent 2b3768b commit 4092152
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 23 deletions.
35 changes: 13 additions & 22 deletions compiler/rustc_borrowck/src/borrowck_errors.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use rustc_errors::{
struct_span_err, DiagCtxt, DiagnosticBuilder, DiagnosticId, DiagnosticMessage, ErrorGuaranteed,
MultiSpan,
};
use rustc_errors::{struct_span_err, DiagCtxt, DiagnosticBuilder, ErrorGuaranteed};
use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_span::Span;

Expand Down Expand Up @@ -261,23 +258,23 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
is_arg: bool,
) -> DiagnosticBuilder<'cx, ErrorGuaranteed> {
let msg = if is_arg { "to immutable argument" } else { "twice to immutable variable" };
struct_span_err!(self, span, E0384, "cannot assign {} {}", msg, desc)
struct_span_err!(self.dcx(), span, E0384, "cannot assign {} {}", msg, desc)
}

pub(crate) fn cannot_assign(
&self,
span: Span,
desc: &str,
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
struct_span_err!(self, span, E0594, "cannot assign to {}", desc)
struct_span_err!(self.dcx(), span, E0594, "cannot assign to {}", desc)
}

pub(crate) fn cannot_move_out_of(
&self,
move_from_span: Span,
move_from_desc: &str,
) -> DiagnosticBuilder<'cx, ErrorGuaranteed> {
struct_span_err!(self, move_from_span, E0507, "cannot move out of {}", move_from_desc)
struct_span_err!(self.dcx(), move_from_span, E0507, "cannot move out of {}", move_from_desc)
}

/// Signal an error due to an attempt to move out of the interior
Expand Down Expand Up @@ -348,7 +345,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
path: &str,
reason: &str,
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
struct_span_err!(self, span, E0596, "cannot borrow {} as mutable{}", path, reason,)
struct_span_err!(self.dcx(), span, E0596, "cannot borrow {} as mutable{}", path, reason,)
}

pub(crate) fn cannot_mutate_in_immutable_section(
Expand Down Expand Up @@ -406,7 +403,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
span: Span,
path: &str,
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
struct_span_err!(self, span, E0597, "{} does not live long enough", path,)
struct_span_err!(self.dcx(), span, E0597, "{} does not live long enough", path,)
}

pub(crate) fn cannot_return_reference_to_local(
Expand Down Expand Up @@ -458,25 +455,19 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
&self,
span: Span,
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
struct_span_err!(self, span, E0712, "thread-local variable borrowed past end of function",)
struct_span_err!(
self.dcx(),
span,
E0712,
"thread-local variable borrowed past end of function",
)
}

pub(crate) fn temporary_value_borrowed_for_too_long(
&self,
span: Span,
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
struct_span_err!(self, span, E0716, "temporary value dropped while borrowed",)
}

#[rustc_lint_diagnostics]
#[track_caller]
pub(crate) fn struct_span_err_with_code<S: Into<MultiSpan>>(
&self,
sp: S,
msg: impl Into<DiagnosticMessage>,
code: DiagnosticId,
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
self.dcx().struct_span_err_with_code(sp, msg, code)
struct_span_err!(self.dcx(), span, E0716, "temporary value dropped while borrowed",)
}
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {

let used = desired_action.as_general_verb_in_past_tense();
let mut err =
struct_span_err!(self, span, E0381, "{used} binding {desc}{isnt_initialized}");
struct_span_err!(self.dcx(), span, E0381, "{used} binding {desc}{isnt_initialized}");
use_spans.var_path_only_subdiag(&mut err, desired_action);

if let InitializationRequiringAction::PartialAssignment
Expand Down

0 comments on commit 4092152

Please sign in to comment.