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};
#[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,
fn suggest_split_at_mut_if_applicable(
&self,
- err: &mut DiagnosticBuilder<'_>,
+ err: &mut Diagnostic,
place: Place<'tcx>,
borrowed_place: Place<'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, .. }, .. }),
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(
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::{
tcx: TyCtxt<'tcx>,
body: &Body<'tcx>,
local_names: &IndexVec<Local, Option<Symbol>>,
- err: &mut DiagnosticBuilder<'_>,
+ err: &mut Diagnostic,
borrow_desc: &str,
borrow_span: Option<Span>,
multiple_borrow_span: Option<(Span, Span)>,
}
pub(crate) fn add_lifetime_bound_suggestion_to_diagnostic(
&self,
- err: &mut DiagnosticBuilder<'_>,
+ err: &mut Diagnostic,
category: &ConstraintCategory,
span: Span,
region_name: &RegionName,
//! 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;
&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();
/// Add a note that a type does not implement `Copy`
pub(super) fn note_type_does_not_implement_copy(
&self,
- err: &mut DiagnosticBuilder<'_>,
+ err: &mut Diagnostic,
place_desc: &str,
ty: Ty<'tcx>,
span: Option<Span>,
}
// Add a span label to the arguments of the closure, if it exists.
- pub(super) fn args_span_label(
- self,
- err: &mut DiagnosticBuilder<'_>,
- message: impl Into<String>,
- ) {
+ pub(super) fn args_span_label(self, err: &mut Diagnostic, message: impl Into<String>) {
if let UseSpans::ClosureUse { args_span, .. } = self {
err.span_label(args_span, message);
}
// Add a span label to the use of the captured variable, if it exists.
// only adds label to the `path_span`
- pub(super) fn var_span_label_path_only(
- self,
- err: &mut DiagnosticBuilder<'_>,
- message: impl Into<String>,
- ) {
+ pub(super) fn var_span_label_path_only(self, err: &mut Diagnostic, message: impl Into<String>) {
if let UseSpans::ClosureUse { path_span, .. } = self {
err.span_label(path_span, message);
}
// Add a span label to the use of the captured variable, if it exists.
pub(super) fn var_span_label(
self,
- err: &mut DiagnosticBuilder<'_>,
+ err: &mut Diagnostic,
message: impl Into<String>,
kind_desc: impl Into<String>,
) {
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;
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) {
}
}
- 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];
}
}
- 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;
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 {
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);
// 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},
}
/// 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();
//! 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;
&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);
//! 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,
/// ```
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,
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;
}
}
- 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) => {
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;
}
/// 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)
}
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;
/// 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!(
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() {
suggest_constraining_type_param(
tcx,
generics,
- &mut err,
+ err,
¶m_ty.name.as_str(),
&constraint,
None,
}
_ => {}
}
-
- err
};
let call_kind = call_kind(tcx, ccx.param_env, callee, substs, span, from_hir_call, None);
};
}
- let err = match kind {
+ let mut err = match kind {
CallDesugaringKind::ForLoopIntoIter => {
error!("cannot convert `{}` into an iterator in {}s")
}
}
};
- 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!(
_ => {}
}
- 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!(
}
}
- 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!(
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,
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<Item = Span>,
+ label: impl AsRef<str>,
+ ) -> &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);
self
}
- crate fn note_expected_found(
+ pub fn note_expected_found(
&mut self,
expected_label: &dyn fmt::Display,
expected: DiagnosticStyledString,
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,
/// Prints the span with a note above it.
/// This is like [`Diagnostic::note()`], but it gets its own span.
- crate fn span_note<S: Into<MultiSpan>>(&mut self, sp: S, msg: &str) -> &mut Self {
+ pub fn span_note<S: Into<MultiSpan>>(&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<S: Into<MultiSpan>>(&mut self, sp: S, msg: &str) -> &mut Self {
+ pub fn span_warn<S: Into<MultiSpan>>(&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<S: Into<MultiSpan>>(&mut self, sp: S, msg: &str) -> &mut Self {
+ pub fn span_help<S: Into<MultiSpan>>(&mut self, sp: S, msg: &str) -> &mut Self {
self.sub(Level::Help, msg, sp.into(), None);
self
}
self.code.clone()
}
- crate fn set_primary_message<M: Into<String>>(&mut self, msg: M) -> &mut Self {
+ pub fn set_primary_message<M: Into<String>>(&mut self, msg: M) -> &mut Self {
self.message[0] = (msg.into(), Style::NoStyle);
self
}
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> {
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
/// 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<String>) -> &mut Self {
- self.diagnostic.span_label(span, label);
- self
- }
+ pub fn span_label(&mut self, span: Span, label: impl Into<String>) -> &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<Item = Span>,
label: impl AsRef<str>,
- ) -> &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,
) -> &mut Self);
forward!(pub fn note(&mut self, msg: &str) -> &mut Self);
- forward!(pub fn span_note<S: Into<MultiSpan>>(
+ forward!(pub fn span_note(
&mut self,
- sp: S,
+ sp: impl Into<MultiSpan>,
msg: &str,
) -> &mut Self);
forward!(pub fn warn(&mut self, msg: &str) -> &mut Self);
- forward!(pub fn span_warn<S: Into<MultiSpan>>(&mut self, sp: S, msg: &str) -> &mut Self);
+ forward!(pub fn span_warn(&mut self, sp: impl Into<MultiSpan>, msg: &str) -> &mut Self);
forward!(pub fn help(&mut self, msg: &str) -> &mut Self);
- forward!(pub fn span_help<S: Into<MultiSpan>>(
+ forward!(pub fn span_help(
&mut self,
- sp: S,
+ sp: impl Into<MultiSpan>,
msg: &str,
) -> &mut Self);
forward!(pub fn set_is_lint(&mut self,) -> &mut Self);
applicability: Applicability,
) -> &mut Self);
- forward!(pub fn set_primary_message<M: Into<String>>(&mut self, msg: M) -> &mut Self);
- forward!(pub fn set_span<S: Into<MultiSpan>>(&mut self, sp: S) -> &mut Self);
+ forward!(pub fn set_primary_message(&mut self, msg: impl Into<String>) -> &mut Self);
+ forward!(pub fn set_span(&mut self, sp: impl Into<MultiSpan>) -> &mut Self);
forward!(pub fn code(&mut self, s: DiagnosticId) -> &mut Self);
/// Convenience function for internal use, clients should use one of the
}
}
+// 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,
(insertion_span, anon_lts)
}
};
- db.span_suggestion(
+ diag.span_suggestion(
replace_span,
&format!("indicate the anonymous lifetime{}", pluralize!(n)),
suggestion,
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,
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");
};
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;
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,
fn explain_free_region<'tcx>(
tcx: TyCtxt<'tcx>,
- err: &mut DiagnosticBuilder<'_>,
+ err: &mut Diagnostic,
prefix: &str,
region: ty::Region<'tcx>,
suffix: &str,
}
fn emit_msg_span(
- err: &mut DiagnosticBuilder<'_>,
+ err: &mut Diagnostic,
prefix: &str,
description: String,
span: Option<Span>,
}
fn label_msg_span(
- err: &mut DiagnosticBuilder<'_>,
+ err: &mut Diagnostic,
prefix: &str,
description: String,
span: Option<Span>,
}
/// 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;
}
}
- 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 {
fn note_error_origin(
&self,
- err: &mut DiagnosticBuilder<'tcx>,
+ err: &mut Diagnostic,
cause: &ObligationCause<'tcx>,
exp_found: Option<ty::error::ExpectedFound<Ty<'tcx>>>,
terr: &TypeError<'tcx>,
fn suggest_boxing_for_return_impl_trait(
&self,
- err: &mut DiagnosticBuilder<'tcx>,
+ err: &mut Diagnostic,
return_sp: Span,
arm_spans: impl Iterator<Item = Span>,
) {
/// 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<ValuePairs<'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<TyCategory, FxHashSet<Span>>,
) {
cause: &ObligationCause<'tcx>,
exp_span: Span,
exp_found: &ty::error::ExpectedFound<Ty<'tcx>>,
- diag: &mut DiagnosticBuilder<'tcx>,
+ diag: &mut Diagnostic,
) {
debug!(
"suggest_await_on_expect_found: exp_span={:?}, expected_ty={:?}, found_ty={:?}",
&self,
cause: &ObligationCause<'tcx>,
exp_found: &ty::error::ExpectedFound<Ty<'tcx>>,
- diag: &mut DiagnosticBuilder<'tcx>,
+ diag: &mut Diagnostic,
) {
debug!(
"suggest_accessing_field_where_appropriate(cause={:?}, exp_found={:?})",
&self,
span: Span,
exp_found: &ty::error::ExpectedFound<Ty<'tcx>>,
- 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())
fn emit_tuple_wrap_err(
&self,
- err: &mut DiagnosticBuilder<'tcx>,
+ err: &mut Diagnostic,
span: Span,
found: Ty<'tcx>,
expected_fields: &List<Ty<'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,
}
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";
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;
}
}
- 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";
/// 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,
&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();
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;
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, _), .. },
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;
/// 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<Region<'tcx>>,
sup_placeholder: Option<Region<'tcx>>,
has_sub: Option<usize>,
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};
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<String>,
/// `'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 {
fn suggest_constrain_dyn_trait_in_impl(
&self,
- err: &mut DiagnosticBuilder<'_>,
+ err: &mut Diagnostic,
found_dids: &FxHashSet<DefId>,
ident: Ident,
self_ty: &hir::Ty<'_>,
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();
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};
}
}
- 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 `<T as Bound>::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,
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;
}
}
-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 {
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;
}
pub fn deprecation_suggestion(
- diag: &mut DiagnosticBuilder<'_>,
+ diag: &mut Diagnostic,
kind: &str,
suggestion: Option<Symbol>,
span: Span,
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;
}
}
- pub fn solution(&self, err: &mut DiagnosticBuilder<'_>) {
+ pub fn solution(&self, err: &mut Diagnostic) {
match *self {
ObjectSafetyViolation::SizedSelf(_) | ObjectSafetyViolation::SupertraitSelf(_) => {}
ObjectSafetyViolation::Method(
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};
pub fn suggest_arbitrary_trait_bound(
generics: &hir::Generics<'_>,
- err: &mut DiagnosticBuilder<'_>,
+ err: &mut Diagnostic,
param_name: &str,
constraint: &str,
) -> bool {
fn suggest_removing_unsized_bound(
generics: &hir::Generics<'_>,
- err: &mut DiagnosticBuilder<'_>,
+ err: &mut Diagnostic,
param_name: &str,
param: &hir::GenericParam<'_>,
def_id: Option<DefId>,
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<DefId>,
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};
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,
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>,
/// 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<Ty<'tcx>>,
body_owner_def_id: DefId,
/// 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>,
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<Symbol>,
proj_ty_item_def_id: DefId,
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 {
/// 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,
/// 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>],
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;
/// 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,
/// 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>],
) {
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
reader: &StringReader<'a>,
pos: BytePos,
ch: char,
- err: &mut DiagnosticBuilder<'a>,
+ err: &mut Diagnostic,
) -> Option<token::TokenKind> {
let Some(&(_u_char, u_name, ascii_char)) = UNICODE_ARRAY.iter().find(|&&(c, _, _)| c == ch) else {
return None;
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;
fn annotate_following_item_if_applicable(
&self,
- err: &mut DiagnosticBuilder<'_>,
+ err: &mut Diagnostic,
span: Span,
attr_type: OuterAttributeType,
) -> Option<Span> {
};
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};
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 {
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() {
/// parenthesising the leftmost comparison.
fn attempt_chained_comparison_suggestion(
&mut self,
- err: &mut DiagnosticBuilder<'_>,
+ err: &mut Diagnostic,
inner_op: &Expr,
outer_op: &Spanned<AssocOp>,
) -> bool /* advanced the cursor */ {
"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,
pub(super) fn parameter_without_type(
&mut self,
- err: &mut DiagnosticBuilder<'_>,
+ err: &mut Diagnostic,
pat: P<ast::Pat>,
require_name: bool,
first_param: bool,
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;
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));
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};
crate fn unresolved_macro_suggestions(
&mut self,
- err: &mut DiagnosticBuilder<'a>,
+ err: &mut Diagnostic,
macro_kind: MacroKind,
parent_scope: &ParentScope<'a>,
ident: Ident,
crate fn add_typo_suggestion(
&self,
- err: &mut DiagnosticBuilder<'_>,
+ err: &mut Diagnostic,
suggestion: Option<TypoSuggestion>,
span: Span,
) -> bool {
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<Span>,
candidates: &[ImportSuggestion],
};
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};
(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 {
}
/// Given `where <T as Bar>::Baz: String`, suggest `where T: Bar<Baz = String>`.
- 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 {
/// 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,
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,
_ => 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, _) => {
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() {
/// 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,
/// 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();
crate fn add_missing_lifetime_specifiers_label(
&self,
- err: &mut DiagnosticBuilder<'_>,
+ err: &mut Diagnostic,
mut spans_with_counts: Vec<(Span, usize)>,
lifetime_names: &FxHashSet<Symbol>,
lifetime_spans: Vec<Span>,
}
let suggest_existing =
- |err: &mut DiagnosticBuilder<'_>,
+ |err: &mut Diagnostic,
name: &str,
formatters: Vec<Option<Box<dyn Fn(&str) -> String>>>| {
if let Some(MissingLifetimeSpot::HigherRanked { span: for_span, span_type }) =
Applicability::MaybeIncorrect,
);
};
- let suggest_new = |err: &mut DiagnosticBuilder<'_>, suggs: Vec<Option<String>>| {
+ let suggest_new = |err: &mut Diagnostic, suggs: Vec<Option<String>>| {
for missing in self.missing_named_lifetime_spots.iter().rev() {
let mut introduce_suggestion = vec![];
let msg;
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};
// 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,
) {
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};
/// ```
fn add_suggestion_for_rename_of_use(
&self,
- err: &mut DiagnosticBuilder<'_>,
+ err: &mut Diagnostic,
name: Symbol,
import: &Import<'_>,
binding_span: Span,
/// 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,
) {
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;
/// 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())],
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;
/// 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,
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]
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;
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",
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;
fn report_similar_impl_candidates(
&self,
impl_candidates: Vec<ImplCandidate<'tcx>>,
- err: &mut DiagnosticBuilder<'_>,
+ err: &mut Diagnostic,
);
/// Gets the parent trait chain start
/// 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`.
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;
fn report_similar_impl_candidates(
&self,
impl_candidates: Vec<ImplCandidate<'tcx>>,
- err: &mut DiagnosticBuilder<'_>,
+ err: &mut Diagnostic,
) {
if impl_candidates.is_empty() {
return;
/// 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)
};
fn annotate_source_of_ambiguity(
&self,
- err: &mut DiagnosticBuilder<'tcx>,
+ err: &mut Diagnostic,
impls: &[DefId],
predicate: ty::Predicate<'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) {
fn suggest_unsized_bound_if_applicable(
&self,
- err: &mut DiagnosticBuilder<'tcx>,
+ err: &mut Diagnostic,
obligation: &PredicateObligation<'tcx>,
) {
let (pred, item_def_id, span) = match (
fn maybe_suggest_unsized_generics<'hir>(
&self,
- err: &mut DiagnosticBuilder<'tcx>,
+ err: &mut Diagnostic,
span: Span,
node: Node<'hir>,
) {
fn maybe_indirection_for_unsized<'hir>(
&self,
- err: &mut DiagnosticBuilder<'tcx>,
+ err: &mut Diagnostic,
item: &'hir Item<'hir>,
param: &'hir GenericParam<'hir>,
) -> bool {
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;
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,
);
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<String>;
+ fn get_closure_name(&self, def_id: DefId, err: &mut Diagnostic, msg: &str) -> Option<String>;
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;
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>,
);
fn suggest_impl_trait(
&self,
- err: &mut DiagnosticBuilder<'_>,
+ err: &mut Diagnostic,
span: Span,
obligation: &PredicateObligation<'tcx>,
trait_pred: ty::PolyTraitPredicate<'tcx>,
fn point_at_returns_when_relevant(
&self,
- err: &mut DiagnosticBuilder<'_>,
+ err: &mut Diagnostic,
obligation: &PredicateObligation<'tcx>,
);
fn suggest_fully_qualified_path(
&self,
- err: &mut DiagnosticBuilder<'_>,
+ err: &mut Diagnostic,
def_id: DefId,
span: Span,
trait_ref: DefId,
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>, Span, Option<hir::HirId>, Option<Span>)>,
inner_generator_body: Option<&hir::Body<'tcx>>,
fn note_obligation_cause_code<T>(
&self,
- err: &mut DiagnosticBuilder<'_>,
+ err: &mut Diagnostic,
predicate: &T,
param_env: ty::ParamEnv<'tcx>,
cause_code: &ObligationCauseCode<'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,
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>,
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,
) {
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
/// 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<String> {
- let get_name =
- |err: &mut DiagnosticBuilder<'_>, kind: &hir::PatKind<'_>| -> Option<String> {
- // 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<String> {
+ let get_name = |err: &mut Diagnostic, kind: &hir::PatKind<'_>| -> Option<String> {
+ // 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()?);
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() {
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 {
fn suggest_remove_reference(
&self,
obligation: &PredicateObligation<'tcx>,
- err: &mut DiagnosticBuilder<'_>,
+ err: &mut Diagnostic,
trait_pred: ty::PolyTraitPredicate<'tcx>,
) {
let span = obligation.cause.span;
}
}
- 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() {
fn suggest_change_mut(
&self,
obligation: &PredicateObligation<'tcx>,
- err: &mut DiagnosticBuilder<'_>,
+ err: &mut Diagnostic,
trait_pred: ty::PolyTraitPredicate<'tcx>,
) {
let points_at_arg = matches!(
fn suggest_semicolon_removal(
&self,
obligation: &PredicateObligation<'tcx>,
- err: &mut DiagnosticBuilder<'_>,
+ err: &mut Diagnostic,
span: Span,
trait_pred: ty::PolyTraitPredicate<'tcx>,
) {
/// emitted.
fn suggest_impl_trait(
&self,
- err: &mut DiagnosticBuilder<'_>,
+ err: &mut Diagnostic,
span: Span,
obligation: &PredicateObligation<'tcx>,
trait_pred: ty::PolyTraitPredicate<'tcx>,
fn point_at_returns_when_relevant(
&self,
- err: &mut DiagnosticBuilder<'_>,
+ err: &mut Diagnostic,
obligation: &PredicateObligation<'tcx>,
) {
match obligation.cause.code().peel_derives() {
fn suggest_fully_qualified_path(
&self,
- err: &mut DiagnosticBuilder<'_>,
+ err: &mut Diagnostic,
def_id: DefId,
span: Span,
trait_ref: DefId,
/// 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!(
/// `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>, Span, Option<hir::HirId>, Option<Span>)>,
inner_generator_body: Option<&hir::Body<'tcx>>,
fn note_obligation_cause_code<T>(
&self,
- err: &mut DiagnosticBuilder<'_>,
+ err: &mut Diagnostic,
predicate: &T,
param_env: ty::ParamEnv<'tcx>,
cause_code: &ObligationCauseCode<'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,
fn suggest_await_before_try(
&self,
- err: &mut DiagnosticBuilder<'_>,
+ err: &mut Diagnostic,
obligation: &PredicateObligation<'tcx>,
trait_pred: ty::PolyTraitPredicate<'tcx>,
span: Span,
}
fn suggest_trait_object_return_type_alternatives(
- err: &mut DiagnosticBuilder<'_>,
+ err: &mut Diagnostic,
ret_ty: Span,
trait_obj: &str,
is_object_safe: bool,
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;
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());
}
-use rustc_errors::DiagnosticBuilder;
+use rustc_errors::Diagnostic;
use rustc_span::Span;
use smallvec::smallvec;
use smallvec::SmallVec;
/// 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) {
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;
}
}
- 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(" }")),
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;
&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();
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};
/// 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,
/// 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 {
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};
&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(
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
fn add_impl_trait_explanation<'a>(
&self,
- err: &mut DiagnosticBuilder<'a>,
+ err: &mut Diagnostic,
cause: &ObligationCause<'tcx>,
fcx: &FnCtxt<'a, 'tcx>,
expected: Ty<'tcx>,
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};
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>,
fn annotate_expected_due_to_let_ty(
&self,
- err: &mut DiagnosticBuilder<'_>,
+ err: &mut Diagnostic,
expr: &hir::Expr<'_>,
error: TypeError<'_>,
) {
/// 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>,
pub fn check_for_cast(
&self,
- err: &mut DiagnosticBuilder<'_>,
+ err: &mut Diagnostic,
expr: &hir::Expr<'_>,
checked_ty: Ty<'tcx>,
expected_ty: Ty<'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",
};
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 =
}
// 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
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;
&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)
}
&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);
fn suggest_await_on_field_access(
&self,
- err: &mut DiagnosticBuilder<'_>,
+ err: &mut Diagnostic,
field_ident: Ident,
base: &'tcx hir::Expr<'tcx>,
ty: Ty<'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 {
fn suggest_fields_on_recordish(
&self,
- err: &mut DiagnosticBuilder<'_>,
+ err: &mut Diagnostic,
def: &'tcx ty::AdtDef,
field: Ident,
access_span: Span,
fn maybe_suggest_array_indexing(
&self,
- err: &mut DiagnosticBuilder<'_>,
+ err: &mut Diagnostic,
expr: &hir::Expr<'_>,
base: &hir::Expr<'_>,
field: Ident,
fn suggest_first_deref_field(
&self,
- err: &mut DiagnosticBuilder<'_>,
+ err: &mut Diagnostic,
expr: &hir::Expr<'_>,
base: &hir::Expr<'_>,
field: Ident,
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;
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>,
pub(in super::super) fn note_need_for_fn_pointer(
&self,
- err: &mut DiagnosticBuilder<'_>,
+ err: &mut Diagnostic,
expected: Ty<'tcx>,
found: Ty<'tcx>,
) {
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;
&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 {
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;
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",
/// - 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>,
/// ```
fn suggest_fn_call(
&self,
- err: &mut DiagnosticBuilder<'_>,
+ err: &mut Diagnostic,
expr: &hir::Expr<'_>,
expected: Ty<'tcx>,
found: Ty<'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>,
/// 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>,
/// 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>,
) {
#[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>,
/// it suggests adding a semicolon.
fn suggest_missing_semicolon(
&self,
- err: &mut DiagnosticBuilder<'_>,
+ err: &mut Diagnostic,
expression: &'tcx hir::Expr<'tcx>,
expected: Ty<'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>,
/// ```
fn try_suggest_return_impl_trait(
&self,
- err: &mut DiagnosticBuilder<'_>,
+ err: &mut Diagnostic,
expected: Ty<'tcx>,
found: Ty<'tcx>,
fn_id: hir::HirId,
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>,
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);
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;
#[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>,
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;
}
let report_candidates = |span: Span,
- err: &mut DiagnosticBuilder<'_>,
+ err: &mut Diagnostic,
mut sources: Vec<CandidateSource>,
sugg_span: Span| {
sources.sort();
}
if self.is_fn_ty(rcvr_ty, span) {
- fn report_function<T: std::fmt::Display>(
- err: &mut DiagnosticBuilder<'_>,
- name: T,
- ) {
+ fn report_function<T: std::fmt::Display>(err: &mut Diagnostic, name: T) {
err.note(
&format!("`{}` is a function, perhaps you wish to call it", name,),
);
crate fn note_unmet_impls_on_type(
&self,
- err: &mut rustc_errors::DiagnosticBuilder<'_>,
+ err: &mut Diagnostic,
errors: Vec<FulfillmentError<'tcx>>,
) {
let all_local_types_needing_impls =
fn suggest_derive(
&self,
- err: &mut DiagnosticBuilder<'_>,
+ err: &mut Diagnostic,
unsatisfied_predicates: &[(
ty::Predicate<'tcx>,
Option<ty::Predicate<'tcx>>,
fn suggest_await_before_method(
&self,
- err: &mut DiagnosticBuilder<'_>,
+ err: &mut Diagnostic,
item_name: Ident,
ty: Ty<'tcx>,
call: &hir::Expr<'_>,
fn suggest_use_candidates(
&self,
- err: &mut DiagnosticBuilder<'_>,
+ err: &mut Diagnostic,
mut msg: String,
candidates: Vec<DefId>,
) {
fn suggest_valid_traits(
&self,
- err: &mut DiagnosticBuilder<'_>,
+ err: &mut Diagnostic,
valid_out_of_scope_traits: Vec<DefId>,
) -> bool {
if !valid_out_of_scope_traits.is_empty() {
fn suggest_traits_to_import(
&self,
- err: &mut DiagnosticBuilder<'_>,
+ err: &mut Diagnostic,
span: Span,
rcvr_ty: Ty<'tcx>,
item_name: Ident,
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,
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::{
/// 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>,
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 {
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,
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;
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));
}
fn borrow_pat_suggestion(
&self,
- err: &mut DiagnosticBuilder<'_>,
+ err: &mut Diagnostic,
pat: &Pat<'_>,
inner: &Pat<'_>,
expected: Ty<'tcx>,
fn maybe_suggest_range_literal(
&self,
- e: &mut DiagnosticBuilder<'_>,
+ e: &mut Diagnostic,
opt_def_id: Option<hir::def_id::DefId>,
ident: Ident,
) -> bool {
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;
}
/// 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();
}
}
- fn suggest(&self, err: &mut DiagnosticBuilder<'_>) {
+ fn suggest(&self, err: &mut Diagnostic) {
debug!(
"suggest(self.provided {:?}, self.gen_args.span(): {:?})",
self.num_provided_args(),
/// ```text
/// type Map = HashMap<String>;
/// ```
- fn suggest_adding_args(&self, err: &mut DiagnosticBuilder<'_>) {
+ fn suggest_adding_args(&self, err: &mut Diagnostic) {
if self.gen_args.parenthesized {
return;
}
}
}
- 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;
}
}
- 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));
/// ```text
/// type Map = HashMap<String, String, String, String>;
/// ```
- 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;
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 {
);
};
- 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 {
}
/// 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()
//! [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, *},
) {
// 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<rustc_span::Span>| {
+ let callback = |diag: &mut Diagnostic, sp: Option<rustc_span::Span>| {
let note = format!(
"this link resolved to {} {}, which is not {} {}",
resolved.article(),
lint: &'static Lint,
msg: &str,
DiagnosticInfo { item, ori_link: _, dox, link_range }: &DiagnosticInfo<'_>,
- decorate: impl FnOnce(&mut DiagnosticBuilder<'_>, Option<rustc_span::Span>),
+ decorate: impl FnOnce(&mut Diagnostic, Option<rustc_span::Span>),
) {
let hir_id = match DocContext::as_local_hir_id(tcx, item.def_id) {
Some(hir_id) => hir_id,
/// disambiguator.
fn suggest_disambiguator(
res: Res,
- diag: &mut DiagnosticBuilder<'_>,
+ diag: &mut Diagnostic,
path_str: &str,
ori_link: &str,
sp: Option<rustc_span::Span>,
};
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};
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");
}
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};
fn suggestion<'tcx>(
cx: &LateContext<'tcx>,
- diag: &mut DiagnosticBuilder<'_>,
+ diag: &mut Diagnostic,
generics_span: Span,
generics_suggestion_span: Span,
target: &ImplicitHasherType<'_>,
//! 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};
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};
}
// 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() {
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;
//! 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!(
where
C: LintContext,
S: Into<MultiSpan>,
- F: FnOnce(&mut DiagnosticBuilder<'_>),
+ F: FnOnce(&mut Diagnostic),
{
cx.struct_span_lint(lint, sp, |diag| {
let mut diag = diag.build(msg);
hir_id: HirId,
sp: impl Into<MultiSpan>,
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);
/// appear once per
/// replacement. In human-readable format though, it only appears once before
/// the whole suggestion.
-pub fn multispan_sugg<I>(diag: &mut DiagnosticBuilder<'_>, help_msg: &str, sugg: I)
+pub fn multispan_sugg<I>(diag: &mut Diagnostic, help_msg: &str, sugg: I)
where
I: IntoIterator<Item = (Span, String)>,
{
/// 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<I>(
- diag: &mut DiagnosticBuilder<'_>,
+ diag: &mut Diagnostic,
help_msg: &str,
applicability: Applicability,
sugg: I,
})
}
-/// Convenience extension trait for `DiagnosticBuilder`.
-pub trait DiagnosticBuilderExt<T: LintContext> {
+/// Convenience extension trait for `Diagnostic`.
+pub trait DiagnosticExt<T: LintContext> {
/// Suggests to add an attribute to an item.
///
/// Correctly handles indentation of the attribute and item.
fn suggest_remove_item(&mut self, cx: &T, item: Span, msg: &str, applicability: Applicability);
}
-impl<T: LintContext> DiagnosticBuilderExt<T> for rustc_errors::DiagnosticBuilder<'_> {
+impl<T: LintContext> DiagnosticExt<T> for rustc_errors::Diagnostic {
fn suggest_item_with_attr<D: Display + ?Sized>(
&mut self,
cx: &T,