Rollup merge of #117091 - compiler-errors:debug, r=lcnr
`OptWithInfcx` naming nits, trait bound simplifications
* Use an associated type `Interner` on `InferCtxtLike` to remove a redundant interner parameter (`I: Interner, Infcx: InferCtxtLike<I>` -> `Infcx: InferCtxtLike`).
* Remove double-`Option` between `infcx: Option<Infcx>` and `fn universe_of_ty(&self, ty: ty::InferTy) -> Option<ty::UniverseIndex>`. We don't need the infcx to be optional if we can provide a "noop" (`NoInfcx`) implementation that just always returns `None` for universe index.
* Also removes the `core::convert::Infallible` implementation which I found a bit weird...
* Some naming nits with params.
* I found `InferCtxt` + `InfCtx` and `Infcx` to be a lot of different ways to spell "inference context", so I got rid of the `InfCtx` type parameter name in favor of `Infcx` which is a more standard name.
* I found `OptWithInfcx` to be a bit redundant -> `WithInfcx`.
I'm making these changes because I intend to reuse the `InferCtxtLike` trait for uplifting the canonicalizer into a new trait -- conveniently, the information I need for uplifting the canonicalizer also is just the universe information of a type var, so it's super convenient 😸
r? `@BoxyUwU` or `@lcnr`
This commit is contained in:
commit
cb651300ec
10 changed files with 100 additions and 89 deletions
|
@ -341,7 +341,9 @@ pub struct InferCtxt<'tcx> {
|
||||||
next_trait_solver: bool,
|
next_trait_solver: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> ty::InferCtxtLike<TyCtxt<'tcx>> for InferCtxt<'tcx> {
|
impl<'tcx> ty::InferCtxtLike for InferCtxt<'tcx> {
|
||||||
|
type Interner = TyCtxt<'tcx>;
|
||||||
|
|
||||||
fn universe_of_ty(&self, ty: ty::InferTy) -> Option<ty::UniverseIndex> {
|
fn universe_of_ty(&self, ty: ty::InferTy) -> Option<ty::UniverseIndex> {
|
||||||
use InferTy::*;
|
use InferTy::*;
|
||||||
match ty {
|
match ty {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::arena::Arena;
|
use crate::arena::Arena;
|
||||||
use rustc_data_structures::aligned::{align_of, Aligned};
|
use rustc_data_structures::aligned::{align_of, Aligned};
|
||||||
use rustc_serialize::{Encodable, Encoder};
|
use rustc_serialize::{Encodable, Encoder};
|
||||||
use rustc_type_ir::{InferCtxtLike, OptWithInfcx};
|
use rustc_type_ir::{InferCtxtLike, WithInfcx};
|
||||||
use std::alloc::Layout;
|
use std::alloc::Layout;
|
||||||
use std::cmp::Ordering;
|
use std::cmp::Ordering;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
@ -121,8 +121,8 @@ impl<T: fmt::Debug> fmt::Debug for List<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl<'tcx, T: super::DebugWithInfcx<TyCtxt<'tcx>>> super::DebugWithInfcx<TyCtxt<'tcx>> for List<T> {
|
impl<'tcx, T: super::DebugWithInfcx<TyCtxt<'tcx>>> super::DebugWithInfcx<TyCtxt<'tcx>> for List<T> {
|
||||||
fn fmt<InfCtx: InferCtxtLike<TyCtxt<'tcx>>>(
|
fn fmt<Infcx: InferCtxtLike<Interner = TyCtxt<'tcx>>>(
|
||||||
this: OptWithInfcx<'_, TyCtxt<'tcx>, InfCtx, &Self>,
|
this: WithInfcx<'_, Infcx, &Self>,
|
||||||
f: &mut core::fmt::Formatter<'_>,
|
f: &mut core::fmt::Formatter<'_>,
|
||||||
) -> core::fmt::Result {
|
) -> core::fmt::Result {
|
||||||
fmt::Debug::fmt(&this.map(|this| this.as_slice()), f)
|
fmt::Debug::fmt(&this.map(|this| this.as_slice()), f)
|
||||||
|
|
|
@ -54,7 +54,7 @@ use rustc_span::symbol::{kw, sym, Ident, Symbol};
|
||||||
use rustc_span::{ExpnId, ExpnKind, Span};
|
use rustc_span::{ExpnId, ExpnKind, Span};
|
||||||
use rustc_target::abi::{Align, FieldIdx, Integer, IntegerType, VariantIdx};
|
use rustc_target::abi::{Align, FieldIdx, Integer, IntegerType, VariantIdx};
|
||||||
pub use rustc_target::abi::{ReprFlags, ReprOptions};
|
pub use rustc_target::abi::{ReprFlags, ReprOptions};
|
||||||
pub use rustc_type_ir::{DebugWithInfcx, InferCtxtLike, OptWithInfcx};
|
pub use rustc_type_ir::{DebugWithInfcx, InferCtxtLike, WithInfcx};
|
||||||
pub use vtable::*;
|
pub use vtable::*;
|
||||||
|
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
|
|
|
@ -10,7 +10,7 @@ use crate::ty::visit::{TypeSuperVisitable, TypeVisitable, TypeVisitor};
|
||||||
use crate::ty::{self, AliasTy, InferConst, Lift, Term, TermKind, Ty, TyCtxt};
|
use crate::ty::{self, AliasTy, InferConst, Lift, Term, TermKind, Ty, TyCtxt};
|
||||||
use rustc_hir::def::Namespace;
|
use rustc_hir::def::Namespace;
|
||||||
use rustc_target::abi::TyAndLayout;
|
use rustc_target::abi::TyAndLayout;
|
||||||
use rustc_type_ir::{ConstKind, DebugWithInfcx, InferCtxtLike, OptWithInfcx};
|
use rustc_type_ir::{ConstKind, DebugWithInfcx, InferCtxtLike, WithInfcx};
|
||||||
|
|
||||||
use std::fmt::{self, Debug};
|
use std::fmt::{self, Debug};
|
||||||
use std::ops::ControlFlow;
|
use std::ops::ControlFlow;
|
||||||
|
@ -87,12 +87,12 @@ impl fmt::Debug for ty::FreeRegion {
|
||||||
|
|
||||||
impl<'tcx> fmt::Debug for ty::FnSig<'tcx> {
|
impl<'tcx> fmt::Debug for ty::FnSig<'tcx> {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
OptWithInfcx::new_no_ctx(self).fmt(f)
|
WithInfcx::with_no_infcx(self).fmt(f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl<'tcx> DebugWithInfcx<TyCtxt<'tcx>> for ty::FnSig<'tcx> {
|
impl<'tcx> DebugWithInfcx<TyCtxt<'tcx>> for ty::FnSig<'tcx> {
|
||||||
fn fmt<InfCtx: InferCtxtLike<TyCtxt<'tcx>>>(
|
fn fmt<Infcx: InferCtxtLike<Interner = TyCtxt<'tcx>>>(
|
||||||
this: OptWithInfcx<'_, TyCtxt<'tcx>, InfCtx, &Self>,
|
this: WithInfcx<'_, Infcx, &Self>,
|
||||||
f: &mut core::fmt::Formatter<'_>,
|
f: &mut core::fmt::Formatter<'_>,
|
||||||
) -> core::fmt::Result {
|
) -> core::fmt::Result {
|
||||||
let sig = this.data;
|
let sig = this.data;
|
||||||
|
@ -147,8 +147,8 @@ impl<'tcx> fmt::Debug for ty::TraitRef<'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> ty::DebugWithInfcx<TyCtxt<'tcx>> for Ty<'tcx> {
|
impl<'tcx> ty::DebugWithInfcx<TyCtxt<'tcx>> for Ty<'tcx> {
|
||||||
fn fmt<InfCtx: InferCtxtLike<TyCtxt<'tcx>>>(
|
fn fmt<Infcx: InferCtxtLike<Interner = TyCtxt<'tcx>>>(
|
||||||
this: OptWithInfcx<'_, TyCtxt<'tcx>, InfCtx, &Self>,
|
this: WithInfcx<'_, Infcx, &Self>,
|
||||||
f: &mut core::fmt::Formatter<'_>,
|
f: &mut core::fmt::Formatter<'_>,
|
||||||
) -> core::fmt::Result {
|
) -> core::fmt::Result {
|
||||||
this.data.fmt(f)
|
this.data.fmt(f)
|
||||||
|
@ -236,12 +236,12 @@ impl<'tcx> fmt::Debug for ty::PredicateKind<'tcx> {
|
||||||
|
|
||||||
impl<'tcx> fmt::Debug for AliasTy<'tcx> {
|
impl<'tcx> fmt::Debug for AliasTy<'tcx> {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
OptWithInfcx::new_no_ctx(self).fmt(f)
|
WithInfcx::with_no_infcx(self).fmt(f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl<'tcx> DebugWithInfcx<TyCtxt<'tcx>> for AliasTy<'tcx> {
|
impl<'tcx> DebugWithInfcx<TyCtxt<'tcx>> for AliasTy<'tcx> {
|
||||||
fn fmt<InfCtx: InferCtxtLike<TyCtxt<'tcx>>>(
|
fn fmt<Infcx: InferCtxtLike<Interner = TyCtxt<'tcx>>>(
|
||||||
this: OptWithInfcx<'_, TyCtxt<'tcx>, InfCtx, &Self>,
|
this: WithInfcx<'_, Infcx, &Self>,
|
||||||
f: &mut core::fmt::Formatter<'_>,
|
f: &mut core::fmt::Formatter<'_>,
|
||||||
) -> core::fmt::Result {
|
) -> core::fmt::Result {
|
||||||
f.debug_struct("AliasTy")
|
f.debug_struct("AliasTy")
|
||||||
|
@ -261,12 +261,12 @@ impl<'tcx> fmt::Debug for ty::InferConst<'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl<'tcx> DebugWithInfcx<TyCtxt<'tcx>> for ty::InferConst<'tcx> {
|
impl<'tcx> DebugWithInfcx<TyCtxt<'tcx>> for ty::InferConst<'tcx> {
|
||||||
fn fmt<InfCtx: InferCtxtLike<TyCtxt<'tcx>>>(
|
fn fmt<Infcx: InferCtxtLike<Interner = TyCtxt<'tcx>>>(
|
||||||
this: OptWithInfcx<'_, TyCtxt<'tcx>, InfCtx, &Self>,
|
this: WithInfcx<'_, Infcx, &Self>,
|
||||||
f: &mut core::fmt::Formatter<'_>,
|
f: &mut core::fmt::Formatter<'_>,
|
||||||
) -> core::fmt::Result {
|
) -> core::fmt::Result {
|
||||||
use ty::InferConst::*;
|
use ty::InferConst::*;
|
||||||
match this.infcx.and_then(|infcx| infcx.universe_of_ct(*this.data)) {
|
match this.infcx.universe_of_ct(*this.data) {
|
||||||
None => write!(f, "{:?}", this.data),
|
None => write!(f, "{:?}", this.data),
|
||||||
Some(universe) => match *this.data {
|
Some(universe) => match *this.data {
|
||||||
Var(vid) => write!(f, "?{}_{}c", vid.index, universe.index()),
|
Var(vid) => write!(f, "?{}_{}c", vid.index, universe.index()),
|
||||||
|
@ -281,12 +281,12 @@ impl<'tcx> DebugWithInfcx<TyCtxt<'tcx>> for ty::InferConst<'tcx> {
|
||||||
|
|
||||||
impl<'tcx> fmt::Debug for ty::consts::Expr<'tcx> {
|
impl<'tcx> fmt::Debug for ty::consts::Expr<'tcx> {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
OptWithInfcx::new_no_ctx(self).fmt(f)
|
WithInfcx::with_no_infcx(self).fmt(f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl<'tcx> DebugWithInfcx<TyCtxt<'tcx>> for ty::consts::Expr<'tcx> {
|
impl<'tcx> DebugWithInfcx<TyCtxt<'tcx>> for ty::consts::Expr<'tcx> {
|
||||||
fn fmt<InfCtx: InferCtxtLike<TyCtxt<'tcx>>>(
|
fn fmt<Infcx: InferCtxtLike<Interner = TyCtxt<'tcx>>>(
|
||||||
this: OptWithInfcx<'_, TyCtxt<'tcx>, InfCtx, &Self>,
|
this: WithInfcx<'_, Infcx, &Self>,
|
||||||
f: &mut core::fmt::Formatter<'_>,
|
f: &mut core::fmt::Formatter<'_>,
|
||||||
) -> core::fmt::Result {
|
) -> core::fmt::Result {
|
||||||
match this.data {
|
match this.data {
|
||||||
|
@ -314,12 +314,12 @@ impl<'tcx> DebugWithInfcx<TyCtxt<'tcx>> for ty::consts::Expr<'tcx> {
|
||||||
|
|
||||||
impl<'tcx> fmt::Debug for ty::UnevaluatedConst<'tcx> {
|
impl<'tcx> fmt::Debug for ty::UnevaluatedConst<'tcx> {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
OptWithInfcx::new_no_ctx(self).fmt(f)
|
WithInfcx::with_no_infcx(self).fmt(f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl<'tcx> DebugWithInfcx<TyCtxt<'tcx>> for ty::UnevaluatedConst<'tcx> {
|
impl<'tcx> DebugWithInfcx<TyCtxt<'tcx>> for ty::UnevaluatedConst<'tcx> {
|
||||||
fn fmt<InfCtx: InferCtxtLike<TyCtxt<'tcx>>>(
|
fn fmt<Infcx: InferCtxtLike<Interner = TyCtxt<'tcx>>>(
|
||||||
this: OptWithInfcx<'_, TyCtxt<'tcx>, InfCtx, &Self>,
|
this: WithInfcx<'_, Infcx, &Self>,
|
||||||
f: &mut core::fmt::Formatter<'_>,
|
f: &mut core::fmt::Formatter<'_>,
|
||||||
) -> core::fmt::Result {
|
) -> core::fmt::Result {
|
||||||
f.debug_struct("UnevaluatedConst")
|
f.debug_struct("UnevaluatedConst")
|
||||||
|
@ -331,12 +331,12 @@ impl<'tcx> DebugWithInfcx<TyCtxt<'tcx>> for ty::UnevaluatedConst<'tcx> {
|
||||||
|
|
||||||
impl<'tcx> fmt::Debug for ty::Const<'tcx> {
|
impl<'tcx> fmt::Debug for ty::Const<'tcx> {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
OptWithInfcx::new_no_ctx(self).fmt(f)
|
WithInfcx::with_no_infcx(self).fmt(f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl<'tcx> DebugWithInfcx<TyCtxt<'tcx>> for ty::Const<'tcx> {
|
impl<'tcx> DebugWithInfcx<TyCtxt<'tcx>> for ty::Const<'tcx> {
|
||||||
fn fmt<InfCtx: InferCtxtLike<TyCtxt<'tcx>>>(
|
fn fmt<Infcx: InferCtxtLike<Interner = TyCtxt<'tcx>>>(
|
||||||
this: OptWithInfcx<'_, TyCtxt<'tcx>, InfCtx, &Self>,
|
this: WithInfcx<'_, Infcx, &Self>,
|
||||||
f: &mut core::fmt::Formatter<'_>,
|
f: &mut core::fmt::Formatter<'_>,
|
||||||
) -> core::fmt::Result {
|
) -> core::fmt::Result {
|
||||||
// If this is a value, we spend some effort to make it look nice.
|
// If this is a value, we spend some effort to make it look nice.
|
||||||
|
@ -392,8 +392,8 @@ impl<'tcx> fmt::Debug for GenericArg<'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl<'tcx> DebugWithInfcx<TyCtxt<'tcx>> for GenericArg<'tcx> {
|
impl<'tcx> DebugWithInfcx<TyCtxt<'tcx>> for GenericArg<'tcx> {
|
||||||
fn fmt<InfCtx: InferCtxtLike<TyCtxt<'tcx>>>(
|
fn fmt<Infcx: InferCtxtLike<Interner = TyCtxt<'tcx>>>(
|
||||||
this: OptWithInfcx<'_, TyCtxt<'tcx>, InfCtx, &Self>,
|
this: WithInfcx<'_, Infcx, &Self>,
|
||||||
f: &mut core::fmt::Formatter<'_>,
|
f: &mut core::fmt::Formatter<'_>,
|
||||||
) -> core::fmt::Result {
|
) -> core::fmt::Result {
|
||||||
match this.data.unpack() {
|
match this.data.unpack() {
|
||||||
|
@ -410,8 +410,8 @@ impl<'tcx> fmt::Debug for Region<'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl<'tcx> DebugWithInfcx<TyCtxt<'tcx>> for Region<'tcx> {
|
impl<'tcx> DebugWithInfcx<TyCtxt<'tcx>> for Region<'tcx> {
|
||||||
fn fmt<InfCtx: InferCtxtLike<TyCtxt<'tcx>>>(
|
fn fmt<Infcx: InferCtxtLike<Interner = TyCtxt<'tcx>>>(
|
||||||
this: OptWithInfcx<'_, TyCtxt<'tcx>, InfCtx, &Self>,
|
this: WithInfcx<'_, Infcx, &Self>,
|
||||||
f: &mut core::fmt::Formatter<'_>,
|
f: &mut core::fmt::Formatter<'_>,
|
||||||
) -> core::fmt::Result {
|
) -> core::fmt::Result {
|
||||||
write!(f, "{:?}", &this.map(|data| data.kind()))
|
write!(f, "{:?}", &this.map(|data| data.kind()))
|
||||||
|
@ -419,11 +419,11 @@ impl<'tcx> DebugWithInfcx<TyCtxt<'tcx>> for Region<'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> DebugWithInfcx<TyCtxt<'tcx>> for ty::RegionVid {
|
impl<'tcx> DebugWithInfcx<TyCtxt<'tcx>> for ty::RegionVid {
|
||||||
fn fmt<InfCtx: InferCtxtLike<TyCtxt<'tcx>>>(
|
fn fmt<Infcx: InferCtxtLike<Interner = TyCtxt<'tcx>>>(
|
||||||
this: OptWithInfcx<'_, TyCtxt<'tcx>, InfCtx, &Self>,
|
this: WithInfcx<'_, Infcx, &Self>,
|
||||||
f: &mut core::fmt::Formatter<'_>,
|
f: &mut core::fmt::Formatter<'_>,
|
||||||
) -> core::fmt::Result {
|
) -> core::fmt::Result {
|
||||||
match this.infcx.and_then(|infcx| infcx.universe_of_lt(*this.data)) {
|
match this.infcx.universe_of_lt(*this.data) {
|
||||||
Some(universe) => write!(f, "'?{}_{}", this.data.index(), universe.index()),
|
Some(universe) => write!(f, "'?{}_{}", this.data.index(), universe.index()),
|
||||||
None => write!(f, "{:?}", this.data),
|
None => write!(f, "{:?}", this.data),
|
||||||
}
|
}
|
||||||
|
@ -431,8 +431,8 @@ impl<'tcx> DebugWithInfcx<TyCtxt<'tcx>> for ty::RegionVid {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx, T: DebugWithInfcx<TyCtxt<'tcx>>> DebugWithInfcx<TyCtxt<'tcx>> for ty::Binder<'tcx, T> {
|
impl<'tcx, T: DebugWithInfcx<TyCtxt<'tcx>>> DebugWithInfcx<TyCtxt<'tcx>> for ty::Binder<'tcx, T> {
|
||||||
fn fmt<InfCtx: InferCtxtLike<TyCtxt<'tcx>>>(
|
fn fmt<Infcx: InferCtxtLike<Interner = TyCtxt<'tcx>>>(
|
||||||
this: OptWithInfcx<'_, TyCtxt<'tcx>, InfCtx, &Self>,
|
this: WithInfcx<'_, Infcx, &Self>,
|
||||||
f: &mut core::fmt::Formatter<'_>,
|
f: &mut core::fmt::Formatter<'_>,
|
||||||
) -> core::fmt::Result {
|
) -> core::fmt::Result {
|
||||||
f.debug_tuple("Binder")
|
f.debug_tuple("Binder")
|
||||||
|
|
|
@ -683,8 +683,8 @@ pub enum ExistentialPredicate<'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> DebugWithInfcx<TyCtxt<'tcx>> for ExistentialPredicate<'tcx> {
|
impl<'tcx> DebugWithInfcx<TyCtxt<'tcx>> for ExistentialPredicate<'tcx> {
|
||||||
fn fmt<InfCtx: rustc_type_ir::InferCtxtLike<TyCtxt<'tcx>>>(
|
fn fmt<Infcx: rustc_type_ir::InferCtxtLike<Interner = TyCtxt<'tcx>>>(
|
||||||
this: rustc_type_ir::OptWithInfcx<'_, TyCtxt<'tcx>, InfCtx, &Self>,
|
this: rustc_type_ir::WithInfcx<'_, Infcx, &Self>,
|
||||||
f: &mut core::fmt::Formatter<'_>,
|
f: &mut core::fmt::Formatter<'_>,
|
||||||
) -> core::fmt::Result {
|
) -> core::fmt::Result {
|
||||||
fmt::Debug::fmt(&this.data, f)
|
fmt::Debug::fmt(&this.data, f)
|
||||||
|
|
|
@ -5,8 +5,8 @@ use std::fmt;
|
||||||
use std::hash;
|
use std::hash;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
DebruijnIndex, DebugWithInfcx, HashStableContext, InferCtxtLike, Interner, OptWithInfcx,
|
DebruijnIndex, DebugWithInfcx, HashStableContext, InferCtxtLike, Interner, TyDecoder,
|
||||||
TyDecoder, TyEncoder,
|
TyEncoder, WithInfcx,
|
||||||
};
|
};
|
||||||
|
|
||||||
use self::ConstKind::*;
|
use self::ConstKind::*;
|
||||||
|
@ -231,13 +231,13 @@ impl<I: Interner> Clone for ConstKind<I> {
|
||||||
|
|
||||||
impl<I: Interner> fmt::Debug for ConstKind<I> {
|
impl<I: Interner> fmt::Debug for ConstKind<I> {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
OptWithInfcx::new_no_ctx(self).fmt(f)
|
WithInfcx::with_no_infcx(self).fmt(f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<I: Interner> DebugWithInfcx<I> for ConstKind<I> {
|
impl<I: Interner> DebugWithInfcx<I> for ConstKind<I> {
|
||||||
fn fmt<InfCtx: InferCtxtLike<I>>(
|
fn fmt<Infcx: InferCtxtLike<Interner = I>>(
|
||||||
this: OptWithInfcx<'_, I, InfCtx, &Self>,
|
this: WithInfcx<'_, Infcx, &Self>,
|
||||||
f: &mut core::fmt::Formatter<'_>,
|
f: &mut core::fmt::Formatter<'_>,
|
||||||
) -> core::fmt::Result {
|
) -> core::fmt::Result {
|
||||||
use ConstKind::*;
|
use ConstKind::*;
|
||||||
|
|
|
@ -3,38 +3,48 @@ use crate::{Interner, UniverseIndex};
|
||||||
use core::fmt;
|
use core::fmt;
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
|
||||||
pub trait InferCtxtLike<I: Interner> {
|
pub trait InferCtxtLike {
|
||||||
fn universe_of_ty(&self, ty: I::InferTy) -> Option<UniverseIndex>;
|
type Interner: Interner;
|
||||||
|
|
||||||
fn universe_of_lt(&self, lt: I::InferRegion) -> Option<UniverseIndex>;
|
fn universe_of_ty(&self, ty: <Self::Interner as Interner>::InferTy) -> Option<UniverseIndex>;
|
||||||
|
|
||||||
fn universe_of_ct(&self, ct: I::InferConst) -> Option<UniverseIndex>;
|
fn universe_of_lt(
|
||||||
|
&self,
|
||||||
|
lt: <Self::Interner as Interner>::InferRegion,
|
||||||
|
) -> Option<UniverseIndex>;
|
||||||
|
|
||||||
|
fn universe_of_ct(&self, ct: <Self::Interner as Interner>::InferConst)
|
||||||
|
-> Option<UniverseIndex>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<I: Interner> InferCtxtLike<I> for core::convert::Infallible {
|
pub struct NoInfcx<I>(PhantomData<I>);
|
||||||
|
|
||||||
|
impl<I: Interner> InferCtxtLike for NoInfcx<I> {
|
||||||
|
type Interner = I;
|
||||||
|
|
||||||
fn universe_of_ty(&self, _ty: <I as Interner>::InferTy) -> Option<UniverseIndex> {
|
fn universe_of_ty(&self, _ty: <I as Interner>::InferTy) -> Option<UniverseIndex> {
|
||||||
match *self {}
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
fn universe_of_ct(&self, _ct: <I as Interner>::InferConst) -> Option<UniverseIndex> {
|
fn universe_of_ct(&self, _ct: <I as Interner>::InferConst) -> Option<UniverseIndex> {
|
||||||
match *self {}
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
fn universe_of_lt(&self, _lt: <I as Interner>::InferRegion) -> Option<UniverseIndex> {
|
fn universe_of_lt(&self, _lt: <I as Interner>::InferRegion) -> Option<UniverseIndex> {
|
||||||
match *self {}
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait DebugWithInfcx<I: Interner>: fmt::Debug {
|
pub trait DebugWithInfcx<I: Interner>: fmt::Debug {
|
||||||
fn fmt<InfCtx: InferCtxtLike<I>>(
|
fn fmt<Infcx: InferCtxtLike<Interner = I>>(
|
||||||
this: OptWithInfcx<'_, I, InfCtx, &Self>,
|
this: WithInfcx<'_, Infcx, &Self>,
|
||||||
f: &mut fmt::Formatter<'_>,
|
f: &mut fmt::Formatter<'_>,
|
||||||
) -> fmt::Result;
|
) -> fmt::Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<I: Interner, T: DebugWithInfcx<I> + ?Sized> DebugWithInfcx<I> for &'_ T {
|
impl<I: Interner, T: DebugWithInfcx<I> + ?Sized> DebugWithInfcx<I> for &'_ T {
|
||||||
fn fmt<InfCtx: InferCtxtLike<I>>(
|
fn fmt<Infcx: InferCtxtLike<Interner = I>>(
|
||||||
this: OptWithInfcx<'_, I, InfCtx, &Self>,
|
this: WithInfcx<'_, Infcx, &Self>,
|
||||||
f: &mut fmt::Formatter<'_>,
|
f: &mut fmt::Formatter<'_>,
|
||||||
) -> fmt::Result {
|
) -> fmt::Result {
|
||||||
<T as DebugWithInfcx<I>>::fmt(this.map(|&data| data), f)
|
<T as DebugWithInfcx<I>>::fmt(this.map(|&data| data), f)
|
||||||
|
@ -42,8 +52,8 @@ impl<I: Interner, T: DebugWithInfcx<I> + ?Sized> DebugWithInfcx<I> for &'_ T {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<I: Interner, T: DebugWithInfcx<I>> DebugWithInfcx<I> for [T] {
|
impl<I: Interner, T: DebugWithInfcx<I>> DebugWithInfcx<I> for [T] {
|
||||||
fn fmt<InfCtx: InferCtxtLike<I>>(
|
fn fmt<Infcx: InferCtxtLike<Interner = I>>(
|
||||||
this: OptWithInfcx<'_, I, InfCtx, &Self>,
|
this: WithInfcx<'_, Infcx, &Self>,
|
||||||
f: &mut fmt::Formatter<'_>,
|
f: &mut fmt::Formatter<'_>,
|
||||||
) -> fmt::Result {
|
) -> fmt::Result {
|
||||||
match f.alternate() {
|
match f.alternate() {
|
||||||
|
@ -70,46 +80,45 @@ impl<I: Interner, T: DebugWithInfcx<I>> DebugWithInfcx<I> for [T] {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct OptWithInfcx<'a, I: Interner, InfCtx: InferCtxtLike<I>, T> {
|
pub struct WithInfcx<'a, Infcx: InferCtxtLike, T> {
|
||||||
pub data: T,
|
pub data: T,
|
||||||
pub infcx: Option<&'a InfCtx>,
|
pub infcx: &'a Infcx,
|
||||||
_interner: PhantomData<I>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<I: Interner, InfCtx: InferCtxtLike<I>, T: Copy> Copy for OptWithInfcx<'_, I, InfCtx, T> {}
|
impl<Infcx: InferCtxtLike, T: Copy> Copy for WithInfcx<'_, Infcx, T> {}
|
||||||
|
|
||||||
impl<I: Interner, InfCtx: InferCtxtLike<I>, T: Clone> Clone for OptWithInfcx<'_, I, InfCtx, T> {
|
impl<Infcx: InferCtxtLike, T: Clone> Clone for WithInfcx<'_, Infcx, T> {
|
||||||
fn clone(&self) -> Self {
|
fn clone(&self) -> Self {
|
||||||
Self { data: self.data.clone(), infcx: self.infcx, _interner: self._interner }
|
Self { data: self.data.clone(), infcx: self.infcx }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, I: Interner, T> OptWithInfcx<'a, I, core::convert::Infallible, T> {
|
impl<'a, I: Interner, T> WithInfcx<'a, NoInfcx<I>, T> {
|
||||||
pub fn new_no_ctx(data: T) -> Self {
|
pub fn with_no_infcx(data: T) -> Self {
|
||||||
Self { data, infcx: None, _interner: PhantomData }
|
Self { data, infcx: &NoInfcx(PhantomData) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, I: Interner, InfCtx: InferCtxtLike<I>, T> OptWithInfcx<'a, I, InfCtx, T> {
|
impl<'a, Infcx: InferCtxtLike, T> WithInfcx<'a, Infcx, T> {
|
||||||
pub fn new(data: T, infcx: &'a InfCtx) -> Self {
|
pub fn new(data: T, infcx: &'a Infcx) -> Self {
|
||||||
Self { data, infcx: Some(infcx), _interner: PhantomData }
|
Self { data, infcx }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn wrap<U>(self, u: U) -> OptWithInfcx<'a, I, InfCtx, U> {
|
pub fn wrap<U>(self, u: U) -> WithInfcx<'a, Infcx, U> {
|
||||||
OptWithInfcx { data: u, infcx: self.infcx, _interner: PhantomData }
|
WithInfcx { data: u, infcx: self.infcx }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn map<U>(self, f: impl FnOnce(T) -> U) -> OptWithInfcx<'a, I, InfCtx, U> {
|
pub fn map<U>(self, f: impl FnOnce(T) -> U) -> WithInfcx<'a, Infcx, U> {
|
||||||
OptWithInfcx { data: f(self.data), infcx: self.infcx, _interner: PhantomData }
|
WithInfcx { data: f(self.data), infcx: self.infcx }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn as_ref(&self) -> OptWithInfcx<'a, I, InfCtx, &T> {
|
pub fn as_ref(&self) -> WithInfcx<'a, Infcx, &T> {
|
||||||
OptWithInfcx { data: &self.data, infcx: self.infcx, _interner: PhantomData }
|
WithInfcx { data: &self.data, infcx: self.infcx }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<I: Interner, InfCtx: InferCtxtLike<I>, T: DebugWithInfcx<I>> fmt::Debug
|
impl<Infcx: InferCtxtLike, T: DebugWithInfcx<Infcx::Interner>> fmt::Debug
|
||||||
for OptWithInfcx<'_, I, InfCtx, T>
|
for WithInfcx<'_, Infcx, T>
|
||||||
{
|
{
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
DebugWithInfcx::fmt(self.as_ref(), f)
|
DebugWithInfcx::fmt(self.as_ref(), f)
|
||||||
|
|
|
@ -34,7 +34,7 @@ mod region_kind;
|
||||||
|
|
||||||
pub use codec::*;
|
pub use codec::*;
|
||||||
pub use const_kind::*;
|
pub use const_kind::*;
|
||||||
pub use debug::{DebugWithInfcx, InferCtxtLike, OptWithInfcx};
|
pub use debug::{DebugWithInfcx, InferCtxtLike, WithInfcx};
|
||||||
pub use flags::*;
|
pub use flags::*;
|
||||||
pub use interner::*;
|
pub use interner::*;
|
||||||
pub use region_kind::*;
|
pub use region_kind::*;
|
||||||
|
|
|
@ -5,8 +5,8 @@ use std::fmt;
|
||||||
use std::hash;
|
use std::hash;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
DebruijnIndex, DebugWithInfcx, HashStableContext, InferCtxtLike, Interner, OptWithInfcx,
|
DebruijnIndex, DebugWithInfcx, HashStableContext, InferCtxtLike, Interner, TyDecoder,
|
||||||
TyDecoder, TyEncoder,
|
TyEncoder, WithInfcx,
|
||||||
};
|
};
|
||||||
|
|
||||||
use self::RegionKind::*;
|
use self::RegionKind::*;
|
||||||
|
@ -274,8 +274,8 @@ impl<I: Interner> hash::Hash for RegionKind<I> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<I: Interner> DebugWithInfcx<I> for RegionKind<I> {
|
impl<I: Interner> DebugWithInfcx<I> for RegionKind<I> {
|
||||||
fn fmt<InfCtx: InferCtxtLike<I>>(
|
fn fmt<Infcx: InferCtxtLike<Interner = I>>(
|
||||||
this: OptWithInfcx<'_, I, InfCtx, &Self>,
|
this: WithInfcx<'_, Infcx, &Self>,
|
||||||
f: &mut core::fmt::Formatter<'_>,
|
f: &mut core::fmt::Formatter<'_>,
|
||||||
) -> core::fmt::Result {
|
) -> core::fmt::Result {
|
||||||
match this.data {
|
match this.data {
|
||||||
|
@ -301,7 +301,7 @@ impl<I: Interner> DebugWithInfcx<I> for RegionKind<I> {
|
||||||
}
|
}
|
||||||
impl<I: Interner> fmt::Debug for RegionKind<I> {
|
impl<I: Interner> fmt::Debug for RegionKind<I> {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
OptWithInfcx::new_no_ctx(self).fmt(f)
|
WithInfcx::with_no_infcx(self).fmt(f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ use crate::HashStableContext;
|
||||||
use crate::Interner;
|
use crate::Interner;
|
||||||
use crate::TyDecoder;
|
use crate::TyDecoder;
|
||||||
use crate::TyEncoder;
|
use crate::TyEncoder;
|
||||||
use crate::{DebruijnIndex, DebugWithInfcx, InferCtxtLike, OptWithInfcx};
|
use crate::{DebruijnIndex, DebugWithInfcx, InferCtxtLike, WithInfcx};
|
||||||
|
|
||||||
use self::TyKind::*;
|
use self::TyKind::*;
|
||||||
|
|
||||||
|
@ -534,8 +534,8 @@ impl<I: Interner> hash::Hash for TyKind<I> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<I: Interner> DebugWithInfcx<I> for TyKind<I> {
|
impl<I: Interner> DebugWithInfcx<I> for TyKind<I> {
|
||||||
fn fmt<InfCtx: InferCtxtLike<I>>(
|
fn fmt<Infcx: InferCtxtLike<Interner = I>>(
|
||||||
this: OptWithInfcx<'_, I, InfCtx, &Self>,
|
this: WithInfcx<'_, Infcx, &Self>,
|
||||||
f: &mut core::fmt::Formatter<'_>,
|
f: &mut core::fmt::Formatter<'_>,
|
||||||
) -> fmt::Result {
|
) -> fmt::Result {
|
||||||
match this.data {
|
match this.data {
|
||||||
|
@ -617,7 +617,7 @@ impl<I: Interner> DebugWithInfcx<I> for TyKind<I> {
|
||||||
// This is manually implemented because a derive would require `I: Debug`
|
// This is manually implemented because a derive would require `I: Debug`
|
||||||
impl<I: Interner> fmt::Debug for TyKind<I> {
|
impl<I: Interner> fmt::Debug for TyKind<I> {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
OptWithInfcx::new_no_ctx(self).fmt(f)
|
WithInfcx::with_no_infcx(self).fmt(f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1239,12 +1239,12 @@ impl fmt::Debug for InferTy {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<I: Interner<InferTy = InferTy>> DebugWithInfcx<I> for InferTy {
|
impl<I: Interner<InferTy = InferTy>> DebugWithInfcx<I> for InferTy {
|
||||||
fn fmt<InfCtx: InferCtxtLike<I>>(
|
fn fmt<Infcx: InferCtxtLike<Interner = I>>(
|
||||||
this: OptWithInfcx<'_, I, InfCtx, &Self>,
|
this: WithInfcx<'_, Infcx, &Self>,
|
||||||
f: &mut fmt::Formatter<'_>,
|
f: &mut fmt::Formatter<'_>,
|
||||||
) -> fmt::Result {
|
) -> fmt::Result {
|
||||||
use InferTy::*;
|
use InferTy::*;
|
||||||
match this.infcx.and_then(|infcx| infcx.universe_of_ty(*this.data)) {
|
match this.infcx.universe_of_ty(*this.data) {
|
||||||
None => write!(f, "{:?}", this.data),
|
None => write!(f, "{:?}", this.data),
|
||||||
Some(universe) => match *this.data {
|
Some(universe) => match *this.data {
|
||||||
TyVar(ty_vid) => write!(f, "?{}_{}t", ty_vid.index(), universe.index()),
|
TyVar(ty_vid) => write!(f, "?{}_{}t", ty_vid.index(), universe.index()),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue