Skip to content

Commit 3901c3b

Browse files
Merge #8115
8115: Rename GenericPredicate -> WhereClause r=flodiebold a=flodiebold Co-authored-by: Florian Diebold <[email protected]>
2 parents 8b16af5 + 7a5fb37 commit 3901c3b

File tree

10 files changed

+89
-105
lines changed

10 files changed

+89
-105
lines changed

crates/hir/src/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ use hir_ty::{
5757
to_assoc_type_id,
5858
traits::{FnTrait, Solution, SolutionVariables},
5959
AliasEq, AliasTy, BoundVar, CallableDefId, CallableSig, Canonical, DebruijnIndex,
60-
GenericPredicate, InEnvironment, Interner, Obligation, ProjectionTy, Scalar, Substitution, Ty,
61-
TyDefId, TyKind, TyVariableKind,
60+
InEnvironment, Interner, Obligation, ProjectionTy, Scalar, Substitution, Ty, TyDefId, TyKind,
61+
TyVariableKind, WhereClause,
6262
};
6363
use itertools::Itertools;
6464
use rustc_hash::FxHashSet;
@@ -1461,7 +1461,7 @@ impl TypeParam {
14611461
db.generic_predicates_for_param(self.id)
14621462
.into_iter()
14631463
.filter_map(|pred| match &pred.value {
1464-
hir_ty::GenericPredicate::Implemented(trait_ref) => {
1464+
hir_ty::WhereClause::Implemented(trait_ref) => {
14651465
Some(Trait::from(trait_ref.hir_trait_id()))
14661466
}
14671467
_ => None,
@@ -2022,7 +2022,7 @@ impl Type {
20222022
self.ty.value.impl_trait_bounds(db).map(|it| {
20232023
it.into_iter()
20242024
.filter_map(|pred| match pred {
2025-
hir_ty::GenericPredicate::Implemented(trait_ref) => {
2025+
hir_ty::WhereClause::Implemented(trait_ref) => {
20262026
Some(Trait::from(trait_ref.hir_trait_id()))
20272027
}
20282028
_ => None,
@@ -2060,12 +2060,12 @@ impl Type {
20602060
fn walk_bounds(
20612061
db: &dyn HirDatabase,
20622062
type_: &Type,
2063-
bounds: &[GenericPredicate],
2063+
bounds: &[WhereClause],
20642064
cb: &mut impl FnMut(Type),
20652065
) {
20662066
for pred in bounds {
20672067
match pred {
2068-
GenericPredicate::Implemented(trait_ref) => {
2068+
WhereClause::Implemented(trait_ref) => {
20692069
cb(type_.clone());
20702070
walk_substs(db, type_, &trait_ref.substitution, cb);
20712071
}

crates/hir_ty/src/db.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ use la_arena::ArenaMap;
1212
use crate::{
1313
method_resolution::{InherentImpls, TraitImpls},
1414
traits::chalk,
15-
Binders, CallableDefId, FnDefId, GenericPredicate, ImplTraitId, InferenceResult, PolyFnSig,
16-
ReturnTypeImplTraits, TraitRef, Ty, TyDefId, ValueTyDefId,
15+
Binders, CallableDefId, FnDefId, ImplTraitId, InferenceResult, PolyFnSig, ReturnTypeImplTraits,
16+
TraitRef, Ty, TyDefId, ValueTyDefId, WhereClause,
1717
};
1818
use hir_expand::name::Name;
1919

@@ -57,13 +57,10 @@ pub trait HirDatabase: DefDatabase + Upcast<dyn DefDatabase> {
5757

5858
#[salsa::invoke(crate::lower::generic_predicates_for_param_query)]
5959
#[salsa::cycle(crate::lower::generic_predicates_for_param_recover)]
60-
fn generic_predicates_for_param(
61-
&self,
62-
param_id: TypeParamId,
63-
) -> Arc<[Binders<GenericPredicate>]>;
60+
fn generic_predicates_for_param(&self, param_id: TypeParamId) -> Arc<[Binders<WhereClause>]>;
6461

6562
#[salsa::invoke(crate::lower::generic_predicates_query)]
66-
fn generic_predicates(&self, def: GenericDefId) -> Arc<[Binders<GenericPredicate>]>;
63+
fn generic_predicates(&self, def: GenericDefId) -> Arc<[Binders<WhereClause>]>;
6764

6865
#[salsa::invoke(crate::lower::trait_environment_query)]
6966
fn trait_environment(&self, def: GenericDefId) -> Arc<crate::TraitEnvironment>;

crates/hir_ty/src/display.rs

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ use hir_expand::name::Name;
1919
use crate::{
2020
db::HirDatabase, from_assoc_type_id, from_foreign_def_id, from_placeholder_idx, primitive,
2121
to_assoc_type_id, traits::chalk::from_chalk, utils::generics, AdtId, AliasEq, AliasTy,
22-
CallableDefId, CallableSig, GenericPredicate, ImplTraitId, Interner, Lifetime, Obligation,
23-
OpaqueTy, ProjectionTy, Scalar, Substitution, TraitRef, Ty, TyKind,
22+
CallableDefId, CallableSig, ImplTraitId, Interner, Lifetime, Obligation, OpaqueTy,
23+
ProjectionTy, Scalar, Substitution, TraitRef, Ty, TyKind, WhereClause,
2424
};
2525

2626
pub struct HirFormatter<'a> {
@@ -353,7 +353,7 @@ impl HirDisplay for Ty {
353353
_ => Cow::Borrowed(&[][..]),
354354
};
355355

356-
if let [GenericPredicate::Implemented(trait_ref), _] = predicates.as_ref() {
356+
if let [WhereClause::Implemented(trait_ref), _] = predicates.as_ref() {
357357
let trait_ = trait_ref.hir_trait_id();
358358
if fn_traits(f.db.upcast(), trait_).any(|it| it == trait_) {
359359
return write!(f, "{}", ty_display);
@@ -652,7 +652,7 @@ fn fn_traits(db: &dyn DefDatabase, trait_: TraitId) -> impl Iterator<Item = Trai
652652

653653
pub fn write_bounds_like_dyn_trait_with_prefix(
654654
prefix: &str,
655-
predicates: &[GenericPredicate],
655+
predicates: &[WhereClause],
656656
f: &mut HirFormatter,
657657
) -> Result<(), HirDisplayError> {
658658
write!(f, "{}", prefix)?;
@@ -665,7 +665,7 @@ pub fn write_bounds_like_dyn_trait_with_prefix(
665665
}
666666

667667
fn write_bounds_like_dyn_trait(
668-
predicates: &[GenericPredicate],
668+
predicates: &[WhereClause],
669669
f: &mut HirFormatter,
670670
) -> Result<(), HirDisplayError> {
671671
// Note: This code is written to produce nice results (i.e.
@@ -679,7 +679,7 @@ fn write_bounds_like_dyn_trait(
679679
let mut is_fn_trait = false;
680680
for p in predicates.iter() {
681681
match p {
682-
GenericPredicate::Implemented(trait_ref) => {
682+
WhereClause::Implemented(trait_ref) => {
683683
let trait_ = trait_ref.hir_trait_id();
684684
if !is_fn_trait {
685685
is_fn_trait = fn_traits(f.db.upcast(), trait_).any(|it| it == trait_);
@@ -710,12 +710,12 @@ fn write_bounds_like_dyn_trait(
710710
}
711711
}
712712
}
713-
GenericPredicate::AliasEq(alias_eq) if is_fn_trait => {
713+
WhereClause::AliasEq(alias_eq) if is_fn_trait => {
714714
is_fn_trait = false;
715715
write!(f, " -> ")?;
716716
alias_eq.ty.hir_fmt(f)?;
717717
}
718-
GenericPredicate::AliasEq(AliasEq { ty, alias }) => {
718+
WhereClause::AliasEq(AliasEq { ty, alias }) => {
719719
// in types in actual Rust, these will always come
720720
// after the corresponding Implemented predicate
721721
if angle_open {
@@ -731,7 +731,7 @@ fn write_bounds_like_dyn_trait(
731731
}
732732
ty.hir_fmt(f)?;
733733
}
734-
GenericPredicate::Error => {
734+
WhereClause::Error => {
735735
if angle_open {
736736
// impl Trait<X, {error}>
737737
write!(f, ", ")?;
@@ -778,18 +778,15 @@ impl HirDisplay for TraitRef {
778778
}
779779
}
780780

781-
impl HirDisplay for GenericPredicate {
781+
impl HirDisplay for WhereClause {
782782
fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> {
783783
if f.should_truncate() {
784784
return write!(f, "{}", TYPE_HINT_TRUNCATION);
785785
}
786786

787787
match self {
788-
GenericPredicate::Implemented(trait_ref) => trait_ref.hir_fmt(f)?,
789-
GenericPredicate::AliasEq(AliasEq {
790-
alias: AliasTy::Projection(projection_ty),
791-
ty,
792-
}) => {
788+
WhereClause::Implemented(trait_ref) => trait_ref.hir_fmt(f)?,
789+
WhereClause::AliasEq(AliasEq { alias: AliasTy::Projection(projection_ty), ty }) => {
793790
write!(f, "<")?;
794791
projection_ty.trait_ref(f.db).hir_fmt_ext(f, true)?;
795792
write!(
@@ -799,7 +796,7 @@ impl HirDisplay for GenericPredicate {
799796
)?;
800797
ty.hir_fmt(f)?;
801798
}
802-
GenericPredicate::AliasEq(_) | GenericPredicate::Error => write!(f, "{{error}}")?,
799+
WhereClause::AliasEq(_) | WhereClause::Error => write!(f, "{{error}}")?,
803800
}
804801
Ok(())
805802
}

crates/hir_ty/src/infer/unify.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use ena::unify::{InPlaceUnificationTable, NoError, UnifyKey, UnifyValue};
77

88
use super::{InferenceContext, Obligation};
99
use crate::{
10-
AliasEq, AliasTy, BoundVar, Canonical, DebruijnIndex, FnPointer, GenericPredicate,
11-
InEnvironment, InferenceVar, Interner, Scalar, Substitution, Ty, TyKind, TypeWalk,
10+
AliasEq, AliasTy, BoundVar, Canonical, DebruijnIndex, FnPointer, InEnvironment, InferenceVar,
11+
Interner, Scalar, Substitution, Ty, TyKind, TypeWalk, WhereClause,
1212
};
1313

1414
impl<'a> InferenceContext<'a> {
@@ -382,21 +382,16 @@ impl InferenceTable {
382382
}
383383
}
384384

385-
fn unify_preds(
386-
&mut self,
387-
pred1: &GenericPredicate,
388-
pred2: &GenericPredicate,
389-
depth: usize,
390-
) -> bool {
385+
fn unify_preds(&mut self, pred1: &WhereClause, pred2: &WhereClause, depth: usize) -> bool {
391386
match (pred1, pred2) {
392-
(GenericPredicate::Implemented(tr1), GenericPredicate::Implemented(tr2))
387+
(WhereClause::Implemented(tr1), WhereClause::Implemented(tr2))
393388
if tr1.trait_id == tr2.trait_id =>
394389
{
395390
self.unify_substs(&tr1.substitution, &tr2.substitution, depth + 1)
396391
}
397392
(
398-
GenericPredicate::AliasEq(AliasEq { alias: alias1, ty: ty1 }),
399-
GenericPredicate::AliasEq(AliasEq { alias: alias2, ty: ty2 }),
393+
WhereClause::AliasEq(AliasEq { alias: alias1, ty: ty1 }),
394+
WhereClause::AliasEq(AliasEq { alias: alias2, ty: ty2 }),
400395
) => {
401396
let (substitution1, substitution2) = match (alias1, alias2) {
402397
(AliasTy::Projection(projection_ty1), AliasTy::Projection(projection_ty2))

crates/hir_ty/src/lib.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ pub enum TyKind {
276276
/// represents the `Self` type inside the bounds. This is currently
277277
/// implicit; Chalk has the `Binders` struct to make it explicit, but it
278278
/// didn't seem worth the overhead yet.
279-
Dyn(Arc<[GenericPredicate]>),
279+
Dyn(Arc<[WhereClause]>),
280280

281281
/// A placeholder for a type which could not be computed; this is propagated
282282
/// to avoid useless error messages. Doubles as a placeholder where type
@@ -564,7 +564,7 @@ impl TypeWalk for TraitRef {
564564
/// Like `generics::WherePredicate`, but with resolved types: A condition on the
565565
/// parameters of a generic item.
566566
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
567-
pub enum GenericPredicate {
567+
pub enum WhereClause {
568568
/// The given trait needs to be implemented for its type parameters.
569569
Implemented(TraitRef),
570570
/// An associated type bindings like in `Iterator<Item = T>`.
@@ -574,32 +574,32 @@ pub enum GenericPredicate {
574574
Error,
575575
}
576576

577-
impl GenericPredicate {
577+
impl WhereClause {
578578
pub fn is_error(&self) -> bool {
579-
matches!(self, GenericPredicate::Error)
579+
matches!(self, WhereClause::Error)
580580
}
581581

582582
pub fn is_implemented(&self) -> bool {
583-
matches!(self, GenericPredicate::Implemented(_))
583+
matches!(self, WhereClause::Implemented(_))
584584
}
585585

586586
pub fn trait_ref(&self, db: &dyn HirDatabase) -> Option<TraitRef> {
587587
match self {
588-
GenericPredicate::Implemented(tr) => Some(tr.clone()),
589-
GenericPredicate::AliasEq(AliasEq { alias: AliasTy::Projection(proj), .. }) => {
588+
WhereClause::Implemented(tr) => Some(tr.clone()),
589+
WhereClause::AliasEq(AliasEq { alias: AliasTy::Projection(proj), .. }) => {
590590
Some(proj.trait_ref(db))
591591
}
592-
GenericPredicate::AliasEq(_) | GenericPredicate::Error => None,
592+
WhereClause::AliasEq(_) | WhereClause::Error => None,
593593
}
594594
}
595595
}
596596

597-
impl TypeWalk for GenericPredicate {
597+
impl TypeWalk for WhereClause {
598598
fn walk(&self, f: &mut impl FnMut(&Ty)) {
599599
match self {
600-
GenericPredicate::Implemented(trait_ref) => trait_ref.walk(f),
601-
GenericPredicate::AliasEq(alias_eq) => alias_eq.walk(f),
602-
GenericPredicate::Error => {}
600+
WhereClause::Implemented(trait_ref) => trait_ref.walk(f),
601+
WhereClause::AliasEq(alias_eq) => alias_eq.walk(f),
602+
WhereClause::Error => {}
603603
}
604604
}
605605

@@ -609,9 +609,9 @@ impl TypeWalk for GenericPredicate {
609609
binders: DebruijnIndex,
610610
) {
611611
match self {
612-
GenericPredicate::Implemented(trait_ref) => trait_ref.walk_mut_binders(f, binders),
613-
GenericPredicate::AliasEq(alias_eq) => alias_eq.walk_mut_binders(f, binders),
614-
GenericPredicate::Error => {}
612+
WhereClause::Implemented(trait_ref) => trait_ref.walk_mut_binders(f, binders),
613+
WhereClause::AliasEq(alias_eq) => alias_eq.walk_mut_binders(f, binders),
614+
WhereClause::Error => {}
615615
}
616616
}
617617
}
@@ -815,7 +815,7 @@ impl Ty {
815815
pub fn dyn_trait_ref(&self) -> Option<&TraitRef> {
816816
match self.interned(&Interner) {
817817
TyKind::Dyn(bounds) => bounds.get(0).and_then(|b| match b {
818-
GenericPredicate::Implemented(trait_ref) => Some(trait_ref),
818+
WhereClause::Implemented(trait_ref) => Some(trait_ref),
819819
_ => None,
820820
}),
821821
_ => None,
@@ -894,7 +894,7 @@ impl Ty {
894894
}
895895
}
896896

897-
pub fn impl_trait_bounds(&self, db: &dyn HirDatabase) -> Option<Vec<GenericPredicate>> {
897+
pub fn impl_trait_bounds(&self, db: &dyn HirDatabase) -> Option<Vec<WhereClause>> {
898898
match self.interned(&Interner) {
899899
TyKind::OpaqueType(opaque_ty_id, ..) => {
900900
match db.lookup_intern_impl_trait_id((*opaque_ty_id).into()) {
@@ -907,7 +907,7 @@ impl Ty {
907907
// This is only used by type walking.
908908
// Parameters will be walked outside, and projection predicate is not used.
909909
// So just provide the Future trait.
910-
let impl_bound = GenericPredicate::Implemented(TraitRef {
910+
let impl_bound = WhereClause::Implemented(TraitRef {
911911
trait_id: to_chalk_trait_id(future_trait),
912912
substitution: Substitution::empty(),
913913
});
@@ -1166,7 +1166,7 @@ pub struct ReturnTypeImplTraits {
11661166

11671167
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
11681168
pub(crate) struct ReturnTypeImplTrait {
1169-
pub(crate) bounds: Binders<Vec<GenericPredicate>>,
1169+
pub(crate) bounds: Binders<Vec<WhereClause>>,
11701170
}
11711171

11721172
pub fn to_foreign_def_id(id: TypeAliasId) -> ForeignDefId {

0 commit comments

Comments
 (0)