Uplift TypeRelation and Relate
This commit is contained in:
parent
82ef3ad980
commit
91274c84b9
34 changed files with 1114 additions and 866 deletions
|
@ -27,8 +27,8 @@
|
|||
|
||||
use super::*;
|
||||
|
||||
use crate::infer::relate::{Relate, StructurallyRelateAliases, TypeRelation};
|
||||
use rustc_middle::bug;
|
||||
use rustc_middle::ty::relate::{Relate, TypeRelation};
|
||||
use rustc_middle::ty::{Const, ImplSubject};
|
||||
|
||||
/// Whether we should define opaque types or just treat them opaquely.
|
||||
|
@ -90,7 +90,7 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
pub trait ToTrace<'tcx>: Relate<'tcx> + Copy {
|
||||
pub trait ToTrace<'tcx>: Relate<TyCtxt<'tcx>> + Copy {
|
||||
fn to_trace(
|
||||
cause: &ObligationCause<'tcx>,
|
||||
a_is_expected: bool,
|
||||
|
|
|
@ -58,6 +58,7 @@ use crate::traits::{
|
|||
PredicateObligation,
|
||||
};
|
||||
|
||||
use crate::infer::relate::{self, RelateResult, TypeRelation};
|
||||
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
|
||||
use rustc_errors::{
|
||||
codes::*, pluralize, struct_span_code_err, Applicability, Diag, DiagCtxt, DiagStyledString,
|
||||
|
@ -73,7 +74,6 @@ use rustc_middle::bug;
|
|||
use rustc_middle::dep_graph::DepContext;
|
||||
use rustc_middle::ty::error::TypeErrorToStringExt;
|
||||
use rustc_middle::ty::print::{with_forced_trimmed_paths, PrintError, PrintTraitRefExt as _};
|
||||
use rustc_middle::ty::relate::{self, RelateResult, TypeRelation};
|
||||
use rustc_middle::ty::Upcast;
|
||||
use rustc_middle::ty::{
|
||||
self, error::TypeError, IsSuggestable, List, Region, Ty, TyCtxt, TypeFoldable,
|
||||
|
@ -2687,7 +2687,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
/// with the other type. A TyVar inference type is compatible with any type, and an IntVar or
|
||||
/// FloatVar inference type are compatible with themselves or their concrete types (Int and
|
||||
/// Float types, respectively). When comparing two ADTs, these rules apply recursively.
|
||||
pub fn same_type_modulo_infer<T: relate::Relate<'tcx>>(&self, a: T, b: T) -> bool {
|
||||
pub fn same_type_modulo_infer<T: relate::Relate<TyCtxt<'tcx>>>(&self, a: T, b: T) -> bool {
|
||||
let (a, b) = self.resolve_vars_if_possible((a, b));
|
||||
SameTypeModuloInfer(self).relate(a, b).is_ok()
|
||||
}
|
||||
|
@ -2695,7 +2695,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
|
||||
struct SameTypeModuloInfer<'a, 'tcx>(&'a InferCtxt<'tcx>);
|
||||
|
||||
impl<'tcx> TypeRelation<'tcx> for SameTypeModuloInfer<'_, 'tcx> {
|
||||
impl<'tcx> TypeRelation<TyCtxt<'tcx>> for SameTypeModuloInfer<'_, 'tcx> {
|
||||
fn tcx(&self) -> TyCtxt<'tcx> {
|
||||
self.0.tcx
|
||||
}
|
||||
|
@ -2704,10 +2704,10 @@ impl<'tcx> TypeRelation<'tcx> for SameTypeModuloInfer<'_, 'tcx> {
|
|||
"SameTypeModuloInfer"
|
||||
}
|
||||
|
||||
fn relate_with_variance<T: relate::Relate<'tcx>>(
|
||||
fn relate_with_variance<T: relate::Relate<TyCtxt<'tcx>>>(
|
||||
&mut self,
|
||||
_variance: ty::Variance,
|
||||
_info: ty::VarianceDiagInfo<'tcx>,
|
||||
_info: ty::VarianceDiagInfo<TyCtxt<'tcx>>,
|
||||
a: T,
|
||||
b: T,
|
||||
) -> relate::RelateResult<'tcx, T> {
|
||||
|
@ -2755,7 +2755,7 @@ impl<'tcx> TypeRelation<'tcx> for SameTypeModuloInfer<'_, 'tcx> {
|
|||
b: ty::Binder<'tcx, T>,
|
||||
) -> relate::RelateResult<'tcx, ty::Binder<'tcx, T>>
|
||||
where
|
||||
T: relate::Relate<'tcx>,
|
||||
T: relate::Relate<TyCtxt<'tcx>>,
|
||||
{
|
||||
Ok(a.rebind(self.relate(a.skip_binder(), b.skip_binder())?))
|
||||
}
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
pub use at::DefineOpaqueTypes;
|
||||
pub use freshen::TypeFreshener;
|
||||
pub use lexical_region_resolve::RegionResolutionError;
|
||||
pub use relate::combine::CombineFields;
|
||||
pub use relate::combine::ObligationEmittingRelation;
|
||||
pub use relate::StructurallyRelateAliases;
|
||||
pub use rustc_macros::{TypeFoldable, TypeVisitable};
|
||||
pub use rustc_middle::ty::IntVarValue;
|
||||
pub use BoundRegionConversionTime::*;
|
||||
|
@ -11,6 +8,7 @@ pub use RegionVariableOrigin::*;
|
|||
pub use SubregionOrigin::*;
|
||||
pub use ValuePairs::*;
|
||||
|
||||
use crate::infer::relate::{CombineFields, RelateResult};
|
||||
use crate::traits::{
|
||||
self, ObligationCause, ObligationInspector, PredicateObligations, TraitEngine,
|
||||
};
|
||||
|
@ -39,7 +37,6 @@ use rustc_middle::traits::select;
|
|||
use rustc_middle::ty::error::{ExpectedFound, TypeError};
|
||||
use rustc_middle::ty::fold::BoundVarReplacerDelegate;
|
||||
use rustc_middle::ty::fold::{TypeFoldable, TypeFolder, TypeSuperFoldable};
|
||||
use rustc_middle::ty::relate::RelateResult;
|
||||
use rustc_middle::ty::visit::TypeVisitableExt;
|
||||
use rustc_middle::ty::{self, GenericParamDefKind, InferConst, Ty, TyCtxt};
|
||||
use rustc_middle::ty::{ConstVid, EffectVid, FloatVid, IntVid, TyVid};
|
||||
|
@ -62,7 +59,7 @@ pub mod opaque_types;
|
|||
pub mod outlives;
|
||||
mod projection;
|
||||
pub mod region_constraints;
|
||||
mod relate;
|
||||
pub mod relate;
|
||||
pub mod resolve;
|
||||
pub(crate) mod snapshot;
|
||||
pub mod type_variable;
|
||||
|
|
|
@ -1,15 +1,12 @@
|
|||
use std::collections::hash_map::Entry;
|
||||
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_middle::ty::error::TypeError;
|
||||
use rustc_middle::ty::TypeVisitableExt;
|
||||
use rustc_middle::ty::{
|
||||
self,
|
||||
error::TypeError,
|
||||
relate::{self, Relate, RelateResult, TypeRelation},
|
||||
Ty, TyCtxt,
|
||||
};
|
||||
use rustc_middle::ty::{self, Ty, TyCtxt};
|
||||
|
||||
use crate::infer::region_constraints::VerifyIfEq;
|
||||
use crate::infer::relate::{self as relate, Relate, RelateResult, TypeRelation};
|
||||
|
||||
/// Given a "verify-if-eq" type test like:
|
||||
///
|
||||
|
@ -135,7 +132,7 @@ impl<'tcx> MatchAgainstHigherRankedOutlives<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'tcx> TypeRelation<'tcx> for MatchAgainstHigherRankedOutlives<'tcx> {
|
||||
impl<'tcx> TypeRelation<TyCtxt<'tcx>> for MatchAgainstHigherRankedOutlives<'tcx> {
|
||||
fn tag(&self) -> &'static str {
|
||||
"MatchAgainstHigherRankedOutlives"
|
||||
}
|
||||
|
@ -145,10 +142,10 @@ impl<'tcx> TypeRelation<'tcx> for MatchAgainstHigherRankedOutlives<'tcx> {
|
|||
}
|
||||
|
||||
#[instrument(level = "trace", skip(self))]
|
||||
fn relate_with_variance<T: Relate<'tcx>>(
|
||||
fn relate_with_variance<T: Relate<TyCtxt<'tcx>>>(
|
||||
&mut self,
|
||||
variance: ty::Variance,
|
||||
_: ty::VarianceDiagInfo<'tcx>,
|
||||
_: ty::VarianceDiagInfo<TyCtxt<'tcx>>,
|
||||
a: T,
|
||||
b: T,
|
||||
) -> RelateResult<'tcx, T> {
|
||||
|
@ -208,7 +205,7 @@ impl<'tcx> TypeRelation<'tcx> for MatchAgainstHigherRankedOutlives<'tcx> {
|
|||
value: ty::Binder<'tcx, T>,
|
||||
) -> RelateResult<'tcx, ty::Binder<'tcx, T>>
|
||||
where
|
||||
T: Relate<'tcx>,
|
||||
T: Relate<TyCtxt<'tcx>>,
|
||||
{
|
||||
self.pattern_depth.shift_in(1);
|
||||
let result = Ok(pattern.rebind(self.relate(pattern.skip_binder(), value.skip_binder())?));
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
use super::*;
|
||||
use crate::infer::relate::RelateResult;
|
||||
use crate::infer::snapshot::CombinedSnapshot;
|
||||
use rustc_data_structures::fx::FxIndexMap;
|
||||
use rustc_data_structures::graph::{scc::Sccs, vec_graph::VecGraph};
|
||||
use rustc_index::Idx;
|
||||
use rustc_middle::span_bug;
|
||||
use rustc_middle::ty::error::TypeError;
|
||||
use rustc_middle::ty::relate::RelateResult;
|
||||
|
||||
impl<'tcx> RegionConstraintCollector<'_, 'tcx> {
|
||||
/// Searches new universes created during `snapshot`, looking for
|
||||
|
|
121
compiler/rustc_infer/src/infer/relate/_match.rs
Normal file
121
compiler/rustc_infer/src/infer/relate/_match.rs
Normal file
|
@ -0,0 +1,121 @@
|
|||
use rustc_middle::ty::error::{ExpectedFound, TypeError};
|
||||
use rustc_middle::ty::{self, InferConst, Ty, TyCtxt};
|
||||
use tracing::{debug, instrument};
|
||||
|
||||
use super::{structurally_relate_tys, Relate, RelateResult, TypeRelation};
|
||||
use crate::infer::relate;
|
||||
|
||||
/// A type "A" *matches* "B" if the fresh types in B could be
|
||||
/// instantiated with values so as to make it equal to A. Matching is
|
||||
/// intended to be used only on freshened types, and it basically
|
||||
/// indicates if the non-freshened versions of A and B could have been
|
||||
/// unified.
|
||||
///
|
||||
/// It is only an approximation. If it yields false, unification would
|
||||
/// definitely fail, but a true result doesn't mean unification would
|
||||
/// succeed. This is because we don't track the "side-constraints" on
|
||||
/// type variables, nor do we track if the same freshened type appears
|
||||
/// more than once. To some extent these approximations could be
|
||||
/// fixed, given effort.
|
||||
///
|
||||
/// Like subtyping, matching is really a binary relation, so the only
|
||||
/// important thing about the result is Ok/Err. Also, matching never
|
||||
/// affects any type variables or unification state.
|
||||
pub struct MatchAgainstFreshVars<'tcx> {
|
||||
tcx: TyCtxt<'tcx>,
|
||||
}
|
||||
|
||||
impl<'tcx> MatchAgainstFreshVars<'tcx> {
|
||||
pub fn new(tcx: TyCtxt<'tcx>) -> MatchAgainstFreshVars<'tcx> {
|
||||
MatchAgainstFreshVars { tcx }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> TypeRelation<TyCtxt<'tcx>> for MatchAgainstFreshVars<'tcx> {
|
||||
fn tag(&self) -> &'static str {
|
||||
"MatchAgainstFreshVars"
|
||||
}
|
||||
|
||||
fn tcx(&self) -> TyCtxt<'tcx> {
|
||||
self.tcx
|
||||
}
|
||||
|
||||
fn relate_with_variance<T: Relate<TyCtxt<'tcx>>>(
|
||||
&mut self,
|
||||
_: ty::Variance,
|
||||
_: ty::VarianceDiagInfo<TyCtxt<'tcx>>,
|
||||
a: T,
|
||||
b: T,
|
||||
) -> RelateResult<'tcx, T> {
|
||||
self.relate(a, b)
|
||||
}
|
||||
|
||||
#[instrument(skip(self), level = "debug")]
|
||||
fn regions(
|
||||
&mut self,
|
||||
a: ty::Region<'tcx>,
|
||||
_b: ty::Region<'tcx>,
|
||||
) -> RelateResult<'tcx, ty::Region<'tcx>> {
|
||||
Ok(a)
|
||||
}
|
||||
|
||||
#[instrument(skip(self), level = "debug")]
|
||||
fn tys(&mut self, a: Ty<'tcx>, b: Ty<'tcx>) -> RelateResult<'tcx, Ty<'tcx>> {
|
||||
if a == b {
|
||||
return Ok(a);
|
||||
}
|
||||
|
||||
match (a.kind(), b.kind()) {
|
||||
(
|
||||
_,
|
||||
&ty::Infer(ty::FreshTy(_))
|
||||
| &ty::Infer(ty::FreshIntTy(_))
|
||||
| &ty::Infer(ty::FreshFloatTy(_)),
|
||||
) => Ok(a),
|
||||
|
||||
(&ty::Infer(_), _) | (_, &ty::Infer(_)) => {
|
||||
Err(TypeError::Sorts(ExpectedFound::new(true, a, b)))
|
||||
}
|
||||
|
||||
(&ty::Error(guar), _) | (_, &ty::Error(guar)) => Ok(Ty::new_error(self.tcx(), guar)),
|
||||
|
||||
_ => structurally_relate_tys(self, a, b),
|
||||
}
|
||||
}
|
||||
|
||||
fn consts(
|
||||
&mut self,
|
||||
a: ty::Const<'tcx>,
|
||||
b: ty::Const<'tcx>,
|
||||
) -> RelateResult<'tcx, ty::Const<'tcx>> {
|
||||
debug!("{}.consts({:?}, {:?})", self.tag(), a, b);
|
||||
if a == b {
|
||||
return Ok(a);
|
||||
}
|
||||
|
||||
match (a.kind(), b.kind()) {
|
||||
(_, ty::ConstKind::Infer(InferConst::Fresh(_))) => {
|
||||
return Ok(a);
|
||||
}
|
||||
|
||||
(ty::ConstKind::Infer(_), _) | (_, ty::ConstKind::Infer(_)) => {
|
||||
return Err(TypeError::ConstMismatch(ExpectedFound::new(true, a, b)));
|
||||
}
|
||||
|
||||
_ => {}
|
||||
}
|
||||
|
||||
relate::structurally_relate_consts(self, a, b)
|
||||
}
|
||||
|
||||
fn binders<T>(
|
||||
&mut self,
|
||||
a: ty::Binder<'tcx, T>,
|
||||
b: ty::Binder<'tcx, T>,
|
||||
) -> RelateResult<'tcx, ty::Binder<'tcx, T>>
|
||||
where
|
||||
T: Relate<TyCtxt<'tcx>>,
|
||||
{
|
||||
Ok(a.rebind(self.relate(a.skip_binder(), b.skip_binder())?))
|
||||
}
|
||||
}
|
|
@ -22,12 +22,13 @@ use super::glb::Glb;
|
|||
use super::lub::Lub;
|
||||
use super::type_relating::TypeRelating;
|
||||
use super::StructurallyRelateAliases;
|
||||
use super::{RelateResult, TypeRelation};
|
||||
use crate::infer::relate;
|
||||
use crate::infer::{DefineOpaqueTypes, InferCtxt, TypeTrace};
|
||||
use crate::traits::{Obligation, PredicateObligations};
|
||||
use rustc_middle::bug;
|
||||
use rustc_middle::infer::unify_key::EffectVarValue;
|
||||
use rustc_middle::ty::error::TypeError;
|
||||
use rustc_middle::ty::relate::{RelateResult, TypeRelation};
|
||||
use rustc_middle::ty::error::{ExpectedFound, TypeError};
|
||||
use rustc_middle::ty::{self, InferConst, Ty, TyCtxt, TypeVisitableExt, Upcast};
|
||||
use rustc_middle::ty::{IntType, UintType};
|
||||
use rustc_span::Span;
|
||||
|
@ -121,7 +122,7 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||
(_, ty::Alias(..)) | (ty::Alias(..), _) if self.next_trait_solver() => {
|
||||
match relation.structurally_relate_aliases() {
|
||||
StructurallyRelateAliases::Yes => {
|
||||
ty::relate::structurally_relate_tys(relation, a, b)
|
||||
relate::structurally_relate_tys(relation, a, b)
|
||||
}
|
||||
StructurallyRelateAliases::No => {
|
||||
relation.register_type_relate_obligation(a, b);
|
||||
|
@ -132,7 +133,7 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||
|
||||
// All other cases of inference are errors
|
||||
(&ty::Infer(_), _) | (_, &ty::Infer(_)) => {
|
||||
Err(TypeError::Sorts(ty::relate::expected_found(a, b)))
|
||||
Err(TypeError::Sorts(ExpectedFound::new(true, a, b)))
|
||||
}
|
||||
|
||||
// During coherence, opaque types should be treated as *possibly*
|
||||
|
@ -144,7 +145,7 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||
Ok(a)
|
||||
}
|
||||
|
||||
_ => ty::relate::structurally_relate_tys(relation, a, b),
|
||||
_ => relate::structurally_relate_tys(relation, a, b),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -234,11 +235,11 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||
Ok(b)
|
||||
}
|
||||
StructurallyRelateAliases::Yes => {
|
||||
ty::relate::structurally_relate_consts(relation, a, b)
|
||||
relate::structurally_relate_consts(relation, a, b)
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => ty::relate::structurally_relate_consts(relation, a, b),
|
||||
_ => relate::structurally_relate_consts(relation, a, b),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -303,7 +304,7 @@ impl<'infcx, 'tcx> CombineFields<'infcx, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
pub trait ObligationEmittingRelation<'tcx>: TypeRelation<'tcx> {
|
||||
pub trait ObligationEmittingRelation<'tcx>: TypeRelation<TyCtxt<'tcx>> {
|
||||
fn span(&self) -> Span;
|
||||
|
||||
fn param_env(&self) -> ty::ParamEnv<'tcx>;
|
||||
|
|
|
@ -1,15 +1,16 @@
|
|||
use std::mem;
|
||||
|
||||
use super::StructurallyRelateAliases;
|
||||
use super::{ObligationEmittingRelation, Relate, RelateResult, TypeRelation};
|
||||
use crate::infer::relate;
|
||||
use crate::infer::type_variable::TypeVariableValue;
|
||||
use crate::infer::{InferCtxt, ObligationEmittingRelation, RegionVariableOrigin};
|
||||
use crate::infer::{InferCtxt, RegionVariableOrigin};
|
||||
use rustc_data_structures::sso::SsoHashMap;
|
||||
use rustc_data_structures::stack::ensure_sufficient_stack;
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_middle::bug;
|
||||
use rustc_middle::infer::unify_key::ConstVariableValue;
|
||||
use rustc_middle::ty::error::TypeError;
|
||||
use rustc_middle::ty::relate::{self, Relate, RelateResult, TypeRelation};
|
||||
use rustc_middle::ty::visit::MaxUniverse;
|
||||
use rustc_middle::ty::{self, Ty, TyCtxt};
|
||||
use rustc_middle::ty::{AliasRelationDirection, InferConst, Term, TypeVisitable, TypeVisitableExt};
|
||||
|
@ -228,7 +229,7 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||
|
||||
/// Attempts to generalize `source_term` for the type variable `target_vid`.
|
||||
/// This checks for cycles -- that is, whether `source_term` references `target_vid`.
|
||||
fn generalize<T: Into<Term<'tcx>> + Relate<'tcx>>(
|
||||
fn generalize<T: Into<Term<'tcx>> + Relate<TyCtxt<'tcx>>>(
|
||||
&self,
|
||||
span: Span,
|
||||
structurally_relate_aliases: StructurallyRelateAliases,
|
||||
|
@ -395,7 +396,7 @@ impl<'tcx> Generalizer<'_, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'tcx> TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
|
||||
impl<'tcx> TypeRelation<TyCtxt<'tcx>> for Generalizer<'_, 'tcx> {
|
||||
fn tcx(&self) -> TyCtxt<'tcx> {
|
||||
self.infcx.tcx
|
||||
}
|
||||
|
@ -430,10 +431,10 @@ impl<'tcx> TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
|
|||
}
|
||||
|
||||
#[instrument(level = "debug", skip(self, variance, b), ret)]
|
||||
fn relate_with_variance<T: Relate<'tcx>>(
|
||||
fn relate_with_variance<T: Relate<TyCtxt<'tcx>>>(
|
||||
&mut self,
|
||||
variance: ty::Variance,
|
||||
_info: ty::VarianceDiagInfo<'tcx>,
|
||||
_info: ty::VarianceDiagInfo<TyCtxt<'tcx>>,
|
||||
a: T,
|
||||
b: T,
|
||||
) -> RelateResult<'tcx, T> {
|
||||
|
@ -695,7 +696,7 @@ impl<'tcx> TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
|
|||
_: ty::Binder<'tcx, T>,
|
||||
) -> RelateResult<'tcx, ty::Binder<'tcx, T>>
|
||||
where
|
||||
T: Relate<'tcx>,
|
||||
T: Relate<TyCtxt<'tcx>>,
|
||||
{
|
||||
let result = self.relate(a.skip_binder(), a.skip_binder())?;
|
||||
Ok(a.rebind(result))
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
//! Greatest lower bound. See [`lattice`].
|
||||
|
||||
use rustc_middle::ty::relate::{Relate, RelateResult, TypeRelation};
|
||||
use super::{Relate, RelateResult, TypeRelation};
|
||||
use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitableExt};
|
||||
use rustc_span::Span;
|
||||
|
||||
|
@ -21,7 +21,7 @@ impl<'combine, 'infcx, 'tcx> Glb<'combine, 'infcx, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'tcx> TypeRelation<'tcx> for Glb<'_, '_, 'tcx> {
|
||||
impl<'tcx> TypeRelation<TyCtxt<'tcx>> for Glb<'_, '_, 'tcx> {
|
||||
fn tag(&self) -> &'static str {
|
||||
"Glb"
|
||||
}
|
||||
|
@ -30,10 +30,10 @@ impl<'tcx> TypeRelation<'tcx> for Glb<'_, '_, 'tcx> {
|
|||
self.fields.tcx()
|
||||
}
|
||||
|
||||
fn relate_with_variance<T: Relate<'tcx>>(
|
||||
fn relate_with_variance<T: Relate<TyCtxt<'tcx>>>(
|
||||
&mut self,
|
||||
variance: ty::Variance,
|
||||
_info: ty::VarianceDiagInfo<'tcx>,
|
||||
_info: ty::VarianceDiagInfo<TyCtxt<'tcx>>,
|
||||
a: T,
|
||||
b: T,
|
||||
) -> RelateResult<'tcx, T> {
|
||||
|
@ -81,7 +81,7 @@ impl<'tcx> TypeRelation<'tcx> for Glb<'_, '_, 'tcx> {
|
|||
b: ty::Binder<'tcx, T>,
|
||||
) -> RelateResult<'tcx, ty::Binder<'tcx, T>>
|
||||
where
|
||||
T: Relate<'tcx>,
|
||||
T: Relate<TyCtxt<'tcx>>,
|
||||
{
|
||||
// GLB of a binder and itself is just itself
|
||||
if a == b {
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
//! Helper routines for higher-ranked things. See the `doc` module at
|
||||
//! the end of the file for details.
|
||||
|
||||
use super::RelateResult;
|
||||
use crate::infer::snapshot::CombinedSnapshot;
|
||||
use crate::infer::InferCtxt;
|
||||
use rustc_middle::ty::fold::FnMutDelegate;
|
||||
use rustc_middle::ty::relate::RelateResult;
|
||||
use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable};
|
||||
|
||||
impl<'tcx> InferCtxt<'tcx> {
|
||||
|
|
|
@ -21,7 +21,7 @@ use super::combine::ObligationEmittingRelation;
|
|||
use crate::infer::{DefineOpaqueTypes, InferCtxt};
|
||||
use crate::traits::ObligationCause;
|
||||
|
||||
use rustc_middle::ty::relate::RelateResult;
|
||||
use super::RelateResult;
|
||||
use rustc_middle::ty::TyVar;
|
||||
use rustc_middle::ty::{self, Ty};
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ use super::StructurallyRelateAliases;
|
|||
use crate::infer::{DefineOpaqueTypes, InferCtxt, SubregionOrigin};
|
||||
use crate::traits::{ObligationCause, PredicateObligations};
|
||||
|
||||
use rustc_middle::ty::relate::{Relate, RelateResult, TypeRelation};
|
||||
use super::{Relate, RelateResult, TypeRelation};
|
||||
use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitableExt};
|
||||
use rustc_span::Span;
|
||||
|
||||
|
@ -21,7 +21,7 @@ impl<'combine, 'infcx, 'tcx> Lub<'combine, 'infcx, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'tcx> TypeRelation<'tcx> for Lub<'_, '_, 'tcx> {
|
||||
impl<'tcx> TypeRelation<TyCtxt<'tcx>> for Lub<'_, '_, 'tcx> {
|
||||
fn tag(&self) -> &'static str {
|
||||
"Lub"
|
||||
}
|
||||
|
@ -30,10 +30,10 @@ impl<'tcx> TypeRelation<'tcx> for Lub<'_, '_, 'tcx> {
|
|||
self.fields.tcx()
|
||||
}
|
||||
|
||||
fn relate_with_variance<T: Relate<'tcx>>(
|
||||
fn relate_with_variance<T: Relate<TyCtxt<'tcx>>>(
|
||||
&mut self,
|
||||
variance: ty::Variance,
|
||||
_info: ty::VarianceDiagInfo<'tcx>,
|
||||
_info: ty::VarianceDiagInfo<TyCtxt<'tcx>>,
|
||||
a: T,
|
||||
b: T,
|
||||
) -> RelateResult<'tcx, T> {
|
||||
|
@ -81,7 +81,7 @@ impl<'tcx> TypeRelation<'tcx> for Lub<'_, '_, 'tcx> {
|
|||
b: ty::Binder<'tcx, T>,
|
||||
) -> RelateResult<'tcx, ty::Binder<'tcx, T>>
|
||||
where
|
||||
T: Relate<'tcx>,
|
||||
T: Relate<TyCtxt<'tcx>>,
|
||||
{
|
||||
// LUB of a binder and itself is just itself
|
||||
if a == b {
|
||||
|
|
|
@ -1,6 +1,14 @@
|
|||
//! This module contains the definitions of most `TypeRelation`s in the type system
|
||||
//! (except for some relations used for diagnostics and heuristics in the compiler).
|
||||
//! As well as the implementation of `Relate` for interned things (`Ty`/`Const`/etc).
|
||||
|
||||
pub use rustc_middle::ty::relate::*;
|
||||
|
||||
pub use self::_match::MatchAgainstFreshVars;
|
||||
pub use self::combine::CombineFields;
|
||||
pub use self::combine::ObligationEmittingRelation;
|
||||
|
||||
pub mod _match;
|
||||
pub(super) mod combine;
|
||||
mod generalize;
|
||||
mod glb;
|
||||
|
@ -8,15 +16,3 @@ mod higher_ranked;
|
|||
mod lattice;
|
||||
mod lub;
|
||||
mod type_relating;
|
||||
|
||||
/// Whether aliases should be related structurally or not. Used
|
||||
/// to adjust the behavior of generalization and combine.
|
||||
///
|
||||
/// This should always be `No` unless in a few special-cases when
|
||||
/// instantiating canonical responses and in the new solver. Each
|
||||
/// such case should have a comment explaining why it is used.
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub enum StructurallyRelateAliases {
|
||||
Yes,
|
||||
No,
|
||||
}
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
use super::combine::CombineFields;
|
||||
use crate::infer::BoundRegionConversionTime::HigherRankedType;
|
||||
use crate::infer::{
|
||||
DefineOpaqueTypes, ObligationEmittingRelation, StructurallyRelateAliases, SubregionOrigin,
|
||||
};
|
||||
use crate::infer::{DefineOpaqueTypes, SubregionOrigin};
|
||||
use crate::traits::{Obligation, PredicateObligations};
|
||||
|
||||
use rustc_middle::ty::relate::{
|
||||
relate_args_invariantly, relate_args_with_variances, Relate, RelateResult, TypeRelation,
|
||||
use super::{
|
||||
relate_args_invariantly, relate_args_with_variances, ObligationEmittingRelation, Relate,
|
||||
RelateResult, StructurallyRelateAliases, TypeRelation,
|
||||
};
|
||||
use rustc_middle::ty::TyVar;
|
||||
use rustc_middle::ty::{self, Ty, TyCtxt};
|
||||
|
@ -29,7 +28,7 @@ impl<'combine, 'infcx, 'tcx> TypeRelating<'combine, 'infcx, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'tcx> TypeRelation<'tcx> for TypeRelating<'_, '_, 'tcx> {
|
||||
impl<'tcx> TypeRelation<TyCtxt<'tcx>> for TypeRelating<'_, '_, 'tcx> {
|
||||
fn tag(&self) -> &'static str {
|
||||
"TypeRelating"
|
||||
}
|
||||
|
@ -56,10 +55,10 @@ impl<'tcx> TypeRelation<'tcx> for TypeRelating<'_, '_, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
fn relate_with_variance<T: Relate<'tcx>>(
|
||||
fn relate_with_variance<T: Relate<TyCtxt<'tcx>>>(
|
||||
&mut self,
|
||||
variance: ty::Variance,
|
||||
_info: ty::VarianceDiagInfo<'tcx>,
|
||||
_info: ty::VarianceDiagInfo<TyCtxt<'tcx>>,
|
||||
a: T,
|
||||
b: T,
|
||||
) -> RelateResult<'tcx, T> {
|
||||
|
@ -226,7 +225,7 @@ impl<'tcx> TypeRelation<'tcx> for TypeRelating<'_, '_, 'tcx> {
|
|||
b: ty::Binder<'tcx, T>,
|
||||
) -> RelateResult<'tcx, ty::Binder<'tcx, T>>
|
||||
where
|
||||
T: Relate<'tcx>,
|
||||
T: Relate<TyCtxt<'tcx>>,
|
||||
{
|
||||
if a == b {
|
||||
// Do nothing
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue