9277: internal: more natural order of sources for TypeParam r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
bors[bot] 2021-06-14 19:44:59 +00:00 committed by GitHub
commit 447d849c9e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 12 additions and 12 deletions

View File

@ -127,7 +127,7 @@ impl HasSource for Impl {
}
impl HasSource for TypeParam {
type Ast = Either<ast::Trait, ast::TypeParam>;
type Ast = Either<ast::TypeParam, ast::Trait>;
fn source(self, db: &dyn HirDatabase) -> Option<InFile<Self::Ast>> {
let child_source = self.id.parent.child_source(db.upcast());
Some(child_source.map(|it| it[self.id.local_id].clone()))

View File

@ -92,7 +92,7 @@ pub enum WherePredicateTypeTarget {
#[derive(Default)]
pub(crate) struct SourceMap {
pub(crate) type_params: ArenaMap<LocalTypeParamId, Either<ast::Trait, ast::TypeParam>>,
pub(crate) type_params: ArenaMap<LocalTypeParamId, Either<ast::TypeParam, ast::Trait>>,
lifetime_params: ArenaMap<LocalLifetimeParamId, ast::LifetimeParam>,
const_params: ArenaMap<LocalConstParamId, ast::ConstParam>,
}
@ -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<LocalTypeParamId> for GenericDefId {
type Value = Either<ast::Trait, ast::TypeParam>;
type Value = Either<ast::TypeParam, ast::Trait>;
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)
}
}

View File

@ -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());

View File

@ -442,10 +442,10 @@ impl TryToNav for hir::TypeParam {
fn try_to_nav(&self, db: &RootDatabase) -> Option<NavigationTarget> {
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(),

View File

@ -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)
}