Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions compiler/rustc_builtin_macros/src/assert/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ impl<'cx, 'a> Context<'cx, 'a> {
self.span,
false,
local_bind,
self.cx.expr_addr_of(self.span, expr.clone()),
self.cx.expr_ref(self.span, expr.clone()),
));
let wrapper = self.cx.expr_call(
self.span,
Expand All @@ -377,7 +377,7 @@ impl<'cx, 'a> Context<'cx, 'a> {
.cx
.stmt_expr(self.cx.expr_method_call(
self.span,
self.cx.expr_paren(self.span, self.cx.expr_addr_of(self.span, wrapper)),
self.cx.expr_paren(self.span, self.cx.expr_ref(self.span, wrapper)),
Ident::new(sym::try_capture, self.span),
thin_vec![expr_addr_of_mut(
self.cx,
Expand Down
18 changes: 8 additions & 10 deletions compiler/rustc_builtin_macros/src/deriving/clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use thin_vec::{ThinVec, thin_vec};
use crate::deriving::generic::*;
use crate::deriving::path_std;

pub(crate) fn expand_deriving_clone(
pub(crate) fn expand_derive_clone(
cx: &ExtCtxt<'_>,
span: Span,
item: &ast::Item,
Expand All @@ -28,7 +28,7 @@ pub(crate) fn expand_deriving_clone(
// enough. Whether Clone is implemented for fields is irrelevant so we
// don't assert it.)
let bounds;
let substructure;
let body: MethodBodyFunc<'_>;
let is_simple;
match &item.kind {
ItemKind::Struct(_, Generics { params, .. }, _)
Expand All @@ -42,18 +42,16 @@ pub(crate) fn expand_deriving_clone(
.any(|param| matches!(param.kind, ast::GenericParamKind::Type { .. }))
{
is_simple = true;
substructure = combine_substructure(|c, s, sub| cs_clone_simple(c, s, sub, false));
body = Box::new(|c, s, sub| clone_simple_body(c, s, sub, false));
} else {
is_simple = false;
substructure = combine_substructure(|c, s, sub| {
cs_clone(c, s, sub, item.kind.ident().unwrap())
});
body = Box::new(|c, s, sub| clone_body(c, s, sub, item.kind.ident().unwrap()));
}
}
ItemKind::Union(..) => {
bounds = smallvec![path_std!(cx, span, marker::Copy)];
is_simple = true;
substructure = combine_substructure(|c, s, sub| cs_clone_simple(c, s, sub, true));
body = Box::new(|c, s, sub| clone_simple_body(c, s, sub, true));
}
_ => cx.dcx().span_bug(span, "`derive(Clone)` on wrong item kind"),
}
Expand Down Expand Up @@ -94,7 +92,7 @@ pub(crate) fn expand_deriving_clone(
ret_ty: cx.ty_self(span),
attributes: thin_vec![cx.generated_attr(span, ast::GeneratedAttr::Inline)],
fieldless_variants_strategy: FieldlessVariantsStrategy::Default,
combine_substructure: substructure,
body,
}],
is_const,
..
Expand All @@ -103,7 +101,7 @@ pub(crate) fn expand_deriving_clone(
trait_def.expand_ext(cx, item, push, is_simple)
}

fn cs_clone_simple(
fn clone_simple_body(
cx: &ExtCtxt<'_>,
trait_span: Span,
substr: Substructure<'_>,
Expand Down Expand Up @@ -162,7 +160,7 @@ fn cs_clone_simple(
BlockOrExpr::new_mixed(stmts, Some(cx.expr_deref(trait_span, cx.expr_self(trait_span))))
}

fn cs_clone(
fn clone_body(
cx: &ExtCtxt<'_>,
trait_span: Span,
substr: Substructure<'_>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::deriving::generic::*;
use crate::deriving::path_std;
use crate::diagnostics;

pub(crate) fn expand_deriving_coerce_pointee(
pub(crate) fn expand_derive_coerce_pointee(
cx: &ExtCtxt<'_>,
span: Span,
item: &ast::Item,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use rustc_span::Span;
use crate::deriving::generic::*;
use crate::deriving::path_std;

pub(crate) fn expand_deriving_const_param_ty(
pub(crate) fn expand_derive_const_param_ty(
cx: &ExtCtxt<'_>,
span: Span,
item: &ast::Item,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_builtin_macros/src/deriving/copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use rustc_span::Span;
use crate::deriving::generic::*;
use crate::deriving::path_std;

pub(crate) fn expand_deriving_copy(
pub(crate) fn expand_derive_copy(
cx: &ExtCtxt<'_>,
span: Span,
item: &ast::Item,
Expand Down
18 changes: 9 additions & 9 deletions compiler/rustc_builtin_macros/src/deriving/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use thin_vec::{ThinVec, thin_vec};
use crate::deriving::generic::*;
use crate::deriving::path_std;

pub(crate) fn expand_deriving_debug(
pub(crate) fn expand_derive_debug(
cx: &ExtCtxt<'_>,
span: Span,
item: &ast::Item,
Expand Down Expand Up @@ -39,12 +39,12 @@ pub(crate) fn expand_deriving_debug(
name: sym::fmt,
generics: cx.empty_generics(span),
explicit_self: true,
nonself_args: smallvec![(fmtr, sym::f)],
nonself_args: smallvec![(sym::f, fmtr)],
has_other_selflike_arg: false,
ret_ty: cx.ty_path(path_std!(cx, span, fmt::Result)),
attributes: thin_vec![cx.generated_attr(span, ast::GeneratedAttr::Inline)],
fieldless_variants_strategy: FieldlessVariantsStrategy::Default,
combine_substructure: combine_substructure(|cx, span, substr| show_substructure(
body: Box::new(|cx, span, substr| debug_body(
cx,
span,
substr,
Expand All @@ -57,7 +57,7 @@ pub(crate) fn expand_deriving_debug(
trait_def.expand_ext(cx, item, push, all_fieldless);
}

fn show_substructure(
fn debug_body(
cx: &ExtCtxt<'_>,
span: Span,
substr: Substructure<'_>,
Expand All @@ -71,7 +71,7 @@ fn show_substructure(
let (ident, vdata, fields) = match substr {
Struct(vdata, fields) => (type_ident, vdata, fields),
EnumMatching(v, fields) => (v.ident, &v.data, fields),
StaticEnum(enum_def) => return show_fieldless_enum(cx, span, enum_def, type_ident),
StaticEnum(enum_def) => return debug_fieldless_enum(cx, span, enum_def, type_ident),
_ => cx.dcx().span_bug(span, "unexpected substructure in `derive(Debug)`"),
};

Expand Down Expand Up @@ -107,7 +107,7 @@ fn show_substructure(
} else {
// Unsized types need an extra indirection, but only the last field
// may be unsized.
cx.expr_addr_of(field.span, field.self_expr)
cx.expr_ref(field.span, field.self_expr)
}
};

Expand Down Expand Up @@ -236,13 +236,13 @@ fn show_substructure(
/// }
/// }
/// ```
fn show_fieldless_enum(
fn debug_fieldless_enum(
cx: &ExtCtxt<'_>,
span: Span,
def: &EnumDef,
type_ident: Ident,
) -> BlockOrExpr {
if let Some(expr) = show_fieldless_enum_concat_str(cx, span, def, type_ident) {
if let Some(expr) = debug_fieldless_enum_concat_str(cx, span, def, type_ident) {
return BlockOrExpr::new_expr(expr);
}
let fmt = cx.expr_name(span, sym::f);
Expand Down Expand Up @@ -287,7 +287,7 @@ fn show_fieldless_enum(
/// }
/// }
/// ```
fn show_fieldless_enum_concat_str(
fn debug_fieldless_enum_concat_str(
cx: &ExtCtxt<'_>,
span: Span,
def: &EnumDef,
Expand Down
14 changes: 6 additions & 8 deletions compiler/rustc_builtin_macros/src/deriving/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use thin_vec::{ThinVec, thin_vec};
use crate::deriving::generic::*;
use crate::diagnostics;

pub(crate) fn expand_deriving_default(
pub(crate) fn expand_derive_default(
cx: &ExtCtxt<'_>,
span: Span,
item: &ast::Item,
Expand All @@ -35,18 +35,16 @@ pub(crate) fn expand_deriving_default(
ret_ty: cx.ty_self(span),
attributes: thin_vec![cx.generated_attr(span, ast::GeneratedAttr::Inline)],
fieldless_variants_strategy: FieldlessVariantsStrategy::Default,
combine_substructure: combine_substructure(|cx, trait_span, substr| {
body: Box::new(|cx, trait_span, substr| {
match substr {
StaticStruct(variant_data) => default_struct_substructure(
StaticStruct(variant_data) => default_struct_body(
cx,
trait_span,
variant_data,
// We cannot use `Self` here, see https://github.com/rust-lang/rust/issues/163800
item.kind.ident().unwrap(),
),
StaticEnum(enum_def) => {
default_enum_substructure(cx, trait_span, enum_def, item.span)
}
StaticEnum(enum_def) => default_enum_body(cx, trait_span, enum_def, item.span),
_ => cx
.dcx()
.span_bug(trait_span, "unexpected substructure in `derive(Default)`"),
Expand All @@ -65,7 +63,7 @@ fn default_call(cx: &ExtCtxt<'_>, span: Span) -> Box<ast::Expr> {
cx.expr_call_global(span, default_ident, ThinVec::new())
}

fn default_struct_substructure(
fn default_struct_body(
cx: &ExtCtxt<'_>,
trait_span: Span,
variant_data: &VariantData,
Expand Down Expand Up @@ -112,7 +110,7 @@ fn default_struct_substructure(
BlockOrExpr::new_expr(expr)
}

fn default_enum_substructure(
fn default_enum_body(
cx: &ExtCtxt<'_>,
trait_span: Span,
enum_def: &EnumDef,
Expand Down
10 changes: 7 additions & 3 deletions compiler/rustc_builtin_macros/src/deriving/eq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use thin_vec::{ThinVec, thin_vec};
use crate::deriving::generic::*;
use crate::deriving::path_std;

pub(crate) fn expand_deriving_eq(
pub(crate) fn expand_derive_eq(
cx: &ExtCtxt<'_>,
span: Span,
item: &ast::Item,
Expand Down Expand Up @@ -37,15 +37,19 @@ pub(crate) fn expand_deriving_eq(
cx.generated_attr(span, ast::GeneratedAttr::CoverageOff),
],
fieldless_variants_strategy: FieldlessVariantsStrategy::Unify,
combine_substructure: combine_substructure(cs_total_eq_assert),
body: Box::new(assert_fields_eq_body),
}],
is_const,
..
};
trait_def.expand_ext(cx, item, push, true)
}

fn cs_total_eq_assert(cx: &ExtCtxt<'_>, trait_span: Span, substr: Substructure<'_>) -> BlockOrExpr {
fn assert_fields_eq_body(
cx: &ExtCtxt<'_>,
trait_span: Span,
substr: Substructure<'_>,
) -> BlockOrExpr {
let mut stmts = ThinVec::new();
let mut seen_type_names = FxHashSet::default();
let mut process_variant = |variant: &ast::VariantData| {
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_builtin_macros/src/deriving/from.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::diagnostics;

/// Generate an implementation of the `From` trait, provided that `item`
/// is a struct or a tuple struct with exactly one field.
pub(crate) fn expand_deriving_from(
pub(crate) fn expand_derive_from(
cx: &ExtCtxt<'_>,
span: Span,
item: &ast::Item,
Expand Down Expand Up @@ -78,12 +78,12 @@ pub(crate) fn expand_deriving_from(
name: sym::from,
generics: cx.empty_generics(span),
explicit_self: false,
nonself_args: smallvec![(from_type, sym::value)],
nonself_args: smallvec![(sym::value, from_type)],
has_other_selflike_arg: false,
ret_ty: cx.ty_self(span),
attributes: thin_vec![cx.generated_attr(span, ast::GeneratedAttr::Inline)],
fieldless_variants_strategy: FieldlessVariantsStrategy::Default,
combine_substructure: combine_substructure(|cx, span, substructure| {
body: Box::new(|cx, span, substructure| {
let field = match field {
Ok(ref field) => field,
Err(guar) => {
Expand Down
Loading
Loading