diff options
| author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2022-01-23 16:43:22 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-01-23 16:43:22 +0000 |
| commit | 17afa2e7780f399df99bec802c4ab7d2f920f158 (patch) | |
| tree | 111c78818f824ac05e41e33002410c0682c1ecc0 | |
| parent | baa5cd95278f36ec9c851c72d6042ed13ab3efac (diff) | |
| parent | ebd723995a56bb4d56def08a3718548c83ec20f0 (diff) | |
| download | rust-17afa2e7780f399df99bec802c4ab7d2f920f158.tar.gz rust-17afa2e7780f399df99bec802c4ab7d2f920f158.zip | |
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 <lukastw97@gmail.com>
| -rw-r--r-- | crates/hir/src/semantics.rs | 3 | ||||
| -rw-r--r-- | crates/hir_def/src/attr.rs | 5 |
2 files changed, 7 insertions, 1 deletions
diff --git a/crates/hir/src/semantics.rs b/crates/hir/src/semantics.rs index 9596e818185..2bffb12deee 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 b4ddfba0d05..98177f43014 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]; |
