From c2015e7d182f3cb2cebe686127dd6a3e683df9e6 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 14 Jun 2021 22:42:43 +0300 Subject: internal: more natural order of sources for TypeParam We usually use first (left) variant of `Either` for "usual" case, and use right for odd things. For example, pat source is Pat | SelfParam. --- crates/hir_def/src/generics.rs | 10 +++++----- crates/hir_def/src/item_tree/lower.rs | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'crates/hir_def') diff --git a/crates/hir_def/src/generics.rs b/crates/hir_def/src/generics.rs index 6933f6e3c..0f04b2bae 100644 --- a/crates/hir_def/src/generics.rs +++ b/crates/hir_def/src/generics.rs @@ -92,7 +92,7 @@ pub enum WherePredicateTypeTarget { #[derive(Default)] pub(crate) struct SourceMap { - pub(crate) type_params: ArenaMap>, + pub(crate) type_params: ArenaMap>, lifetime_params: ArenaMap, const_params: ArenaMap, } @@ -199,7 +199,7 @@ impl GenericParams { default: None, provenance: TypeParamProvenance::TraitSelf, }); - sm.type_params.insert(self_param_id, Either::Left(src.value.clone())); + sm.type_params.insert(self_param_id, Either::Right(src.value.clone())); // add super traits as bounds on Self // i.e., trait Foo: Bar is equivalent to trait Foo where Self: Bar let self_param = TypeRef::Path(name![Self].into()); @@ -277,7 +277,7 @@ impl GenericParams { provenance: TypeParamProvenance::TypeParamList, }; let param_id = self.types.alloc(param); - sm.type_params.insert(param_id, Either::Right(type_param.clone())); + sm.type_params.insert(param_id, Either::Left(type_param.clone())); let type_ref = TypeRef::Path(name.into()); self.fill_bounds(lower_ctx, &type_param, Either::Left(type_ref)); @@ -413,7 +413,7 @@ impl GenericParams { } impl HasChildSource for GenericDefId { - type Value = Either; + type Value = Either; fn child_source( &self, db: &dyn DefDatabase, @@ -449,7 +449,7 @@ impl ChildBySource for GenericDefId { let sm = sm.as_ref(); for (local_id, src) in sm.value.type_params.iter() { let id = TypeParamId { parent: *self, local_id }; - if let Either::Right(type_param) = src { + if let Either::Left(type_param) = src { res[keys::TYPE_PARAM].insert(sm.with_value(type_param.clone()), id) } } diff --git a/crates/hir_def/src/item_tree/lower.rs b/crates/hir_def/src/item_tree/lower.rs index 3f90bda74..5b1386406 100644 --- a/crates/hir_def/src/item_tree/lower.rs +++ b/crates/hir_def/src/item_tree/lower.rs @@ -674,7 +674,7 @@ impl<'a> Ctx<'a> { default: None, provenance: TypeParamProvenance::TraitSelf, }); - sm.type_params.insert(self_param_id, Either::Left(trait_def.clone())); + sm.type_params.insert(self_param_id, Either::Right(trait_def.clone())); // add super traits as bounds on Self // i.e., trait Foo: Bar is equivalent to trait Foo where Self: Bar let self_param = TypeRef::Path(name![Self].into()); -- cgit v1.2.3