Skip to content

Commit c4a0daa

Browse files
committed
Auto merge of #163139 - Zalathar:rollup-lu4guFo, r=Zalathar
Rollup of 4 pull requests Successful merges: - #163049 (Tweak dyn compatibility error when pointing at receiver) - #163051 (Make CovariantUnsafeCell actually covariant) - #163080 (`rustc_builtin_macros` cleanup, part 5) - #163100 (normalize normalizes, avoid next-solver hack)
2 parents 88638df + 142a420 commit c4a0daa

32 files changed

Lines changed: 345 additions & 455 deletions

‎compiler/rustc_builtin_macros/src/deriving/clone.rs‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub(crate) fn expand_deriving_clone(
5050
}
5151
}
5252
ItemKind::Union(..) => {
53-
bounds = smallvec![Path(path_std!(marker::Copy))];
53+
bounds = smallvec![path_std!(cx, span, marker::Copy)];
5454
is_simple = true;
5555
substructure = combine_substructure(|c, s, sub| cs_clone_simple(c, s, sub, true));
5656
}
@@ -62,7 +62,7 @@ pub(crate) fn expand_deriving_clone(
6262
if is_simple {
6363
let trivial_def = TraitDef {
6464
span,
65-
path: path_std!(clone::TrivialClone),
65+
path: path_std!(cx, span, clone::TrivialClone),
6666
skip_path_as_bound: false,
6767
needs_copy_as_bound_if_packed: true,
6868
additional_bounds: bounds.clone(),
@@ -81,7 +81,7 @@ pub(crate) fn expand_deriving_clone(
8181

8282
let trait_def = TraitDef {
8383
span,
84-
path: path_std!(clone::Clone),
84+
path: path_std!(cx, span, clone::Clone),
8585
skip_path_as_bound: false,
8686
needs_copy_as_bound_if_packed: true,
8787
additional_bounds: bounds,
@@ -149,7 +149,7 @@ fn cs_clone_simple(
149149
&[sym::clone, sym::AssertParamIsCopy],
150150
);
151151
} else {
152-
match substr.fields {
152+
match substr {
153153
StaticStruct(vdata, ..) => {
154154
process_variant(vdata);
155155
}
@@ -171,17 +171,18 @@ fn cs_clone(cx: &ExtCtxt<'_>, trait_span: Span, substr: Substructure<'_>) -> Blo
171171
cx.expr_call_global(field.span, fn_path.clone(), args)
172172
};
173173

174+
let self_ident = Ident::new(kw::SelfUpper, trait_span);
174175
let ctor_path;
175176
let all_fields;
176177
let vdata;
177-
match substr.fields {
178+
match substr {
178179
Struct(vdata_, af) => {
179-
ctor_path = cx.path(trait_span, vec![substr.type_ident]);
180+
ctor_path = cx.path(trait_span, vec![self_ident]);
180181
all_fields = af;
181182
vdata = vdata_;
182183
}
183184
EnumMatching(.., variant, af) => {
184-
ctor_path = cx.path(trait_span, vec![substr.type_ident, variant.ident]);
185+
ctor_path = cx.path(trait_span, vec![self_ident, variant.ident]);
185186
all_fields = af;
186187
vdata = &variant.data;
187188
}

‎compiler/rustc_builtin_macros/src/deriving/const_param_ty.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ pub(crate) fn expand_deriving_const_param_ty(
1414
) {
1515
let trait_def = TraitDef {
1616
span,
17-
path: path_std!(marker::ConstParamTy_),
17+
path: path_std!(cx, span, marker::ConstParamTy_),
1818
skip_path_as_bound: false,
1919
needs_copy_as_bound_if_packed: false,
20-
additional_bounds: smallvec![ty::Ty::Path(path_std!(cmp::Eq))],
20+
additional_bounds: smallvec![path_std!(cx, span, cmp::Eq)],
2121
supports_unions: false,
2222
methods: SmallVec::new(),
2323
associated_types: SmallVec::new(),

‎compiler/rustc_builtin_macros/src/deriving/copy.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub(crate) fn expand_deriving_copy(
1414
) {
1515
let trait_def = TraitDef {
1616
span,
17-
path: path_std!(marker::Copy),
17+
path: path_std!(cx, span, marker::Copy),
1818
skip_path_as_bound: false,
1919
needs_copy_as_bound_if_packed: false,
2020
additional_bounds: SmallVec::new(),

‎compiler/rustc_builtin_macros/src/deriving/debug.rs‎

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ pub(crate) fn expand_deriving_debug(
1616
is_const: bool,
1717
) {
1818
// &mut ::std::fmt::Formatter
19-
let fmtr = Ref(Box::new(Path(path_std!(fmt::Formatter))), ast::Mutability::Mut);
19+
let fmtr = Ref(Box::new(Path(path_std!(cx, span, fmt::Formatter))), ast::Mutability::Mut);
2020

2121
let trait_def = TraitDef {
2222
span,
23-
path: path_std!(fmt::Debug),
23+
path: path_std!(cx, span, fmt::Debug),
2424
skip_path_as_bound: false,
2525
needs_copy_as_bound_if_packed: true,
2626
additional_bounds: SmallVec::new(),
@@ -30,11 +30,16 @@ pub(crate) fn expand_deriving_debug(
3030
generics: cx.empty_generics(span),
3131
explicit_self: true,
3232
nonself_args: smallvec![(fmtr, sym::character('f'))],
33-
ret_ty: Path(path_std!(fmt::Result)),
33+
ret_ty: Path(path_std!(cx, span, fmt::Result)),
3434
attributes: thin_vec![cx.attr_word(sym::inline, span)],
3535
fieldless_variants_strategy:
3636
FieldlessVariantsStrategy::SpecializeIfAllVariantsFieldless,
37-
combine_substructure: combine_substructure(show_substructure),
37+
combine_substructure: combine_substructure(|cx, span, substr| show_substructure(
38+
cx,
39+
span,
40+
substr,
41+
item.kind.ident().unwrap()
42+
)),
3843
}],
3944
associated_types: SmallVec::new(),
4045
is_const,
@@ -44,24 +49,30 @@ pub(crate) fn expand_deriving_debug(
4449
trait_def.expand(cx, item, push)
4550
}
4651

47-
fn show_substructure(cx: &ExtCtxt<'_>, span: Span, substr: Substructure<'_>) -> BlockOrExpr {
48-
// We want to make sure we have the ctxt set so that we can use unstable methods
49-
let span = cx.with_def_site_ctxt(span);
52+
fn formatter_ident(cx: &ExtCtxt<'_>, span: Span) -> Box<ast::Expr> {
53+
cx.expr_ident(span, Ident::new(sym::character('f'), span))
54+
}
5055

56+
fn show_substructure(
57+
cx: &ExtCtxt<'_>,
58+
span: Span,
59+
substr: Substructure<'_>,
60+
type_ident: Ident,
61+
) -> BlockOrExpr {
5162
let fmt_detail = cx.sess.opts.unstable_opts.fmt_debug;
5263
if fmt_detail == FmtDebug::None {
5364
return BlockOrExpr::new_expr(cx.expr_ok(span, cx.expr_tuple(span, ThinVec::new())));
5465
}
5566

56-
let (ident, vdata, fields) = match substr.fields {
57-
Struct(vdata, fields) => (substr.type_ident, vdata, fields),
67+
let (ident, vdata, fields) = match substr {
68+
Struct(vdata, fields) => (type_ident, vdata, fields),
5869
EnumMatching(v, fields) => (v.ident, &v.data, fields),
59-
AllFieldlessEnum(enum_def) => return show_fieldless_enum(cx, span, enum_def, substr),
70+
AllFieldlessEnum(enum_def) => return show_fieldless_enum(cx, span, enum_def, type_ident),
6071
_ => cx.dcx().span_bug(span, "unexpected substructure in `derive(Debug)`"),
6172
};
6273

6374
let name = cx.expr_str(span, ident.name);
64-
let fmt = substr.nonselflike_args[0].clone();
75+
let fmt = formatter_ident(cx, span);
6576

6677
// Fieldless enums have been special-cased earlier
6778
if fmt_detail == FmtDebug::Shallow {
@@ -85,13 +96,14 @@ fn show_substructure(cx: &ExtCtxt<'_>, span: Span, substr: Substructure<'_>) ->
8596
// The number of fields that can be handled without an array.
8697
const CUTOFF: usize = 5;
8798

88-
let expr_for_field = |field: &FieldInfo, index: usize| -> Box<ast::Expr> {
89-
if index < fields.len() - 1 {
90-
field.self_expr.clone()
99+
let len = fields.len();
100+
let expr_for_field = |field: FieldInfo, index: usize| -> Box<ast::Expr> {
101+
if index < len - 1 {
102+
field.self_expr
91103
} else {
92104
// Unsized types need an extra indirection, but only the last field
93105
// may be unsized.
94-
cx.expr_addr_of(field.span, field.self_expr.clone())
106+
cx.expr_addr_of(field.span, field.self_expr)
95107
}
96108
};
97109

@@ -111,8 +123,7 @@ fn show_substructure(cx: &ExtCtxt<'_>, span: Span, substr: Substructure<'_>) ->
111123

112124
let mut args = ThinVec::with_capacity(2 + fields.len() * args_per_field);
113125
args.extend([fmt, name]);
114-
for i in 0..fields.len() {
115-
let field = &fields[i];
126+
for (i, field) in fields.into_iter().enumerate() {
116127
if is_struct {
117128
let name = cx.expr_str(field.span, field.name.unwrap().name);
118129
args.push(name);
@@ -128,8 +139,7 @@ fn show_substructure(cx: &ExtCtxt<'_>, span: Span, substr: Substructure<'_>) ->
128139
let mut name_exprs = ThinVec::with_capacity(fields.len());
129140
let mut value_exprs = ThinVec::with_capacity(fields.len());
130141

131-
for i in 0..fields.len() {
132-
let field = &fields[i];
142+
for (i, field) in fields.into_iter().enumerate() {
133143
if is_struct {
134144
name_exprs.push(cx.expr_str(field.span, field.name.unwrap().name));
135145
}
@@ -216,14 +226,14 @@ fn show_fieldless_enum(
216226
cx: &ExtCtxt<'_>,
217227
span: Span,
218228
def: &EnumDef,
219-
substr: Substructure<'_>,
229+
type_ident: Ident,
220230
) -> BlockOrExpr {
221-
let fmt = substr.nonselflike_args[0].clone();
231+
let fmt = formatter_ident(cx, span);
222232
let arms = def
223233
.variants
224234
.iter()
225235
.map(|v| {
226-
let variant_path = cx.path(span, vec![substr.type_ident, v.ident]);
236+
let variant_path = cx.path(span, vec![type_ident, v.ident]);
227237
let pat = match &v.data {
228238
ast::VariantData::Tuple(fields, _) => {
229239
debug_assert!(fields.is_empty());

‎compiler/rustc_builtin_macros/src/deriving/default.rs‎

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub(crate) fn expand_deriving_default(
2222

2323
let trait_def = TraitDef {
2424
span,
25-
path: Path::new(vec![kw::Default, sym::Default]),
25+
path: new_path(cx, span, &[kw::Default, sym::Default], &[]),
2626
skip_path_as_bound: has_a_default_variant(item),
2727
needs_copy_as_bound_if_packed: false,
2828
additional_bounds: SmallVec::new(),
@@ -36,9 +36,9 @@ pub(crate) fn expand_deriving_default(
3636
attributes: thin_vec![cx.attr_word(sym::inline, span)],
3737
fieldless_variants_strategy: FieldlessVariantsStrategy::Default,
3838
combine_substructure: combine_substructure(|cx, trait_span, substr| {
39-
match substr.fields {
39+
match substr {
4040
StaticStruct(variant_data) => {
41-
default_struct_substructure(cx, trait_span, substr, variant_data)
41+
default_struct_substructure(cx, trait_span, variant_data)
4242
}
4343
StaticEnum(enum_def) => {
4444
default_enum_substructure(cx, trait_span, enum_def, item.span)
@@ -66,26 +66,23 @@ fn default_call(cx: &ExtCtxt<'_>, span: Span) -> Box<ast::Expr> {
6666
fn default_struct_substructure(
6767
cx: &ExtCtxt<'_>,
6868
trait_span: Span,
69-
substr: Substructure<'_>,
7069
variant_data: &VariantData,
7170
) -> BlockOrExpr {
7271
let expr = match variant_data {
73-
VariantData::Unit(_) => cx.expr_ident(trait_span, substr.type_ident),
72+
VariantData::Unit(_) => cx.expr_ident(trait_span, Ident::new(kw::SelfUpper, trait_span)),
7473
VariantData::Tuple(fields, _) => {
7574
let exprs = fields
7675
.iter()
7776
.map(|field| default_call(cx, field.span.with_ctxt(trait_span.ctxt())))
7877
.collect();
79-
cx.expr_call_ident(trait_span, substr.type_ident, exprs)
78+
cx.expr_call_ident(trait_span, Ident::new(kw::SelfUpper, trait_span), exprs)
8079
}
8180
VariantData::Struct { fields, .. } => {
8281
let default_fields = fields
8382
.iter()
8483
.map(|field| {
8584
let span = field.span.with_ctxt(trait_span.ctxt());
86-
let value = if let Some(extras) = &field.extras
87-
&& let Some(default_val) = &extras.default
88-
{
85+
let value = if let Some(default_val) = field.default_value() {
8986
// We use the field default const expression.
9087
cx.expr(
9188
default_val.value.span,
@@ -98,7 +95,7 @@ fn default_struct_substructure(
9895
cx.field_imm(span, field.ident.unwrap(), value)
9996
})
10097
.collect();
101-
cx.expr_struct_ident(trait_span, substr.type_ident, default_fields)
98+
cx.expr_struct_ident(trait_span, Ident::new(kw::SelfUpper, trait_span), default_fields)
10299
}
103100
};
104101
BlockOrExpr::new_expr(expr)

‎compiler/rustc_builtin_macros/src/deriving/eq.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub(crate) fn expand_deriving_eq(
1919

2020
let trait_def = TraitDef {
2121
span,
22-
path: path_std!(cmp::Eq),
22+
path: path_std!(cx, span, cmp::Eq),
2323
skip_path_as_bound: false,
2424
needs_copy_as_bound_if_packed: true,
2525
additional_bounds: SmallVec::new(),
@@ -73,7 +73,7 @@ fn cs_total_eq_assert(cx: &ExtCtxt<'_>, trait_span: Span, substr: Substructure<'
7373
}
7474
};
7575

76-
match substr.fields {
76+
match substr {
7777
StaticStruct(vdata, ..) => {
7878
process_variant(vdata);
7979
}

‎compiler/rustc_builtin_macros/src/deriving/from.rs‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_expand::base::{DummyResult, ExtCtxt};
55
use rustc_span::{Ident, Span, kw, sym};
66
use thin_vec::thin_vec;
77

8-
use crate::deriving::generic::ty::{Path, PathKind, Ty};
8+
use crate::deriving::generic::ty::*;
99
use crate::deriving::generic::*;
1010
use crate::deriving::pathvec;
1111
use crate::diagnostics;
@@ -52,8 +52,7 @@ pub(crate) fn expand_deriving_from(
5252
Err(guar) => cx.ty(span, ast::TyKind::Err(guar)),
5353
});
5454

55-
let path =
56-
Path::new_(pathvec!(convert::From), vec![Box::new(from_type.clone())], PathKind::Std);
55+
let path = new_path(cx, span, pathvec!(convert::From), &[from_type.clone()]);
5756

5857
// Generate code like this:
5958
//
@@ -89,8 +88,8 @@ pub(crate) fn expand_deriving_from(
8988
};
9089

9190
let self_kw = Ident::new(kw::SelfUpper, span);
92-
let expr: Box<ast::Expr> = match substructure.fields {
93-
SubstructureFields::StaticStruct(variant) => match variant {
91+
let expr: Box<ast::Expr> = match substructure {
92+
StaticStruct(variant) => match variant {
9493
// Self { field: value }
9594
VariantData::Struct { .. } => cx.expr_struct_ident(
9695
span,

0 commit comments

Comments
 (0)