Skip to content

rematch_impl should be infallible #104395

Closed
@lcnr

Description

@lcnr

fn rematch_impl(
&mut self,
impl_def_id: DefId,
obligation: &TraitObligation<'tcx>,
) -> Normalized<'tcx, SubstsRef<'tcx>> {
let impl_trait_ref = self.tcx().bound_impl_trait_ref(impl_def_id).unwrap();
match self.match_impl(impl_def_id, impl_trait_ref, obligation) {
Ok(substs) => substs,
Err(()) => {
self.infcx.tcx.sess.delay_span_bug(
obligation.cause.span,
&format!(
"Impl {:?} was matchable against {:?} but now is not",
impl_def_id, obligation
),
);
let value = self.infcx.fresh_substs_for_item(obligation.cause.span, impl_def_id);
let err = self.tcx().ty_error();
let value = value.fold_with(&mut BottomUpFolder {
tcx: self.tcx(),
ty_op: |_| err,
lt_op: |l| l,
ct_op: |c| c,
});
Normalized { value, obligations: vec![] }
}
}
}

We currently emit a delay_span_bug if match_impl in rematch_impl fails. Considering that we should only call rematch_impl for impls for which we've already called match_impl before, rematch_impl should always succeed.

There are currently 2 tests which hit that error case:

src/test/ui/impl-trait/issues/issue-62742.rs
src/test/ui/impl-trait/issues/issue-84073.rs

We should figure out why they fail and either fix that, or add a comment to rematch_impl explaining what's going on.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-cleanupCategory: PRs that clean code up or issues documenting cleanup.E-mediumCall for participation: Medium difficulty. Experience needed to fix: Intermediate.T-typesRelevant to the types team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions