1
Fork 0

A more general implementation of IntoDiagnosticArg for Binder (Also removes DiagArg, as it's no longer necessary)

This commit is contained in:
IQuant 2023-03-09 21:59:40 +03:00
parent fd18d9a584
commit 6a05cd85ad
3 changed files with 16 additions and 26 deletions

View file

@ -1146,14 +1146,6 @@ pub struct OpaqueCapturesLifetime<'tcx> {
pub opaque_ty: Ty<'tcx>, pub opaque_ty: Ty<'tcx>,
} }
pub struct DiagArg<T>(pub T);
impl<T: ToString> IntoDiagnosticArg for DiagArg<T> {
fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue<'static> {
self.0.to_string().into_diagnostic_arg()
}
}
#[derive(Subdiagnostic)] #[derive(Subdiagnostic)]
pub enum FunctionPointerSuggestion<'a> { pub enum FunctionPointerSuggestion<'a> {
#[suggestion( #[suggestion(
@ -1221,7 +1213,7 @@ pub enum FunctionPointerSuggestion<'a> {
fn_name: String, fn_name: String,
#[skip_arg] #[skip_arg]
found_sig: Binder<'a, FnSig<'a>>, found_sig: Binder<'a, FnSig<'a>>,
expected_sig: DiagArg<Binder<'a, FnSig<'a>>>, expected_sig: Binder<'a, FnSig<'a>>,
}, },
#[suggestion( #[suggestion(
infer_fps_cast_both, infer_fps_cast_both,
@ -1236,7 +1228,7 @@ pub enum FunctionPointerSuggestion<'a> {
fn_name: String, fn_name: String,
#[skip_arg] #[skip_arg]
found_sig: Binder<'a, FnSig<'a>>, found_sig: Binder<'a, FnSig<'a>>,
expected_sig: DiagArg<Binder<'a, FnSig<'a>>>, expected_sig: Binder<'a, FnSig<'a>>,
}, },
} }

View file

@ -13,7 +13,7 @@ use rustc_span::{sym, BytePos, Span};
use rustc_target::abi::FieldIdx; use rustc_target::abi::FieldIdx;
use crate::errors::{ use crate::errors::{
ConsiderAddingAwait, DiagArg, FnConsiderCasting, FnItemsAreDistinct, FnUniqTypes, ConsiderAddingAwait, FnConsiderCasting, FnItemsAreDistinct, FnUniqTypes,
FunctionPointerSuggestion, SuggestAccessingField, SuggestAsRefWhereAppropriate, FunctionPointerSuggestion, SuggestAccessingField, SuggestAsRefWhereAppropriate,
SuggestBoxingForReturnImplTrait, SuggestRemoveSemiOrReturnBinding, SuggestTuplePatternMany, SuggestBoxingForReturnImplTrait, SuggestRemoveSemiOrReturnBinding, SuggestTuplePatternMany,
SuggestTuplePatternOne, TypeErrorAdditionalDiags, SuggestTuplePatternOne, TypeErrorAdditionalDiags,
@ -379,14 +379,14 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
span, span,
fn_name, fn_name,
found_sig: *found_sig, found_sig: *found_sig,
expected_sig: DiagArg(*expected_sig), expected_sig: *expected_sig,
} }
} else { } else {
FunctionPointerSuggestion::CastBoth { FunctionPointerSuggestion::CastBoth {
span, span,
fn_name, fn_name,
found_sig: *found_sig, found_sig: *found_sig,
expected_sig: DiagArg(*expected_sig), expected_sig: *expected_sig,
} }
}; };

View file

@ -15,6 +15,7 @@ use hir::def::DefKind;
use polonius_engine::Atom; use polonius_engine::Atom;
use rustc_data_structures::captures::Captures; use rustc_data_structures::captures::Captures;
use rustc_data_structures::intern::Interned; use rustc_data_structures::intern::Interned;
use rustc_errors::{DiagnosticArgValue, IntoDiagnosticArg};
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
use rustc_hir::LangItem; use rustc_hir::LangItem;
@ -26,7 +27,7 @@ use rustc_target::abi::{FieldIdx, VariantIdx, FIRST_VARIANT};
use rustc_target::spec::abi::{self, Abi}; use rustc_target::spec::abi::{self, Abi};
use std::borrow::Cow; use std::borrow::Cow;
use std::cmp::Ordering; use std::cmp::Ordering;
use std::fmt; use std::fmt::{self, Display};
use std::marker::PhantomData; use std::marker::PhantomData;
use std::ops::{ControlFlow, Deref, Range}; use std::ops::{ControlFlow, Deref, Range};
use ty::util::IntTypeExt; use ty::util::IntTypeExt;
@ -877,12 +878,6 @@ impl<'tcx> PolyTraitRef<'tcx> {
} }
} }
impl rustc_errors::IntoDiagnosticArg for PolyTraitRef<'_> {
fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue<'static> {
self.to_string().into_diagnostic_arg()
}
}
/// An existential reference to a trait, where `Self` is erased. /// An existential reference to a trait, where `Self` is erased.
/// For example, the trait object `Trait<'a, 'b, X, Y>` is: /// For example, the trait object `Trait<'a, 'b, X, Y>` is:
/// ```ignore (illustrative) /// ```ignore (illustrative)
@ -939,12 +934,6 @@ impl<'tcx> PolyExistentialTraitRef<'tcx> {
} }
} }
impl rustc_errors::IntoDiagnosticArg for PolyExistentialTraitRef<'_> {
fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue<'static> {
self.to_string().into_diagnostic_arg()
}
}
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, TyEncodable, TyDecodable)] #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, TyEncodable, TyDecodable)]
#[derive(HashStable)] #[derive(HashStable)]
pub enum BoundVariableKind { pub enum BoundVariableKind {
@ -1159,6 +1148,15 @@ impl<'tcx, T: IntoIterator> Binder<'tcx, T> {
} }
} }
impl<'tcx, T> IntoDiagnosticArg for Binder<'tcx, T>
where
Binder<'tcx, T>: Display,
{
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
self.to_string().into_diagnostic_arg()
}
}
struct SkipBindersAt<'tcx> { struct SkipBindersAt<'tcx> {
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
index: ty::DebruijnIndex, index: ty::DebruijnIndex,