mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-16 01:38:13 +00:00
Remove identity impls for ToChalk
This commit is contained in:
parent
a163554857
commit
8ce6fea325
4 changed files with 21 additions and 215 deletions
|
@ -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<Interner> =
|
||||
pred.clone().to_chalk(db).cast(&Interner);
|
||||
let program_clause: chalk_ir::ProgramClause<Interner> = 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<Interner> = pred.to_chalk(db).cast(&Interner);
|
||||
let program_clause: chalk_ir::ProgramClause<Interner> = pred.cast(&Interner);
|
||||
clauses.push(program_clause.into_from_env_clause(&Interner));
|
||||
}
|
||||
|
||||
|
|
|
@ -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?)
|
||||
|
|
|
@ -86,7 +86,7 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> 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<Interner> 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<Interner> 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<Interner> for ChalkContext<'a> {
|
|||
|
||||
fn hidden_opaque_type(&self, _id: chalk_ir::OpaqueTyId<Interner>) -> chalk_ir::Ty<Interner> {
|
||||
// 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<Interner>) -> bool {
|
||||
|
@ -293,12 +285,11 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
|
|||
_closure_id: chalk_ir::ClosureId<Interner>,
|
||||
substs: &chalk_ir::Substitution<Interner>,
|
||||
) -> chalk_ir::Binders<rust_ir::FnDefInputsAndOutputDatum<Interner>> {
|
||||
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<Interner> for ChalkContext<'a> {
|
|||
_closure_id: chalk_ir::ClosureId<Interner>,
|
||||
_substs: &chalk_ir::Substitution<Interner>,
|
||||
) -> chalk_ir::Binders<chalk_ir::Ty<Interner>> {
|
||||
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<Interner> for ChalkContext<'a> {
|
|||
_closure_id: chalk_ir::ClosureId<Interner>,
|
||||
_substs: &chalk_ir::Substitution<Interner>,
|
||||
) -> chalk_ir::Substitution<Interner> {
|
||||
Substitution::empty(&Interner).to_chalk(self.db)
|
||||
Substitution::empty(&Interner)
|
||||
}
|
||||
|
||||
fn trait_name(&self, trait_id: chalk_ir::TraitId<Interner>) -> 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,
|
||||
|
|
|
@ -18,55 +18,6 @@ use crate::{
|
|||
use super::interner::*;
|
||||
use super::*;
|
||||
|
||||
impl ToChalk for Ty {
|
||||
type Chalk = chalk_ir::Ty<Interner>;
|
||||
fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Ty<Interner> {
|
||||
self
|
||||
}
|
||||
fn from_chalk(db: &dyn HirDatabase, chalk: chalk_ir::Ty<Interner>) -> Self {
|
||||
chalk
|
||||
}
|
||||
}
|
||||
|
||||
impl ToChalk for GenericArg {
|
||||
type Chalk = chalk_ir::GenericArg<Interner>;
|
||||
|
||||
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<Interner>;
|
||||
|
||||
fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Substitution<Interner> {
|
||||
self
|
||||
}
|
||||
|
||||
fn from_chalk(
|
||||
db: &dyn HirDatabase,
|
||||
parameters: chalk_ir::Substitution<Interner>,
|
||||
) -> Substitution {
|
||||
parameters
|
||||
}
|
||||
}
|
||||
|
||||
impl ToChalk for TraitRef {
|
||||
type Chalk = chalk_ir::TraitRef<Interner>;
|
||||
|
||||
fn to_chalk(self: TraitRef, db: &dyn HirDatabase) -> chalk_ir::TraitRef<Interner> {
|
||||
self
|
||||
}
|
||||
|
||||
fn from_chalk(db: &dyn HirDatabase, trait_ref: chalk_ir::TraitRef<Interner>) -> 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<Interner>;
|
||||
|
||||
fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::WhereClause<Interner> {
|
||||
self
|
||||
}
|
||||
|
||||
fn from_chalk(
|
||||
db: &dyn HirDatabase,
|
||||
where_clause: chalk_ir::WhereClause<Interner>,
|
||||
) -> WhereClause {
|
||||
where_clause
|
||||
}
|
||||
}
|
||||
|
||||
impl ToChalk for ProjectionTy {
|
||||
type Chalk = chalk_ir::ProjectionTy<Interner>;
|
||||
|
||||
fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::ProjectionTy<Interner> {
|
||||
self
|
||||
}
|
||||
|
||||
fn from_chalk(
|
||||
db: &dyn HirDatabase,
|
||||
projection_ty: chalk_ir::ProjectionTy<Interner>,
|
||||
) -> ProjectionTy {
|
||||
projection_ty
|
||||
}
|
||||
}
|
||||
impl ToChalk for OpaqueTy {
|
||||
type Chalk = chalk_ir::OpaqueTy<Interner>;
|
||||
|
||||
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<Interner>;
|
||||
|
||||
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<Interner>;
|
||||
|
||||
fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::AliasEq<Interner> {
|
||||
self
|
||||
}
|
||||
|
||||
fn from_chalk(db: &dyn HirDatabase, alias_eq: chalk_ir::AliasEq<Interner>) -> Self {
|
||||
alias_eq
|
||||
}
|
||||
}
|
||||
|
||||
impl ToChalk for DomainGoal {
|
||||
type Chalk = chalk_ir::DomainGoal<Interner>;
|
||||
|
||||
fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::DomainGoal<Interner> {
|
||||
self
|
||||
}
|
||||
|
||||
fn from_chalk(_db: &dyn HirDatabase, goal: chalk_ir::DomainGoal<Interner>) -> Self {
|
||||
goal
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> ToChalk for Canonical<T>
|
||||
where
|
||||
T: HasInterner<Interner = Interner>,
|
||||
{
|
||||
type Chalk = chalk_ir::Canonical<T>;
|
||||
|
||||
fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Canonical<T> {
|
||||
self
|
||||
}
|
||||
|
||||
fn from_chalk(db: &dyn HirDatabase, canonical: chalk_ir::Canonical<T>) -> Canonical<T> {
|
||||
canonical
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: ToChalk> ToChalk for InEnvironment<T>
|
||||
where
|
||||
T: HasInterner<Interner = Interner>,
|
||||
{
|
||||
type Chalk = chalk_ir::InEnvironment<T>;
|
||||
|
||||
fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::InEnvironment<T> {
|
||||
self
|
||||
}
|
||||
|
||||
fn from_chalk(_db: &dyn HirDatabase, in_env: chalk_ir::InEnvironment<T>) -> InEnvironment<T> {
|
||||
in_env
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: ToChalk> ToChalk for crate::Binders<T>
|
||||
where
|
||||
T: HasInterner<Interner = Interner>,
|
||||
{
|
||||
type Chalk = chalk_ir::Binders<T>;
|
||||
|
||||
fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Binders<T> {
|
||||
self
|
||||
}
|
||||
|
||||
fn from_chalk(db: &dyn HirDatabase, binders: chalk_ir::Binders<T>) -> crate::Binders<T> {
|
||||
binders
|
||||
}
|
||||
}
|
||||
|
||||
impl ToChalk for crate::ConstrainedSubst {
|
||||
type Chalk = chalk_ir::ConstrainedSubst<Interner>;
|
||||
|
||||
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<T>(value: T, num_vars: usize) -> chalk_ir::Binders<T>
|
||||
where
|
||||
T: HasInterner<Interner = Interner>,
|
||||
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue