mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-02 22:54:58 +00:00
refactor: leverage HasAttrs
for code brevity
This commit is contained in:
parent
2e7d2c2d04
commit
356d12eae4
3 changed files with 47 additions and 36 deletions
|
@ -315,26 +315,14 @@ impl AttrsWithOwner {
|
|||
let src = it.parent().child_source(db);
|
||||
RawAttrs::from_attrs_owner(
|
||||
db.upcast(),
|
||||
src.with_value(src.value[it.local_id()].as_ref().either(
|
||||
|it| match it {
|
||||
ast::TypeOrConstParam::Type(it) => it as _,
|
||||
ast::TypeOrConstParam::Const(it) => it as _,
|
||||
},
|
||||
|it| it as _,
|
||||
)),
|
||||
src.with_value(&src.value[it.local_id()]),
|
||||
)
|
||||
}
|
||||
GenericParamId::TypeParamId(it) => {
|
||||
let src = it.parent().child_source(db);
|
||||
RawAttrs::from_attrs_owner(
|
||||
db.upcast(),
|
||||
src.with_value(src.value[it.local_id()].as_ref().either(
|
||||
|it| match it {
|
||||
ast::TypeOrConstParam::Type(it) => it as _,
|
||||
ast::TypeOrConstParam::Const(it) => it as _,
|
||||
},
|
||||
|it| it as _,
|
||||
)),
|
||||
src.with_value(&src.value[it.local_id()]),
|
||||
)
|
||||
}
|
||||
GenericParamId::LifetimeParamId(it) => {
|
||||
|
@ -412,28 +400,14 @@ impl AttrsWithOwner {
|
|||
},
|
||||
AttrDefId::ImplId(id) => id.lookup(db).source(db).map(ast::AnyHasAttrs::new),
|
||||
AttrDefId::GenericParamId(id) => match id {
|
||||
GenericParamId::ConstParamId(id) => {
|
||||
id.parent().child_source(db).map(|source| match &source[id.local_id()] {
|
||||
Either::Left(ast::TypeOrConstParam::Type(id)) => {
|
||||
ast::AnyHasAttrs::new(id.clone())
|
||||
}
|
||||
Either::Left(ast::TypeOrConstParam::Const(id)) => {
|
||||
ast::AnyHasAttrs::new(id.clone())
|
||||
}
|
||||
Either::Right(id) => ast::AnyHasAttrs::new(id.clone()),
|
||||
})
|
||||
}
|
||||
GenericParamId::TypeParamId(id) => {
|
||||
id.parent().child_source(db).map(|source| match &source[id.local_id()] {
|
||||
Either::Left(ast::TypeOrConstParam::Type(id)) => {
|
||||
ast::AnyHasAttrs::new(id.clone())
|
||||
}
|
||||
Either::Left(ast::TypeOrConstParam::Const(id)) => {
|
||||
ast::AnyHasAttrs::new(id.clone())
|
||||
}
|
||||
Either::Right(id) => ast::AnyHasAttrs::new(id.clone()),
|
||||
})
|
||||
}
|
||||
GenericParamId::ConstParamId(id) => id
|
||||
.parent()
|
||||
.child_source(db)
|
||||
.map(|source| ast::AnyHasAttrs::new(source[id.local_id()].clone())),
|
||||
GenericParamId::TypeParamId(id) => id
|
||||
.parent()
|
||||
.child_source(db)
|
||||
.map(|source| ast::AnyHasAttrs::new(source[id.local_id()].clone())),
|
||||
GenericParamId::LifetimeParamId(id) => id
|
||||
.parent
|
||||
.child_source(db)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue