From 02ff9e0aef03d48fdecc2d114311217010ec1d81 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Sun, 23 Jan 2022 20:41:46 +0000 Subject: [PATCH] Replace `&mut DiagnosticBuilder`, in signatures, with `&mut Diagnostic`. --- .../src/diagnostics/conflict_errors.rs | 14 +-- .../src/diagnostics/explain_borrow.rs | 6 +- .../rustc_borrowck/src/diagnostics/mod.rs | 20 +-- .../src/diagnostics/move_errors.rs | 13 +- .../src/diagnostics/mutability_errors.rs | 8 +- .../src/diagnostics/outlives_suggestion.rs | 4 +- .../src/diagnostics/region_errors.rs | 4 +- .../src/diagnostics/region_name.rs | 4 +- .../rustc_borrowck/src/region_infer/mod.rs | 3 +- .../rustc_borrowck/src/universal_regions.rs | 4 +- .../src/transform/check_consts/ops.rs | 20 +-- compiler/rustc_errors/src/diagnostic.rs | 30 +++-- .../rustc_errors/src/diagnostic_builder.rs | 46 ++----- compiler/rustc_errors/src/lib.rs | 5 +- compiler/rustc_expand/src/mbe/macro_rules.rs | 8 +- .../src/infer/error_reporting/mod.rs | 40 +++--- .../infer/error_reporting/need_type_info.rs | 8 +- .../nice_region_error/different_lifetimes.rs | 4 +- .../nice_region_error/placeholder_error.rs | 4 +- .../nice_region_error/static_impl_trait.rs | 8 +- .../src/infer/error_reporting/note.rs | 8 +- compiler/rustc_lint/src/builtin.rs | 12 +- compiler/rustc_middle/src/lint.rs | 8 +- compiler/rustc_middle/src/middle/stability.rs | 4 +- compiler/rustc_middle/src/traits/mod.rs | 4 +- compiler/rustc_middle/src/ty/diagnostics.rs | 8 +- compiler/rustc_middle/src/ty/error.rs | 26 ++-- .../src/thir/pattern/check_match.rs | 11 +- .../rustc_parse/src/lexer/unicode_chars.rs | 4 +- compiler/rustc_parse/src/parser/attr.rs | 4 +- .../rustc_parse/src/parser/diagnostics.rs | 12 +- compiler/rustc_parse/src/parser/expr.rs | 4 +- compiler/rustc_resolve/src/diagnostics.rs | 8 +- .../rustc_resolve/src/late/diagnostics.rs | 33 ++--- compiler/rustc_resolve/src/late/lifetimes.rs | 4 +- compiler/rustc_resolve/src/lib.rs | 6 +- compiler/rustc_session/src/parse.rs | 4 +- compiler/rustc_session/src/session.rs | 34 +++-- .../src/traits/coherence.rs | 3 +- .../src/traits/error_reporting/mod.rs | 53 +++----- .../src/traits/error_reporting/suggestions.rs | 117 ++++++++---------- .../src/traits/select/mod.rs | 4 +- .../rustc_trait_selection/src/traits/util.rs | 9 +- compiler/rustc_typeck/src/astconv/generics.rs | 4 +- compiler/rustc_typeck/src/check/_match.rs | 4 +- compiler/rustc_typeck/src/check/callee.rs | 6 +- compiler/rustc_typeck/src/check/coercion.rs | 8 +- compiler/rustc_typeck/src/check/demand.rs | 20 ++- compiler/rustc_typeck/src/check/expr.rs | 15 +-- .../rustc_typeck/src/check/fn_ctxt/_impl.rs | 6 +- .../rustc_typeck/src/check/fn_ctxt/checks.rs | 4 +- .../src/check/fn_ctxt/suggestions.rs | 30 ++--- compiler/rustc_typeck/src/check/method/mod.rs | 4 +- .../rustc_typeck/src/check/method/suggest.rs | 23 ++-- compiler/rustc_typeck/src/check/op.rs | 8 +- compiler/rustc_typeck/src/check/pat.rs | 8 +- .../wrong_number_of_generic_args.rs | 20 +-- .../passes/collect_intra_doc_links.rs | 8 +- src/tools/clippy/clippy_lints/src/copies.rs | 4 +- .../clippy_lints/src/implicit_hasher.rs | 4 +- .../src/inline_fn_without_body.rs | 2 +- .../src/needless_pass_by_value.rs | 4 +- .../clippy_lints/src/new_without_default.rs | 2 +- .../clippy/clippy_utils/src/diagnostics.rs | 12 +- src/tools/clippy/clippy_utils/src/sugg.rs | 6 +- 65 files changed, 369 insertions(+), 466 deletions(-) diff --git a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs index baa59efbf8d..3da94dd28b1 100644 --- a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs @@ -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}; @@ -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, @@ -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>, ) { @@ -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, .. }, .. }), @@ -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( diff --git a/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs b/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs index b1e5a211cf1..da6610c002e 100644 --- a/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs +++ b/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs @@ -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::{ @@ -60,7 +60,7 @@ impl BorrowExplanation { tcx: TyCtxt<'tcx>, body: &Body<'tcx>, local_names: &IndexVec>, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, borrow_desc: &str, borrow_span: Option, multiple_borrow_span: Option<(Span, Span)>, @@ -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, diff --git a/compiler/rustc_borrowck/src/diagnostics/mod.rs b/compiler/rustc_borrowck/src/diagnostics/mod.rs index 5f533ddcb82..914ee760d01 100644 --- a/compiler/rustc_borrowck/src/diagnostics/mod.rs +++ b/compiler/rustc_borrowck/src/diagnostics/mod.rs @@ -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; @@ -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(); @@ -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, @@ -613,11 +613,7 @@ 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, - ) { + pub(super) fn args_span_label(self, err: &mut Diagnostic, message: impl Into) { if let UseSpans::ClosureUse { args_span, .. } = self { err.span_label(args_span, message); } @@ -625,11 +621,7 @@ impl UseSpans<'_> { // 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, - ) { + pub(super) fn var_span_label_path_only(self, err: &mut Diagnostic, message: impl Into) { if let UseSpans::ClosureUse { path_span, .. } = self { err.span_label(path_span, message); } @@ -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, kind_desc: impl Into, ) { diff --git a/compiler/rustc_borrowck/src/diagnostics/move_errors.rs b/compiler/rustc_borrowck/src/diagnostics/move_errors.rs index d4f238ff71f..71dd6cc9144 100644 --- a/compiler/rustc_borrowck/src/diagnostics/move_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/move_errors.rs @@ -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; @@ -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) { @@ -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]; @@ -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; diff --git a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs index 7d0dde53c2b..2c9bd8ea96e 100644 --- a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs @@ -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 { @@ -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); @@ -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}, @@ -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(); diff --git a/compiler/rustc_borrowck/src/diagnostics/outlives_suggestion.rs b/compiler/rustc_borrowck/src/diagnostics/outlives_suggestion.rs index 21f00af5c0c..72415cb51a0 100644 --- a/compiler/rustc_borrowck/src/diagnostics/outlives_suggestion.rs +++ b/compiler/rustc_borrowck/src/diagnostics/outlives_suggestion.rs @@ -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; @@ -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); diff --git a/compiler/rustc_borrowck/src/diagnostics/region_errors.rs b/compiler/rustc_borrowck/src/diagnostics/region_errors.rs index e6a323d676e..5ac6ea33a26 100644 --- a/compiler/rustc_borrowck/src/diagnostics/region_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/region_errors.rs @@ -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, @@ -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, diff --git a/compiler/rustc_borrowck/src/diagnostics/region_name.rs b/compiler/rustc_borrowck/src/diagnostics/region_name.rs index 5d1d291d3b4..c9395492c9e 100644 --- a/compiler/rustc_borrowck/src/diagnostics/region_name.rs +++ b/compiler/rustc_borrowck/src/diagnostics/region_name.rs @@ -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; @@ -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) => { diff --git a/compiler/rustc_borrowck/src/region_infer/mod.rs b/compiler/rustc_borrowck/src/region_infer/mod.rs index b99fb00599e..3f0ce7dea00 100644 --- a/compiler/rustc_borrowck/src/region_infer/mod.rs +++ b/compiler/rustc_borrowck/src/region_infer/mod.rs @@ -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; @@ -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) } diff --git a/compiler/rustc_borrowck/src/universal_regions.rs b/compiler/rustc_borrowck/src/universal_regions.rs index d21a9d86e5b..478dbe31fba 100644 --- a/compiler/rustc_borrowck/src/universal_regions.rs +++ b/compiler/rustc_borrowck/src/universal_regions.rs @@ -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; @@ -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!( diff --git a/compiler/rustc_const_eval/src/transform/check_consts/ops.rs b/compiler/rustc_const_eval/src/transform/check_consts/ops.rs index 888c4b997dc..a9b1b40ea29 100644 --- a/compiler/rustc_const_eval/src/transform/check_consts/ops.rs +++ b/compiler/rustc_const_eval/src/transform/check_consts/ops.rs @@ -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() { @@ -115,7 +115,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> { suggest_constraining_type_param( tcx, generics, - &mut err, + err, ¶m_ty.name.as_str(), &constraint, None, @@ -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); @@ -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") } @@ -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!( @@ -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!( @@ -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!( @@ -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, diff --git a/compiler/rustc_errors/src/diagnostic.rs b/compiler/rustc_errors/src/diagnostic.rs index f62a3567c56..f32b11e33c8 100644 --- a/compiler/rustc_errors/src/diagnostic.rs +++ b/compiler/rustc_errors/src/diagnostic.rs @@ -202,6 +202,20 @@ impl Diagnostic { self } + /// Labels all the given spans with the provided label. + /// See [`Self::span_label()`] for more information. + pub fn span_labels( + &mut self, + spans: impl IntoIterator, + label: impl AsRef, + ) -> &mut Self { + let label = label.as_ref(); + for span in spans { + self.span_label(span, label); + } + self + } + pub fn replace_span_with(&mut self, after: Span) -> &mut Self { let before = self.span.clone(); self.set_span(after); @@ -213,7 +227,7 @@ impl Diagnostic { self } - crate fn note_expected_found( + pub fn note_expected_found( &mut self, expected_label: &dyn fmt::Display, expected: DiagnosticStyledString, @@ -223,7 +237,7 @@ impl Diagnostic { self.note_expected_found_extra(expected_label, expected, found_label, found, &"", &"") } - crate fn note_unsuccessful_coercion( + pub fn note_unsuccessful_coercion( &mut self, expected: DiagnosticStyledString, found: DiagnosticStyledString, @@ -313,33 +327,33 @@ impl Diagnostic { /// Prints the span with a note above it. /// This is like [`Diagnostic::note()`], but it gets its own span. - crate fn span_note>(&mut self, sp: S, msg: &str) -> &mut Self { + pub fn span_note>(&mut self, sp: S, msg: &str) -> &mut Self { self.sub(Level::Note, msg, sp.into(), None); self } /// Add a warning attached to this diagnostic. - crate fn warn(&mut self, msg: &str) -> &mut Self { + pub fn warn(&mut self, msg: &str) -> &mut Self { self.sub(Level::Warning, msg, MultiSpan::new(), None); self } /// Prints the span with a warning above it. /// This is like [`Diagnostic::warn()`], but it gets its own span. - crate fn span_warn>(&mut self, sp: S, msg: &str) -> &mut Self { + pub fn span_warn>(&mut self, sp: S, msg: &str) -> &mut Self { self.sub(Level::Warning, msg, sp.into(), None); self } /// Add a help message attached to this diagnostic. - crate fn help(&mut self, msg: &str) -> &mut Self { + pub fn help(&mut self, msg: &str) -> &mut Self { self.sub(Level::Help, msg, MultiSpan::new(), None); self } /// Prints the span with some help above it. /// This is like [`Diagnostic::help()`], but it gets its own span. - crate fn span_help>(&mut self, sp: S, msg: &str) -> &mut Self { + pub fn span_help>(&mut self, sp: S, msg: &str) -> &mut Self { self.sub(Level::Help, msg, sp.into(), None); self } @@ -673,7 +687,7 @@ impl Diagnostic { self.code.clone() } - crate fn set_primary_message>(&mut self, msg: M) -> &mut Self { + pub fn set_primary_message>(&mut self, msg: M) -> &mut Self { self.message[0] = (msg.into(), Style::NoStyle); self } diff --git a/compiler/rustc_errors/src/diagnostic_builder.rs b/compiler/rustc_errors/src/diagnostic_builder.rs index b4189cbfc62..e0a5e6ef089 100644 --- a/compiler/rustc_errors/src/diagnostic_builder.rs +++ b/compiler/rustc_errors/src/diagnostic_builder.rs @@ -59,23 +59,6 @@ macro_rules! forward { self } }; - - // Forward pattern for &mut self -> &mut Self, with generic parameters. - ( - $(#[$attrs:meta])* - pub fn $n:ident<$($generic:ident: $bound:path),*>( - &mut self, - $($name:ident: $ty:ty),* - $(,)? - ) -> &mut Self - ) => { - $(#[$attrs])* - #[doc = concat!("See [`Diagnostic::", stringify!($n), "()`].")] - pub fn $n<$($generic: $bound),*>(&mut self, $($name: $ty),*) -> &mut Self { - self.diagnostic.$n($($name),*); - self - } - }; } impl<'a> Deref for DiagnosticBuilder<'a> { @@ -172,6 +155,7 @@ impl<'a> DiagnosticBuilder<'a> { pub fn downgrade_to_delayed_bug(&mut self,) -> &mut Self ); + forward!( /// Appends a labeled span to the diagnostic. /// /// Labels are used to convey additional context for the diagnostic's primary span. They will @@ -184,24 +168,16 @@ impl<'a> DiagnosticBuilder<'a> { /// the diagnostic was constructed. However, the label span is *not* considered a /// ["primary span"][`MultiSpan`]; only the `Span` supplied when creating the diagnostic is /// primary. - pub fn span_label(&mut self, span: Span, label: impl Into) -> &mut Self { - self.diagnostic.span_label(span, label); - self - } + pub fn span_label(&mut self, span: Span, label: impl Into) -> &mut Self); + forward!( /// Labels all the given spans with the provided label. /// See [`Diagnostic::span_label()`] for more information. pub fn span_labels( &mut self, spans: impl IntoIterator, label: impl AsRef, - ) -> &mut Self { - let label = label.as_ref(); - for span in spans { - self.diagnostic.span_label(span, label); - } - self - } + ) -> &mut Self); forward!(pub fn note_expected_found( &mut self, @@ -228,17 +204,17 @@ impl<'a> DiagnosticBuilder<'a> { ) -> &mut Self); forward!(pub fn note(&mut self, msg: &str) -> &mut Self); - forward!(pub fn span_note>( + forward!(pub fn span_note( &mut self, - sp: S, + sp: impl Into, msg: &str, ) -> &mut Self); forward!(pub fn warn(&mut self, msg: &str) -> &mut Self); - forward!(pub fn span_warn>(&mut self, sp: S, msg: &str) -> &mut Self); + forward!(pub fn span_warn(&mut self, sp: impl Into, msg: &str) -> &mut Self); forward!(pub fn help(&mut self, msg: &str) -> &mut Self); - forward!(pub fn span_help>( + forward!(pub fn span_help( &mut self, - sp: S, + sp: impl Into, msg: &str, ) -> &mut Self); forward!(pub fn set_is_lint(&mut self,) -> &mut Self); @@ -312,8 +288,8 @@ impl<'a> DiagnosticBuilder<'a> { applicability: Applicability, ) -> &mut Self); - forward!(pub fn set_primary_message>(&mut self, msg: M) -> &mut Self); - forward!(pub fn set_span>(&mut self, sp: S) -> &mut Self); + forward!(pub fn set_primary_message(&mut self, msg: impl Into) -> &mut Self); + forward!(pub fn set_span(&mut self, sp: impl Into) -> &mut Self); forward!(pub fn code(&mut self, s: DiagnosticId) -> &mut Self); /// Convenience function for internal use, clients should use one of the diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index 539ddcec332..0fae230813b 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -1319,9 +1319,10 @@ impl Level { } } +// FIXME(eddyb) this doesn't belong here AFAICT, should be moved to callsite. pub fn add_elided_lifetime_in_path_suggestion( source_map: &SourceMap, - db: &mut DiagnosticBuilder<'_>, + diag: &mut Diagnostic, n: usize, path_span: Span, incl_angl_brckt: bool, @@ -1353,7 +1354,7 @@ pub fn add_elided_lifetime_in_path_suggestion( (insertion_span, anon_lts) } }; - db.span_suggestion( + diag.span_suggestion( replace_span, &format!("indicate the anonymous lifetime{}", pluralize!(n)), suggestion, diff --git a/compiler/rustc_expand/src/mbe/macro_rules.rs b/compiler/rustc_expand/src/mbe/macro_rules.rs index f71fb58cf6b..ee2b5cf85bd 100644 --- a/compiler/rustc_expand/src/mbe/macro_rules.rs +++ b/compiler/rustc_expand/src/mbe/macro_rules.rs @@ -16,7 +16,7 @@ use rustc_ast_pretty::pprust; use rustc_attr::{self as attr, TransparencyError}; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::sync::Lrc; -use rustc_errors::{Applicability, DiagnosticBuilder}; +use rustc_errors::{Applicability, Diagnostic, DiagnosticBuilder}; use rustc_feature::Features; use rustc_lint_defs::builtin::{ RUST_2021_INCOMPATIBLE_OR_PATTERNS, SEMICOLON_IN_EXPRESSIONS_FROM_MACROS, @@ -49,11 +49,7 @@ crate struct ParserAnyMacro<'a> { is_local: bool, } -crate fn annotate_err_with_kind( - err: &mut DiagnosticBuilder<'_>, - kind: AstFragmentKind, - span: Span, -) { +crate fn annotate_err_with_kind(err: &mut Diagnostic, kind: AstFragmentKind, span: Span) { match kind { AstFragmentKind::Ty => { err.span_label(span, "this macro call doesn't expand to a type"); diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index c42ff168d8c..36c5ce68849 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -58,7 +58,7 @@ use crate::traits::{ }; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; -use rustc_errors::{pluralize, struct_span_err}; +use rustc_errors::{pluralize, struct_span_err, Diagnostic}; use rustc_errors::{Applicability, DiagnosticBuilder, DiagnosticStyledString}; use rustc_hir as hir; use rustc_hir::def_id::DefId; @@ -85,7 +85,7 @@ pub mod nice_region_error; pub(super) fn note_and_explain_region<'tcx>( tcx: TyCtxt<'tcx>, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, prefix: &str, region: ty::Region<'tcx>, suffix: &str, @@ -118,7 +118,7 @@ pub(super) fn note_and_explain_region<'tcx>( fn explain_free_region<'tcx>( tcx: TyCtxt<'tcx>, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, prefix: &str, region: ty::Region<'tcx>, suffix: &str, @@ -194,7 +194,7 @@ fn msg_span_from_early_bound_and_free_regions<'tcx>( } fn emit_msg_span( - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, prefix: &str, description: String, span: Option, @@ -210,7 +210,7 @@ fn emit_msg_span( } fn label_msg_span( - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, prefix: &str, description: String, span: Option, @@ -471,11 +471,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { } /// Adds a note if the types come from similarly named crates - fn check_and_note_conflicting_crates( - &self, - err: &mut DiagnosticBuilder<'_>, - terr: &TypeError<'tcx>, - ) { + fn check_and_note_conflicting_crates(&self, err: &mut Diagnostic, terr: &TypeError<'tcx>) { use hir::def_id::CrateNum; use rustc_hir::definitions::DisambiguatedDefPathData; use ty::print::Printer; @@ -557,7 +553,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { } } - let report_path_match = |err: &mut DiagnosticBuilder<'_>, did1: DefId, did2: DefId| { + let report_path_match = |err: &mut Diagnostic, did1: DefId, did2: DefId| { // Only external crates, if either is from a local // module we could have false positives if !(did1.is_local() || did2.is_local()) && did1.krate != did2.krate { @@ -598,7 +594,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { fn note_error_origin( &self, - err: &mut DiagnosticBuilder<'tcx>, + err: &mut Diagnostic, cause: &ObligationCause<'tcx>, exp_found: Option>>, terr: &TypeError<'tcx>, @@ -792,7 +788,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { fn suggest_boxing_for_return_impl_trait( &self, - err: &mut DiagnosticBuilder<'tcx>, + err: &mut Diagnostic, return_sp: Span, arm_spans: impl Iterator, ) { @@ -1437,7 +1433,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { /// E0271, like `src/test/ui/issues/issue-39970.stderr`. pub fn note_type_err( &self, - diag: &mut DiagnosticBuilder<'tcx>, + diag: &mut Diagnostic, cause: &ObligationCause<'tcx>, secondary_span: Option<(Span, String)>, mut values: Option>, @@ -1484,14 +1480,14 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { types_visitor } - fn report(&self, err: &mut DiagnosticBuilder<'_>) { + fn report(&self, err: &mut Diagnostic) { self.add_labels_for_types(err, "expected", &self.expected); self.add_labels_for_types(err, "found", &self.found); } fn add_labels_for_types( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, target: &str, types: &FxHashMap>, ) { @@ -1818,7 +1814,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { cause: &ObligationCause<'tcx>, exp_span: Span, exp_found: &ty::error::ExpectedFound>, - diag: &mut DiagnosticBuilder<'tcx>, + diag: &mut Diagnostic, ) { debug!( "suggest_await_on_expect_found: exp_span={:?}, expected_ty={:?}, found_ty={:?}", @@ -1906,7 +1902,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { &self, cause: &ObligationCause<'tcx>, exp_found: &ty::error::ExpectedFound>, - diag: &mut DiagnosticBuilder<'tcx>, + diag: &mut Diagnostic, ) { debug!( "suggest_accessing_field_where_appropriate(cause={:?}, exp_found={:?})", @@ -1955,7 +1951,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { &self, span: Span, exp_found: &ty::error::ExpectedFound>, - diag: &mut DiagnosticBuilder<'tcx>, + diag: &mut Diagnostic, ) { if let (ty::Adt(exp_def, exp_substs), ty::Ref(_, found_ty, _)) = (exp_found.expected.kind(), exp_found.found.kind()) @@ -2108,7 +2104,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { fn emit_tuple_wrap_err( &self, - err: &mut DiagnosticBuilder<'tcx>, + err: &mut Diagnostic, span: Span, found: Ty<'tcx>, expected_fields: &List>, @@ -2340,7 +2336,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { } fn binding_suggestion<'tcx, S: fmt::Display>( - err: &mut DiagnosticBuilder<'tcx>, + err: &mut Diagnostic, type_param_span: Option<(Span, bool, bool)>, bound_kind: GenericKind<'tcx>, sub: S, @@ -2374,7 +2370,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { } let new_binding_suggestion = - |err: &mut DiagnosticBuilder<'tcx>, + |err: &mut Diagnostic, type_param_span: Option<(Span, bool, bool)>, bound_kind: GenericKind<'tcx>| { let msg = "consider introducing an explicit lifetime bound"; diff --git a/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs b/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs index 1f504130130..88a65fbb4e6 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs @@ -1,6 +1,6 @@ use crate::infer::type_variable::TypeVariableOriginKind; use crate::infer::{InferCtxt, Symbol}; -use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder}; +use rustc_errors::{pluralize, struct_span_err, Applicability, Diagnostic, DiagnosticBuilder}; use rustc_hir as hir; use rustc_hir::def::{DefKind, Namespace}; use rustc_hir::def_id::DefId; @@ -195,7 +195,7 @@ impl UseDiagnostic<'_> { } } - fn attach_note(&self, err: &mut DiagnosticBuilder<'_>) { + fn attach_note(&self, err: &mut Diagnostic) { match *self { Self::TryConversion { pre_ty, post_ty, .. } => { let intro = "`?` implicitly converts the error value"; @@ -224,7 +224,7 @@ impl UseDiagnostic<'_> { /// Suggest giving an appropriate return type to a closure expression. fn closure_return_type_suggestion( - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, output: &FnRetTy<'_>, body: &Body<'_>, ret: &str, @@ -873,7 +873,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { &self, segment: &hir::PathSegment<'_>, e: &Expr<'_>, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, ) { if let (Some(typeck_results), None) = (self.in_progress_typeck_results, &segment.args) { let borrow = typeck_results.borrow(); diff --git a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/different_lifetimes.rs b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/different_lifetimes.rs index 4eec492b3ae..bbbb0f79acc 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/different_lifetimes.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/different_lifetimes.rs @@ -7,7 +7,7 @@ use crate::infer::error_reporting::nice_region_error::NiceRegionError; use crate::infer::lexical_region_resolve::RegionResolutionError; use crate::infer::SubregionOrigin; -use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder, ErrorReported}; +use rustc_errors::{struct_span_err, Applicability, Diagnostic, ErrorReported}; use rustc_hir as hir; use rustc_hir::{GenericParamKind, Ty}; use rustc_middle::ty::Region; @@ -156,7 +156,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { sub: Region<'tcx>, ty_sup: &Ty<'_>, ty_sub: &Ty<'_>, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, ) { if let ( hir::Ty { kind: hir::TyKind::Rptr(lifetime_sub, _), .. }, diff --git a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/placeholder_error.rs b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/placeholder_error.rs index 7d82c60e6d3..0be7a67a1b8 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/placeholder_error.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/placeholder_error.rs @@ -4,7 +4,7 @@ use crate::infer::ValuePairs; use crate::infer::{SubregionOrigin, TypeTrace}; use crate::traits::{ObligationCause, ObligationCauseCode}; use rustc_data_structures::intern::Interned; -use rustc_errors::DiagnosticBuilder; +use rustc_errors::{Diagnostic, DiagnosticBuilder}; use rustc_hir::def::Namespace; use rustc_hir::def_id::DefId; use rustc_middle::ty::error::ExpectedFound; @@ -306,7 +306,7 @@ impl<'tcx> NiceRegionError<'_, 'tcx> { /// due to the number of combinations we have to deal with. fn explain_actual_impl_that_was_found( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, sub_placeholder: Option>, sup_placeholder: Option>, has_sub: Option, diff --git a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs index 8601180842c..210743d7cef 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs @@ -5,7 +5,7 @@ use crate::infer::lexical_region_resolve::RegionResolutionError; use crate::infer::{SubregionOrigin, TypeTrace}; use crate::traits::{ObligationCauseCode, UnifyReceiverContext}; use rustc_data_structures::stable_set::FxHashSet; -use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder, ErrorReported}; +use rustc_errors::{struct_span_err, Applicability, Diagnostic, ErrorReported}; use rustc_hir::def_id::DefId; use rustc_hir::intravisit::{walk_ty, Visitor}; use rustc_hir::{self as hir, GenericBound, Item, ItemKind, Lifetime, LifetimeName, Node, TyKind}; @@ -286,7 +286,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { pub fn suggest_new_region_bound( tcx: TyCtxt<'_>, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, fn_returns: Vec<&rustc_hir::Ty<'_>>, lifetime_name: String, arg: Option, @@ -483,7 +483,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { /// `'static` obligation. Suggest relaxing that implicit bound. fn find_impl_on_dyn_trait( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, ty: Ty<'_>, ctxt: &UnifyReceiverContext<'tcx>, ) -> bool { @@ -514,7 +514,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { fn suggest_constrain_dyn_trait_in_impl( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, found_dids: &FxHashSet, ident: Ident, self_ty: &hir::Ty<'_>, diff --git a/compiler/rustc_infer/src/infer/error_reporting/note.rs b/compiler/rustc_infer/src/infer/error_reporting/note.rs index 8671ecba6e9..f44dbef46b8 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/note.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/note.rs @@ -1,16 +1,12 @@ use crate::infer::error_reporting::{note_and_explain_region, ObligationCauseExt}; use crate::infer::{self, InferCtxt, SubregionOrigin}; -use rustc_errors::{struct_span_err, DiagnosticBuilder}; +use rustc_errors::{struct_span_err, Diagnostic, DiagnosticBuilder}; use rustc_middle::traits::ObligationCauseCode; use rustc_middle::ty::error::TypeError; use rustc_middle::ty::{self, Region}; impl<'a, 'tcx> InferCtxt<'a, 'tcx> { - pub(super) fn note_region_origin( - &self, - err: &mut DiagnosticBuilder<'_>, - origin: &SubregionOrigin<'tcx>, - ) { + pub(super) fn note_region_origin(&self, err: &mut Diagnostic, origin: &SubregionOrigin<'tcx>) { let mut label_or_note = |span, msg| { let sub_count = err.children.iter().filter(|d| d.span.is_dummy()).count(); let expanded_sub_count = err.children.iter().filter(|d| !d.span.is_dummy()).count(); diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index 30b5f9b34d0..79016972291 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -31,7 +31,7 @@ use rustc_ast::{self as ast, *}; use rustc_ast_pretty::pprust::{self, expr_to_string}; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::stack::ensure_sufficient_stack; -use rustc_errors::{Applicability, DiagnosticBuilder, DiagnosticStyledString}; +use rustc_errors::{Applicability, Diagnostic, DiagnosticStyledString}; use rustc_feature::{deprecated_attributes, AttributeGate, BuiltinAttribute, GateIssue, Stability}; use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; @@ -1469,17 +1469,17 @@ impl TypeAliasBounds { } } - fn suggest_changing_assoc_types(ty: &hir::Ty<'_>, err: &mut DiagnosticBuilder<'_>) { + fn suggest_changing_assoc_types(ty: &hir::Ty<'_>, err: &mut Diagnostic) { // Access to associates types should use `::Assoc`, which does not need a // bound. Let's see if this type does that. // We use a HIR visitor to walk the type. use rustc_hir::intravisit::{self, Visitor}; - struct WalkAssocTypes<'a, 'db> { - err: &'a mut DiagnosticBuilder<'db>, + struct WalkAssocTypes<'a> { + err: &'a mut Diagnostic, } - impl<'a, 'db, 'v> Visitor<'v> for WalkAssocTypes<'a, 'db> { - fn visit_qpath(&mut self, qpath: &'v hir::QPath<'v>, id: hir::HirId, span: Span) { + impl Visitor<'_> for WalkAssocTypes<'_> { + fn visit_qpath(&mut self, qpath: &hir::QPath<'_>, id: hir::HirId, span: Span) { if TypeAliasBounds::is_type_variable_assoc(qpath) { self.err.span_help( span, diff --git a/compiler/rustc_middle/src/lint.rs b/compiler/rustc_middle/src/lint.rs index 294c70f24f8..4388bb87bf0 100644 --- a/compiler/rustc_middle/src/lint.rs +++ b/compiler/rustc_middle/src/lint.rs @@ -2,7 +2,7 @@ use std::cmp; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; -use rustc_errors::{DiagnosticBuilder, DiagnosticId}; +use rustc_errors::{Diagnostic, DiagnosticBuilder, DiagnosticId}; use rustc_hir::HirId; use rustc_index::vec::IndexVec; use rustc_query_system::ich::StableHashingContext; @@ -202,12 +202,12 @@ impl<'a> LintDiagnosticBuilder<'a> { } } -pub fn explain_lint_level_source<'s>( - sess: &'s Session, +pub fn explain_lint_level_source( + sess: &Session, lint: &'static Lint, level: Level, src: LintLevelSource, - err: &mut DiagnosticBuilder<'s>, + err: &mut Diagnostic, ) { let name = lint.name_lower(); match src { diff --git a/compiler/rustc_middle/src/middle/stability.rs b/compiler/rustc_middle/src/middle/stability.rs index ac4a5985c2f..6933ee74393 100644 --- a/compiler/rustc_middle/src/middle/stability.rs +++ b/compiler/rustc_middle/src/middle/stability.rs @@ -7,7 +7,7 @@ use crate::ty::{self, DefIdTree, TyCtxt}; use rustc_ast::NodeId; use rustc_attr::{self as attr, ConstStability, Deprecation, Stability}; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; -use rustc_errors::{Applicability, DiagnosticBuilder}; +use rustc_errors::{Applicability, Diagnostic}; use rustc_feature::GateIssue; use rustc_hir as hir; use rustc_hir::def::DefKind; @@ -167,7 +167,7 @@ pub fn deprecation_in_effect(depr: &Deprecation) -> bool { } pub fn deprecation_suggestion( - diag: &mut DiagnosticBuilder<'_>, + diag: &mut Diagnostic, kind: &str, suggestion: Option, span: Span, diff --git a/compiler/rustc_middle/src/traits/mod.rs b/compiler/rustc_middle/src/traits/mod.rs index b54418e5201..072e6346cde 100644 --- a/compiler/rustc_middle/src/traits/mod.rs +++ b/compiler/rustc_middle/src/traits/mod.rs @@ -15,7 +15,7 @@ use crate::ty::subst::SubstsRef; use crate::ty::{self, AdtKind, Ty, TyCtxt}; use rustc_data_structures::sync::Lrc; -use rustc_errors::{Applicability, DiagnosticBuilder}; +use rustc_errors::{Applicability, Diagnostic}; use rustc_hir as hir; use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_span::symbol::Symbol; @@ -841,7 +841,7 @@ impl ObjectSafetyViolation { } } - pub fn solution(&self, err: &mut DiagnosticBuilder<'_>) { + pub fn solution(&self, err: &mut Diagnostic) { match *self { ObjectSafetyViolation::SizedSelf(_) | ObjectSafetyViolation::SupertraitSelf(_) => {} ObjectSafetyViolation::Method( diff --git a/compiler/rustc_middle/src/ty/diagnostics.rs b/compiler/rustc_middle/src/ty/diagnostics.rs index 934a6a878fe..58cf9fa7a89 100644 --- a/compiler/rustc_middle/src/ty/diagnostics.rs +++ b/compiler/rustc_middle/src/ty/diagnostics.rs @@ -7,7 +7,7 @@ use crate::ty::{ ProjectionTy, Term, Ty, TyCtxt, TypeAndMut, }; -use rustc_errors::{Applicability, DiagnosticBuilder}; +use rustc_errors::{Applicability, Diagnostic}; use rustc_hir as hir; use rustc_hir::def_id::DefId; use rustc_hir::{QPath, TyKind, WhereBoundPredicate, WherePredicate}; @@ -129,7 +129,7 @@ impl<'tcx> Ty<'tcx> { pub fn suggest_arbitrary_trait_bound( generics: &hir::Generics<'_>, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, param_name: &str, constraint: &str, ) -> bool { @@ -159,7 +159,7 @@ pub fn suggest_arbitrary_trait_bound( fn suggest_removing_unsized_bound( generics: &hir::Generics<'_>, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, param_name: &str, param: &hir::GenericParam<'_>, def_id: Option, @@ -266,7 +266,7 @@ fn suggest_removing_unsized_bound( pub fn suggest_constraining_type_param( tcx: TyCtxt<'_>, generics: &hir::Generics<'_>, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, param_name: &str, constraint: &str, def_id: Option, diff --git a/compiler/rustc_middle/src/ty/error.rs b/compiler/rustc_middle/src/ty/error.rs index 5ceabf99eda..5c0b5d0fa33 100644 --- a/compiler/rustc_middle/src/ty/error.rs +++ b/compiler/rustc_middle/src/ty/error.rs @@ -3,7 +3,7 @@ use crate::ty::diagnostics::suggest_constraining_type_param; use crate::ty::print::{FmtPrinter, Printer}; use crate::ty::{self, BoundRegionKind, Region, Ty, TyCtxt}; use rustc_errors::Applicability::{MachineApplicable, MaybeIncorrect}; -use rustc_errors::{pluralize, DiagnosticBuilder}; +use rustc_errors::{pluralize, Diagnostic}; use rustc_hir as hir; use rustc_hir::def_id::DefId; use rustc_span::symbol::{sym, Symbol}; @@ -347,7 +347,8 @@ impl<'tcx> Ty<'tcx> { impl<'tcx> TyCtxt<'tcx> { pub fn note_and_explain_type_err( self, - db: &mut DiagnosticBuilder<'_>, + // FIXME(eddyb) rename this since it's no longer a `DiagnosticBuilder`. + db: &mut Diagnostic, err: &TypeError<'tcx>, cause: &ObligationCause<'tcx>, sp: Span, @@ -584,7 +585,8 @@ impl Trait for X { fn suggest_constraint( self, - db: &mut DiagnosticBuilder<'_>, + // FIXME(eddyb) rename this since it's no longer a `DiagnosticBuilder`. + db: &mut Diagnostic, msg: &str, body_owner_def_id: DefId, proj_ty: &ty::ProjectionTy<'tcx>, @@ -671,7 +673,8 @@ impl Trait for X { /// fn that returns the type. fn expected_projection( self, - db: &mut DiagnosticBuilder<'_>, + // FIXME(eddyb) rename this since it's no longer a `DiagnosticBuilder`. + db: &mut Diagnostic, proj_ty: &ty::ProjectionTy<'tcx>, values: &ExpectedFound>, body_owner_def_id: DefId, @@ -766,7 +769,8 @@ fn foo(&self) -> Self::T { String::new() } /// a return type. This can occur when dealing with `TryStream` (#71035). fn suggest_constraining_opaque_associated_type( self, - db: &mut DiagnosticBuilder<'_>, + // FIXME(eddyb) rename this since it's no longer a `DiagnosticBuilder`. + db: &mut Diagnostic, msg: &str, proj_ty: &ty::ProjectionTy<'tcx>, ty: Ty<'tcx>, @@ -802,7 +806,8 @@ fn foo(&self) -> Self::T { String::new() } fn point_at_methods_that_satisfy_associated_type( self, - db: &mut DiagnosticBuilder<'_>, + // FIXME(eddyb) rename this since it's no longer a `DiagnosticBuilder`. + db: &mut Diagnostic, assoc_container_id: DefId, current_method_ident: Option, proj_ty_item_def_id: DefId, @@ -857,7 +862,8 @@ fn foo(&self) -> Self::T { String::new() } fn point_at_associated_type( self, - db: &mut DiagnosticBuilder<'_>, + // FIXME(eddyb) rename this since it's no longer a `DiagnosticBuilder`. + db: &mut Diagnostic, body_owner_def_id: DefId, found: Ty<'tcx>, ) -> bool { @@ -921,7 +927,8 @@ fn foo(&self) -> Self::T { String::new() } /// type is defined on a supertrait of the one present in the bounds. fn constrain_generic_bound_associated_type_structured_suggestion( self, - db: &mut DiagnosticBuilder<'_>, + // FIXME(eddyb) rename this since it's no longer a `DiagnosticBuilder`. + db: &mut Diagnostic, trait_ref: &ty::TraitRef<'tcx>, bounds: hir::GenericBounds<'_>, assoc: &ty::AssocItem, @@ -958,7 +965,8 @@ fn foo(&self) -> Self::T { String::new() } /// associated type to a given type `ty`. fn constrain_associated_type_structured_suggestion( self, - db: &mut DiagnosticBuilder<'_>, + // FIXME(eddyb) rename this since it's no longer a `DiagnosticBuilder`. + db: &mut Diagnostic, span: Span, assoc: &ty::AssocItem, assoc_substs: &[ty::GenericArg<'tcx>], diff --git a/compiler/rustc_mir_build/src/thir/pattern/check_match.rs b/compiler/rustc_mir_build/src/thir/pattern/check_match.rs index d357ac69302..a2d0fb36eb2 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/check_match.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/check_match.rs @@ -6,7 +6,7 @@ use super::{PatCtxt, PatternError}; use rustc_arena::TypedArena; use rustc_ast::Mutability; -use rustc_errors::{error_code, struct_span_err, Applicability, DiagnosticBuilder}; +use rustc_errors::{error_code, struct_span_err, Applicability, Diagnostic, DiagnosticBuilder}; use rustc_hir as hir; use rustc_hir::def::*; use rustc_hir::def_id::DefId; @@ -281,12 +281,7 @@ impl<'p, 'tcx> MatchVisitor<'_, 'p, 'tcx> { /// A path pattern was interpreted as a constant, not a new variable. /// This caused an irrefutable match failure in e.g. `let`. -fn const_not_var( - err: &mut DiagnosticBuilder<'_>, - tcx: TyCtxt<'_>, - pat: &Pat<'_>, - path: &hir::Path<'_>, -) { +fn const_not_var(err: &mut Diagnostic, tcx: TyCtxt<'_>, pat: &Pat<'_>, path: &hir::Path<'_>) { let descr = path.res.descr(); err.span_label( pat.span, @@ -594,7 +589,7 @@ crate fn pattern_not_covered_label( /// Point at the definition of non-covered `enum` variants. fn adt_defined_here<'p, 'tcx>( cx: &MatchCheckCtxt<'p, 'tcx>, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, ty: Ty<'tcx>, witnesses: &[DeconstructedPat<'p, 'tcx>], ) { diff --git a/compiler/rustc_parse/src/lexer/unicode_chars.rs b/compiler/rustc_parse/src/lexer/unicode_chars.rs index c2a75d2bc2c..1d63b79adc5 100644 --- a/compiler/rustc_parse/src/lexer/unicode_chars.rs +++ b/compiler/rustc_parse/src/lexer/unicode_chars.rs @@ -3,7 +3,7 @@ use super::StringReader; use crate::token; -use rustc_errors::{Applicability, DiagnosticBuilder}; +use rustc_errors::{Applicability, Diagnostic}; use rustc_span::{symbol::kw, BytePos, Pos, Span}; #[rustfmt::skip] // for line breaks @@ -336,7 +336,7 @@ pub(super) fn check_for_substitution<'a>( reader: &StringReader<'a>, pos: BytePos, ch: char, - err: &mut DiagnosticBuilder<'a>, + err: &mut Diagnostic, ) -> Option { let Some(&(_u_char, u_name, ascii_char)) = UNICODE_ARRAY.iter().find(|&&(c, _, _)| c == ch) else { return None; diff --git a/compiler/rustc_parse/src/parser/attr.rs b/compiler/rustc_parse/src/parser/attr.rs index ca92d6b7fd0..a9a0d44c9a6 100644 --- a/compiler/rustc_parse/src/parser/attr.rs +++ b/compiler/rustc_parse/src/parser/attr.rs @@ -3,7 +3,7 @@ use rustc_ast as ast; use rustc_ast::attr; use rustc_ast::token::{self, Nonterminal}; use rustc_ast_pretty::pprust; -use rustc_errors::{error_code, DiagnosticBuilder, PResult}; +use rustc_errors::{error_code, Diagnostic, PResult}; use rustc_span::{sym, BytePos, Span}; use std::convert::TryInto; @@ -147,7 +147,7 @@ impl<'a> Parser<'a> { fn annotate_following_item_if_applicable( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, span: Span, attr_type: OuterAttributeType, ) -> Option { diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index def23005fbe..ccd8fa3dbe9 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -16,7 +16,7 @@ use rustc_ast::{ }; use rustc_ast_pretty::pprust; use rustc_data_structures::fx::FxHashSet; -use rustc_errors::{pluralize, struct_span_err}; +use rustc_errors::{pluralize, struct_span_err, Diagnostic}; use rustc_errors::{Applicability, DiagnosticBuilder, Handler, PResult}; use rustc_span::source_map::Spanned; use rustc_span::symbol::{kw, Ident}; @@ -393,7 +393,7 @@ impl<'a> Parser<'a> { Err(err) } - fn check_too_many_raw_str_terminators(&mut self, err: &mut DiagnosticBuilder<'_>) -> bool { + fn check_too_many_raw_str_terminators(&mut self, err: &mut Diagnostic) -> bool { match (&self.prev_token.kind, &self.token.kind) { ( TokenKind::Literal(Lit { @@ -483,7 +483,7 @@ impl<'a> Parser<'a> { pub fn maybe_annotate_with_ascription( &mut self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, maybe_expected_semicolon: bool, ) { if let Some((sp, likely_path)) = self.last_type_ascription.take() { @@ -767,7 +767,7 @@ impl<'a> Parser<'a> { /// parenthesising the leftmost comparison. fn attempt_chained_comparison_suggestion( &mut self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, inner_op: &Expr, outer_op: &Spanned, ) -> bool /* advanced the cursor */ { @@ -890,7 +890,7 @@ impl<'a> Parser<'a> { "comparison operators cannot be chained", ); - let suggest = |err: &mut DiagnosticBuilder<'_>| { + let suggest = |err: &mut Diagnostic| { err.span_suggestion_verbose( op.span.shrink_to_lo(), TURBOFISH_SUGGESTION_STR, @@ -1637,7 +1637,7 @@ impl<'a> Parser<'a> { pub(super) fn parameter_without_type( &mut self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, pat: P, require_name: bool, first_param: bool, diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index 7cb8c35b868..8283fd0d207 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -17,7 +17,7 @@ use rustc_ast::{self as ast, AttrStyle, AttrVec, CaptureBy, ExprField, Lit, UnOp use rustc_ast::{AnonConst, BinOp, BinOpKind, FnDecl, FnRetTy, MacCall, Param, Ty, TyKind}; use rustc_ast::{Arm, Async, BlockCheckMode, Expr, ExprKind, Label, Movability, RangeLimits}; use rustc_ast_pretty::pprust; -use rustc_errors::{Applicability, DiagnosticBuilder, PResult}; +use rustc_errors::{Applicability, Diagnostic, DiagnosticBuilder, PResult}; use rustc_session::lint::builtin::BREAK_WITH_LABEL_AND_LOOP; use rustc_session::lint::BuiltinLintDiagnostics; use rustc_span::edition::LATEST_STABLE_EDITION; @@ -2653,7 +2653,7 @@ impl<'a> Parser<'a> { let mut base = ast::StructRest::None; let mut recover_async = false; - let mut async_block_err = |e: &mut DiagnosticBuilder<'_>, span: Span| { + let mut async_block_err = |e: &mut Diagnostic, span: Span| { recover_async = true; e.span_label(span, "`async` blocks are only allowed in Rust 2018 or later"); e.help(&format!("set `edition = \"{}\"` in `Cargo.toml`", LATEST_STABLE_EDITION)); diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs index 9a2fb3b86e2..a1d4758c8ed 100644 --- a/compiler/rustc_resolve/src/diagnostics.rs +++ b/compiler/rustc_resolve/src/diagnostics.rs @@ -3,7 +3,7 @@ use std::ptr; use rustc_ast::{self as ast, Path}; use rustc_ast_pretty::pprust; use rustc_data_structures::fx::FxHashSet; -use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder}; +use rustc_errors::{struct_span_err, Applicability, Diagnostic, DiagnosticBuilder}; use rustc_feature::BUILTIN_ATTRIBUTES; use rustc_hir::def::Namespace::{self, *}; use rustc_hir::def::{self, CtorKind, CtorOf, DefKind, NonMacroAttrKind}; @@ -1031,7 +1031,7 @@ impl<'a> Resolver<'a> { crate fn unresolved_macro_suggestions( &mut self, - err: &mut DiagnosticBuilder<'a>, + err: &mut Diagnostic, macro_kind: MacroKind, parent_scope: &ParentScope<'a>, ident: Ident, @@ -1120,7 +1120,7 @@ impl<'a> Resolver<'a> { crate fn add_typo_suggestion( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, suggestion: Option, span: Span, ) -> bool { @@ -1817,7 +1817,7 @@ fn find_span_immediately_after_crate_name( crate fn show_candidates( definitions: &rustc_hir::definitions::Definitions, session: &Session, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, // This is `None` if all placement locations are inside expansions use_placement_span: Option, candidates: &[ImportSuggestion], diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index 159afa1bbbe..70be891aecc 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -12,7 +12,7 @@ use rustc_ast::{ }; use rustc_ast_pretty::pprust::path_segment_to_string; use rustc_data_structures::fx::FxHashSet; -use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder}; +use rustc_errors::{pluralize, struct_span_err, Applicability, Diagnostic, DiagnosticBuilder}; use rustc_hir as hir; use rustc_hir::def::Namespace::{self, *}; use rustc_hir::def::{self, CtorKind, CtorOf, DefKind}; @@ -606,11 +606,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> { (err, candidates) } - fn detect_assoct_type_constraint_meant_as_path( - &self, - base_span: Span, - err: &mut DiagnosticBuilder<'_>, - ) { + fn detect_assoct_type_constraint_meant_as_path(&self, base_span: Span, err: &mut Diagnostic) { let Some(ty) = self.diagnostic_metadata.current_type_path else { return; }; let TyKind::Path(_, path) = &ty.kind else { return; }; for segment in &path.segments { @@ -675,11 +671,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> { } /// Given `where ::Baz: String`, suggest `where T: Bar`. - fn restrict_assoc_type_in_where_clause( - &mut self, - span: Span, - err: &mut DiagnosticBuilder<'_>, - ) -> bool { + fn restrict_assoc_type_in_where_clause(&mut self, span: Span, err: &mut Diagnostic) -> bool { // Detect that we are actually in a `where` predicate. let (bounded_ty, bounds, where_span) = if let Some(ast::WherePredicate::BoundPredicate(ast::WhereBoundPredicate { @@ -875,7 +867,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> { /// Returns `true` if able to provide context-dependent help. fn smart_resolve_context_dependent_help( &mut self, - err: &mut DiagnosticBuilder<'a>, + err: &mut Diagnostic, span: Span, source: PathSource<'_>, res: Res, @@ -885,7 +877,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> { let ns = source.namespace(); let is_expected = &|res| source.is_expected(res); - let path_sep = |err: &mut DiagnosticBuilder<'_>, expr: &Expr| match expr.kind { + let path_sep = |err: &mut Diagnostic, expr: &Expr| match expr.kind { ExprKind::Field(_, ident) => { err.span_suggestion( expr.span, @@ -908,7 +900,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> { _ => false, }; - let find_span = |source: &PathSource<'_>, err: &mut DiagnosticBuilder<'_>| { + let find_span = |source: &PathSource<'_>, err: &mut Diagnostic| { match source { PathSource::Expr(Some(Expr { span, kind: ExprKind::Call(_, _), .. })) | PathSource::TupleStruct(span, _) => { @@ -1435,7 +1427,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> { start.to(sm.next_point(start)) } - fn type_ascription_suggestion(&self, err: &mut DiagnosticBuilder<'_>, base_span: Span) -> bool { + fn type_ascription_suggestion(&self, err: &mut Diagnostic, base_span: Span) -> bool { let sm = self.r.session.source_map(); let base_snippet = sm.span_to_snippet(base_span); if let Some(&sp) = self.diagnostic_metadata.current_type_ascription.last() { @@ -1577,7 +1569,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> { /// Adds a suggestion for using an enum's variant when an enum is used instead. fn suggest_using_enum_variant( &mut self, - err: &mut DiagnosticBuilder<'a>, + err: &mut Diagnostic, source: PathSource<'_>, def_id: DefId, span: Span, @@ -1910,7 +1902,8 @@ impl<'tcx> LifetimeContext<'_, 'tcx> { /// Returns whether to add `'static` lifetime to the suggested lifetime list. crate fn report_elision_failure( &mut self, - db: &mut DiagnosticBuilder<'_>, + // FIXME(eddyb) rename this since it's no longer a `DiagnosticBuilder`. + db: &mut Diagnostic, params: &[ElisionFailureInfo], ) -> bool { let mut m = String::new(); @@ -2059,7 +2052,7 @@ impl<'tcx> LifetimeContext<'_, 'tcx> { crate fn add_missing_lifetime_specifiers_label( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, mut spans_with_counts: Vec<(Span, usize)>, lifetime_names: &FxHashSet, lifetime_spans: Vec, @@ -2090,7 +2083,7 @@ impl<'tcx> LifetimeContext<'_, 'tcx> { } let suggest_existing = - |err: &mut DiagnosticBuilder<'_>, + |err: &mut Diagnostic, name: &str, formatters: Vec String>>>| { if let Some(MissingLifetimeSpot::HigherRanked { span: for_span, span_type }) = @@ -2174,7 +2167,7 @@ impl<'tcx> LifetimeContext<'_, 'tcx> { Applicability::MaybeIncorrect, ); }; - let suggest_new = |err: &mut DiagnosticBuilder<'_>, suggs: Vec>| { + let suggest_new = |err: &mut Diagnostic, suggs: Vec>| { for missing in self.missing_named_lifetime_spots.iter().rev() { let mut introduce_suggestion = vec![]; let msg; diff --git a/compiler/rustc_resolve/src/late/lifetimes.rs b/compiler/rustc_resolve/src/late/lifetimes.rs index 2f0ad60709d..206da43ffd4 100644 --- a/compiler/rustc_resolve/src/late/lifetimes.rs +++ b/compiler/rustc_resolve/src/late/lifetimes.rs @@ -9,7 +9,7 @@ use crate::late::diagnostics::{ForLifetimeSpanType, MissingLifetimeSpot}; use rustc_ast::walk_list; use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap}; -use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder}; +use rustc_errors::{struct_span_err, Applicability, Diagnostic}; use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::{DefIdMap, LocalDefId}; @@ -1873,7 +1873,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { // or from `fn rah<'a>(T<'a>)` to `fn rah(T<'_>)` fn suggest_eliding_single_use_lifetime( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, def_id: DefId, lifetime: &hir::Lifetime, ) { diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index 04b0a18b12b..ca6451b856d 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -40,7 +40,7 @@ use rustc_ast_pretty::pprust; use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap}; use rustc_data_structures::intern::Interned; use rustc_data_structures::sync::Lrc; -use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder}; +use rustc_errors::{struct_span_err, Applicability, Diagnostic, DiagnosticBuilder}; use rustc_expand::base::{DeriveResolutions, SyntaxExtension, SyntaxExtensionKind}; use rustc_hir::def::Namespace::*; use rustc_hir::def::{self, CtorOf, DefKind, NonMacroAttrKind, PartialRes}; @@ -3169,7 +3169,7 @@ impl<'a> Resolver<'a> { /// ``` fn add_suggestion_for_rename_of_use( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, name: Symbol, import: &Import<'_>, binding_span: Span, @@ -3248,7 +3248,7 @@ impl<'a> Resolver<'a> { /// as characters expected by span manipulations won't be present. fn add_suggestion_for_duplicate_nested_use( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, import: &Import<'_>, binding_span: Span, ) { diff --git a/compiler/rustc_session/src/parse.rs b/compiler/rustc_session/src/parse.rs index 7113f9b0a2f..5c71bef31c2 100644 --- a/compiler/rustc_session/src/parse.rs +++ b/compiler/rustc_session/src/parse.rs @@ -7,7 +7,7 @@ use rustc_ast::node_id::NodeId; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::sync::{Lock, Lrc}; use rustc_errors::{emitter::SilentEmitter, ColorConfig, Handler}; -use rustc_errors::{error_code, Applicability, DiagnosticBuilder}; +use rustc_errors::{error_code, Applicability, Diagnostic, DiagnosticBuilder}; use rustc_feature::{find_feature_issue, GateIssue, UnstableFeatures}; use rustc_span::edition::Edition; use rustc_span::hygiene::ExpnId; @@ -243,7 +243,7 @@ impl ParseSess { /// Extend an error with a suggestion to wrap an expression with parentheses to allow the /// parser to continue parsing the following operation as part of the same expression. - pub fn expr_parentheses_needed(&self, err: &mut DiagnosticBuilder<'_>, span: Span) { + pub fn expr_parentheses_needed(&self, err: &mut Diagnostic, span: Span) { err.multipart_suggestion( "parentheses are required to parse this as an expression", vec![(span.shrink_to_lo(), "(".to_string()), (span.shrink_to_hi(), ")".to_string())], diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index 9bcdd7f3da6..c83a60f5feb 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -19,7 +19,7 @@ use rustc_errors::annotate_snippet_emitter_writer::AnnotateSnippetEmitterWriter; use rustc_errors::emitter::{Emitter, EmitterWriter, HumanReadableErrorType}; use rustc_errors::json::JsonEmitter; use rustc_errors::registry::Registry; -use rustc_errors::{DiagnosticBuilder, DiagnosticId, ErrorReported}; +use rustc_errors::{Diagnostic, DiagnosticBuilder, DiagnosticId, ErrorReported}; use rustc_macros::HashStable_Generic; pub use rustc_span::def_id::StableCrateId; use rustc_span::edition::Edition; @@ -478,9 +478,9 @@ impl Session { /// Analogous to calling methods on the given `DiagnosticBuilder`, but /// deduplicates on lint ID, span (if any), and message for this `Session` - fn diag_once<'a, 'b>( - &'a self, - diag_builder: &'b mut DiagnosticBuilder<'a>, + fn diag_once( + &self, + diag: &mut Diagnostic, method: DiagnosticBuilderMethod, msg_id: DiagnosticMessageId, message: &str, @@ -491,39 +491,33 @@ impl Session { if fresh { match method { DiagnosticBuilderMethod::Note => { - diag_builder.note(message); + diag.note(message); } DiagnosticBuilderMethod::SpanNote => { let span = span_maybe.expect("`span_note` needs a span"); - diag_builder.span_note(span, message); + diag.span_note(span, message); } } } } - pub fn diag_span_note_once<'a, 'b>( - &'a self, - diag_builder: &'b mut DiagnosticBuilder<'a>, + pub fn diag_span_note_once( + &self, + diag: &mut Diagnostic, msg_id: DiagnosticMessageId, span: Span, message: &str, ) { - self.diag_once( - diag_builder, - DiagnosticBuilderMethod::SpanNote, - msg_id, - message, - Some(span), - ); + self.diag_once(diag, DiagnosticBuilderMethod::SpanNote, msg_id, message, Some(span)); } - pub fn diag_note_once<'a, 'b>( - &'a self, - diag_builder: &'b mut DiagnosticBuilder<'a>, + pub fn diag_note_once( + &self, + diag: &mut Diagnostic, msg_id: DiagnosticMessageId, message: &str, ) { - self.diag_once(diag_builder, DiagnosticBuilderMethod::Note, msg_id, message, None); + self.diag_once(diag, DiagnosticBuilderMethod::Note, msg_id, message, None); } #[inline] diff --git a/compiler/rustc_trait_selection/src/traits/coherence.rs b/compiler/rustc_trait_selection/src/traits/coherence.rs index 8b76f3f7151..0f6997054b9 100644 --- a/compiler/rustc_trait_selection/src/traits/coherence.rs +++ b/compiler/rustc_trait_selection/src/traits/coherence.rs @@ -14,6 +14,7 @@ use crate::traits::{ PredicateObligations, SelectionContext, }; //use rustc_data_structures::fx::FxHashMap; +use rustc_errors::Diagnostic; use rustc_hir::def_id::{DefId, LOCAL_CRATE}; use rustc_hir::CRATE_HIR_ID; use rustc_infer::infer::TyCtxtInferExt; @@ -50,7 +51,7 @@ pub struct OverlapResult<'tcx> { pub involves_placeholder: bool, } -pub fn add_placeholder_note(err: &mut rustc_errors::DiagnosticBuilder<'_>) { +pub fn add_placeholder_note(err: &mut Diagnostic) { err.note( "this behavior recently changed as a result of a bug fix; \ see rust-lang/rust#56105 for details", diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs index 8746d66ebb6..396a7d37ca7 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs @@ -12,7 +12,9 @@ use crate::infer::error_reporting::{TyCategory, TypeAnnotationNeeded as ErrorCod use crate::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; use crate::infer::{self, InferCtxt, TyCtxtInferExt}; use rustc_data_structures::fx::FxHashMap; -use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder, ErrorReported}; +use rustc_errors::{ + pluralize, struct_span_err, Applicability, Diagnostic, DiagnosticBuilder, ErrorReported, +}; use rustc_hir as hir; use rustc_hir::def_id::DefId; use rustc_hir::intravisit::Visitor; @@ -1174,7 +1176,7 @@ trait InferCtxtPrivExt<'hir, 'tcx> { fn report_similar_impl_candidates( &self, impl_candidates: Vec>, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, ); /// Gets the parent trait chain start @@ -1186,11 +1188,7 @@ trait InferCtxtPrivExt<'hir, 'tcx> { /// If the `Self` type of the unsatisfied trait `trait_ref` implements a trait /// with the same path as `trait_ref`, a help message about /// a probable version mismatch is added to `err` - fn note_version_mismatch( - &self, - err: &mut DiagnosticBuilder<'_>, - trait_ref: &ty::PolyTraitRef<'tcx>, - ); + fn note_version_mismatch(&self, err: &mut Diagnostic, trait_ref: &ty::PolyTraitRef<'tcx>); /// Creates a `PredicateObligation` with `new_self_ty` replacing the existing type in the /// `trait_ref`. @@ -1215,35 +1213,26 @@ trait InferCtxtPrivExt<'hir, 'tcx> { pred: ty::PolyTraitRef<'tcx>, ) -> bool; - fn note_obligation_cause( - &self, - err: &mut DiagnosticBuilder<'tcx>, - obligation: &PredicateObligation<'tcx>, - ); + fn note_obligation_cause(&self, err: &mut Diagnostic, obligation: &PredicateObligation<'tcx>); fn suggest_unsized_bound_if_applicable( &self, - err: &mut DiagnosticBuilder<'tcx>, + err: &mut Diagnostic, obligation: &PredicateObligation<'tcx>, ); fn annotate_source_of_ambiguity( &self, - err: &mut DiagnosticBuilder<'tcx>, + err: &mut Diagnostic, impls: &[DefId], predicate: ty::Predicate<'tcx>, ); - fn maybe_suggest_unsized_generics( - &self, - err: &mut DiagnosticBuilder<'tcx>, - span: Span, - node: Node<'hir>, - ); + fn maybe_suggest_unsized_generics(&self, err: &mut Diagnostic, span: Span, node: Node<'hir>); fn maybe_indirection_for_unsized( &self, - err: &mut DiagnosticBuilder<'tcx>, + err: &mut Diagnostic, item: &'hir Item<'hir>, param: &'hir GenericParam<'hir>, ) -> bool; @@ -1572,7 +1561,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> { fn report_similar_impl_candidates( &self, impl_candidates: Vec>, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, ) { if impl_candidates.is_empty() { return; @@ -1649,11 +1638,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> { /// If the `Self` type of the unsatisfied trait `trait_ref` implements a trait /// with the same path as `trait_ref`, a help message about /// a probable version mismatch is added to `err` - fn note_version_mismatch( - &self, - err: &mut DiagnosticBuilder<'_>, - trait_ref: &ty::PolyTraitRef<'tcx>, - ) { + fn note_version_mismatch(&self, err: &mut Diagnostic, trait_ref: &ty::PolyTraitRef<'tcx>) { let get_trait_impl = |trait_def_id| { self.tcx.find_map_relevant_impl(trait_def_id, trait_ref.skip_binder().self_ty(), Some) }; @@ -1944,7 +1929,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> { fn annotate_source_of_ambiguity( &self, - err: &mut DiagnosticBuilder<'tcx>, + err: &mut Diagnostic, impls: &[DefId], predicate: ty::Predicate<'tcx>, ) { @@ -2088,11 +2073,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> { }) } - fn note_obligation_cause( - &self, - err: &mut DiagnosticBuilder<'tcx>, - obligation: &PredicateObligation<'tcx>, - ) { + fn note_obligation_cause(&self, err: &mut Diagnostic, obligation: &PredicateObligation<'tcx>) { // First, attempt to add note to this error with an async-await-specific // message, and fall back to regular note otherwise. if !self.maybe_note_obligation_cause_for_async_await(err, obligation) { @@ -2110,7 +2091,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> { fn suggest_unsized_bound_if_applicable( &self, - err: &mut DiagnosticBuilder<'tcx>, + err: &mut Diagnostic, obligation: &PredicateObligation<'tcx>, ) { let (pred, item_def_id, span) = match ( @@ -2139,7 +2120,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> { fn maybe_suggest_unsized_generics<'hir>( &self, - err: &mut DiagnosticBuilder<'tcx>, + err: &mut Diagnostic, span: Span, node: Node<'hir>, ) { @@ -2206,7 +2187,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> { fn maybe_indirection_for_unsized<'hir>( &self, - err: &mut DiagnosticBuilder<'tcx>, + err: &mut Diagnostic, item: &'hir Item<'hir>, param: &'hir GenericParam<'hir>, ) -> bool { diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index e162e943e36..0338dd39cf6 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -10,7 +10,7 @@ use crate::traits::normalize_projection_type; use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::stack::ensure_sufficient_stack; use rustc_errors::{ - error_code, pluralize, struct_span_err, Applicability, DiagnosticBuilder, Style, + error_code, pluralize, struct_span_err, Applicability, Diagnostic, DiagnosticBuilder, Style, }; use rustc_hir as hir; use rustc_hir::def::DefKind; @@ -47,7 +47,7 @@ pub enum GeneratorInteriorOrUpvar { pub trait InferCtxtExt<'tcx> { fn suggest_restricting_param_bound( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, trait_pred: ty::PolyTraitPredicate<'tcx>, body_id: hir::HirId, ); @@ -55,28 +55,23 @@ pub trait InferCtxtExt<'tcx> { fn suggest_dereferences( &self, obligation: &PredicateObligation<'tcx>, - err: &mut DiagnosticBuilder<'tcx>, + err: &mut Diagnostic, trait_pred: ty::PolyTraitPredicate<'tcx>, ); - fn get_closure_name( - &self, - def_id: DefId, - err: &mut DiagnosticBuilder<'_>, - msg: &str, - ) -> Option; + fn get_closure_name(&self, def_id: DefId, err: &mut Diagnostic, msg: &str) -> Option; fn suggest_fn_call( &self, obligation: &PredicateObligation<'tcx>, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, trait_pred: ty::PolyTraitPredicate<'tcx>, ); fn suggest_add_reference_to_arg( &self, obligation: &PredicateObligation<'tcx>, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, trait_pred: ty::PolyTraitPredicate<'tcx>, has_custom_message: bool, ) -> bool; @@ -84,27 +79,23 @@ pub trait InferCtxtExt<'tcx> { fn suggest_remove_reference( &self, obligation: &PredicateObligation<'tcx>, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, trait_pred: ty::PolyTraitPredicate<'tcx>, ); - fn suggest_remove_await( - &self, - obligation: &PredicateObligation<'tcx>, - err: &mut DiagnosticBuilder<'_>, - ); + fn suggest_remove_await(&self, obligation: &PredicateObligation<'tcx>, err: &mut Diagnostic); fn suggest_change_mut( &self, obligation: &PredicateObligation<'tcx>, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, trait_pred: ty::PolyTraitPredicate<'tcx>, ); fn suggest_semicolon_removal( &self, obligation: &PredicateObligation<'tcx>, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, span: Span, trait_pred: ty::PolyTraitPredicate<'tcx>, ); @@ -113,7 +104,7 @@ pub trait InferCtxtExt<'tcx> { fn suggest_impl_trait( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, span: Span, obligation: &PredicateObligation<'tcx>, trait_pred: ty::PolyTraitPredicate<'tcx>, @@ -121,7 +112,7 @@ pub trait InferCtxtExt<'tcx> { fn point_at_returns_when_relevant( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, obligation: &PredicateObligation<'tcx>, ); @@ -135,7 +126,7 @@ pub trait InferCtxtExt<'tcx> { fn suggest_fully_qualified_path( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, def_id: DefId, span: Span, trait_ref: DefId, @@ -143,13 +134,13 @@ pub trait InferCtxtExt<'tcx> { fn maybe_note_obligation_cause_for_async_await( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, obligation: &PredicateObligation<'tcx>, ) -> bool; fn note_obligation_cause_for_async_await( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, interior_or_upvar_span: GeneratorInteriorOrUpvar, interior_extra_info: Option<(Option, Span, Option, Option)>, inner_generator_body: Option<&hir::Body<'tcx>>, @@ -163,7 +154,7 @@ pub trait InferCtxtExt<'tcx> { fn note_obligation_cause_code( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, predicate: &T, param_env: ty::ParamEnv<'tcx>, cause_code: &ObligationCauseCode<'tcx>, @@ -172,12 +163,12 @@ pub trait InferCtxtExt<'tcx> { ) where T: fmt::Display; - fn suggest_new_overflow_limit(&self, err: &mut DiagnosticBuilder<'_>); + fn suggest_new_overflow_limit(&self, err: &mut Diagnostic); /// Suggest to await before try: future? => future.await? fn suggest_await_before_try( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, obligation: &PredicateObligation<'tcx>, trait_pred: ty::PolyTraitPredicate<'tcx>, span: Span, @@ -202,7 +193,7 @@ fn suggest_restriction<'tcx>( tcx: TyCtxt<'tcx>, generics: &hir::Generics<'tcx>, msg: &str, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, fn_sig: Option<&hir::FnSig<'_>>, projection: Option<&ty::ProjectionTy<'_>>, trait_pred: ty::PolyTraitPredicate<'tcx>, @@ -329,7 +320,7 @@ fn suggest_restriction<'tcx>( impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { fn suggest_restricting_param_bound( &self, - mut err: &mut DiagnosticBuilder<'_>, + mut err: &mut Diagnostic, trait_pred: ty::PolyTraitPredicate<'tcx>, body_id: hir::HirId, ) { @@ -493,7 +484,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { fn suggest_dereferences( &self, obligation: &PredicateObligation<'tcx>, - err: &mut DiagnosticBuilder<'tcx>, + err: &mut Diagnostic, trait_pred: ty::PolyTraitPredicate<'tcx>, ) { // It only make sense when suggesting dereferences for arguments @@ -549,26 +540,20 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { /// Given a closure's `DefId`, return the given name of the closure. /// /// This doesn't account for reassignments, but it's only used for suggestions. - fn get_closure_name( - &self, - def_id: DefId, - err: &mut DiagnosticBuilder<'_>, - msg: &str, - ) -> Option { - let get_name = - |err: &mut DiagnosticBuilder<'_>, kind: &hir::PatKind<'_>| -> Option { - // Get the local name of this closure. This can be inaccurate because - // of the possibility of reassignment, but this should be good enough. - match &kind { - hir::PatKind::Binding(hir::BindingAnnotation::Unannotated, _, name, None) => { - Some(format!("{}", name)) - } - _ => { - err.note(&msg); - None - } + fn get_closure_name(&self, def_id: DefId, err: &mut Diagnostic, msg: &str) -> Option { + let get_name = |err: &mut Diagnostic, kind: &hir::PatKind<'_>| -> Option { + // Get the local name of this closure. This can be inaccurate because + // of the possibility of reassignment, but this should be good enough. + match &kind { + hir::PatKind::Binding(hir::BindingAnnotation::Unannotated, _, name, None) => { + Some(format!("{}", name)) } - }; + _ => { + err.note(&msg); + None + } + } + }; let hir = self.tcx.hir(); let hir_id = hir.local_def_id_to_hir_id(def_id.as_local()?); @@ -590,7 +575,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { fn suggest_fn_call( &self, obligation: &PredicateObligation<'tcx>, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, trait_pred: ty::PolyTraitPredicate<'tcx>, ) { let self_ty = match trait_pred.self_ty().no_bound_vars() { @@ -683,7 +668,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { fn suggest_add_reference_to_arg( &self, obligation: &PredicateObligation<'tcx>, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, poly_trait_pred: ty::PolyTraitPredicate<'tcx>, has_custom_message: bool, ) -> bool { @@ -817,7 +802,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { fn suggest_remove_reference( &self, obligation: &PredicateObligation<'tcx>, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, trait_pred: ty::PolyTraitPredicate<'tcx>, ) { let span = obligation.cause.span; @@ -874,11 +859,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { } } - fn suggest_remove_await( - &self, - obligation: &PredicateObligation<'tcx>, - err: &mut DiagnosticBuilder<'_>, - ) { + fn suggest_remove_await(&self, obligation: &PredicateObligation<'tcx>, err: &mut Diagnostic) { let span = obligation.cause.span; if let ObligationCauseCode::AwaitableExpr(hir_id) = obligation.cause.code().peel_derives() { @@ -936,7 +917,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { fn suggest_change_mut( &self, obligation: &PredicateObligation<'tcx>, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, trait_pred: ty::PolyTraitPredicate<'tcx>, ) { let points_at_arg = matches!( @@ -1012,7 +993,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { fn suggest_semicolon_removal( &self, obligation: &PredicateObligation<'tcx>, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, span: Span, trait_pred: ty::PolyTraitPredicate<'tcx>, ) { @@ -1063,7 +1044,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { /// emitted. fn suggest_impl_trait( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, span: Span, obligation: &PredicateObligation<'tcx>, trait_pred: ty::PolyTraitPredicate<'tcx>, @@ -1256,7 +1237,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { fn point_at_returns_when_relevant( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, obligation: &PredicateObligation<'tcx>, ) { match obligation.cause.code().peel_derives() { @@ -1345,7 +1326,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { fn suggest_fully_qualified_path( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, def_id: DefId, span: Span, trait_ref: DefId, @@ -1411,7 +1392,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { /// Returns `true` if an async-await specific note was added to the diagnostic. fn maybe_note_obligation_cause_for_async_await( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, obligation: &PredicateObligation<'tcx>, ) -> bool { debug!( @@ -1639,7 +1620,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { /// `maybe_note_obligation_cause_for_async_await`'s documentation comment. fn note_obligation_cause_for_async_await( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, interior_or_upvar_span: GeneratorInteriorOrUpvar, interior_extra_info: Option<(Option, Span, Option, Option)>, inner_generator_body: Option<&hir::Body<'tcx>>, @@ -1896,7 +1877,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { fn note_obligation_cause_code( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, predicate: &T, param_env: ty::ParamEnv<'tcx>, cause_code: &ObligationCauseCode<'tcx>, @@ -2412,7 +2393,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { } } - fn suggest_new_overflow_limit(&self, err: &mut DiagnosticBuilder<'_>) { + fn suggest_new_overflow_limit(&self, err: &mut Diagnostic) { let suggested_limit = match self.tcx.recursion_limit() { Limit(0) => Limit(2), limit => limit * 2, @@ -2427,7 +2408,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { fn suggest_await_before_try( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, obligation: &PredicateObligation<'tcx>, trait_pred: ty::PolyTraitPredicate<'tcx>, span: Span, @@ -2615,7 +2596,7 @@ impl NextTypeParamName for &[hir::GenericParam<'_>] { } fn suggest_trait_object_return_type_alternatives( - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, ret_ty: Span, trait_obj: &str, is_object_safe: bool, diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index 5b646c6d447..8bcb1ccb584 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -29,7 +29,7 @@ use crate::traits::project::ProjectionCacheKeyExt; use crate::traits::ProjectionCacheKey; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::stack::ensure_sufficient_stack; -use rustc_errors::ErrorReported; +use rustc_errors::{Diagnostic, ErrorReported}; use rustc_hir as hir; use rustc_hir::def_id::DefId; use rustc_infer::infer::LateBoundRegionConversionTime; @@ -64,7 +64,7 @@ pub enum IntercrateAmbiguityCause { impl IntercrateAmbiguityCause { /// Emits notes when the overlap is caused by complex intercrate ambiguities. /// See #23980 for details. - pub fn add_intercrate_ambiguity_hint(&self, err: &mut rustc_errors::DiagnosticBuilder<'_>) { + pub fn add_intercrate_ambiguity_hint(&self, err: &mut Diagnostic) { err.note(&self.intercrate_ambiguity_hint()); } diff --git a/compiler/rustc_trait_selection/src/traits/util.rs b/compiler/rustc_trait_selection/src/traits/util.rs index b6e653c0eea..f800e7a1402 100644 --- a/compiler/rustc_trait_selection/src/traits/util.rs +++ b/compiler/rustc_trait_selection/src/traits/util.rs @@ -1,4 +1,4 @@ -use rustc_errors::DiagnosticBuilder; +use rustc_errors::Diagnostic; use rustc_span::Span; use smallvec::smallvec; use smallvec::SmallVec; @@ -43,12 +43,7 @@ impl<'tcx> TraitAliasExpansionInfo<'tcx> { /// Adds diagnostic labels to `diag` for the expansion path of a trait through all intermediate /// trait aliases. - pub fn label_with_exp_info( - &self, - diag: &mut DiagnosticBuilder<'_>, - top_label: &str, - use_desc: &str, - ) { + pub fn label_with_exp_info(&self, diag: &mut Diagnostic, top_label: &str, use_desc: &str) { diag.span_label(self.top().1, top_label); if self.path.len() > 1 { for (_, sp) in self.path.iter().rev().skip(1).take(self.path.len() - 2) { diff --git a/compiler/rustc_typeck/src/astconv/generics.rs b/compiler/rustc_typeck/src/astconv/generics.rs index 05ff7f818c7..b16bf33f06a 100644 --- a/compiler/rustc_typeck/src/astconv/generics.rs +++ b/compiler/rustc_typeck/src/astconv/generics.rs @@ -6,7 +6,7 @@ use crate::astconv::{ use crate::errors::AssocTypeBindingNotAllowed; use crate::structured_errors::{GenericArgsInfo, StructuredDiagnostic, WrongNumberOfGenericArgs}; use rustc_ast::ast::ParamKindOrd; -use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder, ErrorReported}; +use rustc_errors::{struct_span_err, Applicability, Diagnostic, ErrorReported}; use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::DefId; @@ -49,7 +49,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { } } - let add_braces_suggestion = |arg: &GenericArg<'_>, err: &mut DiagnosticBuilder<'_>| { + let add_braces_suggestion = |arg: &GenericArg<'_>, err: &mut Diagnostic| { let suggestions = vec![ (arg.span().shrink_to_lo(), String::from("{ ")), (arg.span().shrink_to_hi(), String::from(" }")), diff --git a/compiler/rustc_typeck/src/check/_match.rs b/compiler/rustc_typeck/src/check/_match.rs index 3701b255b75..9529e1528a8 100644 --- a/compiler/rustc_typeck/src/check/_match.rs +++ b/compiler/rustc_typeck/src/check/_match.rs @@ -1,6 +1,6 @@ use crate::check::coercion::{AsCoercionSite, CoerceMany}; use crate::check::{Diverges, Expectation, FnCtxt, Needs}; -use rustc_errors::{Applicability, DiagnosticBuilder}; +use rustc_errors::{Applicability, Diagnostic}; use rustc_hir::{self as hir, ExprKind}; use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; use rustc_infer::traits::Obligation; @@ -132,7 +132,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { &cause, Some(&arm.body), arm_ty, - Some(&mut |err: &mut DiagnosticBuilder<'_>| { + Some(&mut |err: &mut Diagnostic| { let can_coerce_to_return_ty = match self.ret_coercion.as_ref() { Some(ret_coercion) if self.in_tail_expr => { let ret_ty = ret_coercion.borrow().expected_ty(); diff --git a/compiler/rustc_typeck/src/check/callee.rs b/compiler/rustc_typeck/src/check/callee.rs index 679cac0b82a..d5187c109e3 100644 --- a/compiler/rustc_typeck/src/check/callee.rs +++ b/compiler/rustc_typeck/src/check/callee.rs @@ -2,7 +2,7 @@ use super::method::MethodCallee; use super::{Expectation, FnCtxt, TupleArgumentsFlag}; use crate::type_error_struct; -use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder}; +use rustc_errors::{struct_span_err, Applicability, Diagnostic}; use rustc_hir as hir; use rustc_hir::def::{Namespace, Res}; use rustc_hir::def_id::{DefId, LOCAL_CRATE}; @@ -277,7 +277,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// likely intention is to call the closure, suggest `(||{})()`. (#55851) fn identify_bad_closure_def_and_call( &self, - err: &mut DiagnosticBuilder<'a>, + err: &mut Diagnostic, hir_id: hir::HirId, callee_node: &hir::ExprKind<'_>, callee_span: Span, @@ -304,7 +304,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// likely intention is to create an array containing tuples. fn maybe_suggest_bad_array_definition( &self, - err: &mut DiagnosticBuilder<'a>, + err: &mut Diagnostic, call_expr: &'tcx hir::Expr<'tcx>, callee_expr: &'tcx hir::Expr<'tcx>, ) -> bool { diff --git a/compiler/rustc_typeck/src/check/coercion.rs b/compiler/rustc_typeck/src/check/coercion.rs index b011fb8804d..ed68bcfe433 100644 --- a/compiler/rustc_typeck/src/check/coercion.rs +++ b/compiler/rustc_typeck/src/check/coercion.rs @@ -37,7 +37,7 @@ use crate::astconv::AstConv; use crate::check::FnCtxt; -use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder}; +use rustc_errors::{struct_span_err, Applicability, Diagnostic, DiagnosticBuilder}; use rustc_hir as hir; use rustc_hir::def_id::DefId; use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; @@ -1307,7 +1307,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> { &mut self, fcx: &FnCtxt<'a, 'tcx>, cause: &ObligationCause<'tcx>, - augment_error: &mut dyn FnMut(&mut DiagnosticBuilder<'_>), + augment_error: &mut dyn FnMut(&mut Diagnostic), label_unit_as_expected: bool, ) { self.coerce_inner( @@ -1330,7 +1330,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> { cause: &ObligationCause<'tcx>, expression: Option<&'tcx hir::Expr<'tcx>>, mut expression_ty: Ty<'tcx>, - augment_error: Option<&mut dyn FnMut(&mut DiagnosticBuilder<'_>)>, + augment_error: Option<&mut dyn FnMut(&mut Diagnostic)>, label_expression_as_expected: bool, ) { // Incorporate whatever type inference information we have @@ -1603,7 +1603,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> { fn add_impl_trait_explanation<'a>( &self, - err: &mut DiagnosticBuilder<'a>, + err: &mut Diagnostic, cause: &ObligationCause<'tcx>, fcx: &FnCtxt<'a, 'tcx>, expected: Ty<'tcx>, diff --git a/compiler/rustc_typeck/src/check/demand.rs b/compiler/rustc_typeck/src/check/demand.rs index aa18a2e4b9b..4e22e41588a 100644 --- a/compiler/rustc_typeck/src/check/demand.rs +++ b/compiler/rustc_typeck/src/check/demand.rs @@ -4,7 +4,7 @@ use rustc_trait_selection::infer::InferCtxtExt as _; use rustc_trait_selection::traits::ObligationCause; use rustc_ast::util::parser::PREC_POSTFIX; -use rustc_errors::{Applicability, DiagnosticBuilder}; +use rustc_errors::{Applicability, Diagnostic, DiagnosticBuilder}; use rustc_hir as hir; use rustc_hir::lang_items::LangItem; use rustc_hir::{is_range_literal, Node}; @@ -23,7 +23,7 @@ use std::iter; impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pub fn emit_coerce_suggestions( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, expr: &hir::Expr<'tcx>, expr_ty: Ty<'tcx>, expected: Ty<'tcx>, @@ -155,7 +155,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { fn annotate_expected_due_to_let_ty( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, expr: &hir::Expr<'_>, error: TypeError<'_>, ) { @@ -262,7 +262,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// sole field is of the found type, suggest such variants. (Issue #42764) fn suggest_compatible_variants( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, expr: &hir::Expr<'_>, expected: Ty<'tcx>, expr_ty: Ty<'tcx>, @@ -899,7 +899,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pub fn check_for_cast( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, expr: &hir::Expr<'_>, checked_ty: Ty<'tcx>, expected_ty: Ty<'tcx>, @@ -1039,7 +1039,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let in_const_context = self.tcx.hir().is_inside_const_context(expr.hir_id); let suggest_fallible_into_or_lhs_from = - |err: &mut DiagnosticBuilder<'_>, exp_to_found_is_fallible: bool| { + |err: &mut Diagnostic, exp_to_found_is_fallible: bool| { // If we know the expression the expected type is derived from, we might be able // to suggest a widening conversion rather than a narrowing one (which may // panic). For example, given x: u8 and y: u32, if we know the span of "x", @@ -1083,7 +1083,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { }; let suggest_to_change_suffix_or_into = - |err: &mut DiagnosticBuilder<'_>, + |err: &mut Diagnostic, found_to_exp_is_fallible: bool, exp_to_found_is_fallible: bool| { let exp_is_lhs = @@ -1282,11 +1282,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } // Report the type inferred by the return statement. - fn report_closure_inferred_return_type( - &self, - err: &mut DiagnosticBuilder<'_>, - expected: Ty<'tcx>, - ) { + fn report_closure_inferred_return_type(&self, err: &mut Diagnostic, expected: Ty<'tcx>) { if let Some(sp) = self.ret_coercion_span.get() { // If the closure has an explicit return type annotation, or if // the closure's return type has been inferred from outside diff --git a/compiler/rustc_typeck/src/check/expr.rs b/compiler/rustc_typeck/src/check/expr.rs index b08ee414fa7..a335295587e 100644 --- a/compiler/rustc_typeck/src/check/expr.rs +++ b/compiler/rustc_typeck/src/check/expr.rs @@ -25,6 +25,7 @@ use crate::errors::{AddressOfTemporaryTaken, ReturnStmtOutsideOfFnBody, StructEx use rustc_ast as ast; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::stack::ensure_sufficient_stack; +use rustc_errors::Diagnostic; use rustc_errors::ErrorReported; use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder, DiagnosticId}; use rustc_hir as hir; @@ -60,7 +61,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { &self, expr: &'tcx hir::Expr<'tcx>, expected: Ty<'tcx>, - extend_err: impl Fn(&mut DiagnosticBuilder<'_>), + extend_err: impl Fn(&mut Diagnostic), ) -> Ty<'tcx> { self.check_expr_meets_expectation_or_error(expr, ExpectHasType(expected), extend_err) } @@ -69,7 +70,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { &self, expr: &'tcx hir::Expr<'tcx>, expected: Expectation<'tcx>, - extend_err: impl Fn(&mut DiagnosticBuilder<'_>), + extend_err: impl Fn(&mut Diagnostic), ) -> Ty<'tcx> { let expected_ty = expected.to_option(&self).unwrap_or(self.tcx.types.bool); let mut ty = self.check_expr_with_expectation(expr, expected); @@ -1923,7 +1924,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { fn suggest_await_on_field_access( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, field_ident: Ident, base: &'tcx hir::Expr<'tcx>, ty: Ty<'tcx>, @@ -2123,7 +2124,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { err.emit(); } - fn point_at_param_definition(&self, err: &mut DiagnosticBuilder<'_>, param: ty::ParamTy) { + fn point_at_param_definition(&self, err: &mut Diagnostic, param: ty::ParamTy) { let generics = self.tcx.generics_of(self.body_id.owner.to_def_id()); let generic_param = generics.type_param(¶m, self.tcx); if let ty::GenericParamDefKind::Type { synthetic: true, .. } = generic_param.kind { @@ -2142,7 +2143,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { fn suggest_fields_on_recordish( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, def: &'tcx ty::AdtDef, field: Ident, access_span: Span, @@ -2171,7 +2172,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { fn maybe_suggest_array_indexing( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, expr: &hir::Expr<'_>, base: &hir::Expr<'_>, field: Ident, @@ -2195,7 +2196,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { fn suggest_first_deref_field( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, expr: &hir::Expr<'_>, base: &hir::Expr<'_>, field: Ident, diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs b/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs index f6cd1369403..0fe5e74da89 100644 --- a/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs +++ b/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs @@ -8,7 +8,7 @@ use crate::check::{BreakableCtxt, Diverges, Expectation, FnCtxt, LocalTy}; use rustc_data_structures::captures::Captures; use rustc_data_structures::fx::FxHashSet; -use rustc_errors::{Applicability, DiagnosticBuilder, ErrorReported}; +use rustc_errors::{Applicability, Diagnostic, ErrorReported}; use rustc_hir as hir; use rustc_hir::def::{CtorOf, DefKind, Res}; use rustc_hir::def_id::DefId; @@ -953,7 +953,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pub(in super::super) fn note_internal_mutation_in_method( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, expr: &hir::Expr<'_>, expected: Ty<'tcx>, found: Ty<'tcx>, @@ -998,7 +998,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pub(in super::super) fn note_need_for_fn_pointer( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, expected: Ty<'tcx>, found: Ty<'tcx>, ) { diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs b/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs index 34e30fe49b1..982fd49d0fa 100644 --- a/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs +++ b/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs @@ -11,7 +11,7 @@ use crate::check::{ use rustc_ast as ast; use rustc_data_structures::sync::Lrc; -use rustc_errors::{Applicability, DiagnosticBuilder, DiagnosticId}; +use rustc_errors::{Applicability, Diagnostic, DiagnosticId}; use rustc_hir as hir; use rustc_hir::def::{CtorOf, DefKind, Res}; use rustc_hir::def_id::DefId; @@ -890,7 +890,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { &self, blk: &'tcx hir::Block<'tcx>, expected_ty: Ty<'tcx>, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, ) { if let Some((span_semi, boxed)) = self.could_remove_semicolon(blk, expected_ty) { if let StatementAsExpression::NeedsBoxing = boxed { diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs b/compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs index f6a2447572f..9e4b88e3746 100644 --- a/compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs +++ b/compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs @@ -4,7 +4,7 @@ use crate::astconv::AstConv; use rustc_ast::util::parser::ExprPrecedence; use rustc_span::{self, MultiSpan, Span}; -use rustc_errors::{Applicability, DiagnosticBuilder}; +use rustc_errors::{Applicability, Diagnostic}; use rustc_hir as hir; use rustc_hir::def::{CtorOf, DefKind}; use rustc_hir::lang_items::LangItem; @@ -22,11 +22,7 @@ use rustc_middle::ty::subst::GenericArgKind; use std::iter; impl<'a, 'tcx> FnCtxt<'a, 'tcx> { - pub(in super::super) fn suggest_semicolon_at_end( - &self, - span: Span, - err: &mut DiagnosticBuilder<'_>, - ) { + pub(in super::super) fn suggest_semicolon_at_end(&self, span: Span, err: &mut Diagnostic) { err.span_suggestion_short( span.shrink_to_hi(), "consider using a semicolon here", @@ -42,7 +38,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// - Possible missing return type if the return type is the default, and not `fn main()`. pub fn suggest_mismatched_types_on_tail( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, expr: &'tcx hir::Expr<'tcx>, expected: Ty<'tcx>, found: Ty<'tcx>, @@ -81,7 +77,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// ``` fn suggest_fn_call( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, expr: &hir::Expr<'_>, expected: Ty<'tcx>, found: Ty<'tcx>, @@ -211,7 +207,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pub fn suggest_deref_ref_or_into( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, expr: &hir::Expr<'tcx>, expected: Ty<'tcx>, found: Ty<'tcx>, @@ -312,7 +308,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// in the heap by calling `Box::new()`. pub(in super::super) fn suggest_boxing_when_appropriate( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, expr: &hir::Expr<'_>, expected: Ty<'tcx>, found: Ty<'tcx>, @@ -347,7 +343,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// suggest a non-capturing closure pub(in super::super) fn suggest_no_capture_closure( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, expected: Ty<'tcx>, found: Ty<'tcx>, ) { @@ -382,7 +378,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { #[instrument(skip(self, err))] pub(in super::super) fn suggest_calling_boxed_future_when_appropriate( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, expr: &hir::Expr<'_>, expected: Ty<'tcx>, found: Ty<'tcx>, @@ -477,7 +473,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// it suggests adding a semicolon. fn suggest_missing_semicolon( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, expression: &'tcx hir::Expr<'tcx>, expected: Ty<'tcx>, ) { @@ -518,7 +514,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// type. pub(in super::super) fn suggest_missing_return_type( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, fn_decl: &hir::FnDecl<'_>, expected: Ty<'tcx>, found: Ty<'tcx>, @@ -580,7 +576,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// ``` fn try_suggest_return_impl_trait( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, expected: Ty<'tcx>, found: Ty<'tcx>, fn_id: hir::HirId, @@ -681,7 +677,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pub(in super::super) fn suggest_missing_break_or_return_expr( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, expr: &'tcx hir::Expr<'tcx>, fn_decl: &hir::FnDecl<'_>, expected: Ty<'tcx>, @@ -751,7 +747,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pub(in super::super) fn suggest_missing_parentheses( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, expr: &hir::Expr<'_>, ) { let sp = self.tcx.sess.source_map().start_point(expr.span); diff --git a/compiler/rustc_typeck/src/check/method/mod.rs b/compiler/rustc_typeck/src/check/method/mod.rs index 780a57278c5..999aafbd537 100644 --- a/compiler/rustc_typeck/src/check/method/mod.rs +++ b/compiler/rustc_typeck/src/check/method/mod.rs @@ -14,7 +14,7 @@ pub use self::MethodError::*; use crate::check::FnCtxt; use crate::ObligationCause; use rustc_data_structures::sync::Lrc; -use rustc_errors::{Applicability, DiagnosticBuilder}; +use rustc_errors::{Applicability, Diagnostic}; use rustc_hir as hir; use rustc_hir::def::{CtorOf, DefKind, Namespace}; use rustc_hir::def_id::DefId; @@ -141,7 +141,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { #[instrument(level = "debug", skip(self, err, call_expr))] crate fn suggest_method_call( &self, - err: &mut DiagnosticBuilder<'a>, + err: &mut Diagnostic, msg: &str, method_name: Ident, self_ty: Ty<'tcx>, diff --git a/compiler/rustc_typeck/src/check/method/suggest.rs b/compiler/rustc_typeck/src/check/method/suggest.rs index 3213148f6a3..fadafe013b4 100644 --- a/compiler/rustc_typeck/src/check/method/suggest.rs +++ b/compiler/rustc_typeck/src/check/method/suggest.rs @@ -3,7 +3,7 @@ use crate::check::FnCtxt; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; -use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder}; +use rustc_errors::{pluralize, struct_span_err, Applicability, Diagnostic, DiagnosticBuilder}; use rustc_hir as hir; use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::lang_items::LangItem; @@ -98,7 +98,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } let report_candidates = |span: Span, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, mut sources: Vec, sugg_span: Span| { sources.sort(); @@ -625,10 +625,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } if self.is_fn_ty(rcvr_ty, span) { - fn report_function( - err: &mut DiagnosticBuilder<'_>, - name: T, - ) { + fn report_function(err: &mut Diagnostic, name: T) { err.note( &format!("`{}` is a function, perhaps you wish to call it", name,), ); @@ -1111,7 +1108,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { crate fn note_unmet_impls_on_type( &self, - err: &mut rustc_errors::DiagnosticBuilder<'_>, + err: &mut Diagnostic, errors: Vec>, ) { let all_local_types_needing_impls = @@ -1187,7 +1184,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { fn suggest_derive( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, unsatisfied_predicates: &[( ty::Predicate<'tcx>, Option>, @@ -1287,7 +1284,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { fn suggest_await_before_method( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, item_name: Ident, ty: Ty<'tcx>, call: &hir::Expr<'_>, @@ -1311,7 +1308,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { fn suggest_use_candidates( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, mut msg: String, candidates: Vec, ) { @@ -1416,7 +1413,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { fn suggest_valid_traits( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, valid_out_of_scope_traits: Vec, ) -> bool { if !valid_out_of_scope_traits.is_empty() { @@ -1454,7 +1451,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { fn suggest_traits_to_import( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, span: Span, rcvr_ty: Ty<'tcx>, item_name: Ident, @@ -1983,7 +1980,7 @@ fn find_use_placement<'tcx>(tcx: TyCtxt<'tcx>, target_module: LocalDefId) -> (Op fn print_disambiguation_help<'tcx>( item_name: Ident, args: Option<&'tcx [hir::Expr<'tcx>]>, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, trait_name: String, rcvr_ty: Ty<'_>, kind: ty::AssocKind, diff --git a/compiler/rustc_typeck/src/check/op.rs b/compiler/rustc_typeck/src/check/op.rs index dd49d6f4892..5873b0f52a6 100644 --- a/compiler/rustc_typeck/src/check/op.rs +++ b/compiler/rustc_typeck/src/check/op.rs @@ -3,7 +3,7 @@ use super::method::MethodCallee; use super::{has_expected_num_generic_args, FnCtxt}; use rustc_ast as ast; -use rustc_errors::{self, struct_span_err, Applicability, DiagnosticBuilder}; +use rustc_errors::{self, struct_span_err, Applicability, Diagnostic}; use rustc_hir as hir; use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; use rustc_middle::ty::adjustment::{ @@ -483,7 +483,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// suggest calling the function. Returns `true` if suggestion would apply (even if not given). fn add_type_neq_err_label( &self, - err: &mut rustc_errors::DiagnosticBuilder<'_>, + err: &mut Diagnostic, span: Span, ty: Ty<'tcx>, other_ty: Ty<'tcx>, @@ -545,7 +545,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { rhs_expr: &'tcx hir::Expr<'tcx>, lhs_ty: Ty<'tcx>, rhs_ty: Ty<'tcx>, - err: &mut rustc_errors::DiagnosticBuilder<'_>, + err: &mut Diagnostic, is_assign: IsAssign, op: hir::BinOp, ) -> bool { @@ -937,7 +937,7 @@ fn is_builtin_binop<'tcx>(lhs: Ty<'tcx>, rhs: Ty<'tcx>, op: hir::BinOp) -> bool fn suggest_constraining_param( tcx: TyCtxt<'_>, body_id: hir::HirId, - mut err: &mut DiagnosticBuilder<'_>, + mut err: &mut Diagnostic, lhs_ty: Ty<'_>, rhs_ty: Ty<'_>, missing_trait: &str, diff --git a/compiler/rustc_typeck/src/check/pat.rs b/compiler/rustc_typeck/src/check/pat.rs index 77ab1d1de42..3e01d73b0ba 100644 --- a/compiler/rustc_typeck/src/check/pat.rs +++ b/compiler/rustc_typeck/src/check/pat.rs @@ -2,7 +2,7 @@ use crate::check::FnCtxt; use rustc_ast as ast; use rustc_data_structures::fx::FxHashMap; -use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder}; +use rustc_errors::{pluralize, struct_span_err, Applicability, Diagnostic, DiagnosticBuilder}; use rustc_hir as hir; use rustc_hir::def::{CtorKind, DefKind, Res}; use rustc_hir::pat_util::EnumerateAndAdjustIterator; @@ -512,7 +512,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ty } - fn endpoint_has_type(&self, err: &mut DiagnosticBuilder<'_>, span: Span, ty: Ty<'_>) { + fn endpoint_has_type(&self, err: &mut Diagnostic, span: Span, ty: Ty<'_>) { if !ty.references_error() { err.span_label(span, &format!("this is of type `{}`", ty)); } @@ -645,7 +645,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { fn borrow_pat_suggestion( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut Diagnostic, pat: &Pat<'_>, inner: &Pat<'_>, expected: Ty<'tcx>, @@ -783,7 +783,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { fn maybe_suggest_range_literal( &self, - e: &mut DiagnosticBuilder<'_>, + e: &mut Diagnostic, opt_def_id: Option, ident: Ident, ) -> bool { diff --git a/compiler/rustc_typeck/src/structured_errors/wrong_number_of_generic_args.rs b/compiler/rustc_typeck/src/structured_errors/wrong_number_of_generic_args.rs index a1c29457709..014d2628065 100644 --- a/compiler/rustc_typeck/src/structured_errors/wrong_number_of_generic_args.rs +++ b/compiler/rustc_typeck/src/structured_errors/wrong_number_of_generic_args.rs @@ -1,5 +1,5 @@ use crate::structured_errors::StructuredDiagnostic; -use rustc_errors::{pluralize, Applicability, DiagnosticBuilder, DiagnosticId}; +use rustc_errors::{pluralize, Applicability, Diagnostic, DiagnosticBuilder, DiagnosticId}; use rustc_hir as hir; use rustc_middle::hir::map::fn_sig; use rustc_middle::middle::resolve_lifetime::LifetimeScopeForPath; @@ -370,7 +370,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> { } /// Builds the `expected 1 type argument / supplied 2 type arguments` message. - fn notify(&self, err: &mut DiagnosticBuilder<'_>) { + fn notify(&self, err: &mut Diagnostic) { let (quantifier, bound) = self.get_quantifier_and_bound(); let provided_args = self.num_provided_args(); @@ -422,7 +422,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> { } } - fn suggest(&self, err: &mut DiagnosticBuilder<'_>) { + fn suggest(&self, err: &mut Diagnostic) { debug!( "suggest(self.provided {:?}, self.gen_args.span(): {:?})", self.num_provided_args(), @@ -449,7 +449,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> { /// ```text /// type Map = HashMap; /// ``` - fn suggest_adding_args(&self, err: &mut DiagnosticBuilder<'_>) { + fn suggest_adding_args(&self, err: &mut Diagnostic) { if self.gen_args.parenthesized { return; } @@ -465,7 +465,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> { } } - fn suggest_adding_lifetime_args(&self, err: &mut DiagnosticBuilder<'_>) { + fn suggest_adding_lifetime_args(&self, err: &mut Diagnostic) { debug!("suggest_adding_lifetime_args(path_segment: {:?})", self.path_segment); let num_missing_args = self.num_missing_lifetime_args(); let num_params_to_take = num_missing_args; @@ -547,7 +547,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> { } } - fn suggest_adding_type_and_const_args(&self, err: &mut DiagnosticBuilder<'_>) { + fn suggest_adding_type_and_const_args(&self, err: &mut Diagnostic) { let num_missing_args = self.num_missing_type_or_const_args(); let msg = format!("add missing {} argument{}", self.kind(), pluralize!(num_missing_args)); @@ -602,7 +602,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> { /// ```text /// type Map = HashMap; /// ``` - fn suggest_removing_args_or_generics(&self, err: &mut DiagnosticBuilder<'_>) { + fn suggest_removing_args_or_generics(&self, err: &mut Diagnostic) { let num_provided_lt_args = self.num_provided_lifetime_args(); let num_provided_type_const_args = self.num_provided_type_or_const_args(); let num_provided_args = num_provided_lt_args + num_provided_type_const_args; @@ -617,7 +617,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> { let remove_entire_generics = num_redundant_args >= self.gen_args.args.len(); - let remove_lifetime_args = |err: &mut DiagnosticBuilder<'_>| { + let remove_lifetime_args = |err: &mut Diagnostic| { let mut lt_arg_spans = Vec::new(); let mut found_redundant = false; for arg in self.gen_args.args { @@ -659,7 +659,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> { ); }; - let remove_type_or_const_args = |err: &mut DiagnosticBuilder<'_>| { + let remove_type_or_const_args = |err: &mut Diagnostic| { let mut gen_arg_spans = Vec::new(); let mut found_redundant = false; for arg in self.gen_args.args { @@ -729,7 +729,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> { } /// Builds the `type defined here` message. - fn show_definition(&self, err: &mut DiagnosticBuilder<'_>) { + fn show_definition(&self, err: &mut Diagnostic) { let mut spans: MultiSpan = if let Some(def_span) = self.tcx.def_ident_span(self.def_id) { if self.tcx.sess.source_map().span_to_snippet(def_span).is_ok() { def_span.into() diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index bc2b99cb587..3ebd28e83b1 100644 --- a/src/librustdoc/passes/collect_intra_doc_links.rs +++ b/src/librustdoc/passes/collect_intra_doc_links.rs @@ -3,7 +3,7 @@ //! [RFC 1946]: https://github.com/rust-lang/rfcs/blob/master/text/1946-intra-rustdoc-links.md use rustc_data_structures::{fx::FxHashMap, stable_set::FxHashSet}; -use rustc_errors::{Applicability, DiagnosticBuilder}; +use rustc_errors::{Applicability, Diagnostic}; use rustc_hir::def::{ DefKind, Namespace::{self, *}, @@ -1434,7 +1434,7 @@ impl LinkCollector<'_, '_> { ) { // The resolved item did not match the disambiguator; give a better error than 'not found' let msg = format!("incompatible link kind for `{}`", path_str); - let callback = |diag: &mut DiagnosticBuilder<'_>, sp: Option| { + let callback = |diag: &mut Diagnostic, sp: Option| { let note = format!( "this link resolved to {} {}, which is not {} {}", resolved.article(), @@ -1866,7 +1866,7 @@ fn report_diagnostic( lint: &'static Lint, msg: &str, DiagnosticInfo { item, ori_link: _, dox, link_range }: &DiagnosticInfo<'_>, - decorate: impl FnOnce(&mut DiagnosticBuilder<'_>, Option), + decorate: impl FnOnce(&mut Diagnostic, Option), ) { let hir_id = match DocContext::as_local_hir_id(tcx, item.def_id) { Some(hir_id) => hir_id, @@ -2240,7 +2240,7 @@ fn ambiguity_error( /// disambiguator. fn suggest_disambiguator( res: Res, - diag: &mut DiagnosticBuilder<'_>, + diag: &mut Diagnostic, path_str: &str, ori_link: &str, sp: Option, diff --git a/src/tools/clippy/clippy_lints/src/copies.rs b/src/tools/clippy/clippy_lints/src/copies.rs index 8b79f1600ae..a20aa12c9ff 100644 --- a/src/tools/clippy/clippy_lints/src/copies.rs +++ b/src/tools/clippy/clippy_lints/src/copies.rs @@ -6,7 +6,7 @@ use clippy_utils::{ }; use if_chain::if_chain; use rustc_data_structures::fx::FxHashSet; -use rustc_errors::{Applicability, DiagnosticBuilder}; +use rustc_errors::{Applicability, Diagnostic}; use rustc_hir::intravisit::{self, Visitor}; use rustc_hir::{Block, Expr, ExprKind, HirId}; use rustc_lint::{LateContext, LateLintPass, LintContext}; @@ -489,7 +489,7 @@ fn emit_branches_sharing_code_lint( add_expr_note = !cx.typeck_results().expr_ty(if_expr).is_unit(); } - let add_optional_msgs = |diag: &mut DiagnosticBuilder<'_>| { + let add_optional_msgs = |diag: &mut Diagnostic| { if add_expr_note { diag.note("The end suggestion probably needs some adjustments to use the expression result correctly"); } diff --git a/src/tools/clippy/clippy_lints/src/implicit_hasher.rs b/src/tools/clippy/clippy_lints/src/implicit_hasher.rs index 5e4cde553b5..d5430a8c917 100644 --- a/src/tools/clippy/clippy_lints/src/implicit_hasher.rs +++ b/src/tools/clippy/clippy_lints/src/implicit_hasher.rs @@ -1,7 +1,7 @@ use std::borrow::Cow; use std::collections::BTreeMap; -use rustc_errors::DiagnosticBuilder; +use rustc_errors::Diagnostic; use rustc_hir as hir; use rustc_hir::intravisit::{walk_body, walk_expr, walk_inf, walk_ty, Visitor}; use rustc_hir::{Body, Expr, ExprKind, GenericArg, Item, ItemKind, QPath, TyKind}; @@ -68,7 +68,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitHasher { fn suggestion<'tcx>( cx: &LateContext<'tcx>, - diag: &mut DiagnosticBuilder<'_>, + diag: &mut Diagnostic, generics_span: Span, generics_suggestion_span: Span, target: &ImplicitHasherType<'_>, diff --git a/src/tools/clippy/clippy_lints/src/inline_fn_without_body.rs b/src/tools/clippy/clippy_lints/src/inline_fn_without_body.rs index df69d3dcc51..dd7177e0131 100644 --- a/src/tools/clippy/clippy_lints/src/inline_fn_without_body.rs +++ b/src/tools/clippy/clippy_lints/src/inline_fn_without_body.rs @@ -1,7 +1,7 @@ //! checks for `#[inline]` on trait methods without bodies use clippy_utils::diagnostics::span_lint_and_then; -use clippy_utils::sugg::DiagnosticBuilderExt; +use clippy_utils::sugg::DiagnosticExt; use rustc_ast::ast::Attribute; use rustc_errors::Applicability; use rustc_hir::{TraitFn, TraitItem, TraitItemKind}; diff --git a/src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs b/src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs index ebd4fb0bf51..91d7274f5f5 100644 --- a/src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs +++ b/src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs @@ -6,7 +6,7 @@ use clippy_utils::{get_trait_def_id, is_self, paths}; use if_chain::if_chain; use rustc_ast::ast::Attribute; use rustc_data_structures::fx::FxHashSet; -use rustc_errors::{Applicability, DiagnosticBuilder}; +use rustc_errors::{Applicability, Diagnostic}; use rustc_hir::intravisit::FnKind; use rustc_hir::{BindingAnnotation, Body, FnDecl, GenericArg, HirId, Impl, ItemKind, Node, PatKind, QPath, TyKind}; use rustc_hir::{HirIdMap, HirIdSet}; @@ -196,7 +196,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { } // Dereference suggestion - let sugg = |diag: &mut DiagnosticBuilder<'_>| { + let sugg = |diag: &mut Diagnostic| { if let ty::Adt(def, ..) = ty.kind() { if let Some(span) = cx.tcx.hir().span_if_local(def.did) { if can_type_implement_copy(cx.tcx, cx.param_env, ty).is_ok() { diff --git a/src/tools/clippy/clippy_lints/src/new_without_default.rs b/src/tools/clippy/clippy_lints/src/new_without_default.rs index f86af7a7bb6..4cb79648ae3 100644 --- a/src/tools/clippy/clippy_lints/src/new_without_default.rs +++ b/src/tools/clippy/clippy_lints/src/new_without_default.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::span_lint_hir_and_then; use clippy_utils::return_ty; use clippy_utils::source::snippet; -use clippy_utils::sugg::DiagnosticBuilderExt; +use clippy_utils::sugg::DiagnosticExt; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir as hir; diff --git a/src/tools/clippy/clippy_utils/src/diagnostics.rs b/src/tools/clippy/clippy_utils/src/diagnostics.rs index ca222c3d669..a927788e6a4 100644 --- a/src/tools/clippy/clippy_utils/src/diagnostics.rs +++ b/src/tools/clippy/clippy_utils/src/diagnostics.rs @@ -8,13 +8,13 @@ //! Thank you! //! ~The `INTERNAL_METADATA_COLLECTOR` lint -use rustc_errors::{Applicability, DiagnosticBuilder}; +use rustc_errors::{Applicability, Diagnostic}; use rustc_hir::HirId; use rustc_lint::{LateContext, Lint, LintContext}; use rustc_span::source_map::{MultiSpan, Span}; use std::env; -fn docs_link(diag: &mut DiagnosticBuilder<'_>, lint: &'static Lint) { +fn docs_link(diag: &mut Diagnostic, lint: &'static Lint) { if env::var("CLIPPY_DISABLE_DOCS_LINKS").is_err() { if let Some(lint) = lint.name_lower().strip_prefix("clippy::") { diag.help(&format!( @@ -145,7 +145,7 @@ pub fn span_lint_and_then(cx: &C, lint: &'static Lint, sp: S, msg: &str where C: LintContext, S: Into, - F: FnOnce(&mut DiagnosticBuilder<'_>), + F: FnOnce(&mut Diagnostic), { cx.struct_span_lint(lint, sp, |diag| { let mut diag = diag.build(msg); @@ -169,7 +169,7 @@ pub fn span_lint_hir_and_then( hir_id: HirId, sp: impl Into, msg: &str, - f: impl FnOnce(&mut DiagnosticBuilder<'_>), + f: impl FnOnce(&mut Diagnostic), ) { cx.tcx.struct_span_lint_hir(lint, hir_id, sp, |diag| { let mut diag = diag.build(msg); @@ -219,7 +219,7 @@ pub fn span_lint_and_sugg<'a, T: LintContext>( /// appear once per /// replacement. In human-readable format though, it only appears once before /// the whole suggestion. -pub fn multispan_sugg(diag: &mut DiagnosticBuilder<'_>, help_msg: &str, sugg: I) +pub fn multispan_sugg(diag: &mut Diagnostic, help_msg: &str, sugg: I) where I: IntoIterator, { @@ -232,7 +232,7 @@ where /// multiple spans. This is tracked in issue [rustfix#141](https://github.com/rust-lang/rustfix/issues/141). /// Suggestions with multiple spans will be silently ignored. pub fn multispan_sugg_with_applicability( - diag: &mut DiagnosticBuilder<'_>, + diag: &mut Diagnostic, help_msg: &str, applicability: Applicability, sugg: I, diff --git a/src/tools/clippy/clippy_utils/src/sugg.rs b/src/tools/clippy/clippy_utils/src/sugg.rs index fa63ddff253..63c442e7008 100644 --- a/src/tools/clippy/clippy_utils/src/sugg.rs +++ b/src/tools/clippy/clippy_utils/src/sugg.rs @@ -673,8 +673,8 @@ fn indentation(cx: &T, span: Span) -> Option { }) } -/// Convenience extension trait for `DiagnosticBuilder`. -pub trait DiagnosticBuilderExt { +/// Convenience extension trait for `Diagnostic`. +pub trait DiagnosticExt { /// Suggests to add an attribute to an item. /// /// Correctly handles indentation of the attribute and item. @@ -721,7 +721,7 @@ pub trait DiagnosticBuilderExt { fn suggest_remove_item(&mut self, cx: &T, item: Span, msg: &str, applicability: Applicability); } -impl DiagnosticBuilderExt for rustc_errors::DiagnosticBuilder<'_> { +impl DiagnosticExt for rustc_errors::Diagnostic { fn suggest_item_with_attr( &mut self, cx: &T,