1
Fork 0

Rollup merge of #116358 - compiler-errors:match, r=lcnr

Rename both of the `Match` relations

Both of these names kinda were ambiguous.

r? lcnr
This commit is contained in:
Matthias Krüger 2023-10-03 12:24:12 +02:00 committed by GitHub
commit 12e4c780ee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 15 deletions

View file

@ -44,7 +44,7 @@ pub fn extract_verify_if_eq<'tcx>(
test_ty: Ty<'tcx>, test_ty: Ty<'tcx>,
) -> Option<ty::Region<'tcx>> { ) -> Option<ty::Region<'tcx>> {
assert!(!verify_if_eq_b.has_escaping_bound_vars()); assert!(!verify_if_eq_b.has_escaping_bound_vars());
let mut m = Match::new(tcx, param_env); let mut m = MatchAgainstHigherRankedOutlives::new(tcx, param_env);
let verify_if_eq = verify_if_eq_b.skip_binder(); let verify_if_eq = verify_if_eq_b.skip_binder();
m.relate(verify_if_eq.ty, test_ty).ok()?; m.relate(verify_if_eq.ty, test_ty).ok()?;
@ -87,24 +87,32 @@ pub(super) fn can_match_erased_ty<'tcx>(
// pointless micro-optimization // pointless micro-optimization
true true
} else { } else {
Match::new(tcx, param_env).relate(outlives_ty, erased_ty).is_ok() MatchAgainstHigherRankedOutlives::new(tcx, param_env).relate(outlives_ty, erased_ty).is_ok()
} }
} }
struct Match<'tcx> { struct MatchAgainstHigherRankedOutlives<'tcx> {
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
param_env: ty::ParamEnv<'tcx>, param_env: ty::ParamEnv<'tcx>,
pattern_depth: ty::DebruijnIndex, pattern_depth: ty::DebruijnIndex,
map: FxHashMap<ty::BoundRegion, ty::Region<'tcx>>, map: FxHashMap<ty::BoundRegion, ty::Region<'tcx>>,
} }
impl<'tcx> Match<'tcx> { impl<'tcx> MatchAgainstHigherRankedOutlives<'tcx> {
fn new(tcx: TyCtxt<'tcx>, param_env: ty::ParamEnv<'tcx>) -> Match<'tcx> { fn new(
Match { tcx, param_env, pattern_depth: ty::INNERMOST, map: FxHashMap::default() } tcx: TyCtxt<'tcx>,
param_env: ty::ParamEnv<'tcx>,
) -> MatchAgainstHigherRankedOutlives<'tcx> {
MatchAgainstHigherRankedOutlives {
tcx,
param_env,
pattern_depth: ty::INNERMOST,
map: FxHashMap::default(),
}
} }
} }
impl<'tcx> Match<'tcx> { impl<'tcx> MatchAgainstHigherRankedOutlives<'tcx> {
/// Creates the "Error" variant that signals "no match". /// Creates the "Error" variant that signals "no match".
fn no_match<T>(&self) -> RelateResult<'tcx, T> { fn no_match<T>(&self) -> RelateResult<'tcx, T> {
Err(TypeError::Mismatch) Err(TypeError::Mismatch)
@ -134,7 +142,7 @@ impl<'tcx> Match<'tcx> {
} }
} }
impl<'tcx> TypeRelation<'tcx> for Match<'tcx> { impl<'tcx> TypeRelation<'tcx> for MatchAgainstHigherRankedOutlives<'tcx> {
fn tag(&self) -> &'static str { fn tag(&self) -> &'static str {
"Match" "Match"
} }

View file

@ -18,20 +18,20 @@ use crate::ty::{self, InferConst, Ty, TyCtxt};
/// Like subtyping, matching is really a binary relation, so the only /// Like subtyping, matching is really a binary relation, so the only
/// important thing about the result is Ok/Err. Also, matching never /// important thing about the result is Ok/Err. Also, matching never
/// affects any type variables or unification state. /// affects any type variables or unification state.
pub struct Match<'tcx> { pub struct MatchAgainstFreshVars<'tcx> {
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
param_env: ty::ParamEnv<'tcx>, param_env: ty::ParamEnv<'tcx>,
} }
impl<'tcx> Match<'tcx> { impl<'tcx> MatchAgainstFreshVars<'tcx> {
pub fn new(tcx: TyCtxt<'tcx>, param_env: ty::ParamEnv<'tcx>) -> Match<'tcx> { pub fn new(tcx: TyCtxt<'tcx>, param_env: ty::ParamEnv<'tcx>) -> MatchAgainstFreshVars<'tcx> {
Match { tcx, param_env } MatchAgainstFreshVars { tcx, param_env }
} }
} }
impl<'tcx> TypeRelation<'tcx> for Match<'tcx> { impl<'tcx> TypeRelation<'tcx> for MatchAgainstFreshVars<'tcx> {
fn tag(&self) -> &'static str { fn tag(&self) -> &'static str {
"Match" "MatchAgainstFreshVars"
} }
fn tcx(&self) -> TyCtxt<'tcx> { fn tcx(&self) -> TyCtxt<'tcx> {
self.tcx self.tcx

View file

@ -39,6 +39,7 @@ use rustc_middle::dep_graph::dep_kinds;
use rustc_middle::dep_graph::DepNodeIndex; use rustc_middle::dep_graph::DepNodeIndex;
use rustc_middle::mir::interpret::ErrorHandled; use rustc_middle::mir::interpret::ErrorHandled;
use rustc_middle::traits::DefiningAnchor; use rustc_middle::traits::DefiningAnchor;
use rustc_middle::ty::_match::MatchAgainstFreshVars;
use rustc_middle::ty::abstract_const::NotConstEvaluatable; use rustc_middle::ty::abstract_const::NotConstEvaluatable;
use rustc_middle::ty::fold::BottomUpFolder; use rustc_middle::ty::fold::BottomUpFolder;
use rustc_middle::ty::relate::TypeRelation; use rustc_middle::ty::relate::TypeRelation;
@ -2642,7 +2643,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
current: ty::PolyTraitPredicate<'tcx>, current: ty::PolyTraitPredicate<'tcx>,
param_env: ty::ParamEnv<'tcx>, param_env: ty::ParamEnv<'tcx>,
) -> bool { ) -> bool {
let mut matcher = ty::_match::Match::new(self.tcx(), param_env); let mut matcher = MatchAgainstFreshVars::new(self.tcx(), param_env);
matcher.relate(previous, current).is_ok() matcher.relate(previous, current).is_ok()
} }