Unnamed repository; edit this file 'description' to name the repository.
fix: don't panic in semantics due to `cfg_attr` disrupting offsets
Lukas Wirth 2022-01-23
parent baa5cd9 · commit ebd7239
-rw-r--r--crates/hir/src/semantics.rs3
-rw-r--r--crates/hir_def/src/attr.rs5
2 files changed, 7 insertions, 1 deletions
diff --git a/crates/hir/src/semantics.rs b/crates/hir/src/semantics.rs
index 9596e81818..2bffb12dee 100644
--- a/crates/hir/src/semantics.rs
+++ b/crates/hir/src/semantics.rs
@@ -931,7 +931,8 @@ impl<'db> SemanticsImpl<'db> {
file.with_value(derive.clone()),
)?;
let attrs = adt_def.attrs(self.db);
- let mut derive_paths = attrs[attr_id].parse_path_comma_token_tree()?;
+ // FIXME: https://github.com/rust-analyzer/rust-analyzer/issues/11298
+ let mut derive_paths = attrs.get(attr_id)?.parse_path_comma_token_tree()?;
let derive_idx = tt
.syntax()
diff --git a/crates/hir_def/src/attr.rs b/crates/hir_def/src/attr.rs
index b4ddfba0d0..98177f4301 100644
--- a/crates/hir_def/src/attr.rs
+++ b/crates/hir_def/src/attr.rs
@@ -72,6 +72,11 @@ impl ops::Deref for RawAttrs {
}
}
}
+impl Attrs {
+ pub fn get(&self, AttrId { ast_index, .. }: AttrId) -> Option<&Attr> {
+ (**self).get(ast_index as usize)
+ }
+}
impl ops::Deref for Attrs {
type Target = [Attr];