Skip to content

Commit

Permalink
Return ident for ExprField and PatField HIR nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
gurry committed Sep 1, 2023
1 parent b1b244d commit 19574d2
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
4 changes: 2 additions & 2 deletions compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(..)
Expand All @@ -3737,8 +3739,6 @@ impl<'hir> Node<'hir> {
| Node::Block(..)
| Node::Ctor(..)
| Node::Pat(..)
| Node::PatField(..)
| Node::ExprField(..)
| Node::Arm(..)
| Node::Local(..)
| Node::Crate(..)
Expand Down
17 changes: 17 additions & 0 deletions tests/ui/attributes/issue-115264-expr-field.rs
Original file line number Diff line number Diff line change
@@ -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,
};
}
19 changes: 19 additions & 0 deletions tests/ui/attributes/issue-115264-pat-field.rs
Original file line number Diff line number Diff line change
@@ -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
};
}

0 comments on commit 19574d2

Please sign in to comment.