Skip to content

Commit 985f756

Browse files
committed
Use expr_field in builtin derives and assert that we aren't accessing _
1 parent 6f72620 commit 985f756

File tree

2 files changed

+6
-7
lines changed
  • compiler
    • rustc_builtin_macros/src/deriving/generic
    • rustc_expand/src

2 files changed

+6
-7
lines changed

compiler/rustc_builtin_macros/src/deriving/generic/mod.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -1578,14 +1578,12 @@ impl<'a> TraitDef<'a> {
15781578
// `unwrap_or_else` case otherwise the hygiene is wrong and we get
15791579
// "field `0` of struct `Point` is private" errors on tuple
15801580
// structs.
1581-
let mut field_expr = cx.expr(
1581+
let mut field_expr = cx.expr_field(
15821582
sp,
1583-
ast::ExprKind::Field(
1584-
selflike_arg.clone(),
1585-
struct_field.ident.unwrap_or_else(|| {
1586-
Ident::from_str_and_span(&i.to_string(), struct_field.span)
1587-
}),
1588-
),
1583+
selflike_arg.clone(),
1584+
struct_field.ident.unwrap_or_else(|| {
1585+
Ident::from_str_and_span(&i.to_string(), struct_field.span)
1586+
}),
15891587
);
15901588
if is_packed {
15911589
// In general, fields in packed structs are copied via a

compiler/rustc_expand/src/build.rs

+1
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ impl<'a> ExtCtxt<'a> {
259259
}
260260

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

0 commit comments

Comments
 (0)