From 3411fe3e84e641aad03abbc22eec33fdc29b15f8 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sun, 14 Mar 2021 16:26:12 +0100 Subject: Rename some fields to their Chalk names --- crates/hir/src/lib.rs | 4 ++-- crates/hir_ty/src/autoderef.rs | 2 +- crates/hir_ty/src/display.rs | 16 ++++++++-------- crates/hir_ty/src/infer.rs | 4 ++-- crates/hir_ty/src/infer/expr.rs | 4 ++-- crates/hir_ty/src/infer/unify.rs | 6 +++--- crates/hir_ty/src/lib.rs | 18 +++++++++--------- crates/hir_ty/src/lower.rs | 12 ++++++------ crates/hir_ty/src/traits.rs | 2 +- crates/hir_ty/src/traits/chalk.rs | 4 ++-- crates/hir_ty/src/traits/chalk/mapping.rs | 22 +++++++++++----------- 11 files changed, 47 insertions(+), 47 deletions(-) (limited to 'crates') diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index 10b8171be..5e7226df2 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -1686,8 +1686,8 @@ impl Type { .build(); let predicate = ProjectionPredicate { projection_ty: ProjectionTy { - associated_ty: to_assoc_type_id(alias.id), - parameters: subst, + associated_ty_id: to_assoc_type_id(alias.id), + substitution: subst, }, ty: TyKind::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, 0)).intern(&Interner), }; diff --git a/crates/hir_ty/src/autoderef.rs b/crates/hir_ty/src/autoderef.rs index d739d5d60..d5c2b9a20 100644 --- a/crates/hir_ty/src/autoderef.rs +++ b/crates/hir_ty/src/autoderef.rs @@ -84,7 +84,7 @@ fn deref_by_trait( let projection = super::traits::ProjectionPredicate { ty: TyKind::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, ty.value.kinds.len())) .intern(&Interner), - projection_ty: super::ProjectionTy { associated_ty: to_assoc_type_id(target), parameters }, + projection_ty: super::ProjectionTy { associated_ty_id: to_assoc_type_id(target), substitution: parameters }, }; let obligation = super::Obligation::Projection(projection); diff --git a/crates/hir_ty/src/display.rs b/crates/hir_ty/src/display.rs index e6473586b..21291ddda 100644 --- a/crates/hir_ty/src/display.rs +++ b/crates/hir_ty/src/display.rs @@ -245,19 +245,19 @@ impl HirDisplay for ProjectionTy { } let trait_ = f.db.trait_data(self.trait_(f.db)); - let first_parameter = self.parameters[0].into_displayable( + let first_parameter = self.substitution[0].into_displayable( f.db, f.max_size, f.omit_verbose_types, f.display_target, ); write!(f, "<{} as {}", first_parameter, trait_.name)?; - if self.parameters.len() > 1 { + if self.substitution.len() > 1 { write!(f, "<")?; - f.write_joined(&self.parameters[1..], ", ")?; + f.write_joined(&self.substitution[1..], ", ")?; write!(f, ">")?; } - write!(f, ">::{}", f.db.type_alias_data(from_assoc_type_id(self.associated_ty)).name)?; + write!(f, ">::{}", f.db.type_alias_data(from_assoc_type_id(self.associated_ty_id)).name)?; Ok(()) } } @@ -491,8 +491,8 @@ impl HirDisplay for Ty { } } else { let projection_ty = ProjectionTy { - associated_ty: to_assoc_type_id(type_alias), - parameters: parameters.clone(), + associated_ty_id: to_assoc_type_id(type_alias), + substitution: parameters.clone(), }; projection_ty.hir_fmt(f)?; @@ -709,7 +709,7 @@ fn write_bounds_like_dyn_trait( angle_open = true; } let type_alias = f.db.type_alias_data(from_assoc_type_id( - projection_pred.projection_ty.associated_ty, + projection_pred.projection_ty.associated_ty_id, )); write!(f, "{} = ", type_alias.name)?; projection_pred.ty.hir_fmt(f)?; @@ -782,7 +782,7 @@ impl HirDisplay for GenericPredicate { f, ">::{} = ", f.db.type_alias_data(from_assoc_type_id( - projection_pred.projection_ty.associated_ty + projection_pred.projection_ty.associated_ty_id )) .name, )?; diff --git a/crates/hir_ty/src/infer.rs b/crates/hir_ty/src/infer.rs index 8cf59821f..fbfedb4e6 100644 --- a/crates/hir_ty/src/infer.rs +++ b/crates/hir_ty/src/infer.rs @@ -385,8 +385,8 @@ impl<'a> InferenceContext<'a> { let projection = ProjectionPredicate { ty: ty.clone(), projection_ty: ProjectionTy { - associated_ty: to_assoc_type_id(res_assoc_ty), - parameters: substs, + associated_ty_id: to_assoc_type_id(res_assoc_ty), + substitution: substs, }, }; self.obligations.push(Obligation::Trait(trait_ref)); diff --git a/crates/hir_ty/src/infer/expr.rs b/crates/hir_ty/src/infer/expr.rs index eee3e6ec5..b7870e771 100644 --- a/crates/hir_ty/src/infer/expr.rs +++ b/crates/hir_ty/src/infer/expr.rs @@ -99,8 +99,8 @@ impl<'a> InferenceContext<'a> { if self.db.trait_solve(krate, goal.value).is_some() { self.obligations.push(implements_fn_trait); let output_proj_ty = crate::ProjectionTy { - associated_ty: to_assoc_type_id(output_assoc_type), - parameters: substs, + associated_ty_id: to_assoc_type_id(output_assoc_type), + substitution: substs, }; let return_ty = self.normalize_projection_ty(output_proj_ty); Some((arg_tys, return_ty)) diff --git a/crates/hir_ty/src/infer/unify.rs b/crates/hir_ty/src/infer/unify.rs index 16d89ed1b..ebc612ca9 100644 --- a/crates/hir_ty/src/infer/unify.rs +++ b/crates/hir_ty/src/infer/unify.rs @@ -381,11 +381,11 @@ impl InferenceTable { self.unify_substs(&tr1.substs, &tr2.substs, depth + 1) } (GenericPredicate::Projection(proj1), GenericPredicate::Projection(proj2)) - if proj1.projection_ty.associated_ty == proj2.projection_ty.associated_ty => + if proj1.projection_ty.associated_ty_id == proj2.projection_ty.associated_ty_id => { self.unify_substs( - &proj1.projection_ty.parameters, - &proj2.projection_ty.parameters, + &proj1.projection_ty.substitution, + &proj2.projection_ty.substitution, depth + 1, ) && self.unify_inner(&proj1.ty, &proj2.ty, depth + 1) } diff --git a/crates/hir_ty/src/lib.rs b/crates/hir_ty/src/lib.rs index d6ff968f0..ddcee2084 100644 --- a/crates/hir_ty/src/lib.rs +++ b/crates/hir_ty/src/lib.rs @@ -74,17 +74,17 @@ pub struct OpaqueTy { /// trait and all its parameters are fully known. #[derive(Clone, PartialEq, Eq, Debug, Hash)] pub struct ProjectionTy { - pub associated_ty: AssocTypeId, - pub parameters: Substs, + pub associated_ty_id: AssocTypeId, + pub substitution: Substs, } impl ProjectionTy { pub fn trait_ref(&self, db: &dyn HirDatabase) -> TraitRef { - TraitRef { trait_: self.trait_(db), substs: self.parameters.clone() } + TraitRef { trait_: self.trait_(db), substs: self.substitution.clone() } } fn trait_(&self, db: &dyn HirDatabase) -> TraitId { - match from_assoc_type_id(self.associated_ty).lookup(db.upcast()).container { + match from_assoc_type_id(self.associated_ty_id).lookup(db.upcast()).container { AssocContainerId::TraitId(it) => it, _ => panic!("projection ty without parent trait"), } @@ -93,7 +93,7 @@ impl ProjectionTy { impl TypeWalk for ProjectionTy { fn walk(&self, f: &mut impl FnMut(&Ty)) { - self.parameters.walk(f); + self.substitution.walk(f); } fn walk_mut_binders( @@ -101,7 +101,7 @@ impl TypeWalk for ProjectionTy { f: &mut impl FnMut(&mut Ty, DebruijnIndex), binders: DebruijnIndex, ) { - self.parameters.walk_mut_binders(f, binders); + self.substitution.walk_mut_binders(f, binders); } } @@ -945,7 +945,7 @@ impl Ty { } } TyKind::Alias(AliasTy::Projection(projection_ty)) => { - match from_assoc_type_id(projection_ty.associated_ty).lookup(db.upcast()).container + match from_assoc_type_id(projection_ty.associated_ty_id).lookup(db.upcast()).container { AssocContainerId::TraitId(trait_id) => Some(trait_id), _ => None, @@ -1055,7 +1055,7 @@ impl TypeWalk for Ty { fn walk(&self, f: &mut impl FnMut(&Ty)) { match self.interned(&Interner) { TyKind::Alias(AliasTy::Projection(p_ty)) => { - for t in p_ty.parameters.iter() { + for t in p_ty.substitution.iter() { t.walk(f); } } @@ -1087,7 +1087,7 @@ impl TypeWalk for Ty { ) { match &mut self.0 { TyKind::Alias(AliasTy::Projection(p_ty)) => { - p_ty.parameters.walk_mut_binders(f, binders); + p_ty.substitution.walk_mut_binders(f, binders); } TyKind::Dyn(predicates) => { for p in make_mut_slice(predicates) { diff --git a/crates/hir_ty/src/lower.rs b/crates/hir_ty/src/lower.rs index c32dca9d7..17eb29911 100644 --- a/crates/hir_ty/src/lower.rs +++ b/crates/hir_ty/src/lower.rs @@ -357,8 +357,8 @@ impl<'a> TyLoweringContext<'a> { Some((super_trait_ref, associated_ty)) => { // FIXME handle type parameters on the segment TyKind::Alias(AliasTy::Projection(ProjectionTy { - associated_ty: to_assoc_type_id(associated_ty), - parameters: super_trait_ref.substs, + associated_ty_id: to_assoc_type_id(associated_ty), + substitution: super_trait_ref.substs, })) .intern(&Interner) } @@ -478,8 +478,8 @@ impl<'a> TyLoweringContext<'a> { // FIXME handle type parameters on the segment return Some( TyKind::Alias(AliasTy::Projection(ProjectionTy { - associated_ty: to_assoc_type_id(associated_ty), - parameters: substs, + associated_ty_id: to_assoc_type_id(associated_ty), + substitution: substs, })) .intern(&Interner), ); @@ -736,8 +736,8 @@ impl<'a> TyLoweringContext<'a> { Some(t) => t, }; let projection_ty = ProjectionTy { - associated_ty: to_assoc_type_id(associated_ty), - parameters: super_trait_ref.substs, + associated_ty_id: to_assoc_type_id(associated_ty), + substitution: super_trait_ref.substs, }; let mut preds = SmallVec::with_capacity( binding.type_ref.as_ref().map_or(0, |_| 1) + binding.bounds.len(), diff --git a/crates/hir_ty/src/traits.rs b/crates/hir_ty/src/traits.rs index edfafdff8..a6a63c673 100644 --- a/crates/hir_ty/src/traits.rs +++ b/crates/hir_ty/src/traits.rs @@ -143,7 +143,7 @@ pub(crate) fn trait_solve_query( log::info!("trait_solve_query({})", goal.value.value.display(db)); if let Obligation::Projection(pred) = &goal.value.value { - if let TyKind::BoundVar(_) = &pred.projection_ty.parameters[0].interned(&Interner) { + if let TyKind::BoundVar(_) = &pred.projection_ty.substitution[0].interned(&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)); } diff --git a/crates/hir_ty/src/traits/chalk.rs b/crates/hir_ty/src/traits/chalk.rs index ef1e6b2df..232cf9cd0 100644 --- a/crates/hir_ty/src/traits/chalk.rs +++ b/crates/hir_ty/src/traits/chalk.rs @@ -234,9 +234,9 @@ impl<'a> chalk_solve::RustIrDatabase for ChalkContext<'a> { ty: TyKind::BoundVar(BoundVar { debruijn: DebruijnIndex::ONE, index: 0 }) .intern(&Interner), projection_ty: ProjectionTy { - associated_ty: to_assoc_type_id(future_output), + associated_ty_id: to_assoc_type_id(future_output), // Self type as the first parameter. - parameters: Substs::single( + substitution: Substs::single( TyKind::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, 0)) .intern(&Interner), ), diff --git a/crates/hir_ty/src/traits/chalk/mapping.rs b/crates/hir_ty/src/traits/chalk/mapping.rs index 2a66a2310..68effbbf3 100644 --- a/crates/hir_ty/src/traits/chalk/mapping.rs +++ b/crates/hir_ty/src/traits/chalk/mapping.rs @@ -78,8 +78,8 @@ impl ToChalk for Ty { chalk_ir::TyKind::Adt(adt_id, substitution).intern(&Interner) } TyKind::Alias(AliasTy::Projection(proj_ty)) => { - let associated_ty_id = proj_ty.associated_ty; - let substitution = proj_ty.parameters.to_chalk(db); + let associated_ty_id = proj_ty.associated_ty_id; + let substitution = proj_ty.substitution.to_chalk(db); chalk_ir::AliasTy::Projection(chalk_ir::ProjectionTy { associated_ty_id, substitution, @@ -121,7 +121,7 @@ impl ToChalk for Ty { chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Projection(proj)) => { let associated_ty = proj.associated_ty_id; let parameters = from_chalk(db, proj.substitution); - TyKind::Alias(AliasTy::Projection(ProjectionTy { associated_ty, parameters })) + TyKind::Alias(AliasTy::Projection(ProjectionTy { associated_ty_id: associated_ty, substitution: parameters })) } chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Opaque(opaque_ty)) => { let opaque_ty_id = opaque_ty.opaque_ty_id; @@ -372,8 +372,8 @@ impl ToChalk for ProjectionTy { fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::ProjectionTy { chalk_ir::ProjectionTy { - associated_ty_id: self.associated_ty, - substitution: self.parameters.to_chalk(db), + associated_ty_id: self.associated_ty_id, + substitution: self.substitution.to_chalk(db), } } @@ -382,8 +382,8 @@ impl ToChalk for ProjectionTy { projection_ty: chalk_ir::ProjectionTy, ) -> ProjectionTy { ProjectionTy { - associated_ty: projection_ty.associated_ty_id, - parameters: from_chalk(db, projection_ty.substitution), + associated_ty_id: projection_ty.associated_ty_id, + substitution: from_chalk(db, projection_ty.substitution), } } } @@ -533,24 +533,24 @@ pub(super) fn generic_predicate_to_inline_bound( Some(rust_ir::InlineBound::TraitBound(trait_bound)) } GenericPredicate::Projection(proj) => { - if &proj.projection_ty.parameters[0] != self_ty { + if &proj.projection_ty.substitution[0] != self_ty { return None; } - let trait_ = match from_assoc_type_id(proj.projection_ty.associated_ty) + let trait_ = match from_assoc_type_id(proj.projection_ty.associated_ty_id) .lookup(db.upcast()) .container { AssocContainerId::TraitId(t) => t, _ => panic!("associated type not in trait"), }; - let args_no_self = proj.projection_ty.parameters[1..] + let args_no_self = proj.projection_ty.substitution[1..] .iter() .map(|ty| ty.clone().to_chalk(db).cast(&Interner)) .collect(); let alias_eq_bound = rust_ir::AliasEqBound { value: proj.ty.clone().to_chalk(db), trait_bound: rust_ir::TraitBound { trait_id: trait_.to_chalk(db), args_no_self }, - associated_ty_id: proj.projection_ty.associated_ty, + associated_ty_id: proj.projection_ty.associated_ty_id, parameters: Vec::new(), // FIXME we don't support generic associated types yet }; Some(rust_ir::InlineBound::AliasEqBound(alias_eq_bound)) -- cgit v1.2.3 From eea777c7148ac6c52434e8ea4913cdb50a466a3e Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sun, 14 Mar 2021 16:30:02 +0100 Subject: Use chalk_ir::FnSig --- crates/hir_ty/src/autoderef.rs | 5 ++++- crates/hir_ty/src/infer/expr.rs | 2 +- crates/hir_ty/src/lib.rs | 13 ++++++------- crates/hir_ty/src/lower.rs | 4 ++-- crates/hir_ty/src/traits/chalk/mapping.rs | 19 +++++++++---------- 5 files changed, 22 insertions(+), 21 deletions(-) (limited to 'crates') diff --git a/crates/hir_ty/src/autoderef.rs b/crates/hir_ty/src/autoderef.rs index d5c2b9a20..56c6b92d4 100644 --- a/crates/hir_ty/src/autoderef.rs +++ b/crates/hir_ty/src/autoderef.rs @@ -84,7 +84,10 @@ fn deref_by_trait( let projection = super::traits::ProjectionPredicate { ty: TyKind::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, ty.value.kinds.len())) .intern(&Interner), - projection_ty: super::ProjectionTy { associated_ty_id: to_assoc_type_id(target), substitution: parameters }, + projection_ty: super::ProjectionTy { + associated_ty_id: to_assoc_type_id(target), + substitution: parameters, + }, }; let obligation = super::Obligation::Projection(projection); diff --git a/crates/hir_ty/src/infer/expr.rs b/crates/hir_ty/src/infer/expr.rs index b7870e771..55163c963 100644 --- a/crates/hir_ty/src/infer/expr.rs +++ b/crates/hir_ty/src/infer/expr.rs @@ -261,7 +261,7 @@ impl<'a> InferenceContext<'a> { sig_tys.push(ret_ty.clone()); let sig_ty = TyKind::Function(FnPointer { num_args: sig_tys.len() - 1, - sig: FnSig { variadic: false }, + sig: FnSig { abi: (), safety: chalk_ir::Safety::Safe, variadic: false }, substs: Substs(sig_tys.clone().into()), }) .intern(&Interner); diff --git a/crates/hir_ty/src/lib.rs b/crates/hir_ty/src/lib.rs index ddcee2084..bc7a7369a 100644 --- a/crates/hir_ty/src/lib.rs +++ b/crates/hir_ty/src/lib.rs @@ -46,7 +46,7 @@ pub use lower::{ }; pub use traits::{InEnvironment, Obligation, ProjectionPredicate, TraitEnvironment}; -pub use chalk_ir::{AdtId, BoundVar, DebruijnIndex, Mutability, Scalar, TyVariableKind}; +pub use chalk_ir::{AdtId, BoundVar, DebruijnIndex, Mutability, Safety, Scalar, TyVariableKind}; pub use crate::traits::chalk::Interner; @@ -105,10 +105,7 @@ impl TypeWalk for ProjectionTy { } } -#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)] -pub struct FnSig { - pub variadic: bool, -} +pub type FnSig = chalk_ir::FnSig; #[derive(Clone, PartialEq, Eq, Debug, Hash)] pub struct FnPointer { @@ -643,7 +640,7 @@ impl Ty { pub fn fn_ptr(sig: CallableSig) -> Self { TyKind::Function(FnPointer { num_args: sig.params().len(), - sig: FnSig { variadic: sig.is_varargs }, + sig: FnSig { abi: (), safety: Safety::Safe, variadic: sig.is_varargs }, substs: Substs(sig.params_and_return), }) .intern(&Interner) @@ -945,7 +942,9 @@ impl Ty { } } TyKind::Alias(AliasTy::Projection(projection_ty)) => { - match from_assoc_type_id(projection_ty.associated_ty_id).lookup(db.upcast()).container + match from_assoc_type_id(projection_ty.associated_ty_id) + .lookup(db.upcast()) + .container { AssocContainerId::TraitId(trait_id) => Some(trait_id), _ => None, diff --git a/crates/hir_ty/src/lower.rs b/crates/hir_ty/src/lower.rs index 17eb29911..76b2124af 100644 --- a/crates/hir_ty/src/lower.rs +++ b/crates/hir_ty/src/lower.rs @@ -8,7 +8,7 @@ use std::{iter, sync::Arc}; use base_db::CrateId; -use chalk_ir::{cast::Cast, Mutability}; +use chalk_ir::{cast::Cast, Mutability, Safety}; use hir_def::{ adt::StructKind, builtin_type::BuiltinType, @@ -181,7 +181,7 @@ impl<'a> TyLoweringContext<'a> { let substs = Substs(params.iter().map(|tr| self.lower_ty(tr)).collect()); TyKind::Function(FnPointer { num_args: substs.len() - 1, - sig: FnSig { variadic: *is_varargs }, + sig: FnSig { abi: (), safety: Safety::Safe, variadic: *is_varargs }, substs, }) .intern(&Interner) diff --git a/crates/hir_ty/src/traits/chalk/mapping.rs b/crates/hir_ty/src/traits/chalk/mapping.rs index 68effbbf3..1a6fca611 100644 --- a/crates/hir_ty/src/traits/chalk/mapping.rs +++ b/crates/hir_ty/src/traits/chalk/mapping.rs @@ -14,7 +14,7 @@ use crate::{ from_assoc_type_id, primitive::UintTy, traits::{Canonical, Obligation}, - AliasTy, CallableDefId, FnPointer, FnSig, GenericPredicate, InEnvironment, OpaqueTy, + AliasTy, CallableDefId, FnPointer, GenericPredicate, InEnvironment, OpaqueTy, ProjectionPredicate, ProjectionTy, Scalar, Substs, TraitRef, Ty, }; @@ -27,11 +27,11 @@ impl ToChalk for Ty { match self.0 { TyKind::Ref(m, parameters) => ref_to_chalk(db, m, parameters), TyKind::Array(parameters) => array_to_chalk(db, parameters), - TyKind::Function(FnPointer { sig: FnSig { variadic }, substs, .. }) => { + TyKind::Function(FnPointer { sig, substs, .. }) => { let substitution = chalk_ir::FnSubst(substs.to_chalk(db).shifted_in(&Interner)); chalk_ir::TyKind::Function(chalk_ir::FnPointer { num_binders: 0, - sig: chalk_ir::FnSig { abi: (), safety: chalk_ir::Safety::Safe, variadic }, + sig, substitution, }) .intern(&Interner) @@ -121,7 +121,10 @@ impl ToChalk for Ty { chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Projection(proj)) => { let associated_ty = proj.associated_ty_id; let parameters = from_chalk(db, proj.substitution); - TyKind::Alias(AliasTy::Projection(ProjectionTy { associated_ty_id: associated_ty, substitution: parameters })) + TyKind::Alias(AliasTy::Projection(ProjectionTy { + associated_ty_id: associated_ty, + substitution: parameters, + })) } chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Opaque(opaque_ty)) => { let opaque_ty_id = opaque_ty.opaque_ty_id; @@ -130,7 +133,7 @@ impl ToChalk for Ty { } chalk_ir::TyKind::Function(chalk_ir::FnPointer { num_binders, - sig: chalk_ir::FnSig { variadic, .. }, + sig, substitution, .. }) => { @@ -139,11 +142,7 @@ impl ToChalk for Ty { db, substitution.0.shifted_out(&Interner).expect("fn ptr should have no binders"), ); - TyKind::Function(FnPointer { - num_args: (substs.len() - 1), - sig: FnSig { variadic }, - substs, - }) + TyKind::Function(FnPointer { num_args: (substs.len() - 1), sig, substs }) } chalk_ir::TyKind::BoundVar(idx) => TyKind::BoundVar(idx), chalk_ir::TyKind::InferenceVar(_iv, _kind) => TyKind::Unknown, -- cgit v1.2.3 From 195414783402d6973f4e673e84be9b7bc19cbfa6 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sun, 14 Mar 2021 16:33:27 +0100 Subject: More renaming --- crates/hir/src/lib.rs | 2 +- crates/hir_ty/src/display.rs | 7 +++++-- crates/hir_ty/src/lib.rs | 8 ++++---- crates/hir_ty/src/lower.rs | 7 +++++-- crates/hir_ty/src/traits/chalk/mapping.rs | 18 ++++++++---------- 5 files changed, 23 insertions(+), 19 deletions(-) (limited to 'crates') diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index 5e7226df2..eb1cd66fb 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -1979,7 +1979,7 @@ impl Type { walk_bounds(db, &type_.derived(ty.clone()), &bounds, cb); } - walk_substs(db, type_, &opaque_ty.parameters, cb); + walk_substs(db, type_, &opaque_ty.substitution, cb); } TyKind::Placeholder(_) => { if let Some(bounds) = ty.impl_trait_bounds(db) { diff --git a/crates/hir_ty/src/display.rs b/crates/hir_ty/src/display.rs index 21291ddda..378c951c5 100644 --- a/crates/hir_ty/src/display.rs +++ b/crates/hir_ty/src/display.rs @@ -319,7 +319,10 @@ impl HirDisplay for Ty { TyKind::Dyn(predicates) if predicates.len() > 1 => { Cow::Borrowed(predicates.as_ref()) } - &TyKind::Alias(AliasTy::Opaque(OpaqueTy { opaque_ty_id, ref parameters })) => { + &TyKind::Alias(AliasTy::Opaque(OpaqueTy { + opaque_ty_id, + substitution: ref parameters, + })) => { let impl_trait_id = f.db.lookup_intern_impl_trait_id(opaque_ty_id.into()); if let ImplTraitId::ReturnTypeImplTrait(func, idx) = impl_trait_id { datas = @@ -579,7 +582,7 @@ impl HirDisplay for Ty { let data = (*datas) .as_ref() .map(|rpit| rpit.impl_traits[idx as usize].bounds.clone()); - let bounds = data.subst(&opaque_ty.parameters); + let bounds = data.subst(&opaque_ty.substitution); write_bounds_like_dyn_trait_with_prefix("impl", &bounds.value, f)?; } ImplTraitId::AsyncBlockTypeImplTrait(..) => { diff --git a/crates/hir_ty/src/lib.rs b/crates/hir_ty/src/lib.rs index bc7a7369a..484652073 100644 --- a/crates/hir_ty/src/lib.rs +++ b/crates/hir_ty/src/lib.rs @@ -66,7 +66,7 @@ pub enum Lifetime { #[derive(Clone, PartialEq, Eq, Debug, Hash)] pub struct OpaqueTy { pub opaque_ty_id: OpaqueTyId, - pub parameters: Substs, + pub substitution: Substs, } /// A "projection" type corresponds to an (unnormalized) @@ -903,7 +903,7 @@ impl Ty { let data = (*it) .as_ref() .map(|rpit| rpit.impl_traits[idx as usize].bounds.clone()); - data.subst(&opaque_ty.parameters) + data.subst(&opaque_ty.substitution) }) } // It always has an parameter for Future::Output type. @@ -1059,7 +1059,7 @@ impl TypeWalk for Ty { } } TyKind::Alias(AliasTy::Opaque(o_ty)) => { - for t in o_ty.parameters.iter() { + for t in o_ty.substitution.iter() { t.walk(f); } } @@ -1094,7 +1094,7 @@ impl TypeWalk for Ty { } } TyKind::Alias(AliasTy::Opaque(o_ty)) => { - o_ty.parameters.walk_mut_binders(f, binders); + o_ty.substitution.walk_mut_binders(f, binders); } _ => { if let Some(substs) = self.substs_mut() { diff --git a/crates/hir_ty/src/lower.rs b/crates/hir_ty/src/lower.rs index 76b2124af..d026310f4 100644 --- a/crates/hir_ty/src/lower.rs +++ b/crates/hir_ty/src/lower.rs @@ -230,8 +230,11 @@ impl<'a> TyLoweringContext<'a> { let opaque_ty_id = self.db.intern_impl_trait_id(impl_trait_id).into(); let generics = generics(self.db.upcast(), func.into()); let parameters = Substs::bound_vars(&generics, self.in_binders); - TyKind::Alias(AliasTy::Opaque(OpaqueTy { opaque_ty_id, parameters })) - .intern(&Interner) + TyKind::Alias(AliasTy::Opaque(OpaqueTy { + opaque_ty_id, + substitution: parameters, + })) + .intern(&Interner) } ImplTraitLoweringMode::Param => { let idx = self.impl_trait_counter.get(); diff --git a/crates/hir_ty/src/traits/chalk/mapping.rs b/crates/hir_ty/src/traits/chalk/mapping.rs index 1a6fca611..05a4bf0df 100644 --- a/crates/hir_ty/src/traits/chalk/mapping.rs +++ b/crates/hir_ty/src/traits/chalk/mapping.rs @@ -87,6 +87,13 @@ impl ToChalk for Ty { .cast(&Interner) .intern(&Interner) } + TyKind::Alias(AliasTy::Opaque(opaque_ty)) => { + let opaque_ty_id = opaque_ty.opaque_ty_id; + let substitution = opaque_ty.substitution.to_chalk(db); + chalk_ir::AliasTy::Opaque(chalk_ir::OpaqueTy { opaque_ty_id, substitution }) + .cast(&Interner) + .intern(&Interner) + } TyKind::Placeholder(idx) => idx.to_ty::(&Interner), TyKind::BoundVar(idx) => chalk_ir::TyKind::BoundVar(idx).intern(&Interner), TyKind::InferenceVar(..) => panic!("uncanonicalized infer ty"), @@ -101,15 +108,6 @@ impl ToChalk for Ty { }; chalk_ir::TyKind::Dyn(bounded_ty).intern(&Interner) } - TyKind::Alias(AliasTy::Opaque(opaque_ty)) => { - let opaque_ty_id = opaque_ty.opaque_ty_id; - let substitution = opaque_ty.parameters.to_chalk(db); - chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Opaque(chalk_ir::OpaqueTy { - opaque_ty_id, - substitution, - })) - .intern(&Interner) - } TyKind::Unknown => chalk_ir::TyKind::Error.intern(&Interner), } } @@ -129,7 +127,7 @@ impl ToChalk for Ty { chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Opaque(opaque_ty)) => { let opaque_ty_id = opaque_ty.opaque_ty_id; let parameters = from_chalk(db, opaque_ty.substitution); - TyKind::Alias(AliasTy::Opaque(OpaqueTy { opaque_ty_id, parameters })) + TyKind::Alias(AliasTy::Opaque(OpaqueTy { opaque_ty_id, substitution: parameters })) } chalk_ir::TyKind::Function(chalk_ir::FnPointer { num_binders, -- cgit v1.2.3