diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index 0bfd62d68b2..a9b25a390b3 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -3729,6 +3729,8 @@ impl<'hir> Node<'hir> { Node::Lifetime(lt) => Some(lt.ident), Node::GenericParam(p) => Some(p.name.ident()), Node::TypeBinding(b) => Some(b.ident), + Node::PatField(f) => Some(f.ident), + Node::ExprField(f) => Some(f.ident), Node::Param(..) | Node::AnonConst(..) | Node::ConstBlock(..) @@ -3737,8 +3739,6 @@ impl<'hir> Node<'hir> { | Node::Block(..) | Node::Ctor(..) | Node::Pat(..) - | Node::PatField(..) - | Node::ExprField(..) | Node::Arm(..) | Node::Local(..) | Node::Crate(..) diff --git a/tests/ui/attributes/issue-115264-expr-field.rs b/tests/ui/attributes/issue-115264-expr-field.rs new file mode 100644 index 00000000000..f53ac4aee66 --- /dev/null +++ b/tests/ui/attributes/issue-115264-expr-field.rs @@ -0,0 +1,17 @@ +// Regression test for issue 115264 +// Tests that retrieving the ident of the X::foo field +// in main() does not cause an ICE + +// check-pass + +#[allow(dead_code)] +struct X { + foo: i32, +} + +fn main() { + let _ = X { + #[doc(alias = "StructItem")] + foo: 123, + }; +} diff --git a/tests/ui/attributes/issue-115264-pat-field.rs b/tests/ui/attributes/issue-115264-pat-field.rs new file mode 100644 index 00000000000..8c6bbe16726 --- /dev/null +++ b/tests/ui/attributes/issue-115264-pat-field.rs @@ -0,0 +1,19 @@ +// Regression test for issue 115264 +// Tests that retrieving the ident of 'foo' variable in +// the pattern inside main() does not cause an ICE + +// check-pass + +struct X { + foo: i32, +} + +#[allow(unused_variables)] +fn main() { + let X { + #[doc(alias = "StructItem")] + foo + } = X { + foo: 123 + }; +}