Skip to content

Commit

Permalink
Use expr_field in builtin derives and assert that we aren't accessi…
Browse files Browse the repository at this point in the history
…ng `_`
  • Loading branch information
clubby789 committed Feb 19, 2024
1 parent 6f72620 commit 985f756
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
12 changes: 5 additions & 7 deletions compiler/rustc_builtin_macros/src/deriving/generic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1578,14 +1578,12 @@ impl<'a> TraitDef<'a> {
// `unwrap_or_else` case otherwise the hygiene is wrong and we get
// "field `0` of struct `Point` is private" errors on tuple
// structs.
let mut field_expr = cx.expr(
let mut field_expr = cx.expr_field(
sp,
ast::ExprKind::Field(
selflike_arg.clone(),
struct_field.ident.unwrap_or_else(|| {
Ident::from_str_and_span(&i.to_string(), struct_field.span)
}),
),
selflike_arg.clone(),
struct_field.ident.unwrap_or_else(|| {
Ident::from_str_and_span(&i.to_string(), struct_field.span)
}),
);
if is_packed {
// In general, fields in packed structs are copied via a
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_expand/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ impl<'a> ExtCtxt<'a> {
}

pub fn expr_field(&self, span: Span, expr: P<Expr>, field: Ident) -> P<ast::Expr> {
debug_assert_ne!(field.name, kw::Underscore);
self.expr(span, ast::ExprKind::Field(expr, field))
}

Expand Down

0 comments on commit 985f756

Please sign in to comment.