From 7a5fb37cf12f4e25ce1ba7e464dd257408444bfb Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sat, 20 Mar 2021 10:46:36 +0100 Subject: Rename GenericPredicate -> WhereClause --- crates/hir/src/lib.rs | 12 +++++----- crates/hir_ty/src/db.rs | 11 ++++----- crates/hir_ty/src/display.rs | 29 +++++++++++------------ crates/hir_ty/src/infer/unify.rs | 17 +++++--------- crates/hir_ty/src/lib.rs | 38 +++++++++++++++---------------- crates/hir_ty/src/lower.rs | 37 ++++++++++++++---------------- crates/hir_ty/src/traits.rs | 12 +++++----- crates/hir_ty/src/traits/chalk.rs | 8 +++---- crates/hir_ty/src/traits/chalk/mapping.rs | 26 ++++++++++----------- crates/hir_ty/src/utils.rs | 4 ++-- 10 files changed, 89 insertions(+), 105 deletions(-) (limited to 'crates') diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index 300087f1f..268a2b901 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -57,8 +57,8 @@ use hir_ty::{ to_assoc_type_id, traits::{FnTrait, Solution, SolutionVariables}, AliasEq, AliasTy, BoundVar, CallableDefId, CallableSig, Canonical, DebruijnIndex, - GenericPredicate, InEnvironment, Interner, Obligation, ProjectionTy, Scalar, Substitution, Ty, - TyDefId, TyKind, TyVariableKind, + InEnvironment, Interner, Obligation, ProjectionTy, Scalar, Substitution, Ty, TyDefId, TyKind, + TyVariableKind, WhereClause, }; use itertools::Itertools; use rustc_hash::FxHashSet; @@ -1461,7 +1461,7 @@ impl TypeParam { db.generic_predicates_for_param(self.id) .into_iter() .filter_map(|pred| match &pred.value { - hir_ty::GenericPredicate::Implemented(trait_ref) => { + hir_ty::WhereClause::Implemented(trait_ref) => { Some(Trait::from(trait_ref.hir_trait_id())) } _ => None, @@ -2022,7 +2022,7 @@ impl Type { self.ty.value.impl_trait_bounds(db).map(|it| { it.into_iter() .filter_map(|pred| match pred { - hir_ty::GenericPredicate::Implemented(trait_ref) => { + hir_ty::WhereClause::Implemented(trait_ref) => { Some(Trait::from(trait_ref.hir_trait_id())) } _ => None, @@ -2060,12 +2060,12 @@ impl Type { fn walk_bounds( db: &dyn HirDatabase, type_: &Type, - bounds: &[GenericPredicate], + bounds: &[WhereClause], cb: &mut impl FnMut(Type), ) { for pred in bounds { match pred { - GenericPredicate::Implemented(trait_ref) => { + WhereClause::Implemented(trait_ref) => { cb(type_.clone()); walk_substs(db, type_, &trait_ref.substitution, cb); } diff --git a/crates/hir_ty/src/db.rs b/crates/hir_ty/src/db.rs index 74a048672..300da0f38 100644 --- a/crates/hir_ty/src/db.rs +++ b/crates/hir_ty/src/db.rs @@ -12,8 +12,8 @@ use la_arena::ArenaMap; use crate::{ method_resolution::{InherentImpls, TraitImpls}, traits::chalk, - Binders, CallableDefId, FnDefId, GenericPredicate, ImplTraitId, InferenceResult, PolyFnSig, - ReturnTypeImplTraits, TraitRef, Ty, TyDefId, ValueTyDefId, + Binders, CallableDefId, FnDefId, ImplTraitId, InferenceResult, PolyFnSig, ReturnTypeImplTraits, + TraitRef, Ty, TyDefId, ValueTyDefId, WhereClause, }; use hir_expand::name::Name; @@ -57,13 +57,10 @@ pub trait HirDatabase: DefDatabase + Upcast { #[salsa::invoke(crate::lower::generic_predicates_for_param_query)] #[salsa::cycle(crate::lower::generic_predicates_for_param_recover)] - fn generic_predicates_for_param( - &self, - param_id: TypeParamId, - ) -> Arc<[Binders]>; + fn generic_predicates_for_param(&self, param_id: TypeParamId) -> Arc<[Binders]>; #[salsa::invoke(crate::lower::generic_predicates_query)] - fn generic_predicates(&self, def: GenericDefId) -> Arc<[Binders]>; + fn generic_predicates(&self, def: GenericDefId) -> Arc<[Binders]>; #[salsa::invoke(crate::lower::trait_environment_query)] fn trait_environment(&self, def: GenericDefId) -> Arc; diff --git a/crates/hir_ty/src/display.rs b/crates/hir_ty/src/display.rs index 59a1bd9b0..2721b8312 100644 --- a/crates/hir_ty/src/display.rs +++ b/crates/hir_ty/src/display.rs @@ -19,8 +19,8 @@ use hir_expand::name::Name; use crate::{ db::HirDatabase, from_assoc_type_id, from_foreign_def_id, from_placeholder_idx, primitive, to_assoc_type_id, traits::chalk::from_chalk, utils::generics, AdtId, AliasEq, AliasTy, - CallableDefId, CallableSig, GenericPredicate, ImplTraitId, Interner, Lifetime, Obligation, - OpaqueTy, ProjectionTy, Scalar, Substitution, TraitRef, Ty, TyKind, + CallableDefId, CallableSig, ImplTraitId, Interner, Lifetime, Obligation, OpaqueTy, + ProjectionTy, Scalar, Substitution, TraitRef, Ty, TyKind, WhereClause, }; pub struct HirFormatter<'a> { @@ -353,7 +353,7 @@ impl HirDisplay for Ty { _ => Cow::Borrowed(&[][..]), }; - if let [GenericPredicate::Implemented(trait_ref), _] = predicates.as_ref() { + if let [WhereClause::Implemented(trait_ref), _] = predicates.as_ref() { let trait_ = trait_ref.hir_trait_id(); if fn_traits(f.db.upcast(), trait_).any(|it| it == trait_) { return write!(f, "{}", ty_display); @@ -652,7 +652,7 @@ fn fn_traits(db: &dyn DefDatabase, trait_: TraitId) -> impl Iterator Result<(), HirDisplayError> { write!(f, "{}", prefix)?; @@ -665,7 +665,7 @@ pub fn write_bounds_like_dyn_trait_with_prefix( } fn write_bounds_like_dyn_trait( - predicates: &[GenericPredicate], + predicates: &[WhereClause], f: &mut HirFormatter, ) -> Result<(), HirDisplayError> { // Note: This code is written to produce nice results (i.e. @@ -679,7 +679,7 @@ fn write_bounds_like_dyn_trait( let mut is_fn_trait = false; for p in predicates.iter() { match p { - GenericPredicate::Implemented(trait_ref) => { + WhereClause::Implemented(trait_ref) => { let trait_ = trait_ref.hir_trait_id(); if !is_fn_trait { is_fn_trait = fn_traits(f.db.upcast(), trait_).any(|it| it == trait_); @@ -710,12 +710,12 @@ fn write_bounds_like_dyn_trait( } } } - GenericPredicate::AliasEq(alias_eq) if is_fn_trait => { + WhereClause::AliasEq(alias_eq) if is_fn_trait => { is_fn_trait = false; write!(f, " -> ")?; alias_eq.ty.hir_fmt(f)?; } - GenericPredicate::AliasEq(AliasEq { ty, alias }) => { + WhereClause::AliasEq(AliasEq { ty, alias }) => { // in types in actual Rust, these will always come // after the corresponding Implemented predicate if angle_open { @@ -731,7 +731,7 @@ fn write_bounds_like_dyn_trait( } ty.hir_fmt(f)?; } - GenericPredicate::Error => { + WhereClause::Error => { if angle_open { // impl Trait write!(f, ", ")?; @@ -778,18 +778,15 @@ impl HirDisplay for TraitRef { } } -impl HirDisplay for GenericPredicate { +impl HirDisplay for WhereClause { fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { if f.should_truncate() { return write!(f, "{}", TYPE_HINT_TRUNCATION); } match self { - GenericPredicate::Implemented(trait_ref) => trait_ref.hir_fmt(f)?, - GenericPredicate::AliasEq(AliasEq { - alias: AliasTy::Projection(projection_ty), - ty, - }) => { + WhereClause::Implemented(trait_ref) => trait_ref.hir_fmt(f)?, + WhereClause::AliasEq(AliasEq { alias: AliasTy::Projection(projection_ty), ty }) => { write!(f, "<")?; projection_ty.trait_ref(f.db).hir_fmt_ext(f, true)?; write!( @@ -799,7 +796,7 @@ impl HirDisplay for GenericPredicate { )?; ty.hir_fmt(f)?; } - GenericPredicate::AliasEq(_) | GenericPredicate::Error => write!(f, "{{error}}")?, + WhereClause::AliasEq(_) | WhereClause::Error => write!(f, "{{error}}")?, } Ok(()) } diff --git a/crates/hir_ty/src/infer/unify.rs b/crates/hir_ty/src/infer/unify.rs index 4738ec08a..5b7b423fa 100644 --- a/crates/hir_ty/src/infer/unify.rs +++ b/crates/hir_ty/src/infer/unify.rs @@ -7,8 +7,8 @@ use ena::unify::{InPlaceUnificationTable, NoError, UnifyKey, UnifyValue}; use super::{InferenceContext, Obligation}; use crate::{ - AliasEq, AliasTy, BoundVar, Canonical, DebruijnIndex, FnPointer, GenericPredicate, - InEnvironment, InferenceVar, Interner, Scalar, Substitution, Ty, TyKind, TypeWalk, + AliasEq, AliasTy, BoundVar, Canonical, DebruijnIndex, FnPointer, InEnvironment, InferenceVar, + Interner, Scalar, Substitution, Ty, TyKind, TypeWalk, WhereClause, }; impl<'a> InferenceContext<'a> { @@ -382,21 +382,16 @@ impl InferenceTable { } } - fn unify_preds( - &mut self, - pred1: &GenericPredicate, - pred2: &GenericPredicate, - depth: usize, - ) -> bool { + fn unify_preds(&mut self, pred1: &WhereClause, pred2: &WhereClause, depth: usize) -> bool { match (pred1, pred2) { - (GenericPredicate::Implemented(tr1), GenericPredicate::Implemented(tr2)) + (WhereClause::Implemented(tr1), WhereClause::Implemented(tr2)) if tr1.trait_id == tr2.trait_id => { self.unify_substs(&tr1.substitution, &tr2.substitution, depth + 1) } ( - GenericPredicate::AliasEq(AliasEq { alias: alias1, ty: ty1 }), - GenericPredicate::AliasEq(AliasEq { alias: alias2, ty: ty2 }), + WhereClause::AliasEq(AliasEq { alias: alias1, ty: ty1 }), + WhereClause::AliasEq(AliasEq { alias: alias2, ty: ty2 }), ) => { let (substitution1, substitution2) = match (alias1, alias2) { (AliasTy::Projection(projection_ty1), AliasTy::Projection(projection_ty2)) diff --git a/crates/hir_ty/src/lib.rs b/crates/hir_ty/src/lib.rs index 2afcb5413..5c4d5a7d7 100644 --- a/crates/hir_ty/src/lib.rs +++ b/crates/hir_ty/src/lib.rs @@ -276,7 +276,7 @@ pub enum TyKind { /// represents the `Self` type inside the bounds. This is currently /// implicit; Chalk has the `Binders` struct to make it explicit, but it /// didn't seem worth the overhead yet. - Dyn(Arc<[GenericPredicate]>), + Dyn(Arc<[WhereClause]>), /// A placeholder for a type which could not be computed; this is propagated /// to avoid useless error messages. Doubles as a placeholder where type @@ -564,7 +564,7 @@ impl TypeWalk for TraitRef { /// Like `generics::WherePredicate`, but with resolved types: A condition on the /// parameters of a generic item. #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub enum GenericPredicate { +pub enum WhereClause { /// The given trait needs to be implemented for its type parameters. Implemented(TraitRef), /// An associated type bindings like in `Iterator`. @@ -574,32 +574,32 @@ pub enum GenericPredicate { Error, } -impl GenericPredicate { +impl WhereClause { pub fn is_error(&self) -> bool { - matches!(self, GenericPredicate::Error) + matches!(self, WhereClause::Error) } pub fn is_implemented(&self) -> bool { - matches!(self, GenericPredicate::Implemented(_)) + matches!(self, WhereClause::Implemented(_)) } pub fn trait_ref(&self, db: &dyn HirDatabase) -> Option { match self { - GenericPredicate::Implemented(tr) => Some(tr.clone()), - GenericPredicate::AliasEq(AliasEq { alias: AliasTy::Projection(proj), .. }) => { + WhereClause::Implemented(tr) => Some(tr.clone()), + WhereClause::AliasEq(AliasEq { alias: AliasTy::Projection(proj), .. }) => { Some(proj.trait_ref(db)) } - GenericPredicate::AliasEq(_) | GenericPredicate::Error => None, + WhereClause::AliasEq(_) | WhereClause::Error => None, } } } -impl TypeWalk for GenericPredicate { +impl TypeWalk for WhereClause { fn walk(&self, f: &mut impl FnMut(&Ty)) { match self { - GenericPredicate::Implemented(trait_ref) => trait_ref.walk(f), - GenericPredicate::AliasEq(alias_eq) => alias_eq.walk(f), - GenericPredicate::Error => {} + WhereClause::Implemented(trait_ref) => trait_ref.walk(f), + WhereClause::AliasEq(alias_eq) => alias_eq.walk(f), + WhereClause::Error => {} } } @@ -609,9 +609,9 @@ impl TypeWalk for GenericPredicate { binders: DebruijnIndex, ) { match self { - GenericPredicate::Implemented(trait_ref) => trait_ref.walk_mut_binders(f, binders), - GenericPredicate::AliasEq(alias_eq) => alias_eq.walk_mut_binders(f, binders), - GenericPredicate::Error => {} + WhereClause::Implemented(trait_ref) => trait_ref.walk_mut_binders(f, binders), + WhereClause::AliasEq(alias_eq) => alias_eq.walk_mut_binders(f, binders), + WhereClause::Error => {} } } } @@ -815,7 +815,7 @@ impl Ty { pub fn dyn_trait_ref(&self) -> Option<&TraitRef> { match self.interned(&Interner) { TyKind::Dyn(bounds) => bounds.get(0).and_then(|b| match b { - GenericPredicate::Implemented(trait_ref) => Some(trait_ref), + WhereClause::Implemented(trait_ref) => Some(trait_ref), _ => None, }), _ => None, @@ -894,7 +894,7 @@ impl Ty { } } - pub fn impl_trait_bounds(&self, db: &dyn HirDatabase) -> Option> { + pub fn impl_trait_bounds(&self, db: &dyn HirDatabase) -> Option> { match self.interned(&Interner) { TyKind::OpaqueType(opaque_ty_id, ..) => { match db.lookup_intern_impl_trait_id((*opaque_ty_id).into()) { @@ -907,7 +907,7 @@ impl Ty { // This is only used by type walking. // Parameters will be walked outside, and projection predicate is not used. // So just provide the Future trait. - let impl_bound = GenericPredicate::Implemented(TraitRef { + let impl_bound = WhereClause::Implemented(TraitRef { trait_id: to_chalk_trait_id(future_trait), substitution: Substitution::empty(), }); @@ -1166,7 +1166,7 @@ pub struct ReturnTypeImplTraits { #[derive(Clone, PartialEq, Eq, Debug, Hash)] pub(crate) struct ReturnTypeImplTrait { - pub(crate) bounds: Binders>, + pub(crate) bounds: Binders>, } pub fn to_foreign_def_id(id: TypeAliasId) -> ForeignDefId { diff --git a/crates/hir_ty/src/lower.rs b/crates/hir_ty/src/lower.rs index 7d22c3df5..4199dc7a6 100644 --- a/crates/hir_ty/src/lower.rs +++ b/crates/hir_ty/src/lower.rs @@ -33,9 +33,9 @@ use crate::{ all_super_trait_refs, associated_type_by_name_including_super_traits, generics, variant_data, }, - AliasEq, AliasTy, Binders, BoundVar, CallableSig, DebruijnIndex, FnPointer, FnSig, - GenericPredicate, ImplTraitId, OpaqueTy, PolyFnSig, ProjectionTy, ReturnTypeImplTrait, - ReturnTypeImplTraits, Substitution, TraitEnvironment, TraitRef, Ty, TyKind, TypeWalk, + AliasEq, AliasTy, Binders, BoundVar, CallableSig, DebruijnIndex, FnPointer, FnSig, ImplTraitId, + OpaqueTy, PolyFnSig, ProjectionTy, ReturnTypeImplTrait, ReturnTypeImplTraits, Substitution, + TraitEnvironment, TraitRef, Ty, TyKind, TypeWalk, WhereClause, }; #[derive(Debug)] @@ -373,8 +373,7 @@ impl<'a> TyLoweringContext<'a> { // FIXME report error (ambiguous associated type) TyKind::Unknown.intern(&Interner) } else { - TyKind::Dyn(Arc::new([GenericPredicate::Implemented(trait_ref)])) - .intern(&Interner) + TyKind::Dyn(Arc::new([WhereClause::Implemented(trait_ref)])).intern(&Interner) }; return (ty, None); } @@ -667,7 +666,7 @@ impl<'a> TyLoweringContext<'a> { pub(crate) fn lower_where_predicate( &'a self, where_predicate: &'a WherePredicate, - ) -> impl Iterator + 'a { + ) -> impl Iterator + 'a { match where_predicate { WherePredicate::ForLifetime { target, bound, .. } | WherePredicate::TypeBound { target, bound } => { @@ -699,17 +698,15 @@ impl<'a> TyLoweringContext<'a> { &'a self, bound: &'a TypeBound, self_ty: Ty, - ) -> impl Iterator + 'a { + ) -> impl Iterator + 'a { let mut bindings = None; let trait_ref = match bound { TypeBound::Path(path) => { bindings = self.lower_trait_ref_from_path(path, Some(self_ty)); - Some( - bindings.clone().map_or(GenericPredicate::Error, GenericPredicate::Implemented), - ) + Some(bindings.clone().map_or(WhereClause::Error, WhereClause::Implemented)) } TypeBound::Lifetime(_) => None, - TypeBound::Error => Some(GenericPredicate::Error), + TypeBound::Error => Some(WhereClause::Error), }; trait_ref.into_iter().chain( bindings @@ -722,7 +719,7 @@ impl<'a> TyLoweringContext<'a> { &'a self, bound: &'a TypeBound, trait_ref: TraitRef, - ) -> impl Iterator + 'a { + ) -> impl Iterator + 'a { let last_segment = match bound { TypeBound::Path(path) => path.segments().last(), TypeBound::Error | TypeBound::Lifetime(_) => None, @@ -738,7 +735,7 @@ impl<'a> TyLoweringContext<'a> { &binding.name, ); let (super_trait_ref, associated_ty) = match found { - None => return SmallVec::<[GenericPredicate; 1]>::new(), + None => return SmallVec::<[WhereClause; 1]>::new(), Some(t) => t, }; let projection_ty = ProjectionTy { @@ -752,7 +749,7 @@ impl<'a> TyLoweringContext<'a> { let ty = self.lower_ty(type_ref); let alias_eq = AliasEq { alias: AliasTy::Projection(projection_ty.clone()), ty }; - preds.push(GenericPredicate::AliasEq(alias_eq)); + preds.push(WhereClause::AliasEq(alias_eq)); } for bound in &binding.bounds { preds.extend(self.lower_type_bound( @@ -809,7 +806,7 @@ pub fn associated_type_shorthand_candidates( let mut traits_: Vec<_> = predicates .iter() .filter_map(|pred| match &pred.value { - GenericPredicate::Implemented(tr) => Some(tr.clone()), + WhereClause::Implemented(tr) => Some(tr.clone()), _ => None, }) .collect(); @@ -881,7 +878,7 @@ pub(crate) fn field_types_query( pub(crate) fn generic_predicates_for_param_query( db: &dyn HirDatabase, param_id: TypeParamId, -) -> Arc<[Binders]> { +) -> Arc<[Binders]> { let resolver = param_id.parent.resolver(db.upcast()); let ctx = TyLoweringContext::new(db, &resolver).with_type_param_mode(TypeParamLoweringMode::Variable); @@ -907,7 +904,7 @@ pub(crate) fn generic_predicates_for_param_recover( _db: &dyn HirDatabase, _cycle: &[String], _param_id: &TypeParamId, -) -> Arc<[Binders]> { +) -> Arc<[Binders]> { Arc::new([]) } @@ -925,7 +922,7 @@ pub(crate) fn trait_environment_query( if pred.is_error() { continue; } - if let GenericPredicate::Implemented(tr) = &pred { + if let WhereClause::Implemented(tr) = &pred { traits_in_scope.push((tr.self_type_parameter().clone(), tr.hir_trait_id())); } let program_clause: chalk_ir::ProgramClause = @@ -951,7 +948,7 @@ pub(crate) fn trait_environment_query( cov_mark::hit!(trait_self_implements_self); let substs = Substitution::type_params(db, trait_id); let trait_ref = TraitRef { trait_id: to_chalk_trait_id(trait_id), substitution: substs }; - let pred = GenericPredicate::Implemented(trait_ref); + let pred = WhereClause::Implemented(trait_ref); let program_clause: chalk_ir::ProgramClause = pred.clone().to_chalk(db).cast(&Interner); clauses.push(program_clause.into_from_env_clause(&Interner)); @@ -966,7 +963,7 @@ pub(crate) fn trait_environment_query( pub(crate) fn generic_predicates_query( db: &dyn HirDatabase, def: GenericDefId, -) -> Arc<[Binders]> { +) -> Arc<[Binders]> { let resolver = def.resolver(db.upcast()); let ctx = TyLoweringContext::new(db, &resolver).with_type_param_mode(TypeParamLoweringMode::Variable); diff --git a/crates/hir_ty/src/traits.rs b/crates/hir_ty/src/traits.rs index ac7de7605..6feb64ceb 100644 --- a/crates/hir_ty/src/traits.rs +++ b/crates/hir_ty/src/traits.rs @@ -9,8 +9,8 @@ use hir_def::{lang_item::LangItemTarget, TraitId}; use stdx::panic_context; use crate::{ - db::HirDatabase, AliasTy, Canonical, DebruijnIndex, GenericPredicate, HirDisplay, Substitution, - TraitRef, Ty, TyKind, TypeWalk, + db::HirDatabase, AliasTy, Canonical, DebruijnIndex, HirDisplay, Substitution, TraitRef, Ty, + TyKind, TypeWalk, WhereClause, }; use self::chalk::{from_chalk, Interner, ToChalk}; @@ -96,11 +96,11 @@ pub enum Obligation { } impl Obligation { - pub fn from_predicate(predicate: GenericPredicate) -> Option { + pub fn from_predicate(predicate: WhereClause) -> Option { match predicate { - GenericPredicate::Implemented(trait_ref) => Some(Obligation::Trait(trait_ref)), - GenericPredicate::AliasEq(alias_eq) => Some(Obligation::AliasEq(alias_eq)), - GenericPredicate::Error => None, + WhereClause::Implemented(trait_ref) => Some(Obligation::Trait(trait_ref)), + WhereClause::AliasEq(alias_eq) => Some(Obligation::AliasEq(alias_eq)), + WhereClause::Error => None, } } } diff --git a/crates/hir_ty/src/traits/chalk.rs b/crates/hir_ty/src/traits/chalk.rs index 080764e76..4144035cd 100644 --- a/crates/hir_ty/src/traits/chalk.rs +++ b/crates/hir_ty/src/traits/chalk.rs @@ -21,8 +21,8 @@ use crate::{ method_resolution::{TyFingerprint, ALL_FLOAT_FPS, ALL_INT_FPS}, to_assoc_type_id, to_chalk_trait_id, utils::generics, - AliasEq, AliasTy, BoundVar, CallableDefId, CallableSig, DebruijnIndex, FnDefId, - GenericPredicate, ProjectionTy, Substitution, TraitRef, Ty, TyKind, + AliasEq, AliasTy, BoundVar, CallableDefId, CallableSig, DebruijnIndex, FnDefId, ProjectionTy, + Substitution, TraitRef, Ty, TyKind, WhereClause, }; use mapping::{ convert_where_clauses, generic_predicate_to_inline_bound, make_binders, TypeAliasAsValue, @@ -218,7 +218,7 @@ impl<'a> chalk_solve::RustIrDatabase for ChalkContext<'a> { // |-------------OpaqueTyDatumBound--------------| // for [Future, Future::Output = T] // ^1 ^0 ^0 ^0 ^1 - let impl_bound = GenericPredicate::Implemented(TraitRef { + let impl_bound = WhereClause::Implemented(TraitRef { trait_id: to_chalk_trait_id(future_trait), // Self type as the first parameter. substitution: Substitution::single( @@ -229,7 +229,7 @@ impl<'a> chalk_solve::RustIrDatabase for ChalkContext<'a> { .intern(&Interner), ), }); - let proj_bound = GenericPredicate::AliasEq(AliasEq { + let proj_bound = WhereClause::AliasEq(AliasEq { alias: AliasTy::Projection(ProjectionTy { associated_ty_id: to_assoc_type_id(future_output), // Self type as the first parameter. diff --git a/crates/hir_ty/src/traits/chalk/mapping.rs b/crates/hir_ty/src/traits/chalk/mapping.rs index 62b779008..5756e9754 100644 --- a/crates/hir_ty/src/traits/chalk/mapping.rs +++ b/crates/hir_ty/src/traits/chalk/mapping.rs @@ -14,8 +14,8 @@ use crate::{ from_assoc_type_id, primitive::UintTy, traits::{Canonical, Obligation}, - AliasTy, CallableDefId, FnPointer, GenericPredicate, InEnvironment, OpaqueTy, ProjectionTy, - Scalar, Substitution, TraitRef, Ty, + AliasTy, CallableDefId, FnPointer, InEnvironment, OpaqueTy, ProjectionTy, Scalar, Substitution, + TraitRef, Ty, WhereClause, }; use super::interner::*; @@ -304,28 +304,28 @@ impl ToChalk for TypeAliasAsValue { } } -impl ToChalk for GenericPredicate { +impl ToChalk for WhereClause { type Chalk = chalk_ir::QuantifiedWhereClause; fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::QuantifiedWhereClause { match self { - GenericPredicate::Implemented(trait_ref) => { + WhereClause::Implemented(trait_ref) => { let chalk_trait_ref = trait_ref.to_chalk(db); let chalk_trait_ref = chalk_trait_ref.shifted_in(&Interner); make_binders(chalk_ir::WhereClause::Implemented(chalk_trait_ref), 0) } - GenericPredicate::AliasEq(alias_eq) => make_binders( + WhereClause::AliasEq(alias_eq) => make_binders( chalk_ir::WhereClause::AliasEq(alias_eq.to_chalk(db).shifted_in(&Interner)), 0, ), - GenericPredicate::Error => panic!("tried passing GenericPredicate::Error to Chalk"), + WhereClause::Error => panic!("tried passing GenericPredicate::Error to Chalk"), } } fn from_chalk( db: &dyn HirDatabase, where_clause: chalk_ir::QuantifiedWhereClause, - ) -> GenericPredicate { + ) -> WhereClause { // we don't produce any where clauses with binders and can't currently deal with them match where_clause .skip_binders() @@ -333,11 +333,9 @@ impl ToChalk for GenericPredicate { .shifted_out(&Interner) .expect("unexpected bound vars in where clause") { - chalk_ir::WhereClause::Implemented(tr) => { - GenericPredicate::Implemented(from_chalk(db, tr)) - } + chalk_ir::WhereClause::Implemented(tr) => WhereClause::Implemented(from_chalk(db, tr)), chalk_ir::WhereClause::AliasEq(alias_eq) => { - GenericPredicate::AliasEq(from_chalk(db, alias_eq)) + WhereClause::AliasEq(from_chalk(db, alias_eq)) } chalk_ir::WhereClause::LifetimeOutlives(_) => { @@ -534,13 +532,13 @@ pub(super) fn convert_where_clauses( pub(super) fn generic_predicate_to_inline_bound( db: &dyn HirDatabase, - pred: &GenericPredicate, + pred: &WhereClause, self_ty: &Ty, ) -> Option> { // An InlineBound is like a GenericPredicate, except the self type is left out. // We don't have a special type for this, but Chalk does. match pred { - GenericPredicate::Implemented(trait_ref) => { + WhereClause::Implemented(trait_ref) => { if &trait_ref.substitution[0] != self_ty { // we can only convert predicates back to type bounds if they // have the expected self type @@ -553,7 +551,7 @@ pub(super) fn generic_predicate_to_inline_bound( let trait_bound = rust_ir::TraitBound { trait_id: trait_ref.trait_id, args_no_self }; Some(rust_ir::InlineBound::TraitBound(trait_bound)) } - GenericPredicate::AliasEq(AliasEq { alias: AliasTy::Projection(projection_ty), ty }) => { + WhereClause::AliasEq(AliasEq { alias: AliasTy::Projection(projection_ty), ty }) => { if &projection_ty.substitution[0] != self_ty { return None; } diff --git a/crates/hir_ty/src/utils.rs b/crates/hir_ty/src/utils.rs index b66243d48..1ec1ecd43 100644 --- a/crates/hir_ty/src/utils.rs +++ b/crates/hir_ty/src/utils.rs @@ -15,7 +15,7 @@ use hir_def::{ }; use hir_expand::name::{name, Name}; -use crate::{db::HirDatabase, GenericPredicate, TraitRef}; +use crate::{db::HirDatabase, TraitRef, WhereClause}; fn direct_super_traits(db: &dyn DefDatabase, trait_: TraitId) -> Vec { let resolver = trait_.resolver(db); @@ -64,7 +64,7 @@ fn direct_super_trait_refs(db: &dyn HirDatabase, trait_ref: &TraitRef) -> Vec Some(tr.clone()), + WhereClause::Implemented(tr) => Some(tr.clone()), _ => None, }) }) -- cgit v1.2.3