diff --git a/crates/hir_ty/src/lower.rs b/crates/hir_ty/src/lower.rs index 109157a5eb..6584bcf34d 100644 --- a/crates/hir_ty/src/lower.rs +++ b/crates/hir_ty/src/lower.rs @@ -950,8 +950,7 @@ pub(crate) fn trait_environment_query( traits_in_scope .push((tr.self_type_parameter(&Interner).clone(), tr.hir_trait_id())); } - let program_clause: chalk_ir::ProgramClause = - pred.clone().to_chalk(db).cast(&Interner); + let program_clause: chalk_ir::ProgramClause = pred.clone().cast(&Interner); clauses.push(program_clause.into_from_env_clause(&Interner)); } } @@ -974,7 +973,7 @@ pub(crate) fn trait_environment_query( let substs = TyBuilder::type_params_subst(db, trait_id); let trait_ref = TraitRef { trait_id: to_chalk_trait_id(trait_id), substitution: substs }; let pred = WhereClause::Implemented(trait_ref); - let program_clause: chalk_ir::ProgramClause = pred.to_chalk(db).cast(&Interner); + let program_clause: chalk_ir::ProgramClause = pred.cast(&Interner); clauses.push(program_clause.into_from_env_clause(&Interner)); } diff --git a/crates/hir_ty/src/traits.rs b/crates/hir_ty/src/traits.rs index de1d37e178..63d87fe610 100644 --- a/crates/hir_ty/src/traits.rs +++ b/crates/hir_ty/src/traits.rs @@ -96,7 +96,7 @@ pub(crate) fn trait_solve_query( } } - let canonical = goal.to_chalk(db).cast(&Interner); + let canonical = goal.cast(&Interner); // We currently don't deal with universes (I think / hope they're not yet // relevant for our use cases?) diff --git a/crates/hir_ty/src/traits/chalk.rs b/crates/hir_ty/src/traits/chalk.rs index a5aa40c10e..fcdcc2b4df 100644 --- a/crates/hir_ty/src/traits/chalk.rs +++ b/crates/hir_ty/src/traits/chalk.rs @@ -86,7 +86,7 @@ impl<'a> chalk_solve::RustIrDatabase for ChalkContext<'a> { debug!("impls_for_trait {:?}", trait_id); let trait_: hir_def::TraitId = from_chalk(self.db, trait_id); - let ty: Ty = from_chalk(self.db, parameters[0].assert_ty_ref(&Interner).clone()); + let ty: Ty = parameters[0].assert_ty_ref(&Interner).clone(); fn binder_kind( ty: &Ty, @@ -187,15 +187,7 @@ impl<'a> chalk_solve::RustIrDatabase for ChalkContext<'a> { let (datas, binders) = (*datas).as_ref().into_value_and_skipped_binders(); let data = &datas.impl_traits[idx as usize]; let bound = OpaqueTyDatumBound { - bounds: make_binders( - data.bounds - .skip_binders() - .iter() - .cloned() - .map(|b| b.to_chalk(self.db)) - .collect(), - 1, - ), + bounds: make_binders(data.bounds.skip_binders().iter().cloned().collect(), 1), where_clauses: make_binders(vec![], 0), }; chalk_ir::Binders::new(binders, bound) @@ -246,8 +238,8 @@ impl<'a> chalk_solve::RustIrDatabase for ChalkContext<'a> { let bound = OpaqueTyDatumBound { bounds: make_binders( vec![ - crate::wrap_empty_binders(impl_bound).to_chalk(self.db), - crate::wrap_empty_binders(proj_bound).to_chalk(self.db), + crate::wrap_empty_binders(impl_bound), + crate::wrap_empty_binders(proj_bound), ], 1, ), @@ -272,7 +264,7 @@ impl<'a> chalk_solve::RustIrDatabase for ChalkContext<'a> { fn hidden_opaque_type(&self, _id: chalk_ir::OpaqueTyId) -> chalk_ir::Ty { // FIXME: actually provide the hidden type; it is relevant for auto traits - TyKind::Error.intern(&Interner).to_chalk(self.db) + TyKind::Error.intern(&Interner) } fn is_object_safe(&self, _trait_id: chalk_ir::TraitId) -> bool { @@ -293,12 +285,11 @@ impl<'a> chalk_solve::RustIrDatabase for ChalkContext<'a> { _closure_id: chalk_ir::ClosureId, substs: &chalk_ir::Substitution, ) -> chalk_ir::Binders> { - let sig_ty: Ty = - from_chalk(self.db, substs.at(&Interner, 0).assert_ty_ref(&Interner).clone()); + let sig_ty = substs.at(&Interner, 0).assert_ty_ref(&Interner).clone(); let sig = &sig_ty.callable_sig(self.db).expect("first closure param should be fn ptr"); let io = rust_ir::FnDefInputsAndOutputDatum { - argument_types: sig.params().iter().map(|ty| ty.clone().to_chalk(self.db)).collect(), - return_type: sig.ret().clone().to_chalk(self.db), + argument_types: sig.params().iter().cloned().collect(), + return_type: sig.ret().clone(), }; make_binders(io.shifted_in(&Interner), 0) } @@ -307,7 +298,7 @@ impl<'a> chalk_solve::RustIrDatabase for ChalkContext<'a> { _closure_id: chalk_ir::ClosureId, _substs: &chalk_ir::Substitution, ) -> chalk_ir::Binders> { - let ty = TyBuilder::unit().to_chalk(self.db); + let ty = TyBuilder::unit(); make_binders(ty, 0) } fn closure_fn_substitution( @@ -315,7 +306,7 @@ impl<'a> chalk_solve::RustIrDatabase for ChalkContext<'a> { _closure_id: chalk_ir::ClosureId, _substs: &chalk_ir::Substitution, ) -> chalk_ir::Substitution { - Substitution::empty(&Interner).to_chalk(self.db) + Substitution::empty(&Interner) } fn trait_name(&self, trait_id: chalk_ir::TraitId) -> String { @@ -410,7 +401,7 @@ pub(crate) fn associated_ty_data_query( let where_clauses = convert_where_clauses(db, type_alias.into(), &bound_vars); let bound_data = rust_ir::AssociatedTyDatumBound { bounds, where_clauses }; let datum = AssociatedTyDatum { - trait_id: trait_.to_chalk(db), + trait_id: to_chalk_trait_id(trait_), id, name: type_alias, binders: make_binders(bound_data, generic_params.len()), @@ -563,7 +554,6 @@ fn impl_def_datum( trait_ref.display(db), where_clauses ); - let trait_ref = trait_ref.to_chalk(db); let polarity = if negative { rust_ir::Polarity::Negative } else { rust_ir::Polarity::Positive }; @@ -624,7 +614,7 @@ fn type_alias_associated_ty_value( .associated_type_by_name(&type_alias_data.name) .expect("assoc ty value should not exist"); // validated when building the impl data as well let (ty, binders) = db.ty(type_alias.into()).into_value_and_skipped_binders(); - let value_bound = rust_ir::AssociatedTyValueBound { ty: ty.to_chalk(db) }; + let value_bound = rust_ir::AssociatedTyValueBound { ty }; let value = rust_ir::AssociatedTyValue { impl_id: impl_id.to_chalk(db), associated_ty_id: to_assoc_type_id(assoc_ty), @@ -647,8 +637,8 @@ pub(crate) fn fn_def_datum_query( // Note: Chalk doesn't actually use this information yet as far as I am aware, but we provide it anyway inputs_and_output: make_binders( rust_ir::FnDefInputsAndOutputDatum { - argument_types: sig.params().iter().map(|ty| ty.clone().to_chalk(db)).collect(), - return_type: sig.ret().clone().to_chalk(db), + argument_types: sig.params().iter().cloned().collect(), + return_type: sig.ret().clone(), } .shifted_in(&Interner), 0, diff --git a/crates/hir_ty/src/traits/chalk/mapping.rs b/crates/hir_ty/src/traits/chalk/mapping.rs index 62cf0fecf6..54783b58c3 100644 --- a/crates/hir_ty/src/traits/chalk/mapping.rs +++ b/crates/hir_ty/src/traits/chalk/mapping.rs @@ -18,55 +18,6 @@ use crate::{ use super::interner::*; use super::*; -impl ToChalk for Ty { - type Chalk = chalk_ir::Ty; - fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Ty { - self - } - fn from_chalk(db: &dyn HirDatabase, chalk: chalk_ir::Ty) -> Self { - chalk - } -} - -impl ToChalk for GenericArg { - type Chalk = chalk_ir::GenericArg; - - fn to_chalk(self, db: &dyn HirDatabase) -> Self::Chalk { - self - } - - fn from_chalk(db: &dyn HirDatabase, chalk: Self::Chalk) -> Self { - chalk - } -} - -impl ToChalk for Substitution { - type Chalk = chalk_ir::Substitution; - - fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Substitution { - self - } - - fn from_chalk( - db: &dyn HirDatabase, - parameters: chalk_ir::Substitution, - ) -> Substitution { - parameters - } -} - -impl ToChalk for TraitRef { - type Chalk = chalk_ir::TraitRef; - - fn to_chalk(self: TraitRef, db: &dyn HirDatabase) -> chalk_ir::TraitRef { - self - } - - fn from_chalk(db: &dyn HirDatabase, trait_ref: chalk_ir::TraitRef) -> Self { - trait_ref - } -} - impl ToChalk for hir_def::TraitId { type Chalk = TraitId; @@ -120,140 +71,6 @@ impl ToChalk for TypeAliasAsValue { } } -impl ToChalk for WhereClause { - type Chalk = chalk_ir::WhereClause; - - fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::WhereClause { - self - } - - fn from_chalk( - db: &dyn HirDatabase, - where_clause: chalk_ir::WhereClause, - ) -> WhereClause { - where_clause - } -} - -impl ToChalk for ProjectionTy { - type Chalk = chalk_ir::ProjectionTy; - - fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::ProjectionTy { - self - } - - fn from_chalk( - db: &dyn HirDatabase, - projection_ty: chalk_ir::ProjectionTy, - ) -> ProjectionTy { - projection_ty - } -} -impl ToChalk for OpaqueTy { - type Chalk = chalk_ir::OpaqueTy; - - fn to_chalk(self, db: &dyn HirDatabase) -> Self::Chalk { - self - } - - fn from_chalk(db: &dyn HirDatabase, chalk: Self::Chalk) -> Self { - chalk - } -} - -impl ToChalk for AliasTy { - type Chalk = chalk_ir::AliasTy; - - fn to_chalk(self, db: &dyn HirDatabase) -> Self::Chalk { - self - } - - fn from_chalk(db: &dyn HirDatabase, chalk: Self::Chalk) -> Self { - chalk - } -} - -impl ToChalk for AliasEq { - type Chalk = chalk_ir::AliasEq; - - fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::AliasEq { - self - } - - fn from_chalk(db: &dyn HirDatabase, alias_eq: chalk_ir::AliasEq) -> Self { - alias_eq - } -} - -impl ToChalk for DomainGoal { - type Chalk = chalk_ir::DomainGoal; - - fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::DomainGoal { - self - } - - fn from_chalk(_db: &dyn HirDatabase, goal: chalk_ir::DomainGoal) -> Self { - goal - } -} - -impl ToChalk for Canonical -where - T: HasInterner, -{ - type Chalk = chalk_ir::Canonical; - - fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Canonical { - self - } - - fn from_chalk(db: &dyn HirDatabase, canonical: chalk_ir::Canonical) -> Canonical { - canonical - } -} - -impl ToChalk for InEnvironment -where - T: HasInterner, -{ - type Chalk = chalk_ir::InEnvironment; - - fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::InEnvironment { - self - } - - fn from_chalk(_db: &dyn HirDatabase, in_env: chalk_ir::InEnvironment) -> InEnvironment { - in_env - } -} - -impl ToChalk for crate::Binders -where - T: HasInterner, -{ - type Chalk = chalk_ir::Binders; - - fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Binders { - self - } - - fn from_chalk(db: &dyn HirDatabase, binders: chalk_ir::Binders) -> crate::Binders { - binders - } -} - -impl ToChalk for crate::ConstrainedSubst { - type Chalk = chalk_ir::ConstrainedSubst; - - fn to_chalk(self, _db: &dyn HirDatabase) -> Self::Chalk { - self - } - - fn from_chalk(db: &dyn HirDatabase, chalk: Self::Chalk) -> Self { - chalk - } -} - pub(super) fn make_binders(value: T, num_vars: usize) -> chalk_ir::Binders where T: HasInterner, @@ -276,7 +93,7 @@ pub(super) fn convert_where_clauses( let generic_predicates = db.generic_predicates(def); let mut result = Vec::with_capacity(generic_predicates.len()); for pred in generic_predicates.iter() { - result.push(pred.clone().substitute(&Interner, substs).to_chalk(db)); + result.push(pred.clone().substitute(&Interner, substs)); } result } @@ -299,7 +116,7 @@ pub(super) fn generic_predicate_to_inline_bound( } let args_no_self = trait_ref.substitution.interned()[1..] .iter() - .map(|ty| ty.clone().to_chalk(db).cast(&Interner)) + .map(|ty| ty.clone().cast(&Interner)) .collect(); let trait_bound = rust_ir::TraitBound { trait_id: trait_ref.trait_id, args_no_self }; Some(chalk_ir::Binders::new(binders, rust_ir::InlineBound::TraitBound(trait_bound))) @@ -311,10 +128,10 @@ pub(super) fn generic_predicate_to_inline_bound( let trait_ = projection_ty.trait_(db); let args_no_self = projection_ty.substitution.interned()[1..] .iter() - .map(|ty| ty.clone().to_chalk(db).cast(&Interner)) + .map(|ty| ty.clone().cast(&Interner)) .collect(); let alias_eq_bound = rust_ir::AliasEqBound { - value: ty.clone().to_chalk(db), + value: ty.clone(), trait_bound: rust_ir::TraitBound { trait_id: trait_.to_chalk(db), args_no_self }, associated_ty_id: projection_ty.associated_ty_id, parameters: Vec::new(), // FIXME we don't support generic associated types yet