Skip to content

Commit ebd7239

Browse files
committed
fix: don't panic in semantics due to cfg_attr disrupting offsets
1 parent baa5cd9 commit ebd7239

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

crates/hir/src/semantics.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -931,7 +931,8 @@ impl<'db> SemanticsImpl<'db> {
931931
file.with_value(derive.clone()),
932932
)?;
933933
let attrs = adt_def.attrs(self.db);
934-
let mut derive_paths = attrs[attr_id].parse_path_comma_token_tree()?;
934+
// FIXME: https://github.com/rust-analyzer/rust-analyzer/issues/11298
935+
let mut derive_paths = attrs.get(attr_id)?.parse_path_comma_token_tree()?;
935936

936937
let derive_idx = tt
937938
.syntax()

crates/hir_def/src/attr.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ impl ops::Deref for RawAttrs {
7272
}
7373
}
7474
}
75+
impl Attrs {
76+
pub fn get(&self, AttrId { ast_index, .. }: AttrId) -> Option<&Attr> {
77+
(**self).get(ast_index as usize)
78+
}
79+
}
7580

7681
impl ops::Deref for Attrs {
7782
type Target = [Attr];

0 commit comments

Comments
 (0)