Skip to content

Commit

Permalink
Replace &mut DiagnosticBuilder, in signatures, with &mut Diagnostic.
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyb committed Feb 23, 2022
1 parent f24ff18 commit 02ff9e0
Show file tree
Hide file tree
Showing 65 changed files with 369 additions and 466 deletions.
14 changes: 5 additions & 9 deletions compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use either::Either;
use rustc_const_eval::util::{CallDesugaringKind, CallKind};
use rustc_data_structures::fx::FxHashSet;
use rustc_errors::{Applicability, DiagnosticBuilder};
use rustc_errors::{Applicability, Diagnostic, DiagnosticBuilder};
use rustc_hir as hir;
use rustc_hir::def_id::DefId;
use rustc_hir::{AsyncGeneratorKind, GeneratorKind};
Expand Down Expand Up @@ -782,7 +782,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
#[instrument(level = "debug", skip(self, err))]
fn suggest_using_local_if_applicable(
&self,
err: &mut DiagnosticBuilder<'_>,
err: &mut Diagnostic,
location: Location,
(place, span): (Place<'tcx>, Span),
gen_borrow_kind: BorrowKind,
Expand Down Expand Up @@ -855,7 +855,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {

fn suggest_split_at_mut_if_applicable(
&self,
err: &mut DiagnosticBuilder<'_>,
err: &mut Diagnostic,
place: Place<'tcx>,
borrowed_place: Place<'tcx>,
) {
Expand Down Expand Up @@ -1835,7 +1835,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
self.buffer_error(err);
}

fn explain_deref_coercion(&mut self, loan: &BorrowData<'tcx>, err: &mut DiagnosticBuilder<'_>) {
fn explain_deref_coercion(&mut self, loan: &BorrowData<'tcx>, err: &mut Diagnostic) {
let tcx = self.infcx.tcx;
if let (
Some(Terminator { kind: TerminatorKind::Call { from_hir_call: false, .. }, .. }),
Expand Down Expand Up @@ -2362,11 +2362,7 @@ enum AnnotatedBorrowFnSignature<'tcx> {
impl<'tcx> AnnotatedBorrowFnSignature<'tcx> {
/// Annotate the provided diagnostic with information about borrow from the fn signature that
/// helps explain.
pub(crate) fn emit(
&self,
cx: &mut MirBorrowckCtxt<'_, 'tcx>,
diag: &mut DiagnosticBuilder<'_>,
) -> String {
pub(crate) fn emit(&self, cx: &mut MirBorrowckCtxt<'_, 'tcx>, diag: &mut Diagnostic) -> String {
match self {
&AnnotatedBorrowFnSignature::Closure { argument_ty, argument_span } => {
diag.span_label(
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use std::collections::VecDeque;

use rustc_data_structures::fx::FxHashSet;
use rustc_errors::{Applicability, DiagnosticBuilder};
use rustc_errors::{Applicability, Diagnostic};
use rustc_index::vec::IndexVec;
use rustc_infer::infer::NllRegionVariableOrigin;
use rustc_middle::mir::{
Expand Down Expand Up @@ -60,7 +60,7 @@ impl BorrowExplanation {
tcx: TyCtxt<'tcx>,
body: &Body<'tcx>,
local_names: &IndexVec<Local, Option<Symbol>>,
err: &mut DiagnosticBuilder<'_>,
err: &mut Diagnostic,
borrow_desc: &str,
borrow_span: Option<Span>,
multiple_borrow_span: Option<(Span, Span)>,
Expand Down Expand Up @@ -275,7 +275,7 @@ impl BorrowExplanation {
}
pub(crate) fn add_lifetime_bound_suggestion_to_diagnostic(
&self,
err: &mut DiagnosticBuilder<'_>,
err: &mut Diagnostic,
category: &ConstraintCategory,
span: Span,
region_name: &RegionName,
Expand Down
20 changes: 6 additions & 14 deletions compiler/rustc_borrowck/src/diagnostics/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Borrow checker diagnostics.
use rustc_const_eval::util::call_kind;
use rustc_errors::DiagnosticBuilder;
use rustc_errors::Diagnostic;
use rustc_hir as hir;
use rustc_hir::def::Namespace;
use rustc_hir::def_id::DefId;
Expand Down Expand Up @@ -57,7 +57,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
&self,
location: Location,
place: PlaceRef<'tcx>,
diag: &mut DiagnosticBuilder<'_>,
diag: &mut Diagnostic,
) {
debug!("add_moved_or_invoked_closure_note: location={:?} place={:?}", location, place);
let mut target = place.local_or_deref_local();
Expand Down Expand Up @@ -409,7 +409,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
/// Add a note that a type does not implement `Copy`
pub(super) fn note_type_does_not_implement_copy(
&self,
err: &mut DiagnosticBuilder<'_>,
err: &mut Diagnostic,
place_desc: &str,
ty: Ty<'tcx>,
span: Option<Span>,
Expand Down Expand Up @@ -613,23 +613,15 @@ impl UseSpans<'_> {
}

// Add a span label to the arguments of the closure, if it exists.
pub(super) fn args_span_label(
self,
err: &mut DiagnosticBuilder<'_>,
message: impl Into<String>,
) {
pub(super) fn args_span_label(self, err: &mut Diagnostic, message: impl Into<String>) {
if let UseSpans::ClosureUse { args_span, .. } = self {
err.span_label(args_span, message);
}
}

// Add a span label to the use of the captured variable, if it exists.
// only adds label to the `path_span`
pub(super) fn var_span_label_path_only(
self,
err: &mut DiagnosticBuilder<'_>,
message: impl Into<String>,
) {
pub(super) fn var_span_label_path_only(self, err: &mut Diagnostic, message: impl Into<String>) {
if let UseSpans::ClosureUse { path_span, .. } = self {
err.span_label(path_span, message);
}
Expand All @@ -638,7 +630,7 @@ impl UseSpans<'_> {
// Add a span label to the use of the captured variable, if it exists.
pub(super) fn var_span_label(
self,
err: &mut DiagnosticBuilder<'_>,
err: &mut Diagnostic,
message: impl Into<String>,
kind_desc: impl Into<String>,
) {
Expand Down
13 changes: 4 additions & 9 deletions compiler/rustc_borrowck/src/diagnostics/move_errors.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use rustc_const_eval::util::CallDesugaringKind;
use rustc_errors::{Applicability, DiagnosticBuilder};
use rustc_errors::{Applicability, Diagnostic, DiagnosticBuilder};
use rustc_infer::infer::TyCtxtInferExt;
use rustc_middle::mir::*;
use rustc_middle::ty;
Expand Down Expand Up @@ -441,12 +441,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
err
}

fn add_move_hints(
&self,
error: GroupedMoveError<'tcx>,
err: &mut DiagnosticBuilder<'a>,
span: Span,
) {
fn add_move_hints(&self, error: GroupedMoveError<'tcx>, err: &mut Diagnostic, span: Span) {
match error {
GroupedMoveError::MovesFromPlace { mut binds_to, move_from, .. } => {
if let Ok(snippet) = self.infcx.tcx.sess.source_map().span_to_snippet(span) {
Expand Down Expand Up @@ -505,7 +500,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
}
}

fn add_move_error_suggestions(&self, err: &mut DiagnosticBuilder<'a>, binds_to: &[Local]) {
fn add_move_error_suggestions(&self, err: &mut Diagnostic, binds_to: &[Local]) {
let mut suggestions: Vec<(Span, &str, String)> = Vec::new();
for local in binds_to {
let bind_to = &self.body.local_decls[*local];
Expand Down Expand Up @@ -541,7 +536,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
}
}

fn add_move_error_details(&self, err: &mut DiagnosticBuilder<'a>, binds_to: &[Local]) {
fn add_move_error_details(&self, err: &mut Diagnostic, binds_to: &[Local]) {
for (j, local) in binds_to.iter().enumerate() {
let bind_to = &self.body.local_decls[*local];
let binding_span = bind_to.source_info.span;
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use rustc_span::{BytePos, Span};
use crate::diagnostics::BorrowedContentSource;
use crate::MirBorrowckCtxt;
use rustc_const_eval::util::collect_writes::FindAssignments;
use rustc_errors::{Applicability, DiagnosticBuilder};
use rustc_errors::{Applicability, Diagnostic};

#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub(crate) enum AccessKind {
Expand Down Expand Up @@ -689,7 +689,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
tcx: TyCtxt<'_>,
id: &hir::def_id::DefId,
the_place_err: PlaceRef<'tcx>,
err: &mut DiagnosticBuilder<'_>,
err: &mut Diagnostic,
) {
let closure_local_def_id = id.expect_local();
let tables = tcx.typeck(closure_local_def_id);
Expand Down Expand Up @@ -754,7 +754,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {

// Attempt to search similar mutable associated items for suggestion.
// In the future, attempt in all path but initially for RHS of for_loop
fn suggest_similar_mut_method_for_for_loop(&self, err: &mut DiagnosticBuilder<'_>) {
fn suggest_similar_mut_method_for_for_loop(&self, err: &mut Diagnostic) {
use hir::{
BodyId, Expr,
ExprKind::{Block, Call, DropTemps, Match, MethodCall},
Expand Down Expand Up @@ -843,7 +843,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
}

/// Targeted error when encountering an `FnMut` closure where an `Fn` closure was expected.
fn expected_fn_found_fn_mut_call(&self, err: &mut DiagnosticBuilder<'_>, sp: Span, act: &str) {
fn expected_fn_found_fn_mut_call(&self, err: &mut Diagnostic, sp: Span, act: &str) {
err.span_label(sp, format!("cannot {}", act));

let hir = self.infcx.tcx.hir();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//! outlives constraints.
use rustc_data_structures::fx::FxHashSet;
use rustc_errors::DiagnosticBuilder;
use rustc_errors::Diagnostic;
use rustc_middle::ty::RegionVid;
use smallvec::SmallVec;
use std::collections::BTreeMap;
Expand Down Expand Up @@ -162,7 +162,7 @@ impl OutlivesSuggestionBuilder {
&mut self,
mbcx: &MirBorrowckCtxt<'_, '_>,
errci: &ErrorConstraintInfo,
diag: &mut DiagnosticBuilder<'_>,
diag: &mut Diagnostic,
) {
// Emit an intermediate note.
let fr_name = self.region_vid_to_name(mbcx, errci.fr);
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_borrowck/src/diagnostics/region_errors.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Error reporting machinery for lifetime errors.
use rustc_errors::{Applicability, DiagnosticBuilder};
use rustc_errors::{Applicability, Diagnostic, DiagnosticBuilder};
use rustc_infer::infer::{
error_reporting::nice_region_error::NiceRegionError,
error_reporting::unexpected_hidden_region_diagnostic, NllRegionVariableOrigin,
Expand Down Expand Up @@ -632,7 +632,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
/// ```
fn add_static_impl_trait_suggestion(
&self,
diag: &mut DiagnosticBuilder<'tcx>,
diag: &mut Diagnostic,
fr: RegionVid,
// We need to pass `fr_name` - computing it again will label it twice.
fr_name: RegionName,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_borrowck/src/diagnostics/region_name.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::fmt::{self, Display};
use std::iter;

use rustc_errors::DiagnosticBuilder;
use rustc_errors::Diagnostic;
use rustc_hir as hir;
use rustc_hir::def::{DefKind, Res};
use rustc_middle::ty::print::RegionHighlightMode;
Expand Down Expand Up @@ -98,7 +98,7 @@ impl RegionName {
}
}

crate fn highlight_region_name(&self, diag: &mut DiagnosticBuilder<'_>) {
crate fn highlight_region_name(&self, diag: &mut Diagnostic) {
match &self.source {
RegionNameSource::NamedFreeRegion(span)
| RegionNameSource::NamedEarlyBoundRegion(span) => {
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_borrowck/src/region_infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use rustc_data_structures::binary_search_util;
use rustc_data_structures::frozen::Frozen;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::graph::scc::Sccs;
use rustc_errors::Diagnostic;
use rustc_hir::def_id::{DefId, CRATE_DEF_ID};
use rustc_hir::CRATE_HIR_ID;
use rustc_index::vec::IndexVec;
Expand Down Expand Up @@ -510,7 +511,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
}

/// Adds annotations for `#[rustc_regions]`; see `UniversalRegions::annotate`.
crate fn annotate(&self, tcx: TyCtxt<'tcx>, err: &mut rustc_errors::DiagnosticBuilder<'_>) {
crate fn annotate(&self, tcx: TyCtxt<'tcx>, err: &mut Diagnostic) {
self.universal_regions.annotate(tcx, err)
}

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_borrowck/src/universal_regions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use either::Either;
use rustc_data_structures::fx::FxHashMap;
use rustc_errors::DiagnosticBuilder;
use rustc_errors::Diagnostic;
use rustc_hir as hir;
use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_hir::lang_items::LangItem;
Expand Down Expand Up @@ -336,7 +336,7 @@ impl<'tcx> UniversalRegions<'tcx> {
/// that this region imposes on others. The methods in this file
/// handle the part about dumping the inference context internal
/// state.
crate fn annotate(&self, tcx: TyCtxt<'tcx>, err: &mut DiagnosticBuilder<'_>) {
crate fn annotate(&self, tcx: TyCtxt<'tcx>, err: &mut Diagnostic) {
match self.defining_ty {
DefiningTy::Closure(def_id, substs) => {
err.note(&format!(
Expand Down
20 changes: 11 additions & 9 deletions compiler/rustc_const_eval/src/transform/check_consts/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
let FnCallNonConst { caller, callee, substs, span, from_hir_call } = *self;
let ConstCx { tcx, param_env, .. } = *ccx;

let diag_trait = |mut err, self_ty: Ty<'_>, trait_id| {
let diag_trait = |err, self_ty: Ty<'_>, trait_id| {
let trait_ref = TraitRef::from_method(tcx, trait_id, substs);

match self_ty.kind() {
Expand All @@ -115,7 +115,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
suggest_constraining_type_param(
tcx,
generics,
&mut err,
err,
&param_ty.name.as_str(),
&constraint,
None,
Expand Down Expand Up @@ -146,8 +146,6 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
}
_ => {}
}

err
};

let call_kind = call_kind(tcx, ccx.param_env, callee, substs, span, from_hir_call, None);
Expand All @@ -162,7 +160,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
};
}

let err = match kind {
let mut err = match kind {
CallDesugaringKind::ForLoopIntoIter => {
error!("cannot convert `{}` into an iterator in {}s")
}
Expand All @@ -177,7 +175,8 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
}
};

diag_trait(err, self_ty, kind.trait_def_id(tcx))
diag_trait(&mut err, self_ty, kind.trait_def_id(tcx));
err
}
CallKind::FnCall { fn_trait_id, self_ty } => {
let mut err = struct_span_err!(
Expand Down Expand Up @@ -212,7 +211,8 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
_ => {}
}

diag_trait(err, self_ty, fn_trait_id)
diag_trait(&mut err, self_ty, fn_trait_id);
err
}
CallKind::Operator { trait_id, self_ty, .. } => {
let mut err = struct_span_err!(
Expand Down Expand Up @@ -262,7 +262,8 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
}
}

diag_trait(err, self_ty, trait_id)
diag_trait(&mut err, self_ty, trait_id);
err
}
CallKind::DerefCoercion { deref_target, deref_target_ty, self_ty } => {
let mut err = struct_span_err!(
Expand All @@ -281,7 +282,8 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
err.span_note(deref_target, "deref defined here");
}

diag_trait(err, self_ty, tcx.lang_items().deref_trait().unwrap())
diag_trait(&mut err, self_ty, tcx.lang_items().deref_trait().unwrap());
err
}
_ => struct_span_err!(
ccx.tcx.sess,
Expand Down
Loading

0 comments on commit 02ff9e0

Please sign in to comment.