diff --git a/Cargo.lock b/Cargo.lock index b9581e9aa32..bbcc4ad29f6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -171,9 +171,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chalk-derive" -version = "0.82.0" +version = "0.83.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee9cd790d543c29ce953abcb28d54b9fbaf9c4033bfd3024de99b1aa0f3c3ada" +checksum = "83553c2ef7717e58aecdf42dd9e3c876229f5a1f35a16435b5ddc4addef81827" dependencies = [ "proc-macro2", "quote", @@ -183,9 +183,9 @@ dependencies = [ [[package]] name = "chalk-ir" -version = "0.82.0" +version = "0.83.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dddf2c11f9de666c08c7591eb113efcdc740bd8ac602915475b045bcbe7f27a5" +checksum = "2dd42107d579d8ec2a5af20a8de62a37524a67bf6a4c0ff08a950068f0bfea91" dependencies = [ "bitflags", "chalk-derive", @@ -194,9 +194,9 @@ dependencies = [ [[package]] name = "chalk-recursive" -version = "0.82.0" +version = "0.83.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a60d5b35598702963ffd145b8bfa0d8d8ae9da3a731e4e0814aa21541b85c2d5" +checksum = "c444031541a76c13c145e76d91f1548e9feb2240e7f0c3e77879ceb694994f2d" dependencies = [ "chalk-derive", "chalk-ir", @@ -207,9 +207,9 @@ dependencies = [ [[package]] name = "chalk-solve" -version = "0.82.0" +version = "0.83.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d99da4fa3b224c07f6c2506e6905bca9d6aad665f11d25364e6818a7ea149215" +checksum = "c76f2db19c5e8a3d42340cf5b4d90b8c218750536fca35e2bb285ab6653c0bc8" dependencies = [ "chalk-derive", "chalk-ir", diff --git a/crates/hir-ty/Cargo.toml b/crates/hir-ty/Cargo.toml index aede750a8fd..d359cb0ed14 100644 --- a/crates/hir-ty/Cargo.toml +++ b/crates/hir-ty/Cargo.toml @@ -18,9 +18,9 @@ ena = "0.14.0" tracing = "0.1.35" rustc-hash = "1.1.0" scoped-tls = "1.0.0" -chalk-solve = { version = "0.82.0", default-features = false } -chalk-ir = "0.82.0" -chalk-recursive = { version = "0.82.0", default-features = false } +chalk-solve = { version = "0.83.0", default-features = false } +chalk-ir = "0.83.0" +chalk-recursive = { version = "0.83.0", default-features = false } la-arena = { version = "0.3.0", path = "../../lib/la-arena" } once_cell = "1.12.0" typed-arena = "2.0.1" diff --git a/crates/hir-ty/src/builder.rs b/crates/hir-ty/src/builder.rs index 8c47e9ce1cb..23587cc6d0d 100644 --- a/crates/hir-ty/src/builder.rs +++ b/crates/hir-ty/src/builder.rs @@ -4,7 +4,7 @@ use chalk_ir::{ cast::{Cast, CastTo, Caster}, - fold::Fold, + fold::TypeFoldable, interner::HasInterner, AdtId, BoundVar, DebruijnIndex, Scalar, }; @@ -276,7 +276,7 @@ pub fn build(self) -> ProjectionTy { } } -impl + Fold> TyBuilder> { +impl + TypeFoldable> TyBuilder> { fn subst_binders(b: Binders) -> Self { let param_kinds = b .binders @@ -290,7 +290,7 @@ fn subst_binders(b: Binders) -> Self { TyBuilder::new(b, param_kinds) } - pub fn build(self) -> >::Result { + pub fn build(self) -> T { let (b, subst) = self.build_internal(); b.substitute(Interner, &subst) } diff --git a/crates/hir-ty/src/infer/unify.rs b/crates/hir-ty/src/infer/unify.rs index 84ca1660afb..014109f03d2 100644 --- a/crates/hir-ty/src/infer/unify.rs +++ b/crates/hir-ty/src/infer/unify.rs @@ -3,8 +3,8 @@ use std::{fmt, mem, sync::Arc}; use chalk_ir::{ - cast::Cast, fold::Fold, interner::HasInterner, zip::Zip, CanonicalVarKind, FloatTy, IntTy, - NoSolution, TyVariableKind, UniverseIndex, + cast::Cast, fold::TypeFoldable, interner::HasInterner, zip::Zip, CanonicalVarKind, FloatTy, + IntTy, NoSolution, TyVariableKind, UniverseIndex, }; use chalk_solve::infer::ParameterEnaVariableExt; use ena::unify::UnifyKey; @@ -20,12 +20,12 @@ }; impl<'a> InferenceContext<'a> { - pub(super) fn canonicalize + HasInterner>( + pub(super) fn canonicalize + HasInterner>( &mut self, t: T, - ) -> Canonicalized + ) -> Canonicalized where - T::Result: HasInterner, + T: HasInterner, { self.table.canonicalize(t) } @@ -200,12 +200,12 @@ fn fallback_value(&self, iv: InferenceVar, kind: TyVariableKind) -> Ty { .intern(Interner) } - pub(crate) fn canonicalize + HasInterner>( + pub(crate) fn canonicalize + HasInterner>( &mut self, t: T, - ) -> Canonicalized + ) -> Canonicalized where - T::Result: HasInterner, + T: HasInterner, { // try to resolve obligations before canonicalizing, since this might // result in new knowledge about variables @@ -292,9 +292,9 @@ pub(crate) fn resolve_with_fallback( &mut self, t: T, fallback: &dyn Fn(InferenceVar, VariableKind, GenericArg, DebruijnIndex) -> GenericArg, - ) -> T::Result + ) -> T where - T: HasInterner + Fold, + T: HasInterner + TypeFoldable, { self.resolve_with_fallback_inner(&mut Vec::new(), t, &fallback) } @@ -310,9 +310,9 @@ pub(crate) fn fresh_subst(&mut self, binders: &[CanonicalVarKind]) -> ) } - pub(crate) fn instantiate_canonical(&mut self, canonical: Canonical) -> T::Result + pub(crate) fn instantiate_canonical(&mut self, canonical: Canonical) -> T where - T: HasInterner + Fold + std::fmt::Debug, + T: HasInterner + TypeFoldable + std::fmt::Debug, { let subst = self.fresh_subst(canonical.binders.as_slice(Interner)); subst.apply(canonical.value, Interner) @@ -323,9 +323,9 @@ fn resolve_with_fallback_inner( var_stack: &mut Vec, t: T, fallback: &dyn Fn(InferenceVar, VariableKind, GenericArg, DebruijnIndex) -> GenericArg, - ) -> T::Result + ) -> T where - T: HasInterner + Fold, + T: HasInterner + TypeFoldable, { t.fold_with( &mut resolve::Resolver { table: self, var_stack, fallback }, @@ -334,9 +334,9 @@ fn resolve_with_fallback_inner( .expect("fold failed unexpectedly") } - pub(crate) fn resolve_completely(&mut self, t: T) -> T::Result + pub(crate) fn resolve_completely(&mut self, t: T) -> T where - T: HasInterner + Fold, + T: HasInterner + TypeFoldable, { self.resolve_with_fallback(t, &|_, _, d, _| d) } @@ -447,19 +447,19 @@ pub(crate) fn resolve_obligations_as_possible(&mut self) { } } - pub(crate) fn fudge_inference>( + pub(crate) fn fudge_inference>( &mut self, f: impl FnOnce(&mut Self) -> T, - ) -> T::Result { - use chalk_ir::fold::Folder; + ) -> T { + use chalk_ir::fold::TypeFolder; struct VarFudger<'a, 'b> { table: &'a mut InferenceTable<'b>, highest_known_var: InferenceVar, } - impl<'a, 'b> Folder for VarFudger<'a, 'b> { + impl<'a, 'b> TypeFolder for VarFudger<'a, 'b> { type Error = NoSolution; - fn as_dyn(&mut self) -> &mut dyn Folder { + fn as_dyn(&mut self) -> &mut dyn TypeFolder { self } @@ -635,7 +635,7 @@ mod resolve { }; use chalk_ir::{ cast::Cast, - fold::{Fold, Folder}, + fold::{TypeFoldable, TypeFolder}, Fallible, NoSolution, }; use hir_def::type_ref::ConstScalar; @@ -645,13 +645,13 @@ pub(super) struct Resolver<'a, 'b, F> { pub(super) var_stack: &'a mut Vec, pub(super) fallback: F, } - impl<'a, 'b, 'i, F> Folder for Resolver<'a, 'b, F> + impl<'a, 'b, 'i, F> TypeFolder for Resolver<'a, 'b, F> where F: Fn(InferenceVar, VariableKind, GenericArg, DebruijnIndex) -> GenericArg + 'i, { type Error = NoSolution; - fn as_dyn(&mut self) -> &mut dyn Folder { + fn as_dyn(&mut self) -> &mut dyn TypeFolder { self } diff --git a/crates/hir-ty/src/lib.rs b/crates/hir-ty/src/lib.rs index 15bcbda25de..5abbee89711 100644 --- a/crates/hir-ty/src/lib.rs +++ b/crates/hir-ty/src/lib.rs @@ -33,7 +33,7 @@ macro_rules! eprintln { use std::sync::Arc; use chalk_ir::{ - fold::{Fold, Shift}, + fold::{Shift, TypeFoldable}, interner::HasInterner, NoSolution, }; @@ -136,7 +136,7 @@ pub fn param_idx(db: &dyn HirDatabase, id: TypeOrConstParamId) -> Option pub(crate) fn wrap_empty_binders(value: T) -> Binders where - T: Fold + HasInterner, + T: TypeFoldable + HasInterner, { Binders::empty(Interner, value.shifted_in_from(Interner, DebruijnIndex::ONE)) } @@ -264,14 +264,12 @@ pub fn ret(&self) -> &Ty { } } -impl Fold for CallableSig { - type Result = CallableSig; - +impl TypeFoldable for CallableSig { fn fold_with( self, - folder: &mut dyn chalk_ir::fold::Folder, + folder: &mut dyn chalk_ir::fold::TypeFolder, outer_binder: DebruijnIndex, - ) -> Result { + ) -> Result { let vec = self.params_and_return.to_vec(); let folded = vec.fold_with(folder, outer_binder)?; Ok(CallableSig { params_and_return: folded.into(), is_varargs: self.is_varargs }) @@ -300,22 +298,22 @@ pub fn static_lifetime() -> Lifetime { LifetimeData::Static.intern(Interner) } -pub(crate) fn fold_free_vars + Fold>( +pub(crate) fn fold_free_vars + TypeFoldable>( t: T, for_ty: impl FnMut(BoundVar, DebruijnIndex) -> Ty, for_const: impl FnMut(Ty, BoundVar, DebruijnIndex) -> Const, -) -> T::Result { - use chalk_ir::{fold::Folder, Fallible}; +) -> T { + use chalk_ir::{fold::TypeFolder, Fallible}; struct FreeVarFolder(F1, F2); impl< 'i, F1: FnMut(BoundVar, DebruijnIndex) -> Ty + 'i, F2: FnMut(Ty, BoundVar, DebruijnIndex) -> Const + 'i, - > Folder for FreeVarFolder + > TypeFolder for FreeVarFolder { type Error = NoSolution; - fn as_dyn(&mut self) -> &mut dyn Folder { + fn as_dyn(&mut self) -> &mut dyn TypeFolder { self } @@ -344,11 +342,11 @@ fn fold_free_var_const( .expect("fold failed unexpectedly") } -pub(crate) fn fold_tys + Fold>( +pub(crate) fn fold_tys + TypeFoldable>( t: T, mut for_ty: impl FnMut(Ty, DebruijnIndex) -> Ty, binders: DebruijnIndex, -) -> T::Result { +) -> T { fold_tys_and_consts( t, |x, d| match x { @@ -359,22 +357,22 @@ pub(crate) fn fold_tys + Fold>( ) } -pub(crate) fn fold_tys_and_consts + Fold>( +pub(crate) fn fold_tys_and_consts + TypeFoldable>( t: T, f: impl FnMut(Either, DebruijnIndex) -> Either, binders: DebruijnIndex, -) -> T::Result { +) -> T { use chalk_ir::{ - fold::{Folder, SuperFold}, + fold::{TypeFolder, TypeSuperFoldable}, Fallible, }; struct TyFolder(F); - impl<'i, F: FnMut(Either, DebruijnIndex) -> Either + 'i> Folder - for TyFolder + impl<'i, F: FnMut(Either, DebruijnIndex) -> Either + 'i> + TypeFolder for TyFolder { type Error = NoSolution; - fn as_dyn(&mut self) -> &mut dyn Folder { + fn as_dyn(&mut self) -> &mut dyn TypeFolder { self } @@ -397,22 +395,22 @@ fn fold_const(&mut self, c: Const, outer_binder: DebruijnIndex) -> Fallible(t: &T) -> Canonical +pub fn replace_errors_with_variables(t: &T) -> Canonical where - T: HasInterner + Fold + Clone, - T::Result: HasInterner, + T: HasInterner + TypeFoldable + Clone, + T: HasInterner, { use chalk_ir::{ - fold::{Folder, SuperFold}, + fold::{TypeFolder, TypeSuperFoldable}, Fallible, }; struct ErrorReplacer { vars: usize, } - impl Folder for ErrorReplacer { + impl TypeFolder for ErrorReplacer { type Error = NoSolution; - fn as_dyn(&mut self) -> &mut dyn Folder { + fn as_dyn(&mut self) -> &mut dyn TypeFolder { self } diff --git a/crates/hir-ty/src/lower.rs b/crates/hir-ty/src/lower.rs index adee8cf958f..f9747f3b34d 100644 --- a/crates/hir-ty/src/lower.rs +++ b/crates/hir-ty/src/lower.rs @@ -12,7 +12,9 @@ }; use base_db::CrateId; -use chalk_ir::{cast::Cast, fold::Fold, fold::Shift, interner::HasInterner, Mutability, Safety}; +use chalk_ir::{ + cast::Cast, fold::Shift, fold::TypeFoldable, interner::HasInterner, Mutability, Safety, +}; use hir_def::{ adt::StructKind, @@ -1751,10 +1753,10 @@ pub(crate) fn const_or_path_to_chalk( /// This replaces any 'free' Bound vars in `s` (i.e. those with indices past /// num_vars_to_keep) by `TyKind::Unknown`. -fn fallback_bound_vars + HasInterner>( +fn fallback_bound_vars + HasInterner>( s: T, num_vars_to_keep: usize, -) -> T::Result { +) -> T { crate::fold_free_vars( s, |bound, binders| {