Skip to content

Commit d5af08a

Browse files
committed
XXX: Diagnostic -> DiagnosticBuilder
some require <G: EmissionGuarantee>, used for errors and warnings
1 parent 3304bfe commit d5af08a

Some content is hidden

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

66 files changed

+599
-504
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+21-14
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
use either::Either;
44
use rustc_data_structures::captures::Captures;
55
use rustc_data_structures::fx::FxIndexSet;
6-
use rustc_errors::{
7-
codes::*, struct_span_code_err, Applicability, Diagnostic, DiagnosticBuilder, MultiSpan,
8-
};
6+
use rustc_errors::{codes::*, struct_span_code_err, Applicability, DiagnosticBuilder, MultiSpan};
97
use rustc_hir as hir;
108
use rustc_hir::def::{DefKind, Res};
119
use rustc_hir::intravisit::{walk_block, walk_expr, Visitor};
@@ -633,7 +631,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
633631

634632
fn suggest_assign_value(
635633
&self,
636-
err: &mut Diagnostic,
634+
err: &mut DiagnosticBuilder<'_>,
637635
moved_place: PlaceRef<'tcx>,
638636
sugg_span: Span,
639637
) {
@@ -672,7 +670,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
672670

673671
fn suggest_borrow_fn_like(
674672
&self,
675-
err: &mut Diagnostic,
673+
err: &mut DiagnosticBuilder<'_>,
676674
ty: Ty<'tcx>,
677675
move_sites: &[MoveSite],
678676
value_name: &str,
@@ -740,7 +738,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
740738

741739
fn suggest_cloning(
742740
&self,
743-
err: &mut Diagnostic,
741+
err: &mut DiagnosticBuilder<'_>,
744742
ty: Ty<'tcx>,
745743
expr: &hir::Expr<'_>,
746744
span: Span,
@@ -776,7 +774,12 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
776774
}
777775
}
778776

779-
fn suggest_adding_copy_bounds(&self, err: &mut Diagnostic, ty: Ty<'tcx>, span: Span) {
777+
fn suggest_adding_copy_bounds(
778+
&self,
779+
err: &mut DiagnosticBuilder<'_>,
780+
ty: Ty<'tcx>,
781+
span: Span,
782+
) {
780783
let tcx = self.infcx.tcx;
781784
let generics = tcx.generics_of(self.mir_def_id());
782785

@@ -1207,7 +1210,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
12071210
#[instrument(level = "debug", skip(self, err))]
12081211
fn suggest_using_local_if_applicable(
12091212
&self,
1210-
err: &mut Diagnostic,
1213+
err: &mut DiagnosticBuilder<'_>,
12111214
location: Location,
12121215
issued_borrow: &BorrowData<'tcx>,
12131216
explanation: BorrowExplanation<'tcx>,
@@ -1303,7 +1306,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
13031306

13041307
fn suggest_slice_method_if_applicable(
13051308
&self,
1306-
err: &mut Diagnostic,
1309+
err: &mut DiagnosticBuilder<'_>,
13071310
place: Place<'tcx>,
13081311
borrowed_place: Place<'tcx>,
13091312
) {
@@ -1412,7 +1415,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
14121415
/// ```
14131416
pub(crate) fn explain_iterator_advancement_in_for_loop_if_applicable(
14141417
&self,
1415-
err: &mut Diagnostic,
1418+
err: &mut DiagnosticBuilder<'_>,
14161419
span: Span,
14171420
issued_spans: &UseSpans<'tcx>,
14181421
) {
@@ -1599,7 +1602,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
15991602
/// ```
16001603
fn suggest_using_closure_argument_instead_of_capture(
16011604
&self,
1602-
err: &mut Diagnostic,
1605+
err: &mut DiagnosticBuilder<'_>,
16031606
borrowed_place: Place<'tcx>,
16041607
issued_spans: &UseSpans<'tcx>,
16051608
) {
@@ -1734,7 +1737,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
17341737

17351738
fn suggest_binding_for_closure_capture_self(
17361739
&self,
1737-
err: &mut Diagnostic,
1740+
err: &mut DiagnosticBuilder<'_>,
17381741
issued_spans: &UseSpans<'tcx>,
17391742
) {
17401743
let UseSpans::ClosureUse { capture_kind_span, .. } = issued_spans else { return };
@@ -2977,7 +2980,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
29772980
self.buffer_error(err);
29782981
}
29792982

2980-
fn explain_deref_coercion(&mut self, loan: &BorrowData<'tcx>, err: &mut Diagnostic) {
2983+
fn explain_deref_coercion(&mut self, loan: &BorrowData<'tcx>, err: &mut DiagnosticBuilder<'_>) {
29812984
let tcx = self.infcx.tcx;
29822985
if let (
29832986
Some(Terminator {
@@ -3513,7 +3516,11 @@ enum AnnotatedBorrowFnSignature<'tcx> {
35133516
impl<'tcx> AnnotatedBorrowFnSignature<'tcx> {
35143517
/// Annotate the provided diagnostic with information about borrow from the fn signature that
35153518
/// helps explain.
3516-
pub(crate) fn emit(&self, cx: &mut MirBorrowckCtxt<'_, 'tcx>, diag: &mut Diagnostic) -> String {
3519+
pub(crate) fn emit(
3520+
&self,
3521+
cx: &mut MirBorrowckCtxt<'_, 'tcx>,
3522+
diag: &mut DiagnosticBuilder<'_>,
3523+
) -> String {
35173524
match self {
35183525
&AnnotatedBorrowFnSignature::Closure { argument_ty, argument_span } => {
35193526
diag.span_label(

compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Print diagnostics to explain why values are borrowed.
22
3-
use rustc_errors::{Applicability, Diagnostic};
3+
use rustc_errors::{Applicability, DiagnosticBuilder};
44
use rustc_hir as hir;
55
use rustc_hir::intravisit::Visitor;
66
use rustc_index::IndexSlice;
@@ -62,7 +62,7 @@ impl<'tcx> BorrowExplanation<'tcx> {
6262
tcx: TyCtxt<'tcx>,
6363
body: &Body<'tcx>,
6464
local_names: &IndexSlice<Local, Option<Symbol>>,
65-
err: &mut Diagnostic,
65+
err: &mut DiagnosticBuilder<'_>,
6666
borrow_desc: &str,
6767
borrow_span: Option<Span>,
6868
multiple_borrow_span: Option<(Span, Span)>,
@@ -303,7 +303,7 @@ impl<'tcx> BorrowExplanation<'tcx> {
303303
fn add_object_lifetime_default_note(
304304
&self,
305305
tcx: TyCtxt<'tcx>,
306-
err: &mut Diagnostic,
306+
err: &mut DiagnosticBuilder<'_>,
307307
unsize_ty: Ty<'tcx>,
308308
) {
309309
if let ty::Adt(def, args) = unsize_ty.kind() {
@@ -356,7 +356,7 @@ impl<'tcx> BorrowExplanation<'tcx> {
356356

357357
fn add_lifetime_bound_suggestion_to_diagnostic(
358358
&self,
359-
err: &mut Diagnostic,
359+
err: &mut DiagnosticBuilder<'_>,
360360
category: &ConstraintCategory<'tcx>,
361361
span: Span,
362362
region_name: &RegionName,

compiler/rustc_borrowck/src/diagnostics/mod.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::session_diagnostics::{
55
CaptureVarKind, CaptureVarPathUseCause, OnClosureNote,
66
};
77
use itertools::Itertools;
8-
use rustc_errors::{Applicability, Diagnostic};
8+
use rustc_errors::{Applicability, DiagnosticBuilder};
99
use rustc_hir as hir;
1010
use rustc_hir::def::{CtorKind, Namespace};
1111
use rustc_hir::CoroutineKind;
@@ -80,7 +80,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
8080
&self,
8181
location: Location,
8282
place: PlaceRef<'tcx>,
83-
diag: &mut Diagnostic,
83+
diag: &mut DiagnosticBuilder<'_>,
8484
) -> bool {
8585
debug!("add_moved_or_invoked_closure_note: location={:?} place={:?}", location, place);
8686
let mut target = place.local_or_deref_local();
@@ -587,7 +587,7 @@ impl UseSpans<'_> {
587587
/// Add a span label to the arguments of the closure, if it exists.
588588
pub(super) fn args_subdiag(
589589
self,
590-
err: &mut Diagnostic,
590+
err: &mut DiagnosticBuilder<'_>,
591591
f: impl FnOnce(Span) -> CaptureArgLabel,
592592
) {
593593
if let UseSpans::ClosureUse { args_span, .. } = self {
@@ -599,7 +599,7 @@ impl UseSpans<'_> {
599599
/// only adds label to the `path_span`
600600
pub(super) fn var_path_only_subdiag(
601601
self,
602-
err: &mut Diagnostic,
602+
err: &mut DiagnosticBuilder<'_>,
603603
action: crate::InitializationRequiringAction,
604604
) {
605605
use crate::InitializationRequiringAction::*;
@@ -630,7 +630,7 @@ impl UseSpans<'_> {
630630
pub(super) fn var_subdiag(
631631
self,
632632
dcx: Option<&rustc_errors::DiagCtxt>,
633-
err: &mut Diagnostic,
633+
err: &mut DiagnosticBuilder<'_>,
634634
kind: Option<rustc_middle::mir::BorrowKind>,
635635
f: impl FnOnce(hir::ClosureKind, Span) -> CaptureVarCause,
636636
) {
@@ -1002,7 +1002,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
10021002

10031003
fn explain_captures(
10041004
&mut self,
1005-
err: &mut Diagnostic,
1005+
err: &mut DiagnosticBuilder<'_>,
10061006
span: Span,
10071007
move_span: Span,
10081008
move_spans: UseSpans<'tcx>,

compiler/rustc_borrowck/src/diagnostics/move_errors.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use rustc_errors::{Applicability, Diagnostic, DiagnosticBuilder};
1+
use rustc_errors::{Applicability, DiagnosticBuilder};
22
use rustc_middle::mir::*;
33
use rustc_middle::ty::{self, Ty};
44
use rustc_mir_dataflow::move_paths::{LookupResult, MovePathIndex};
@@ -434,7 +434,12 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
434434
err
435435
}
436436

437-
fn add_move_hints(&self, error: GroupedMoveError<'tcx>, err: &mut Diagnostic, span: Span) {
437+
fn add_move_hints(
438+
&self,
439+
error: GroupedMoveError<'tcx>,
440+
err: &mut DiagnosticBuilder<'_>,
441+
span: Span,
442+
) {
438443
match error {
439444
GroupedMoveError::MovesFromPlace { mut binds_to, move_from, .. } => {
440445
self.add_borrow_suggestions(err, span);
@@ -491,7 +496,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
491496
}
492497
}
493498

494-
fn add_borrow_suggestions(&self, err: &mut Diagnostic, span: Span) {
499+
fn add_borrow_suggestions(&self, err: &mut DiagnosticBuilder<'_>, span: Span) {
495500
match self.infcx.tcx.sess.source_map().span_to_snippet(span) {
496501
Ok(snippet) if snippet.starts_with('*') => {
497502
err.span_suggestion_verbose(
@@ -512,7 +517,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
512517
}
513518
}
514519

515-
fn add_move_error_suggestions(&self, err: &mut Diagnostic, binds_to: &[Local]) {
520+
fn add_move_error_suggestions(&self, err: &mut DiagnosticBuilder<'_>, binds_to: &[Local]) {
516521
let mut suggestions: Vec<(Span, String, String)> = Vec::new();
517522
for local in binds_to {
518523
let bind_to = &self.body.local_decls[*local];
@@ -564,7 +569,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
564569
}
565570
}
566571

567-
fn add_move_error_details(&self, err: &mut Diagnostic, binds_to: &[Local]) {
572+
fn add_move_error_details(&self, err: &mut DiagnosticBuilder<'_>, binds_to: &[Local]) {
568573
for (j, local) in binds_to.iter().enumerate() {
569574
let bind_to = &self.body.local_decls[*local];
570575
let binding_span = bind_to.source_info.span;
@@ -598,7 +603,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
598603
/// expansion of a packed struct.
599604
/// Such errors happen because derive macro expansions shy away from taking
600605
/// references to the struct's fields since doing so would be undefined behaviour
601-
fn add_note_for_packed_struct_derive(&self, err: &mut Diagnostic, local: Local) {
606+
fn add_note_for_packed_struct_derive(&self, err: &mut DiagnosticBuilder<'_>, local: Local) {
602607
let local_place: PlaceRef<'tcx> = local.into();
603608
let local_ty = local_place.ty(self.body.local_decls(), self.infcx.tcx).ty.peel_refs();
604609

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use hir::ExprKind;
2-
use rustc_errors::{Applicability, Diagnostic, DiagnosticBuilder};
2+
use rustc_errors::{Applicability, DiagnosticBuilder};
33
use rustc_hir as hir;
44
use rustc_hir::intravisit::Visitor;
55
use rustc_hir::Node;
@@ -539,15 +539,20 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
539539
}
540540
}
541541

542-
fn suggest_map_index_mut_alternatives(&self, ty: Ty<'tcx>, err: &mut Diagnostic, span: Span) {
542+
fn suggest_map_index_mut_alternatives(
543+
&self,
544+
ty: Ty<'tcx>,
545+
err: &mut DiagnosticBuilder<'tcx>,
546+
span: Span,
547+
) {
543548
let Some(adt) = ty.ty_adt_def() else { return };
544549
let did = adt.did();
545550
if self.infcx.tcx.is_diagnostic_item(sym::HashMap, did)
546551
|| self.infcx.tcx.is_diagnostic_item(sym::BTreeMap, did)
547552
{
548553
struct V<'a, 'tcx> {
549554
assign_span: Span,
550-
err: &'a mut Diagnostic,
555+
err: &'a mut DiagnosticBuilder<'tcx>,
551556
ty: Ty<'tcx>,
552557
suggested: bool,
553558
}
@@ -789,7 +794,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
789794
tcx: TyCtxt<'_>,
790795
closure_local_def_id: hir::def_id::LocalDefId,
791796
the_place_err: PlaceRef<'tcx>,
792-
err: &mut Diagnostic,
797+
err: &mut DiagnosticBuilder<'_>,
793798
) {
794799
let tables = tcx.typeck(closure_local_def_id);
795800
if let Some((span, closure_kind_origin)) = tcx.closure_kind_origin(closure_local_def_id) {
@@ -851,7 +856,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
851856

852857
// Attempt to search similar mutable associated items for suggestion.
853858
// In the future, attempt in all path but initially for RHS of for_loop
854-
fn suggest_similar_mut_method_for_for_loop(&self, err: &mut Diagnostic, span: Span) {
859+
fn suggest_similar_mut_method_for_for_loop(&self, err: &mut DiagnosticBuilder<'_>, span: Span) {
855860
use hir::{
856861
BorrowKind, Expr,
857862
ExprKind::{AddrOf, Block, Call, MethodCall},
@@ -935,7 +940,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
935940
}
936941

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

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

compiler/rustc_borrowck/src/diagnostics/outlives_suggestion.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//! outlives constraints.
33
44
use rustc_data_structures::fx::FxIndexSet;
5-
use rustc_errors::Diagnostic;
5+
use rustc_errors::DiagnosticBuilder;
66
use rustc_middle::ty::RegionVid;
77
use smallvec::SmallVec;
88
use std::collections::BTreeMap;
@@ -155,13 +155,13 @@ impl OutlivesSuggestionBuilder {
155155
self.constraints_to_add.entry(fr).or_default().push(outlived_fr);
156156
}
157157

158-
/// Emit an intermediate note on the given `Diagnostic` if the involved regions are
158+
/// Emit an intermediate note on the given `DiagnosticBuilder` if the involved regions are
159159
/// suggestable.
160160
pub(crate) fn intermediate_suggestion(
161161
&mut self,
162162
mbcx: &MirBorrowckCtxt<'_, '_>,
163163
errci: &ErrorConstraintInfo<'_>,
164-
diag: &mut Diagnostic,
164+
diag: &mut DiagnosticBuilder<'_>,
165165
) {
166166
// Emit an intermediate note.
167167
let fr_name = self.region_vid_to_name(mbcx, errci.fr);

compiler/rustc_borrowck/src/diagnostics/region_errors.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//! Error reporting machinery for lifetime errors.
44
55
use rustc_data_structures::fx::FxIndexSet;
6-
use rustc_errors::{Applicability, Diagnostic, DiagnosticBuilder, MultiSpan};
6+
use rustc_errors::{Applicability, DiagnosticBuilder, MultiSpan};
77
use rustc_hir as hir;
88
use rustc_hir::def::Res::Def;
99
use rustc_hir::def_id::DefId;
@@ -806,7 +806,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
806806
/// ```
807807
fn add_static_impl_trait_suggestion(
808808
&self,
809-
diag: &mut Diagnostic,
809+
diag: &mut DiagnosticBuilder<'_>,
810810
fr: RegionVid,
811811
// We need to pass `fr_name` - computing it again will label it twice.
812812
fr_name: RegionName,
@@ -895,7 +895,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
895895

896896
fn maybe_suggest_constrain_dyn_trait_impl(
897897
&self,
898-
diag: &mut Diagnostic,
898+
diag: &mut DiagnosticBuilder<'_>,
899899
f: Region<'tcx>,
900900
o: Region<'tcx>,
901901
category: &ConstraintCategory<'tcx>,
@@ -957,7 +957,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
957957
#[instrument(skip(self, err), level = "debug")]
958958
fn suggest_constrain_dyn_trait_in_impl(
959959
&self,
960-
err: &mut Diagnostic,
960+
err: &mut DiagnosticBuilder<'_>,
961961
found_dids: &FxIndexSet<DefId>,
962962
ident: Ident,
963963
self_ty: &hir::Ty<'_>,
@@ -992,7 +992,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
992992

993993
fn suggest_adding_lifetime_params(
994994
&self,
995-
diag: &mut Diagnostic,
995+
diag: &mut DiagnosticBuilder<'_>,
996996
sub: RegionVid,
997997
sup: RegionVid,
998998
) {
@@ -1021,7 +1021,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
10211021
suggest_adding_lifetime_params(self.infcx.tcx, sub, ty_sup, ty_sub, diag);
10221022
}
10231023

1024-
fn suggest_move_on_borrowing_closure(&self, diag: &mut Diagnostic) {
1024+
fn suggest_move_on_borrowing_closure(&self, diag: &mut DiagnosticBuilder<'_>) {
10251025
let map = self.infcx.tcx.hir();
10261026
let body_id = map.body_owned_by(self.mir_def_id());
10271027
let expr = &map.body(body_id).value.peel_blocks();

0 commit comments

Comments
 (0)