Skip to content

Commit 02ff9e0

Browse files
committed
Replace &mut DiagnosticBuilder, in signatures, with &mut Diagnostic.
1 parent f24ff18 commit 02ff9e0

File tree

65 files changed

+369
-466
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+369
-466
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+5-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use either::Either;
22
use rustc_const_eval::util::{CallDesugaringKind, CallKind};
33
use rustc_data_structures::fx::FxHashSet;
4-
use rustc_errors::{Applicability, DiagnosticBuilder};
4+
use rustc_errors::{Applicability, Diagnostic, DiagnosticBuilder};
55
use rustc_hir as hir;
66
use rustc_hir::def_id::DefId;
77
use rustc_hir::{AsyncGeneratorKind, GeneratorKind};
@@ -782,7 +782,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
782782
#[instrument(level = "debug", skip(self, err))]
783783
fn suggest_using_local_if_applicable(
784784
&self,
785-
err: &mut DiagnosticBuilder<'_>,
785+
err: &mut Diagnostic,
786786
location: Location,
787787
(place, span): (Place<'tcx>, Span),
788788
gen_borrow_kind: BorrowKind,
@@ -855,7 +855,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
855855

856856
fn suggest_split_at_mut_if_applicable(
857857
&self,
858-
err: &mut DiagnosticBuilder<'_>,
858+
err: &mut Diagnostic,
859859
place: Place<'tcx>,
860860
borrowed_place: Place<'tcx>,
861861
) {
@@ -1835,7 +1835,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
18351835
self.buffer_error(err);
18361836
}
18371837

1838-
fn explain_deref_coercion(&mut self, loan: &BorrowData<'tcx>, err: &mut DiagnosticBuilder<'_>) {
1838+
fn explain_deref_coercion(&mut self, loan: &BorrowData<'tcx>, err: &mut Diagnostic) {
18391839
let tcx = self.infcx.tcx;
18401840
if let (
18411841
Some(Terminator { kind: TerminatorKind::Call { from_hir_call: false, .. }, .. }),
@@ -2362,11 +2362,7 @@ enum AnnotatedBorrowFnSignature<'tcx> {
23622362
impl<'tcx> AnnotatedBorrowFnSignature<'tcx> {
23632363
/// Annotate the provided diagnostic with information about borrow from the fn signature that
23642364
/// helps explain.
2365-
pub(crate) fn emit(
2366-
&self,
2367-
cx: &mut MirBorrowckCtxt<'_, 'tcx>,
2368-
diag: &mut DiagnosticBuilder<'_>,
2369-
) -> String {
2365+
pub(crate) fn emit(&self, cx: &mut MirBorrowckCtxt<'_, 'tcx>, diag: &mut Diagnostic) -> String {
23702366
match self {
23712367
&AnnotatedBorrowFnSignature::Closure { argument_ty, argument_span } => {
23722368
diag.span_label(

compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use std::collections::VecDeque;
44

55
use rustc_data_structures::fx::FxHashSet;
6-
use rustc_errors::{Applicability, DiagnosticBuilder};
6+
use rustc_errors::{Applicability, Diagnostic};
77
use rustc_index::vec::IndexVec;
88
use rustc_infer::infer::NllRegionVariableOrigin;
99
use rustc_middle::mir::{
@@ -60,7 +60,7 @@ impl BorrowExplanation {
6060
tcx: TyCtxt<'tcx>,
6161
body: &Body<'tcx>,
6262
local_names: &IndexVec<Local, Option<Symbol>>,
63-
err: &mut DiagnosticBuilder<'_>,
63+
err: &mut Diagnostic,
6464
borrow_desc: &str,
6565
borrow_span: Option<Span>,
6666
multiple_borrow_span: Option<(Span, Span)>,
@@ -275,7 +275,7 @@ impl BorrowExplanation {
275275
}
276276
pub(crate) fn add_lifetime_bound_suggestion_to_diagnostic(
277277
&self,
278-
err: &mut DiagnosticBuilder<'_>,
278+
err: &mut Diagnostic,
279279
category: &ConstraintCategory,
280280
span: Span,
281281
region_name: &RegionName,

compiler/rustc_borrowck/src/diagnostics/mod.rs

+6-14
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Borrow checker diagnostics.
22
33
use rustc_const_eval::util::call_kind;
4-
use rustc_errors::DiagnosticBuilder;
4+
use rustc_errors::Diagnostic;
55
use rustc_hir as hir;
66
use rustc_hir::def::Namespace;
77
use rustc_hir::def_id::DefId;
@@ -57,7 +57,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
5757
&self,
5858
location: Location,
5959
place: PlaceRef<'tcx>,
60-
diag: &mut DiagnosticBuilder<'_>,
60+
diag: &mut Diagnostic,
6161
) {
6262
debug!("add_moved_or_invoked_closure_note: location={:?} place={:?}", location, place);
6363
let mut target = place.local_or_deref_local();
@@ -409,7 +409,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
409409
/// Add a note that a type does not implement `Copy`
410410
pub(super) fn note_type_does_not_implement_copy(
411411
&self,
412-
err: &mut DiagnosticBuilder<'_>,
412+
err: &mut Diagnostic,
413413
place_desc: &str,
414414
ty: Ty<'tcx>,
415415
span: Option<Span>,
@@ -613,23 +613,15 @@ impl UseSpans<'_> {
613613
}
614614

615615
// Add a span label to the arguments of the closure, if it exists.
616-
pub(super) fn args_span_label(
617-
self,
618-
err: &mut DiagnosticBuilder<'_>,
619-
message: impl Into<String>,
620-
) {
616+
pub(super) fn args_span_label(self, err: &mut Diagnostic, message: impl Into<String>) {
621617
if let UseSpans::ClosureUse { args_span, .. } = self {
622618
err.span_label(args_span, message);
623619
}
624620
}
625621

626622
// Add a span label to the use of the captured variable, if it exists.
627623
// only adds label to the `path_span`
628-
pub(super) fn var_span_label_path_only(
629-
self,
630-
err: &mut DiagnosticBuilder<'_>,
631-
message: impl Into<String>,
632-
) {
624+
pub(super) fn var_span_label_path_only(self, err: &mut Diagnostic, message: impl Into<String>) {
633625
if let UseSpans::ClosureUse { path_span, .. } = self {
634626
err.span_label(path_span, message);
635627
}
@@ -638,7 +630,7 @@ impl UseSpans<'_> {
638630
// Add a span label to the use of the captured variable, if it exists.
639631
pub(super) fn var_span_label(
640632
self,
641-
err: &mut DiagnosticBuilder<'_>,
633+
err: &mut Diagnostic,
642634
message: impl Into<String>,
643635
kind_desc: impl Into<String>,
644636
) {

compiler/rustc_borrowck/src/diagnostics/move_errors.rs

+4-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use rustc_const_eval::util::CallDesugaringKind;
2-
use rustc_errors::{Applicability, DiagnosticBuilder};
2+
use rustc_errors::{Applicability, Diagnostic, DiagnosticBuilder};
33
use rustc_infer::infer::TyCtxtInferExt;
44
use rustc_middle::mir::*;
55
use rustc_middle::ty;
@@ -441,12 +441,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
441441
err
442442
}
443443

444-
fn add_move_hints(
445-
&self,
446-
error: GroupedMoveError<'tcx>,
447-
err: &mut DiagnosticBuilder<'a>,
448-
span: Span,
449-
) {
444+
fn add_move_hints(&self, error: GroupedMoveError<'tcx>, err: &mut Diagnostic, span: Span) {
450445
match error {
451446
GroupedMoveError::MovesFromPlace { mut binds_to, move_from, .. } => {
452447
if let Ok(snippet) = self.infcx.tcx.sess.source_map().span_to_snippet(span) {
@@ -505,7 +500,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
505500
}
506501
}
507502

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

544-
fn add_move_error_details(&self, err: &mut DiagnosticBuilder<'a>, binds_to: &[Local]) {
539+
fn add_move_error_details(&self, err: &mut Diagnostic, binds_to: &[Local]) {
545540
for (j, local) in binds_to.iter().enumerate() {
546541
let bind_to = &self.body.local_decls[*local];
547542
let binding_span = bind_to.source_info.span;

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use rustc_span::{BytePos, Span};
1717
use crate::diagnostics::BorrowedContentSource;
1818
use crate::MirBorrowckCtxt;
1919
use rustc_const_eval::util::collect_writes::FindAssignments;
20-
use rustc_errors::{Applicability, DiagnosticBuilder};
20+
use rustc_errors::{Applicability, Diagnostic};
2121

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

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

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

849849
let hir = self.infcx.tcx.hir();

compiler/rustc_borrowck/src/diagnostics/outlives_suggestion.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//! outlives constraints.
33
44
use rustc_data_structures::fx::FxHashSet;
5-
use rustc_errors::DiagnosticBuilder;
5+
use rustc_errors::Diagnostic;
66
use rustc_middle::ty::RegionVid;
77
use smallvec::SmallVec;
88
use std::collections::BTreeMap;
@@ -162,7 +162,7 @@ impl OutlivesSuggestionBuilder {
162162
&mut self,
163163
mbcx: &MirBorrowckCtxt<'_, '_>,
164164
errci: &ErrorConstraintInfo,
165-
diag: &mut DiagnosticBuilder<'_>,
165+
diag: &mut Diagnostic,
166166
) {
167167
// Emit an intermediate note.
168168
let fr_name = self.region_vid_to_name(mbcx, errci.fr);

compiler/rustc_borrowck/src/diagnostics/region_errors.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Error reporting machinery for lifetime errors.
22
3-
use rustc_errors::{Applicability, DiagnosticBuilder};
3+
use rustc_errors::{Applicability, Diagnostic, DiagnosticBuilder};
44
use rustc_infer::infer::{
55
error_reporting::nice_region_error::NiceRegionError,
66
error_reporting::unexpected_hidden_region_diagnostic, NllRegionVariableOrigin,
@@ -632,7 +632,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
632632
/// ```
633633
fn add_static_impl_trait_suggestion(
634634
&self,
635-
diag: &mut DiagnosticBuilder<'tcx>,
635+
diag: &mut Diagnostic,
636636
fr: RegionVid,
637637
// We need to pass `fr_name` - computing it again will label it twice.
638638
fr_name: RegionName,

compiler/rustc_borrowck/src/diagnostics/region_name.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::fmt::{self, Display};
22
use std::iter;
33

4-
use rustc_errors::DiagnosticBuilder;
4+
use rustc_errors::Diagnostic;
55
use rustc_hir as hir;
66
use rustc_hir::def::{DefKind, Res};
77
use rustc_middle::ty::print::RegionHighlightMode;
@@ -98,7 +98,7 @@ impl RegionName {
9898
}
9999
}
100100

101-
crate fn highlight_region_name(&self, diag: &mut DiagnosticBuilder<'_>) {
101+
crate fn highlight_region_name(&self, diag: &mut Diagnostic) {
102102
match &self.source {
103103
RegionNameSource::NamedFreeRegion(span)
104104
| RegionNameSource::NamedEarlyBoundRegion(span) => {

compiler/rustc_borrowck/src/region_infer/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use rustc_data_structures::binary_search_util;
55
use rustc_data_structures::frozen::Frozen;
66
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
77
use rustc_data_structures::graph::scc::Sccs;
8+
use rustc_errors::Diagnostic;
89
use rustc_hir::def_id::{DefId, CRATE_DEF_ID};
910
use rustc_hir::CRATE_HIR_ID;
1011
use rustc_index::vec::IndexVec;
@@ -510,7 +511,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
510511
}
511512

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

compiler/rustc_borrowck/src/universal_regions.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
1515
use either::Either;
1616
use rustc_data_structures::fx::FxHashMap;
17-
use rustc_errors::DiagnosticBuilder;
17+
use rustc_errors::Diagnostic;
1818
use rustc_hir as hir;
1919
use rustc_hir::def_id::{DefId, LocalDefId};
2020
use rustc_hir::lang_items::LangItem;
@@ -336,7 +336,7 @@ impl<'tcx> UniversalRegions<'tcx> {
336336
/// that this region imposes on others. The methods in this file
337337
/// handle the part about dumping the inference context internal
338338
/// state.
339-
crate fn annotate(&self, tcx: TyCtxt<'tcx>, err: &mut DiagnosticBuilder<'_>) {
339+
crate fn annotate(&self, tcx: TyCtxt<'tcx>, err: &mut Diagnostic) {
340340
match self.defining_ty {
341341
DefiningTy::Closure(def_id, substs) => {
342342
err.note(&format!(

compiler/rustc_const_eval/src/transform/check_consts/ops.rs

+11-9
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
9595
let FnCallNonConst { caller, callee, substs, span, from_hir_call } = *self;
9696
let ConstCx { tcx, param_env, .. } = *ccx;
9797

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

101101
match self_ty.kind() {
@@ -115,7 +115,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
115115
suggest_constraining_type_param(
116116
tcx,
117117
generics,
118-
&mut err,
118+
err,
119119
&param_ty.name.as_str(),
120120
&constraint,
121121
None,
@@ -146,8 +146,6 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
146146
}
147147
_ => {}
148148
}
149-
150-
err
151149
};
152150

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

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

180-
diag_trait(err, self_ty, kind.trait_def_id(tcx))
178+
diag_trait(&mut err, self_ty, kind.trait_def_id(tcx));
179+
err
181180
}
182181
CallKind::FnCall { fn_trait_id, self_ty } => {
183182
let mut err = struct_span_err!(
@@ -212,7 +211,8 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
212211
_ => {}
213212
}
214213

215-
diag_trait(err, self_ty, fn_trait_id)
214+
diag_trait(&mut err, self_ty, fn_trait_id);
215+
err
216216
}
217217
CallKind::Operator { trait_id, self_ty, .. } => {
218218
let mut err = struct_span_err!(
@@ -262,7 +262,8 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
262262
}
263263
}
264264

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

284-
diag_trait(err, self_ty, tcx.lang_items().deref_trait().unwrap())
285+
diag_trait(&mut err, self_ty, tcx.lang_items().deref_trait().unwrap());
286+
err
285287
}
286288
_ => struct_span_err!(
287289
ccx.tcx.sess,

0 commit comments

Comments
 (0)