Bump chalk to 0.86
Two breaking changes: - `TypeFolder` has been split into `TypeFolder` and `FallibleTypeFolder` - `ProjectionTy::self_type_parameter()` has been removed
This commit is contained in:
parent
a0ab61fb6c
commit
310a72bf47
17
Cargo.lock
generated
17
Cargo.lock
generated
@ -171,9 +171,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "chalk-derive"
|
||||
version = "0.84.0"
|
||||
version = "0.86.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cf29c109d57f8d57b0e7675391be37a9285d86dd93278bd5f14a0ad3c447a6c2"
|
||||
checksum = "5499d415d855b5094366a824815341893ad3de0ecb6048c430118bdae6d27402"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@ -183,9 +183,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "chalk-ir"
|
||||
version = "0.84.0"
|
||||
version = "0.86.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d391763027b5e50a5e15caf6d2857ec585fd68160367bbeac9e1804209620918"
|
||||
checksum = "3800118c76a48507b0eece3a01f3a429b5c478d203c493096e6040c67ab960e1"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"chalk-derive",
|
||||
@ -194,9 +194,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "chalk-recursive"
|
||||
version = "0.84.0"
|
||||
version = "0.86.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "afafd92dcdc7fe0ea940ee94bdd8cc5bd18f4a4a84c593d6d7025fe16c150478"
|
||||
checksum = "1baf60628fd73104d1f8562586a52d48f37f1e84435aab2e62674b1fd935b8c8"
|
||||
dependencies = [
|
||||
"chalk-derive",
|
||||
"chalk-ir",
|
||||
@ -207,9 +207,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "chalk-solve"
|
||||
version = "0.84.0"
|
||||
version = "0.86.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3af1d111f11c91c48ace02e93e470c5bae6d2631bd112e4545317da53660d7fc"
|
||||
checksum = "0e9c3c068f9358786348e58a1b94ef0a5cf90a9810fc1f10fda896f0b5d80185"
|
||||
dependencies = [
|
||||
"chalk-derive",
|
||||
"chalk-ir",
|
||||
@ -546,6 +546,7 @@ version = "0.0.0"
|
||||
dependencies = [
|
||||
"arrayvec",
|
||||
"base-db",
|
||||
"chalk-derive",
|
||||
"chalk-ir",
|
||||
"chalk-recursive",
|
||||
"chalk-solve",
|
||||
|
@ -27,6 +27,7 @@ debug = 0
|
||||
# chalk-solve = { path = "../chalk/chalk-solve" }
|
||||
# chalk-ir = { path = "../chalk/chalk-ir" }
|
||||
# chalk-recursive = { path = "../chalk/chalk-recursive" }
|
||||
# chalk-derive = { path = "../chalk/chalk-derive" }
|
||||
|
||||
# ungrammar = { path = "../ungrammar" }
|
||||
|
||||
|
@ -18,9 +18,10 @@ ena = "0.14.0"
|
||||
tracing = "0.1.35"
|
||||
rustc-hash = "1.1.0"
|
||||
scoped-tls = "1.0.0"
|
||||
chalk-solve = { version = "0.84.0", default-features = false }
|
||||
chalk-ir = "0.84.0"
|
||||
chalk-recursive = { version = "0.84.0", default-features = false }
|
||||
chalk-solve = { version = "0.86.0", default-features = false }
|
||||
chalk-ir = "0.86.0"
|
||||
chalk-recursive = { version = "0.86.0", default-features = false }
|
||||
chalk-derive = "0.86.0"
|
||||
la-arena = { version = "0.3.0", path = "../../lib/la-arena" }
|
||||
once_cell = "1.12.0"
|
||||
typed-arena = "2.0.1"
|
||||
|
@ -823,10 +823,10 @@ pub(super) fn generic_predicate_to_inline_bound(
|
||||
Some(chalk_ir::Binders::new(binders, rust_ir::InlineBound::TraitBound(trait_bound)))
|
||||
}
|
||||
WhereClause::AliasEq(AliasEq { alias: AliasTy::Projection(projection_ty), ty }) => {
|
||||
if projection_ty.self_type_parameter(Interner) != self_ty_shifted_in {
|
||||
let trait_ = projection_ty.trait_(db);
|
||||
if projection_ty.self_type_parameter(db) != self_ty_shifted_in {
|
||||
return None;
|
||||
}
|
||||
let trait_ = projection_ty.trait_(db);
|
||||
let args_no_self = projection_ty.substitution.as_slice(Interner)[1..]
|
||||
.iter()
|
||||
.map(|ty| ty.clone().cast(Interner))
|
||||
|
@ -262,7 +262,7 @@ fn impl_trait_bounds(&self, db: &dyn HirDatabase) -> Option<Vec<QuantifiedWhereC
|
||||
WhereClause::AliasEq(AliasEq {
|
||||
alias: AliasTy::Projection(proj),
|
||||
ty: _,
|
||||
}) => &proj.self_type_parameter(Interner) == self,
|
||||
}) => &proj.self_type_parameter(db) == self,
|
||||
_ => false,
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
@ -333,6 +333,7 @@ fn equals_ctor(&self, other: &Ty) -> bool {
|
||||
pub trait ProjectionTyExt {
|
||||
fn trait_ref(&self, db: &dyn HirDatabase) -> TraitRef;
|
||||
fn trait_(&self, db: &dyn HirDatabase) -> TraitId;
|
||||
fn self_type_parameter(&self, db: &dyn HirDatabase) -> Ty;
|
||||
}
|
||||
|
||||
impl ProjectionTyExt for ProjectionTy {
|
||||
@ -349,6 +350,10 @@ fn trait_(&self, db: &dyn HirDatabase) -> TraitId {
|
||||
_ => panic!("projection ty without parent trait"),
|
||||
}
|
||||
}
|
||||
|
||||
fn self_type_parameter(&self, db: &dyn HirDatabase) -> Ty {
|
||||
self.trait_ref(db).self_type_parameter(Interner)
|
||||
}
|
||||
}
|
||||
|
||||
pub trait TraitRefExt {
|
||||
|
@ -291,7 +291,7 @@ fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> {
|
||||
|
||||
let trait_ = f.db.trait_data(self.trait_(f.db));
|
||||
write!(f, "<")?;
|
||||
self.self_type_parameter(Interner).hir_fmt(f)?;
|
||||
self.self_type_parameter(f.db).hir_fmt(f)?;
|
||||
write!(f, " as {}", trait_.name)?;
|
||||
if self.substitution.len(Interner) > 1 {
|
||||
write!(f, "<")?;
|
||||
@ -731,7 +731,7 @@ fn should_show(
|
||||
WhereClause::AliasEq(AliasEq {
|
||||
alias: AliasTy::Projection(proj),
|
||||
ty: _,
|
||||
}) => &proj.self_type_parameter(Interner) == self,
|
||||
}) => &proj.self_type_parameter(f.db) == self,
|
||||
_ => false,
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
use chalk_ir::{
|
||||
cast::Cast, fold::TypeFoldable, interner::HasInterner, zip::Zip, CanonicalVarKind, FloatTy,
|
||||
IntTy, NoSolution, TyVariableKind, UniverseIndex,
|
||||
IntTy, TyVariableKind, UniverseIndex,
|
||||
};
|
||||
use chalk_solve::infer::ParameterEnaVariableExt;
|
||||
use ena::unify::UnifyKey;
|
||||
@ -331,7 +331,6 @@ fn resolve_with_fallback_inner<T>(
|
||||
&mut resolve::Resolver { table: self, var_stack, fallback },
|
||||
DebruijnIndex::INNERMOST,
|
||||
)
|
||||
.expect("fold failed unexpectedly")
|
||||
}
|
||||
|
||||
pub(crate) fn resolve_completely<T>(&mut self, t: T) -> T
|
||||
@ -452,13 +451,14 @@ pub(crate) fn fudge_inference<T: TypeFoldable<Interner>>(
|
||||
f: impl FnOnce(&mut Self) -> T,
|
||||
) -> T {
|
||||
use chalk_ir::fold::TypeFolder;
|
||||
|
||||
#[derive(chalk_derive::FallibleTypeFolder)]
|
||||
#[has_interner(Interner)]
|
||||
struct VarFudger<'a, 'b> {
|
||||
table: &'a mut InferenceTable<'b>,
|
||||
highest_known_var: InferenceVar,
|
||||
}
|
||||
impl<'a, 'b> TypeFolder<Interner> for VarFudger<'a, 'b> {
|
||||
type Error = NoSolution;
|
||||
|
||||
fn as_dyn(&mut self) -> &mut dyn TypeFolder<Interner, Error = Self::Error> {
|
||||
self
|
||||
}
|
||||
@ -472,24 +472,24 @@ fn fold_inference_ty(
|
||||
var: chalk_ir::InferenceVar,
|
||||
kind: TyVariableKind,
|
||||
_outer_binder: chalk_ir::DebruijnIndex,
|
||||
) -> chalk_ir::Fallible<chalk_ir::Ty<Interner>> {
|
||||
Ok(if var < self.highest_known_var {
|
||||
) -> chalk_ir::Ty<Interner> {
|
||||
if var < self.highest_known_var {
|
||||
var.to_ty(Interner, kind)
|
||||
} else {
|
||||
self.table.new_type_var()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fn fold_inference_lifetime(
|
||||
&mut self,
|
||||
var: chalk_ir::InferenceVar,
|
||||
_outer_binder: chalk_ir::DebruijnIndex,
|
||||
) -> chalk_ir::Fallible<chalk_ir::Lifetime<Interner>> {
|
||||
Ok(if var < self.highest_known_var {
|
||||
) -> chalk_ir::Lifetime<Interner> {
|
||||
if var < self.highest_known_var {
|
||||
var.to_lifetime(Interner)
|
||||
} else {
|
||||
self.table.new_lifetime_var()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fn fold_inference_const(
|
||||
@ -497,12 +497,12 @@ fn fold_inference_const(
|
||||
ty: chalk_ir::Ty<Interner>,
|
||||
var: chalk_ir::InferenceVar,
|
||||
_outer_binder: chalk_ir::DebruijnIndex,
|
||||
) -> chalk_ir::Fallible<chalk_ir::Const<Interner>> {
|
||||
Ok(if var < self.highest_known_var {
|
||||
) -> chalk_ir::Const<Interner> {
|
||||
if var < self.highest_known_var {
|
||||
var.to_const(Interner, ty)
|
||||
} else {
|
||||
self.table.new_const_var(ty)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -512,7 +512,6 @@ fn fold_inference_const(
|
||||
self.rollback_to(snapshot);
|
||||
result
|
||||
.fold_with(&mut VarFudger { table: self, highest_known_var }, DebruijnIndex::INNERMOST)
|
||||
.expect("fold_with with VarFudger")
|
||||
}
|
||||
|
||||
/// This checks whether any of the free variables in the `canonicalized`
|
||||
@ -639,21 +638,24 @@ mod resolve {
|
||||
use chalk_ir::{
|
||||
cast::Cast,
|
||||
fold::{TypeFoldable, TypeFolder},
|
||||
Fallible, NoSolution,
|
||||
};
|
||||
use hir_def::type_ref::ConstScalar;
|
||||
|
||||
pub(super) struct Resolver<'a, 'b, F> {
|
||||
#[derive(chalk_derive::FallibleTypeFolder)]
|
||||
#[has_interner(Interner)]
|
||||
pub(super) struct Resolver<
|
||||
'a,
|
||||
'b,
|
||||
F: Fn(InferenceVar, VariableKind, GenericArg, DebruijnIndex) -> GenericArg,
|
||||
> {
|
||||
pub(super) table: &'a mut InferenceTable<'b>,
|
||||
pub(super) var_stack: &'a mut Vec<InferenceVar>,
|
||||
pub(super) fallback: F,
|
||||
}
|
||||
impl<'a, 'b, 'i, F> TypeFolder<Interner> for Resolver<'a, 'b, F>
|
||||
impl<'a, 'b, F> TypeFolder<Interner> for Resolver<'a, 'b, F>
|
||||
where
|
||||
F: Fn(InferenceVar, VariableKind, GenericArg, DebruijnIndex) -> GenericArg + 'i,
|
||||
F: Fn(InferenceVar, VariableKind, GenericArg, DebruijnIndex) -> GenericArg,
|
||||
{
|
||||
type Error = NoSolution;
|
||||
|
||||
fn as_dyn(&mut self) -> &mut dyn TypeFolder<Interner, Error = Self::Error> {
|
||||
self
|
||||
}
|
||||
@ -667,20 +669,19 @@ fn fold_inference_ty(
|
||||
var: InferenceVar,
|
||||
kind: TyVariableKind,
|
||||
outer_binder: DebruijnIndex,
|
||||
) -> Fallible<Ty> {
|
||||
) -> Ty {
|
||||
let var = self.table.var_unification_table.inference_var_root(var);
|
||||
if self.var_stack.contains(&var) {
|
||||
// recursive type
|
||||
let default = self.table.fallback_value(var, kind).cast(Interner);
|
||||
return Ok((self.fallback)(var, VariableKind::Ty(kind), default, outer_binder)
|
||||
return (self.fallback)(var, VariableKind::Ty(kind), default, outer_binder)
|
||||
.assert_ty_ref(Interner)
|
||||
.clone());
|
||||
.clone();
|
||||
}
|
||||
let result = if let Some(known_ty) = self.table.var_unification_table.probe_var(var) {
|
||||
// known_ty may contain other variables that are known by now
|
||||
self.var_stack.push(var);
|
||||
let result =
|
||||
known_ty.fold_with(self, outer_binder).expect("fold failed unexpectedly");
|
||||
let result = known_ty.fold_with(self, outer_binder);
|
||||
self.var_stack.pop();
|
||||
result.assert_ty_ref(Interner).clone()
|
||||
} else {
|
||||
@ -689,7 +690,7 @@ fn fold_inference_ty(
|
||||
.assert_ty_ref(Interner)
|
||||
.clone()
|
||||
};
|
||||
Ok(result)
|
||||
result
|
||||
}
|
||||
|
||||
fn fold_inference_const(
|
||||
@ -697,7 +698,7 @@ fn fold_inference_const(
|
||||
ty: Ty,
|
||||
var: InferenceVar,
|
||||
outer_binder: DebruijnIndex,
|
||||
) -> Fallible<Const> {
|
||||
) -> Const {
|
||||
let var = self.table.var_unification_table.inference_var_root(var);
|
||||
let default = ConstData {
|
||||
ty: ty.clone(),
|
||||
@ -707,35 +708,33 @@ fn fold_inference_const(
|
||||
.cast(Interner);
|
||||
if self.var_stack.contains(&var) {
|
||||
// recursive
|
||||
return Ok((self.fallback)(var, VariableKind::Const(ty), default, outer_binder)
|
||||
return (self.fallback)(var, VariableKind::Const(ty), default, outer_binder)
|
||||
.assert_const_ref(Interner)
|
||||
.clone());
|
||||
.clone();
|
||||
}
|
||||
let result = if let Some(known_ty) = self.table.var_unification_table.probe_var(var) {
|
||||
if let Some(known_ty) = self.table.var_unification_table.probe_var(var) {
|
||||
// known_ty may contain other variables that are known by now
|
||||
self.var_stack.push(var);
|
||||
let result =
|
||||
known_ty.fold_with(self, outer_binder).expect("fold failed unexpectedly");
|
||||
let result = known_ty.fold_with(self, outer_binder);
|
||||
self.var_stack.pop();
|
||||
result.assert_const_ref(Interner).clone()
|
||||
} else {
|
||||
(self.fallback)(var, VariableKind::Const(ty), default, outer_binder)
|
||||
.assert_const_ref(Interner)
|
||||
.clone()
|
||||
};
|
||||
Ok(result)
|
||||
}
|
||||
}
|
||||
|
||||
fn fold_inference_lifetime(
|
||||
&mut self,
|
||||
_var: InferenceVar,
|
||||
_outer_binder: DebruijnIndex,
|
||||
) -> Fallible<Lifetime> {
|
||||
) -> Lifetime {
|
||||
// fall back all lifetimes to 'static -- currently we don't deal
|
||||
// with any lifetimes, but we can sometimes get some lifetime
|
||||
// variables through Chalk's unification, and this at least makes
|
||||
// sure we don't leak them outside of inference
|
||||
Ok(crate::static_lifetime())
|
||||
crate::static_lifetime()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -254,13 +254,13 @@ pub fn ret(&self) -> &Ty {
|
||||
}
|
||||
|
||||
impl TypeFoldable<Interner> for CallableSig {
|
||||
fn fold_with<E>(
|
||||
fn try_fold_with<E>(
|
||||
self,
|
||||
folder: &mut dyn chalk_ir::fold::TypeFolder<Interner, Error = E>,
|
||||
folder: &mut dyn chalk_ir::fold::FallibleTypeFolder<Interner, Error = E>,
|
||||
outer_binder: DebruijnIndex,
|
||||
) -> Result<Self, E> {
|
||||
let vec = self.params_and_return.to_vec();
|
||||
let folded = vec.fold_with(folder, outer_binder)?;
|
||||
let folded = vec.try_fold_with(folder, outer_binder)?;
|
||||
Ok(CallableSig { params_and_return: folded.into(), is_varargs: self.is_varargs })
|
||||
}
|
||||
}
|
||||
@ -292,16 +292,19 @@ pub(crate) fn fold_free_vars<T: HasInterner<Interner = Interner> + TypeFoldable<
|
||||
for_ty: impl FnMut(BoundVar, DebruijnIndex) -> Ty,
|
||||
for_const: impl FnMut(Ty, BoundVar, DebruijnIndex) -> Const,
|
||||
) -> T {
|
||||
use chalk_ir::{fold::TypeFolder, Fallible};
|
||||
struct FreeVarFolder<F1, F2>(F1, F2);
|
||||
use chalk_ir::fold::TypeFolder;
|
||||
|
||||
#[derive(chalk_derive::FallibleTypeFolder)]
|
||||
#[has_interner(Interner)]
|
||||
struct FreeVarFolder<
|
||||
F1: FnMut(BoundVar, DebruijnIndex) -> Ty,
|
||||
F2: FnMut(Ty, BoundVar, DebruijnIndex) -> Const,
|
||||
>(F1, F2);
|
||||
impl<
|
||||
'i,
|
||||
F1: FnMut(BoundVar, DebruijnIndex) -> Ty + 'i,
|
||||
F2: FnMut(Ty, BoundVar, DebruijnIndex) -> Const + 'i,
|
||||
F1: FnMut(BoundVar, DebruijnIndex) -> Ty,
|
||||
F2: FnMut(Ty, BoundVar, DebruijnIndex) -> Const,
|
||||
> TypeFolder<Interner> for FreeVarFolder<F1, F2>
|
||||
{
|
||||
type Error = NoSolution;
|
||||
|
||||
fn as_dyn(&mut self) -> &mut dyn TypeFolder<Interner, Error = Self::Error> {
|
||||
self
|
||||
}
|
||||
@ -310,12 +313,8 @@ fn interner(&self) -> Interner {
|
||||
Interner
|
||||
}
|
||||
|
||||
fn fold_free_var_ty(
|
||||
&mut self,
|
||||
bound_var: BoundVar,
|
||||
outer_binder: DebruijnIndex,
|
||||
) -> Fallible<Ty> {
|
||||
Ok(self.0(bound_var, outer_binder))
|
||||
fn fold_free_var_ty(&mut self, bound_var: BoundVar, outer_binder: DebruijnIndex) -> Ty {
|
||||
self.0(bound_var, outer_binder)
|
||||
}
|
||||
|
||||
fn fold_free_var_const(
|
||||
@ -323,12 +322,11 @@ fn fold_free_var_const(
|
||||
ty: Ty,
|
||||
bound_var: BoundVar,
|
||||
outer_binder: DebruijnIndex,
|
||||
) -> Fallible<Const> {
|
||||
Ok(self.1(ty, bound_var, outer_binder))
|
||||
) -> Const {
|
||||
self.1(ty, bound_var, outer_binder)
|
||||
}
|
||||
}
|
||||
t.fold_with(&mut FreeVarFolder(for_ty, for_const), DebruijnIndex::INNERMOST)
|
||||
.expect("fold failed unexpectedly")
|
||||
}
|
||||
|
||||
pub(crate) fn fold_tys<T: HasInterner<Interner = Interner> + TypeFoldable<Interner>>(
|
||||
@ -351,16 +349,13 @@ pub(crate) fn fold_tys_and_consts<T: HasInterner<Interner = Interner> + TypeFold
|
||||
f: impl FnMut(Either<Ty, Const>, DebruijnIndex) -> Either<Ty, Const>,
|
||||
binders: DebruijnIndex,
|
||||
) -> T {
|
||||
use chalk_ir::{
|
||||
fold::{TypeFolder, TypeSuperFoldable},
|
||||
Fallible,
|
||||
};
|
||||
struct TyFolder<F>(F);
|
||||
impl<'i, F: FnMut(Either<Ty, Const>, DebruijnIndex) -> Either<Ty, Const> + 'i>
|
||||
TypeFolder<Interner> for TyFolder<F>
|
||||
use chalk_ir::fold::{TypeFolder, TypeSuperFoldable};
|
||||
#[derive(chalk_derive::FallibleTypeFolder)]
|
||||
#[has_interner(Interner)]
|
||||
struct TyFolder<F: FnMut(Either<Ty, Const>, DebruijnIndex) -> Either<Ty, Const>>(F);
|
||||
impl<F: FnMut(Either<Ty, Const>, DebruijnIndex) -> Either<Ty, Const>> TypeFolder<Interner>
|
||||
for TyFolder<F>
|
||||
{
|
||||
type Error = NoSolution;
|
||||
|
||||
fn as_dyn(&mut self) -> &mut dyn TypeFolder<Interner, Error = Self::Error> {
|
||||
self
|
||||
}
|
||||
@ -369,16 +364,16 @@ fn interner(&self) -> Interner {
|
||||
Interner
|
||||
}
|
||||
|
||||
fn fold_ty(&mut self, ty: Ty, outer_binder: DebruijnIndex) -> Fallible<Ty> {
|
||||
let ty = ty.super_fold_with(self.as_dyn(), outer_binder)?;
|
||||
Ok(self.0(Either::Left(ty), outer_binder).left().unwrap())
|
||||
fn fold_ty(&mut self, ty: Ty, outer_binder: DebruijnIndex) -> Ty {
|
||||
let ty = ty.super_fold_with(self.as_dyn(), outer_binder);
|
||||
self.0(Either::Left(ty), outer_binder).left().unwrap()
|
||||
}
|
||||
|
||||
fn fold_const(&mut self, c: Const, outer_binder: DebruijnIndex) -> Fallible<Const> {
|
||||
Ok(self.0(Either::Right(c), outer_binder).right().unwrap())
|
||||
fn fold_const(&mut self, c: Const, outer_binder: DebruijnIndex) -> Const {
|
||||
self.0(Either::Right(c), outer_binder).right().unwrap()
|
||||
}
|
||||
}
|
||||
t.fold_with(&mut TyFolder(f), binders).expect("fold failed unexpectedly")
|
||||
t.fold_with(&mut TyFolder(f), binders)
|
||||
}
|
||||
|
||||
/// 'Canonicalizes' the `t` by replacing any errors with new variables. Also
|
||||
@ -390,16 +385,16 @@ pub fn replace_errors_with_variables<T>(t: &T) -> Canonical<T>
|
||||
T: HasInterner<Interner = Interner>,
|
||||
{
|
||||
use chalk_ir::{
|
||||
fold::{TypeFolder, TypeSuperFoldable},
|
||||
fold::{FallibleTypeFolder, TypeSuperFoldable},
|
||||
Fallible,
|
||||
};
|
||||
struct ErrorReplacer {
|
||||
vars: usize,
|
||||
}
|
||||
impl TypeFolder<Interner> for ErrorReplacer {
|
||||
impl FallibleTypeFolder<Interner> for ErrorReplacer {
|
||||
type Error = NoSolution;
|
||||
|
||||
fn as_dyn(&mut self) -> &mut dyn TypeFolder<Interner, Error = Self::Error> {
|
||||
fn as_dyn(&mut self) -> &mut dyn FallibleTypeFolder<Interner, Error = Self::Error> {
|
||||
self
|
||||
}
|
||||
|
||||
@ -407,18 +402,17 @@ fn interner(&self) -> Interner {
|
||||
Interner
|
||||
}
|
||||
|
||||
fn fold_ty(&mut self, ty: Ty, outer_binder: DebruijnIndex) -> Fallible<Ty> {
|
||||
fn try_fold_ty(&mut self, ty: Ty, outer_binder: DebruijnIndex) -> Fallible<Ty> {
|
||||
if let TyKind::Error = ty.kind(Interner) {
|
||||
let index = self.vars;
|
||||
self.vars += 1;
|
||||
Ok(TyKind::BoundVar(BoundVar::new(outer_binder, index)).intern(Interner))
|
||||
} else {
|
||||
let ty = ty.super_fold_with(self.as_dyn(), outer_binder)?;
|
||||
Ok(ty)
|
||||
ty.try_super_fold_with(self.as_dyn(), outer_binder)
|
||||
}
|
||||
}
|
||||
|
||||
fn fold_inference_ty(
|
||||
fn try_fold_inference_ty(
|
||||
&mut self,
|
||||
_var: InferenceVar,
|
||||
_kind: TyVariableKind,
|
||||
@ -433,7 +427,7 @@ fn fold_inference_ty(
|
||||
}
|
||||
}
|
||||
|
||||
fn fold_free_var_ty(
|
||||
fn try_fold_free_var_ty(
|
||||
&mut self,
|
||||
_bound_var: BoundVar,
|
||||
_outer_binder: DebruijnIndex,
|
||||
@ -447,7 +441,7 @@ fn fold_free_var_ty(
|
||||
}
|
||||
}
|
||||
|
||||
fn fold_inference_const(
|
||||
fn try_fold_inference_const(
|
||||
&mut self,
|
||||
ty: Ty,
|
||||
_var: InferenceVar,
|
||||
@ -460,7 +454,7 @@ fn fold_inference_const(
|
||||
}
|
||||
}
|
||||
|
||||
fn fold_free_var_const(
|
||||
fn try_fold_free_var_const(
|
||||
&mut self,
|
||||
ty: Ty,
|
||||
_bound_var: BoundVar,
|
||||
@ -473,7 +467,7 @@ fn fold_free_var_const(
|
||||
}
|
||||
}
|
||||
|
||||
fn fold_inference_lifetime(
|
||||
fn try_fold_inference_lifetime(
|
||||
&mut self,
|
||||
_var: InferenceVar,
|
||||
_outer_binder: DebruijnIndex,
|
||||
@ -485,7 +479,7 @@ fn fold_inference_lifetime(
|
||||
}
|
||||
}
|
||||
|
||||
fn fold_free_var_lifetime(
|
||||
fn try_fold_free_var_lifetime(
|
||||
&mut self,
|
||||
_bound_var: BoundVar,
|
||||
_outer_binder: DebruijnIndex,
|
||||
@ -498,7 +492,7 @@ fn fold_free_var_lifetime(
|
||||
}
|
||||
}
|
||||
let mut error_replacer = ErrorReplacer { vars: 0 };
|
||||
let value = match t.clone().fold_with(&mut error_replacer, DebruijnIndex::INNERMOST) {
|
||||
let value = match t.clone().try_fold_with(&mut error_replacer, DebruijnIndex::INNERMOST) {
|
||||
Ok(t) => t,
|
||||
Err(_) => panic!("Encountered unbound or inference vars in {:?}", t),
|
||||
};
|
||||
|
@ -13,8 +13,8 @@
|
||||
|
||||
use crate::{
|
||||
db::HirDatabase, infer::unify::InferenceTable, AliasEq, AliasTy, Canonical, DomainGoal, Goal,
|
||||
Guidance, InEnvironment, Interner, ProjectionTy, Solution, TraitRefExt, Ty, TyKind,
|
||||
WhereClause,
|
||||
Guidance, InEnvironment, Interner, ProjectionTy, ProjectionTyExt, Solution, TraitRefExt, Ty,
|
||||
TyKind, WhereClause,
|
||||
};
|
||||
|
||||
/// This controls how much 'time' we give the Chalk solver before giving up.
|
||||
@ -95,7 +95,7 @@ pub(crate) fn trait_solve_query(
|
||||
..
|
||||
}))) = &goal.value.goal.data(Interner)
|
||||
{
|
||||
if let TyKind::BoundVar(_) = projection_ty.self_type_parameter(Interner).kind(Interner) {
|
||||
if let TyKind::BoundVar(_) = projection_ty.self_type_parameter(db).kind(Interner) {
|
||||
// Hack: don't ask Chalk to normalize with an unknown self type, it'll say that's impossible
|
||||
return Some(Solution::Ambig(Guidance::Unknown));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user