Fix cfg_attr invalidating derive identifier IDE functionality

This commit is contained in:
Lukas Wirth 2022-01-30 22:46:05 +01:00
parent cc04cfc982
commit ddf7b70a0f
3 changed files with 14 additions and 15 deletions

View file

@ -73,8 +73,8 @@ impl ops::Deref for RawAttrs {
}
}
impl Attrs {
pub fn get(&self, AttrId { ast_index, .. }: AttrId) -> Option<&Attr> {
(**self).get(ast_index as usize)
pub fn get(&self, id: AttrId) -> Option<&Attr> {
(**self).iter().find(|attr| attr.id == id)
}
}
@ -89,14 +89,6 @@ impl ops::Deref for Attrs {
}
}
impl ops::Index<AttrId> for Attrs {
type Output = Attr;
fn index(&self, AttrId { ast_index, .. }: AttrId) -> &Self::Output {
&(**self)[ast_index as usize]
}
}
impl ops::Deref for AttrsWithOwner {
type Target = Attrs;
@ -110,7 +102,7 @@ impl RawAttrs {
pub(crate) fn new(db: &dyn DefDatabase, owner: &dyn ast::HasAttrs, hygiene: &Hygiene) -> Self {
let entries = collect_attrs(owner)
.flat_map(|(id, attr)| match attr {
.filter_map(|(id, attr)| match attr {
Either::Left(attr) => {
attr.meta().and_then(|meta| Attr::from_src(db, meta, hygiene, id))
}