1
Fork 0

OutputTypeParameterMismatch -> SignatureMismatch

This commit is contained in:
Michael Goulet 2024-01-12 16:20:12 +00:00
parent f37a919e96
commit fbdc116e6e
4 changed files with 23 additions and 25 deletions

View file

@ -362,9 +362,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
span: Span, span: Span,
) -> bool { ) -> bool {
if let traits::FulfillmentErrorCode::SelectionError( if let traits::FulfillmentErrorCode::SelectionError(
traits::SelectionError::OutputTypeParameterMismatch( traits::SelectionError::SignatureMismatch(box traits::SignatureMismatchData {
box traits::SelectionOutputTypeParameterMismatch { expected_trait_ref, .. }, expected_trait_ref,
), ..
}),
) = error.code ) = error.code
&& let ty::Closure(def_id, _) | ty::Coroutine(def_id, ..) = && let ty::Closure(def_id, _) | ty::Coroutine(def_id, ..) =
expected_trait_ref.skip_binder().self_ty().kind() expected_trait_ref.skip_binder().self_ty().kind()

View file

@ -604,7 +604,7 @@ pub enum SelectionError<'tcx> {
/// After a closure impl has selected, its "outputs" were evaluated /// After a closure impl has selected, its "outputs" were evaluated
/// (which for closures includes the "input" type params) and they /// (which for closures includes the "input" type params) and they
/// didn't resolve. See `confirm_poly_trait_refs` for more. /// didn't resolve. See `confirm_poly_trait_refs` for more.
OutputTypeParameterMismatch(Box<SelectionOutputTypeParameterMismatch<'tcx>>), SignatureMismatch(Box<SignatureMismatchData<'tcx>>),
/// The trait pointed by `DefId` is not object safe. /// The trait pointed by `DefId` is not object safe.
TraitNotObjectSafe(DefId), TraitNotObjectSafe(DefId),
/// A given constant couldn't be evaluated. /// A given constant couldn't be evaluated.
@ -621,7 +621,7 @@ pub enum SelectionError<'tcx> {
} }
#[derive(Clone, Debug, TypeVisitable)] #[derive(Clone, Debug, TypeVisitable)]
pub struct SelectionOutputTypeParameterMismatch<'tcx> { pub struct SignatureMismatchData<'tcx> {
pub found_trait_ref: ty::PolyTraitRef<'tcx>, pub found_trait_ref: ty::PolyTraitRef<'tcx>,
pub expected_trait_ref: ty::PolyTraitRef<'tcx>, pub expected_trait_ref: ty::PolyTraitRef<'tcx>,
pub terr: ty::error::TypeError<'tcx>, pub terr: ty::error::TypeError<'tcx>,

View file

@ -14,8 +14,8 @@ use crate::traits::specialize::to_pretty_impl_header;
use crate::traits::NormalizeExt; use crate::traits::NormalizeExt;
use crate::traits::{ use crate::traits::{
elaborate, FulfillmentError, FulfillmentErrorCode, MismatchedProjectionTypes, Obligation, elaborate, FulfillmentError, FulfillmentErrorCode, MismatchedProjectionTypes, Obligation,
ObligationCause, ObligationCauseCode, ObligationCtxt, OutputTypeParameterMismatch, Overflow, ObligationCause, ObligationCauseCode, ObligationCtxt, Overflow, PredicateObligation,
PredicateObligation, SelectionError, TraitNotObjectSafe, SelectionError, SignatureMismatch, TraitNotObjectSafe,
}; };
use rustc_data_structures::fx::{FxHashMap, FxIndexMap}; use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
use rustc_errors::{ use rustc_errors::{
@ -30,7 +30,7 @@ use rustc_hir::{GenericParam, Item, Node};
use rustc_infer::infer::error_reporting::TypeErrCtxt; use rustc_infer::infer::error_reporting::TypeErrCtxt;
use rustc_infer::infer::{InferOk, TypeTrace}; use rustc_infer::infer::{InferOk, TypeTrace};
use rustc_middle::traits::select::OverflowError; use rustc_middle::traits::select::OverflowError;
use rustc_middle::traits::{DefiningAnchor, SelectionOutputTypeParameterMismatch}; use rustc_middle::traits::{DefiningAnchor, SignatureMismatchData};
use rustc_middle::ty::abstract_const::NotConstEvaluatable; use rustc_middle::ty::abstract_const::NotConstEvaluatable;
use rustc_middle::ty::error::{ExpectedFound, TypeError}; use rustc_middle::ty::error::{ExpectedFound, TypeError};
use rustc_middle::ty::fold::{BottomUpFolder, TypeFolder, TypeSuperFoldable}; use rustc_middle::ty::fold::{BottomUpFolder, TypeFolder, TypeSuperFoldable};
@ -891,22 +891,22 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
} }
} }
OutputTypeParameterMismatch(box SelectionOutputTypeParameterMismatch { SignatureMismatch(box SignatureMismatchData {
found_trait_ref, found_trait_ref,
expected_trait_ref, expected_trait_ref,
terr: terr @ TypeError::CyclicTy(_), terr: terr @ TypeError::CyclicTy(_),
}) => self.report_type_parameter_mismatch_cyclic_type_error( }) => self.report_cyclic_signature_error(
&obligation, &obligation,
found_trait_ref, found_trait_ref,
expected_trait_ref, expected_trait_ref,
terr, terr,
), ),
OutputTypeParameterMismatch(box SelectionOutputTypeParameterMismatch { SignatureMismatch(box SignatureMismatchData {
found_trait_ref, found_trait_ref,
expected_trait_ref, expected_trait_ref,
terr: _, terr: _,
}) => { }) => {
match self.report_type_parameter_mismatch_error( match self.report_signature_mismatch_error(
&obligation, &obligation,
span, span,
found_trait_ref, found_trait_ref,
@ -1495,7 +1495,7 @@ pub(super) trait InferCtxtPrivExt<'tcx> {
kind: ty::ClosureKind, kind: ty::ClosureKind,
) -> DiagnosticBuilder<'tcx>; ) -> DiagnosticBuilder<'tcx>;
fn report_type_parameter_mismatch_cyclic_type_error( fn report_cyclic_signature_error(
&self, &self,
obligation: &PredicateObligation<'tcx>, obligation: &PredicateObligation<'tcx>,
found_trait_ref: ty::Binder<'tcx, ty::TraitRef<'tcx>>, found_trait_ref: ty::Binder<'tcx, ty::TraitRef<'tcx>>,
@ -1509,7 +1509,7 @@ pub(super) trait InferCtxtPrivExt<'tcx> {
def_id: DefId, def_id: DefId,
) -> DiagnosticBuilder<'tcx>; ) -> DiagnosticBuilder<'tcx>;
fn report_type_parameter_mismatch_error( fn report_signature_mismatch_error(
&self, &self,
obligation: &PredicateObligation<'tcx>, obligation: &PredicateObligation<'tcx>,
span: Span, span: Span,
@ -3369,7 +3369,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
self.dcx().create_err(err) self.dcx().create_err(err)
} }
fn report_type_parameter_mismatch_cyclic_type_error( fn report_cyclic_signature_error(
&self, &self,
obligation: &PredicateObligation<'tcx>, obligation: &PredicateObligation<'tcx>,
found_trait_ref: ty::Binder<'tcx, ty::TraitRef<'tcx>>, found_trait_ref: ty::Binder<'tcx, ty::TraitRef<'tcx>>,
@ -3430,7 +3430,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
err err
} }
fn report_type_parameter_mismatch_error( fn report_signature_mismatch_error(
&self, &self,
obligation: &PredicateObligation<'tcx>, obligation: &PredicateObligation<'tcx>,
span: Span, span: Span,
@ -3449,10 +3449,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
}; };
let found_did = match *found_trait_ty.kind() { let found_did = match *found_trait_ty.kind() {
ty::Closure(did, _) | ty::Foreign(did) | ty::FnDef(did, _) | ty::Coroutine(did, ..) => { ty::Closure(did, _) | ty::FnDef(did, _) | ty::Coroutine(did, ..) => Some(did),
Some(did)
}
ty::Adt(def, _) => Some(def.did()),
_ => None, _ => None,
}; };

View file

@ -11,7 +11,7 @@ use rustc_data_structures::stack::ensure_sufficient_stack;
use rustc_hir::lang_items::LangItem; use rustc_hir::lang_items::LangItem;
use rustc_infer::infer::BoundRegionConversionTime::HigherRankedType; use rustc_infer::infer::BoundRegionConversionTime::HigherRankedType;
use rustc_infer::infer::{DefineOpaqueTypes, InferOk}; use rustc_infer::infer::{DefineOpaqueTypes, InferOk};
use rustc_middle::traits::{BuiltinImplSource, SelectionOutputTypeParameterMismatch}; use rustc_middle::traits::{BuiltinImplSource, SignatureMismatchData};
use rustc_middle::ty::{ use rustc_middle::ty::{
self, GenericArgs, GenericArgsRef, GenericParamDefKind, ToPolyTraitRef, ToPredicate, self, GenericArgs, GenericArgsRef, GenericParamDefKind, ToPolyTraitRef, ToPredicate,
TraitPredicate, Ty, TyCtxt, TypeVisitableExt, TraitPredicate, Ty, TyCtxt, TypeVisitableExt,
@ -26,9 +26,9 @@ use crate::traits::vtable::{
}; };
use crate::traits::{ use crate::traits::{
BuiltinDerivedObligation, ImplDerivedObligation, ImplDerivedObligationCause, ImplSource, BuiltinDerivedObligation, ImplDerivedObligation, ImplDerivedObligationCause, ImplSource,
ImplSourceUserDefinedData, Normalized, Obligation, ObligationCause, ImplSourceUserDefinedData, Normalized, Obligation, ObligationCause, PolyTraitObligation,
OutputTypeParameterMismatch, PolyTraitObligation, PredicateObligation, Selection, PredicateObligation, Selection, SelectionError, SignatureMismatch, TraitNotObjectSafe,
SelectionError, TraitNotObjectSafe, Unimplemented, Unimplemented,
}; };
use super::BuiltinImplConditions; use super::BuiltinImplConditions;
@ -922,7 +922,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
obligations obligations
}) })
.map_err(|terr| { .map_err(|terr| {
OutputTypeParameterMismatch(Box::new(SelectionOutputTypeParameterMismatch { SignatureMismatch(Box::new(SignatureMismatchData {
expected_trait_ref: obligation_trait_ref, expected_trait_ref: obligation_trait_ref,
found_trait_ref: expected_trait_ref, found_trait_ref: expected_trait_ref,
terr, terr,