diff options
author | bors <bors@rust-lang.org> | 2023-05-15 22:16:50 +0000 |
---|---|---|
committer | bors <bors@rust-lang.org> | 2023-05-15 22:16:50 +0000 |
commit | ea54255501221b26bf2242c09cbd0924dc8ee1ea (patch) | |
tree | 0090044836e6c0d9045d273e084a7e1879f2b4ce /compiler/rustc_middle | |
parent | ce5919fcef67103098219e1868f741e56fc90963 (diff) | |
parent | a2678e15e559bb7d779fd1e04d73d8ae3b9093e3 (diff) | |
download | rust-ea54255501221b26bf2242c09cbd0924dc8ee1ea.tar.gz |
Auto merge of #111221 - compiler-errors:yeet-generalizer, r=lcnr
Combine three generalizer implementations
Fixes #111092
Fixes #109505
This code is a bit delicate and there were subtle changes between them, so I'll leave inline comments where further inspection is needed.
Regarding this comment from #109813 -- "add tests triggering all codepaths: at least the combine and the const generalizer", can't really do that now, and I don't really know how we'd get a higher-ranked const error since non-lifetime binders doesn't *really* support `for<const ..>` (it errors out when you try to use it).
r? `@lcnr`
Diffstat (limited to 'compiler/rustc_middle')
-rw-r--r-- | compiler/rustc_middle/src/ty/_match.rs | 4 | ||||
-rw-r--r-- | compiler/rustc_middle/src/ty/mod.rs | 18 | ||||
-rw-r--r-- | compiler/rustc_middle/src/ty/relate.rs | 31 |
3 files changed, 37 insertions, 16 deletions
diff --git a/compiler/rustc_middle/src/ty/_match.rs b/compiler/rustc_middle/src/ty/_match.rs index 468c2c818b2..cbc68fde9d9 100644 --- a/compiler/rustc_middle/src/ty/_match.rs +++ b/compiler/rustc_middle/src/ty/_match.rs @@ -83,7 +83,7 @@ impl<'tcx> TypeRelation<'tcx> for Match<'tcx> { (&ty::Error(guar), _) | (_, &ty::Error(guar)) => Ok(self.tcx().ty_error(guar)), - _ => relate::super_relate_tys(self, a, b), + _ => relate::structurally_relate_tys(self, a, b), } } @@ -109,7 +109,7 @@ impl<'tcx> TypeRelation<'tcx> for Match<'tcx> { _ => {} } - relate::super_relate_consts(self, a, b) + relate::structurally_relate_consts(self, a, b) } fn binders<T>( diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index a497b6a335d..df324bcc52c 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -1072,6 +1072,24 @@ impl ParamTerm { } } +#[derive(Copy, Clone, Eq, PartialEq, Debug)] +pub enum TermVid<'tcx> { + Ty(ty::TyVid), + Const(ty::ConstVid<'tcx>), +} + +impl From<ty::TyVid> for TermVid<'_> { + fn from(value: ty::TyVid) -> Self { + TermVid::Ty(value) + } +} + +impl<'tcx> From<ty::ConstVid<'tcx>> for TermVid<'tcx> { + fn from(value: ty::ConstVid<'tcx>) -> Self { + TermVid::Const(value) + } +} + /// This kind of predicate has no *direct* correspondent in the /// syntax, but it roughly corresponds to the syntactic forms: /// diff --git a/compiler/rustc_middle/src/ty/relate.rs b/compiler/rustc_middle/src/ty/relate.rs index da43475941e..3bbe6a23b66 100644 --- a/compiler/rustc_middle/src/ty/relate.rs +++ b/compiler/rustc_middle/src/ty/relate.rs @@ -388,24 +388,24 @@ impl<'tcx> Relate<'tcx> for Ty<'tcx> { } } -/// The main "type relation" routine. Note that this does not handle -/// inference artifacts, so you should filter those out before calling -/// it. -pub fn super_relate_tys<'tcx, R: TypeRelation<'tcx>>( +/// Relates `a` and `b` structurally, calling the relation for all nested values. +/// Any semantic equality, e.g. of projections, and inference variables have to be +/// handled by the caller. +pub fn structurally_relate_tys<'tcx, R: TypeRelation<'tcx>>( relation: &mut R, a: Ty<'tcx>, b: Ty<'tcx>, ) -> RelateResult<'tcx, Ty<'tcx>> { let tcx = relation.tcx(); - debug!("super_relate_tys: a={:?} b={:?}", a, b); + debug!("structurally_relate_tys: a={:?} b={:?}", a, b); match (a.kind(), b.kind()) { (&ty::Infer(_), _) | (_, &ty::Infer(_)) => { // The caller should handle these cases! - bug!("var types encountered in super_relate_tys") + bug!("var types encountered in structurally_relate_tys") } (ty::Bound(..), _) | (_, ty::Bound(..)) => { - bug!("bound types encountered in super_relate_tys") + bug!("bound types encountered in structurally_relate_tys") } (&ty::Error(guar), _) | (_, &ty::Error(guar)) => Ok(tcx.ty_error(guar)), @@ -575,15 +575,18 @@ pub fn super_relate_tys<'tcx, R: TypeRelation<'tcx>>( } } -/// The main "const relation" routine. Note that this does not handle -/// inference artifacts, so you should filter those out before calling -/// it. -pub fn super_relate_consts<'tcx, R: TypeRelation<'tcx>>( +/// Relates `a` and `b` structurally, calling the relation for all nested values. +/// Any semantic equality, e.g. of unevaluated consts, and inference variables have +/// to be handled by the caller. +/// +/// FIXME: This is not totally structual, which probably should be fixed. +/// See the HACKs below. +pub fn structurally_relate_consts<'tcx, R: TypeRelation<'tcx>>( relation: &mut R, mut a: ty::Const<'tcx>, mut b: ty::Const<'tcx>, ) -> RelateResult<'tcx, ty::Const<'tcx>> { - debug!("{}.super_relate_consts(a = {:?}, b = {:?})", relation.tag(), a, b); + debug!("{}.structurally_relate_consts(a = {:?}, b = {:?})", relation.tag(), a, b); let tcx = relation.tcx(); // HACK(const_generics): We still need to eagerly evaluate consts when @@ -602,7 +605,7 @@ pub fn super_relate_consts<'tcx, R: TypeRelation<'tcx>>( b = tcx.expand_abstract_consts(b); } - debug!("{}.super_relate_consts(normed_a = {:?}, normed_b = {:?})", relation.tag(), a, b); + debug!("{}.structurally_relate_consts(normed_a = {:?}, normed_b = {:?})", relation.tag(), a, b); // Currently, the values that can be unified are primitive types, // and those that derive both `PartialEq` and `Eq`, corresponding @@ -610,7 +613,7 @@ pub fn super_relate_consts<'tcx, R: TypeRelation<'tcx>>( let is_match = match (a.kind(), b.kind()) { (ty::ConstKind::Infer(_), _) | (_, ty::ConstKind::Infer(_)) => { // The caller should handle these cases! - bug!("var types encountered in super_relate_consts: {:?} {:?}", a, b) + bug!("var types encountered in structurally_relate_consts: {:?} {:?}", a, b) } (ty::ConstKind::Error(_), _) => return Ok(a), |