Break up long function in trait selection error reporting

- Move blocks of code into their own functions
- Replace a few function argument types with their type aliases
This commit is contained in:
Bryan Garza 2023-04-19 14:59:36 -07:00
parent 409661936f
commit d0d40d2a40
6 changed files with 659 additions and 430 deletions

View file

@ -300,8 +300,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
trait_def_id: DefId, trait_def_id: DefId,
self_ty: Ty<'tcx>, self_ty: Ty<'tcx>,
opt_input_types: Option<&[Ty<'tcx>]>, opt_input_types: Option<&[Ty<'tcx>]>,
) -> (traits::Obligation<'tcx, ty::Predicate<'tcx>>, &'tcx ty::List<ty::subst::GenericArg<'tcx>>) ) -> (traits::PredicateObligation<'tcx>, &'tcx ty::List<ty::subst::GenericArg<'tcx>>) {
{
// Construct a trait-reference `self_ty : Trait<input_tys>` // Construct a trait-reference `self_ty : Trait<input_tys>`
let substs = InternalSubsts::for_item(self.tcx, trait_def_id, |param, _| { let substs = InternalSubsts::for_item(self.tcx, trait_def_id, |param, _| {
match param.kind { match param.kind {

View file

@ -123,7 +123,7 @@ pub struct FulfillmentError<'tcx> {
#[derive(Clone)] #[derive(Clone)]
pub enum FulfillmentErrorCode<'tcx> { pub enum FulfillmentErrorCode<'tcx> {
/// Inherently impossible to fulfill; this trait is implemented if and only if it is already implemented. /// Inherently impossible to fulfill; this trait is implemented if and only if it is already implemented.
CodeCycle(Vec<Obligation<'tcx, ty::Predicate<'tcx>>>), CodeCycle(Vec<PredicateObligation<'tcx>>),
CodeSelectionError(SelectionError<'tcx>), CodeSelectionError(SelectionError<'tcx>),
CodeProjectionError(MismatchedProjectionTypes<'tcx>), CodeProjectionError(MismatchedProjectionTypes<'tcx>),
CodeSubtypeError(ExpectedFound<Ty<'tcx>>, TypeError<'tcx>), // always comes from a SubtypePredicate CodeSubtypeError(ExpectedFound<Ty<'tcx>>, TypeError<'tcx>), // always comes from a SubtypePredicate

View file

@ -591,7 +591,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {
fn evaluate_nested_obligations( fn evaluate_nested_obligations(
&self, &self,
ty: Ty<'_>, ty: Ty<'_>,
nested: impl Iterator<Item = Obligation<'tcx, ty::Predicate<'tcx>>>, nested: impl Iterator<Item = PredicateObligation<'tcx>>,
computed_preds: &mut FxIndexSet<ty::Predicate<'tcx>>, computed_preds: &mut FxIndexSet<ty::Predicate<'tcx>>,
fresh_preds: &mut FxHashSet<ty::Predicate<'tcx>>, fresh_preds: &mut FxHashSet<ty::Predicate<'tcx>>,
predicates: &mut VecDeque<ty::PolyTraitPredicate<'tcx>>, predicates: &mut VecDeque<ty::PolyTraitPredicate<'tcx>>,

View file

@ -341,6 +341,7 @@ pub struct OnUnimplementedNote {
/// should fallback to a generic message, `Some(None)` suggests using the default /// should fallback to a generic message, `Some(None)` suggests using the default
/// appended message, `Some(Some(s))` suggests use the `s` message instead of the /// appended message, `Some(Some(s))` suggests use the `s` message instead of the
/// default one.. /// default one..
/// FIXME(bryangarza): Change this to an enum with the 3 variants described above.
pub append_const_msg: Option<Option<Symbol>>, pub append_const_msg: Option<Option<Symbol>>,
} }

View file

@ -386,7 +386,7 @@ pub trait TypeErrCtxtExt<'tcx> {
fn maybe_suggest_convert_to_slice( fn maybe_suggest_convert_to_slice(
&self, &self,
err: &mut Diagnostic, err: &mut Diagnostic,
trait_ref: ty::Binder<'tcx, ty::TraitRef<'tcx>>, trait_ref: ty::PolyTraitRef<'tcx>,
candidate_impls: &[ImplCandidate<'tcx>], candidate_impls: &[ImplCandidate<'tcx>],
span: Span, span: Span,
); );
@ -3848,7 +3848,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
fn maybe_suggest_convert_to_slice( fn maybe_suggest_convert_to_slice(
&self, &self,
err: &mut Diagnostic, err: &mut Diagnostic,
trait_ref: ty::Binder<'tcx, ty::TraitRef<'tcx>>, trait_ref: ty::PolyTraitRef<'tcx>,
candidate_impls: &[ImplCandidate<'tcx>], candidate_impls: &[ImplCandidate<'tcx>],
span: Span, span: Span,
) { ) {