Give DiagnosticBuilder
a default type.
`IntoDiagnostic` defaults to `ErrorGuaranteed`, because errors are the most common diagnostic level. It makes sense to do likewise for the closely-related (and much more widely used) `DiagnosticBuilder` type, letting us write `DiagnosticBuilder<'a, ErrorGuaranteed>` as just `DiagnosticBuilder<'a>`. This cuts over 200 lines of code due to many multi-line things becoming single line things.
This commit is contained in:
parent
6257f3bf1f
commit
757d6f6ef8
59 changed files with 250 additions and 454 deletions
|
@ -1,7 +1,7 @@
|
|||
use crate::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
|
||||
use crate::infer::InferCtxt;
|
||||
use crate::traits::{Obligation, ObligationCause, ObligationCtxt};
|
||||
use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder, ErrorGuaranteed};
|
||||
use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::Node;
|
||||
use rustc_middle::ty::{self, Ty};
|
||||
|
@ -29,7 +29,7 @@ pub trait InferCtxtExt<'tcx> {
|
|||
found_args: Vec<ArgKind>,
|
||||
is_closure: bool,
|
||||
closure_pipe_span: Option<Span>,
|
||||
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed>;
|
||||
) -> DiagnosticBuilder<'tcx>;
|
||||
|
||||
/// Checks if the type implements one of `Fn`, `FnMut`, or `FnOnce`
|
||||
/// in that order, and returns the generic type corresponding to the
|
||||
|
@ -118,7 +118,7 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
|
|||
found_args: Vec<ArgKind>,
|
||||
is_closure: bool,
|
||||
closure_arg_span: Option<Span>,
|
||||
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
|
||||
) -> DiagnosticBuilder<'tcx> {
|
||||
let kind = if is_closure { "closure" } else { "function" };
|
||||
|
||||
let args_str = |arguments: &[ArgKind], other: &[ArgKind]| {
|
||||
|
|
|
@ -14,7 +14,7 @@ use rustc_data_structures::fx::FxHashSet;
|
|||
use rustc_data_structures::stack::ensure_sufficient_stack;
|
||||
use rustc_errors::{
|
||||
error_code, pluralize, struct_span_err, Applicability, Diagnostic, DiagnosticBuilder,
|
||||
ErrorGuaranteed, MultiSpan, Style, SuggestionStyle,
|
||||
MultiSpan, Style, SuggestionStyle,
|
||||
};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::{DefKind, Res};
|
||||
|
@ -207,7 +207,7 @@ pub trait TypeErrCtxtExt<'tcx> {
|
|||
|
||||
fn point_at_returns_when_relevant(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'tcx, ErrorGuaranteed>,
|
||||
err: &mut DiagnosticBuilder<'tcx>,
|
||||
obligation: &PredicateObligation<'tcx>,
|
||||
);
|
||||
|
||||
|
@ -220,7 +220,7 @@ pub trait TypeErrCtxtExt<'tcx> {
|
|||
cause: &ObligationCauseCode<'tcx>,
|
||||
found_node: Option<Node<'_>>,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed>;
|
||||
) -> DiagnosticBuilder<'tcx>;
|
||||
|
||||
fn note_conflicting_fn_args(
|
||||
&self,
|
||||
|
@ -234,7 +234,7 @@ pub trait TypeErrCtxtExt<'tcx> {
|
|||
fn note_conflicting_closure_bounds(
|
||||
&self,
|
||||
cause: &ObligationCauseCode<'tcx>,
|
||||
err: &mut DiagnosticBuilder<'tcx, ErrorGuaranteed>,
|
||||
err: &mut DiagnosticBuilder<'tcx>,
|
||||
);
|
||||
|
||||
fn suggest_fully_qualified_path(
|
||||
|
@ -1920,7 +1920,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
|
||||
fn point_at_returns_when_relevant(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'tcx, ErrorGuaranteed>,
|
||||
err: &mut DiagnosticBuilder<'tcx>,
|
||||
obligation: &PredicateObligation<'tcx>,
|
||||
) {
|
||||
match obligation.cause.code().peel_derives() {
|
||||
|
@ -1961,7 +1961,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
cause: &ObligationCauseCode<'tcx>,
|
||||
found_node: Option<Node<'_>>,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
|
||||
) -> DiagnosticBuilder<'tcx> {
|
||||
pub(crate) fn build_fn_sig_ty<'tcx>(
|
||||
infcx: &InferCtxt<'tcx>,
|
||||
trait_ref: ty::PolyTraitRef<'tcx>,
|
||||
|
@ -2187,7 +2187,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
fn note_conflicting_closure_bounds(
|
||||
&self,
|
||||
cause: &ObligationCauseCode<'tcx>,
|
||||
err: &mut DiagnosticBuilder<'tcx, ErrorGuaranteed>,
|
||||
err: &mut DiagnosticBuilder<'tcx>,
|
||||
) {
|
||||
// First, look for an `ExprBindingObligation`, which means we can get
|
||||
// the unsubstituted predicate list of the called function. And check
|
||||
|
|
|
@ -59,7 +59,7 @@ pub trait TypeErrCtxtExt<'tcx> {
|
|||
predicate: &T,
|
||||
span: Span,
|
||||
suggest_increasing_limit: bool,
|
||||
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed>
|
||||
) -> DiagnosticBuilder<'tcx>
|
||||
where
|
||||
T: fmt::Display + TypeFoldable<TyCtxt<'tcx>> + Print<'tcx, FmtPrinter<'tcx, 'tcx>>;
|
||||
|
||||
|
@ -118,7 +118,7 @@ pub trait TypeErrCtxtExt<'tcx> {
|
|||
&self,
|
||||
ty: Ty<'tcx>,
|
||||
obligation: &PredicateObligation<'tcx>,
|
||||
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed>;
|
||||
) -> DiagnosticBuilder<'tcx>;
|
||||
}
|
||||
|
||||
impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
||||
|
@ -263,7 +263,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
predicate: &T,
|
||||
span: Span,
|
||||
suggest_increasing_limit: bool,
|
||||
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed>
|
||||
) -> DiagnosticBuilder<'tcx>
|
||||
where
|
||||
T: fmt::Display + TypeFoldable<TyCtxt<'tcx>> + Print<'tcx, FmtPrinter<'tcx, 'tcx>>,
|
||||
{
|
||||
|
@ -1226,7 +1226,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
&self,
|
||||
ty: Ty<'tcx>,
|
||||
obligation: &PredicateObligation<'tcx>,
|
||||
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
|
||||
) -> DiagnosticBuilder<'tcx> {
|
||||
let span = obligation.cause.span;
|
||||
|
||||
let mut diag = match ty.kind() {
|
||||
|
@ -1491,7 +1491,7 @@ pub(super) trait InferCtxtPrivExt<'tcx> {
|
|||
closure_def_id: DefId,
|
||||
found_kind: ty::ClosureKind,
|
||||
kind: ty::ClosureKind,
|
||||
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed>;
|
||||
) -> DiagnosticBuilder<'tcx>;
|
||||
|
||||
fn report_type_parameter_mismatch_cyclic_type_error(
|
||||
&self,
|
||||
|
@ -1499,13 +1499,13 @@ pub(super) trait InferCtxtPrivExt<'tcx> {
|
|||
found_trait_ref: ty::Binder<'tcx, ty::TraitRef<'tcx>>,
|
||||
expected_trait_ref: ty::Binder<'tcx, ty::TraitRef<'tcx>>,
|
||||
terr: TypeError<'tcx>,
|
||||
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed>;
|
||||
) -> DiagnosticBuilder<'tcx>;
|
||||
|
||||
fn report_opaque_type_auto_trait_leakage(
|
||||
&self,
|
||||
obligation: &PredicateObligation<'tcx>,
|
||||
def_id: DefId,
|
||||
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed>;
|
||||
) -> DiagnosticBuilder<'tcx>;
|
||||
|
||||
fn report_type_parameter_mismatch_error(
|
||||
&self,
|
||||
|
@ -1513,13 +1513,13 @@ pub(super) trait InferCtxtPrivExt<'tcx> {
|
|||
span: Span,
|
||||
found_trait_ref: ty::Binder<'tcx, ty::TraitRef<'tcx>>,
|
||||
expected_trait_ref: ty::Binder<'tcx, ty::TraitRef<'tcx>>,
|
||||
) -> Option<DiagnosticBuilder<'tcx, ErrorGuaranteed>>;
|
||||
) -> Option<DiagnosticBuilder<'tcx>>;
|
||||
|
||||
fn report_not_const_evaluatable_error(
|
||||
&self,
|
||||
obligation: &PredicateObligation<'tcx>,
|
||||
span: Span,
|
||||
) -> Option<DiagnosticBuilder<'tcx, ErrorGuaranteed>>;
|
||||
) -> Option<DiagnosticBuilder<'tcx>>;
|
||||
}
|
||||
|
||||
impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
||||
|
@ -3305,7 +3305,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
closure_def_id: DefId,
|
||||
found_kind: ty::ClosureKind,
|
||||
kind: ty::ClosureKind,
|
||||
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
|
||||
) -> DiagnosticBuilder<'tcx> {
|
||||
let closure_span = self.tcx.def_span(closure_def_id);
|
||||
|
||||
let mut err = ClosureKindMismatch {
|
||||
|
@ -3347,7 +3347,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
found_trait_ref: ty::Binder<'tcx, ty::TraitRef<'tcx>>,
|
||||
expected_trait_ref: ty::Binder<'tcx, ty::TraitRef<'tcx>>,
|
||||
terr: TypeError<'tcx>,
|
||||
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
|
||||
) -> DiagnosticBuilder<'tcx> {
|
||||
let self_ty = found_trait_ref.self_ty().skip_binder();
|
||||
let (cause, terr) = if let ty::Closure(def_id, _) = self_ty.kind() {
|
||||
(
|
||||
|
@ -3367,7 +3367,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
&self,
|
||||
obligation: &PredicateObligation<'tcx>,
|
||||
def_id: DefId,
|
||||
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
|
||||
) -> DiagnosticBuilder<'tcx> {
|
||||
let name = match self.tcx.opaque_type_origin(def_id.expect_local()) {
|
||||
hir::OpaqueTyOrigin::FnReturn(_) | hir::OpaqueTyOrigin::AsyncFn(_) => {
|
||||
"opaque type".to_string()
|
||||
|
@ -3409,7 +3409,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
span: Span,
|
||||
found_trait_ref: ty::Binder<'tcx, ty::TraitRef<'tcx>>,
|
||||
expected_trait_ref: ty::Binder<'tcx, ty::TraitRef<'tcx>>,
|
||||
) -> Option<DiagnosticBuilder<'tcx, ErrorGuaranteed>> {
|
||||
) -> Option<DiagnosticBuilder<'tcx>> {
|
||||
let found_trait_ref = self.resolve_vars_if_possible(found_trait_ref);
|
||||
let expected_trait_ref = self.resolve_vars_if_possible(expected_trait_ref);
|
||||
|
||||
|
@ -3515,7 +3515,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
&self,
|
||||
obligation: &PredicateObligation<'tcx>,
|
||||
span: Span,
|
||||
) -> Option<DiagnosticBuilder<'tcx, ErrorGuaranteed>> {
|
||||
) -> Option<DiagnosticBuilder<'tcx>> {
|
||||
if !self.tcx.features().generic_const_exprs {
|
||||
let mut err = self
|
||||
.tcx
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue