1
Fork 0

Account for for<'a> types when checking for non-structural type in constant as pattern

When we encounter a constant in a pattern, we check if it is non-structural. If so, we check if the type implements `PartialEq`, but for types with escaping bound vars the check would be incorrect as is, so we break early. This is ok because these types would be filtered anyways.

Fix #134764.
This commit is contained in:
Esteban Küber 2024-12-26 01:30:29 +00:00
parent 760b6f8de4
commit 05c39438e2
3 changed files with 40 additions and 3 deletions

View file

@ -8,7 +8,9 @@ use rustc_infer::infer::TyCtxtInferExt;
use rustc_infer::traits::Obligation;
use rustc_middle::mir::interpret::ErrorHandled;
use rustc_middle::thir::{FieldPat, Pat, PatKind};
use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitableExt, TypeVisitor, ValTree};
use rustc_middle::ty::{
self, Ty, TyCtxt, TypeSuperVisitable, TypeVisitableExt, TypeVisitor, ValTree,
};
use rustc_middle::{mir, span_bug};
use rustc_span::def_id::DefId;
use rustc_span::{Span, sym};
@ -387,7 +389,9 @@ fn extend_type_not_partial_eq<'tcx>(
impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for UsedParamsNeedInstantiationVisitor<'tcx> {
fn visit_ty(&mut self, ty: Ty<'tcx>) -> Self::Result {
if let ty::Adt(def, _args) = ty.kind() {
if let ty::Adt(def, _args) = ty.kind()
&& !ty.has_escaping_bound_vars()
{
let ty_def_id = def.did();
let ty_def_span = self.tcx.def_span(ty_def_id);
let (impls_partial_eq, derived, structural, impl_def_id) =
@ -412,7 +416,6 @@ fn extend_type_not_partial_eq<'tcx>(
_ => {}
};
}
use rustc_middle::ty::TypeSuperVisitable;
ty.super_visit_with(self)
}
}
@ -468,6 +471,10 @@ fn type_has_partial_eq_impl<'tcx>(
let partial_eq_trait_id = tcx.require_lang_item(hir::LangItem::PartialEq, None);
let structural_partial_eq_trait_id = tcx.require_lang_item(hir::LangItem::StructuralPeq, None);
if ty.has_escaping_bound_vars() {
return (false, false, false, None);
}
let partial_eq_obligation = Obligation::new(
tcx,
ObligationCause::dummy(),