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/src/has_source.rs | 2 +- crates/hir_def/src/generics.rs | 10 +++++----- crates/hir_def/src/item_tree/lower.rs | 2 +- crates/ide/src/display/navigation_target.rs | 6 +++--- crates/ide_db/src/rename.rs | 4 ++-- 5 files changed, 12 insertions(+), 12 deletions(-) (limited to 'crates') diff --git a/crates/hir/src/has_source.rs b/crates/hir/src/has_source.rs index dc10a4d0f..197149c5e 100644 --- a/crates/hir/src/has_source.rs +++ b/crates/hir/src/has_source.rs @@ -127,7 +127,7 @@ impl HasSource for Impl { } impl HasSource for TypeParam { - type Ast = Either; + type Ast = Either; fn source(self, db: &dyn HirDatabase) -> Option> { let child_source = self.id.parent.child_source(db.upcast()); Some(child_source.map(|it| it[self.id.local_id].clone())) 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()); diff --git a/crates/ide/src/display/navigation_target.rs b/crates/ide/src/display/navigation_target.rs index b75ec411c..455b32456 100644 --- a/crates/ide/src/display/navigation_target.rs +++ b/crates/ide/src/display/navigation_target.rs @@ -442,10 +442,10 @@ impl TryToNav for hir::TypeParam { fn try_to_nav(&self, db: &RootDatabase) -> Option { let src = self.source(db)?; let full_range = match &src.value { - Either::Left(it) => it + Either::Left(type_param) => type_param.syntax().text_range(), + Either::Right(trait_) => trait_ .name() - .map_or_else(|| it.syntax().text_range(), |name| name.syntax().text_range()), - Either::Right(it) => it.syntax().text_range(), + .map_or_else(|| trait_.syntax().text_range(), |name| name.syntax().text_range()), }; let focus_range = match &src.value { Either::Left(it) => it.name(), diff --git a/crates/ide_db/src/rename.rs b/crates/ide_db/src/rename.rs index 82855725f..643e67781 100644 --- a/crates/ide_db/src/rename.rs +++ b/crates/ide_db/src/rename.rs @@ -143,8 +143,8 @@ impl Definition { hir::GenericParam::TypeParam(type_param) => { let src = type_param.source(sema.db)?; let name = match &src.value { - Either::Left(_) => return None, - Either::Right(type_param) => type_param.name()?, + Either::Left(type_param) => type_param.name()?, + Either::Right(_trait) => return None, }; src.with_value(name.syntax()).original_file_range(sema.db) } -- cgit v1.2.3