Skip to content
Merged
6 changes: 2 additions & 4 deletions compiler/rustc_builtin_macros/src/deriving/clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use rustc_expand::base::ExtCtxt;
use rustc_span::{DUMMY_SP, Ident, Span, kw, sym};
use thin_vec::{ThinVec, thin_vec};

use crate::deriving::generic::ty::*;
use crate::deriving::generic::*;
use crate::deriving::path_std;

Expand Down Expand Up @@ -68,7 +67,6 @@ pub(crate) fn expand_deriving_clone(
additional_bounds: bounds.clone(),
supports_unions: true,
methods: SmallVec::new(),
associated_types: SmallVec::new(),
is_const,
safety: Safety::Unsafe(DUMMY_SP),
// `TrivialClone` is not part of an API guarantee, so it shouldn't
Expand All @@ -91,12 +89,12 @@ pub(crate) fn expand_deriving_clone(
generics: cx.empty_generics(span),
explicit_self: true,
nonself_args: SmallVec::new(),
ret_ty: Self_,
has_other_selflike_arg: false,
ret_ty: cx.ty_self(span),
attributes: thin_vec![cx.attr_word(sym::inline, span)],
fieldless_variants_strategy: FieldlessVariantsStrategy::Default,
combine_substructure: substructure,
}],
associated_types: SmallVec::new(),
is_const,
safety: Safety::Default,
document: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ pub(crate) fn expand_deriving_const_param_ty(
additional_bounds: smallvec![path_std!(cx, span, cmp::Eq)],
supports_unions: false,
methods: SmallVec::new(),
associated_types: SmallVec::new(),
is_const,
safety: Safety::Default,
document: true,
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_builtin_macros/src/deriving/copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ pub(crate) fn expand_deriving_copy(
additional_bounds: SmallVec::new(),
supports_unions: true,
methods: SmallVec::new(),
associated_types: SmallVec::new(),
is_const,
safety: Safety::Default,
document: true,
Expand Down
18 changes: 11 additions & 7 deletions compiler/rustc_builtin_macros/src/deriving/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use rustc_session::config::FmtDebug;
use rustc_span::{Ident, Span, Symbol, sym};
use thin_vec::{ThinVec, thin_vec};

use crate::deriving::generic::ty::*;
use crate::deriving::generic::*;
use crate::deriving::path_std;

Expand All @@ -16,7 +15,12 @@ pub(crate) fn expand_deriving_debug(
is_const: bool,
) {
// &mut ::std::fmt::Formatter
let fmtr = Ref(Box::new(Path(path_std!(cx, span, fmt::Formatter))), ast::Mutability::Mut);
let fmtr = cx.ty_ref(
span,
cx.ty_path(path_std!(cx, span, fmt::Formatter)),
None,
ast::Mutability::Mut,
);

let trait_def = TraitDef {
span,
Expand All @@ -30,7 +34,8 @@ pub(crate) fn expand_deriving_debug(
generics: cx.empty_generics(span),
explicit_self: true,
nonself_args: smallvec![(fmtr, sym::character('f'))],
ret_ty: Path(path_std!(cx, span, fmt::Result)),
has_other_selflike_arg: false,
ret_ty: cx.ty_path(path_std!(cx, span, fmt::Result)),
attributes: thin_vec![cx.attr_word(sym::inline, span)],
fieldless_variants_strategy:
FieldlessVariantsStrategy::SpecializeIfAllVariantsFieldless,
Expand All @@ -41,7 +46,6 @@ pub(crate) fn expand_deriving_debug(
item.kind.ident().unwrap()
)),
}],
associated_types: SmallVec::new(),
is_const,
safety: Safety::Default,
document: true,
Expand All @@ -50,7 +54,7 @@ pub(crate) fn expand_deriving_debug(
}

fn formatter_ident(cx: &ExtCtxt<'_>, span: Span) -> Box<ast::Expr> {
cx.expr_ident(span, Ident::new(sym::character('f'), span))
cx.expr_ident_sym(span, sym::character('f'))
}

fn show_substructure(
Expand Down Expand Up @@ -195,9 +199,9 @@ fn show_substructure(
args.push(fmt);
args.push(name);
if is_struct {
args.push(cx.expr_ident(span, Ident::new(sym::names, span)));
args.push(cx.expr_ident_sym(span, sym::names));
}
args.push(cx.expr_ident(span, Ident::new(sym::values, span)));
args.push(cx.expr_ident_sym(span, sym::values));
let expr = cx.expr_call_global(span, fn_path_debug_internal, args);

let mut stmts = ThinVec::with_capacity(2);
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_builtin_macros/src/deriving/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use rustc_span::{ErrorGuaranteed, Ident, Span, kw, sym};
use smallvec::SmallVec;
use thin_vec::{ThinVec, thin_vec};

use crate::deriving::generic::ty::*;
use crate::deriving::generic::*;
use crate::deriving::new_path;
use crate::diagnostics;

pub(crate) fn expand_deriving_default(
Expand All @@ -22,7 +22,7 @@ pub(crate) fn expand_deriving_default(

let trait_def = TraitDef {
span,
path: new_path(cx, span, &[kw::Default, sym::Default], &[]),
path: new_path(cx, span, &[kw::Default, sym::Default], vec![]),
skip_path_as_bound: has_a_default_variant(item),
needs_copy_as_bound_if_packed: false,
additional_bounds: SmallVec::new(),
Expand All @@ -32,7 +32,8 @@ pub(crate) fn expand_deriving_default(
generics: cx.empty_generics(span),
explicit_self: false,
nonself_args: SmallVec::new(),
ret_ty: Self_,
has_other_selflike_arg: false,
ret_ty: cx.ty_self(span),
attributes: thin_vec![cx.attr_word(sym::inline, span)],
fieldless_variants_strategy: FieldlessVariantsStrategy::Default,
combine_substructure: combine_substructure(|cx, trait_span, substr| {
Expand All @@ -49,7 +50,6 @@ pub(crate) fn expand_deriving_default(
}
}),
}],
associated_types: SmallVec::new(),
is_const,
safety: Safety::Default,
document: true,
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_builtin_macros/src/deriving/eq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use rustc_expand::base::ExtCtxt;
use rustc_span::{Span, sym};
use thin_vec::{ThinVec, thin_vec};

use crate::deriving::generic::ty::*;
use crate::deriving::generic::*;
use crate::deriving::path_std;

Expand All @@ -29,7 +28,8 @@ pub(crate) fn expand_deriving_eq(
generics: cx.empty_generics(span),
explicit_self: true,
nonself_args: smallvec![],
ret_ty: Unit,
has_other_selflike_arg: false,
ret_ty: cx.ty_unit(span),
attributes: thin_vec![
// This method will never be called, so doing codegen etc. for it is unnecessary.
// We prevent this by adding `#[inline]`, which improves compile-time.
Expand All @@ -40,7 +40,6 @@ pub(crate) fn expand_deriving_eq(
fieldless_variants_strategy: FieldlessVariantsStrategy::Unify,
combine_substructure: combine_substructure(cs_total_eq_assert),
}],
associated_types: SmallVec::new(),
is_const,
safety: Safety::Default,
document: true,
Expand Down
17 changes: 8 additions & 9 deletions compiler/rustc_builtin_macros/src/deriving/from.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ use rustc_expand::base::{DummyResult, ExtCtxt};
use rustc_span::{Ident, Span, kw, sym};
use thin_vec::thin_vec;

use crate::deriving::generic::ty::*;
use crate::deriving::generic::*;
use crate::deriving::pathvec;
use crate::deriving::{new_path, pathvec};
use crate::diagnostics;

/// Generate an implementation of the `From` trait, provided that `item`
Expand Down Expand Up @@ -47,12 +46,12 @@ pub(crate) fn expand_deriving_from(
_ => cx.dcx().bug("Invalid derive(From) ADT input"),
};

let from_type = Ty::AstTy(match field {
let from_type = match field {
Ok(ref field) => field.ty.clone(),
Err(guar) => cx.ty(span, ast::TyKind::Err(guar)),
});
};

let path = new_path(cx, span, pathvec!(convert::From), &[from_type.clone()]);
let path = new_path(cx, span, pathvec!(convert::From), vec![from_type.clone()]);

// Generate code like this:
//
Expand All @@ -76,7 +75,8 @@ pub(crate) fn expand_deriving_from(
generics: cx.empty_generics(span),
explicit_self: false,
nonself_args: smallvec![(from_type, sym::value)],
ret_ty: Ty::Self_,
has_other_selflike_arg: false,
ret_ty: cx.ty_self(span),
attributes: thin_vec![cx.attr_word(sym::inline, span)],
fieldless_variants_strategy: FieldlessVariantsStrategy::Default,
combine_substructure: combine_substructure(|cx, span, substructure| {
Expand All @@ -97,14 +97,14 @@ pub(crate) fn expand_deriving_from(
thin_vec![cx.field_imm(
span,
field.ident.unwrap(),
cx.expr_ident(span, Ident::new(sym::value, span))
cx.expr_ident_sym(span, sym::value)
)],
),
// Self(value)
VariantData::Tuple(_, _) => cx.expr_call_ident(
span,
self_kw,
thin_vec![cx.expr_ident(span, Ident::new(sym::value, span))],
thin_vec![cx.expr_ident_sym(span, sym::value)],
),
variant => {
cx.dcx().bug(format!("Invalid derive(From) ADT variant: {variant:?}"));
Expand All @@ -115,7 +115,6 @@ pub(crate) fn expand_deriving_from(
BlockOrExpr::new_expr(expr)
}),
}],
associated_types: SmallVec::new(),
is_const,
safety: Safety::Default,
document: true,
Expand Down
Loading
Loading