Unnamed repository; edit this file 'description' to name the repository.
Merge #11334
11334: fix: don't panic in semantics due to `cfg_attr` disrupting offsets r=Veykril a=Veykril Reduces the panic in https://github.com/rust-analyzer/rust-analyzer/issues/11298 to an early return, that means we won't resolve these cases again for now, but this is better than constantly panicking in highlighting and hovering. bors r+ Co-authored-by: Lukas Wirth <[email protected]>
bors[bot] 2022-01-23
parent baa5cd9 · parent ebd7239 · commit 17afa2e
-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];