Skip to content

Commit f3db639

Browse files
committed
Auto merge of #142613 - workingjubilee:rollup-yuod2hg, r=workingjubilee
Rollup of 13 pull requests Successful merges: - #138538 (Make performance description of String::{insert,insert_str,remove} more precise) - #141946 (std: refactor explanation of `NonNull`) - #142216 (Miscellaneous RefCell cleanups) - #142542 (Manually invalidate caches in SimplifyCfg.) - #142563 (Refine run-make test ignores due to unpredictable `i686-pc-windows-gnu` unwind mechanism) - #142570 (Reject union default field values) - #142584 (Handle same-crate macro for borrowck semicolon suggestion) - #142585 (Update books) - #142586 (Fold unnecessary `visit_struct_field_def` in AstValidator) - #142587 (Make sure to propagate result from `visit_expr_fields`) - #142595 (Revert overeager warning for misuse of `--print native-static-libs`) - #142598 (Set elf e_flags on ppc64 targets according to abi) - #142601 (Add a comment to `FORMAT_VERSION`.) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 86d0aef + 68ebae9 commit f3db639

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+337
-302
lines changed

compiler/rustc_ast/src/visit.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -884,7 +884,7 @@ macro_rules! common_visitor_and_walkers {
884884
TyKind::BareFn(function_declaration) => {
885885
let BareFnTy { safety, ext: _, generic_params, decl, decl_span } =
886886
&$($mut)? **function_declaration;
887-
visit_safety(vis, safety);
887+
try_visit!(visit_safety(vis, safety));
888888
try_visit!(visit_generic_params(vis, generic_params));
889889
try_visit!(vis.visit_fn_decl(decl));
890890
try_visit!(visit_span(vis, decl_span));
@@ -1235,7 +1235,7 @@ macro_rules! common_visitor_and_walkers {
12351235
bounds,
12361236
bound_generic_params,
12371237
}) => {
1238-
visit_generic_params(vis, bound_generic_params);
1238+
try_visit!(visit_generic_params(vis, bound_generic_params));
12391239
try_visit!(vis.visit_ty(bounded_ty));
12401240
walk_list!(vis, visit_param_bound, bounds, BoundKind::Bound);
12411241
}
@@ -1420,7 +1420,7 @@ macro_rules! common_visitor_and_walkers {
14201420
let StructExpr { qself, path, fields, rest } = &$($mut)?**se;
14211421
try_visit!(vis.visit_qself(qself));
14221422
try_visit!(vis.visit_path(path));
1423-
visit_expr_fields(vis, fields);
1423+
try_visit!(visit_expr_fields(vis, fields));
14241424
match rest {
14251425
StructRest::Base(expr) => try_visit!(vis.visit_expr(expr)),
14261426
StructRest::Rest(_span) => {}

compiler/rustc_ast_lowering/messages.ftl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ ast_lowering_underscore_expr_lhs_assign =
179179
in expressions, `_` can only be used on the left-hand side of an assignment
180180
.label = `_` not allowed here
181181
182+
ast_lowering_union_default_field_values = unions cannot have default field values
183+
182184
ast_lowering_unstable_inline_assembly = inline assembly is not stable yet on this architecture
183185
ast_lowering_unstable_inline_assembly_label_operand_with_outputs =
184186
using both label and output operands for inline assembly is unstable

compiler/rustc_ast_lowering/src/errors.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,3 +475,10 @@ pub(crate) struct UseConstGenericArg {
475475
#[suggestion_part(code = "{other_args}")]
476476
pub call_args: Span,
477477
}
478+
479+
#[derive(Diagnostic)]
480+
#[diag(ast_lowering_union_default_field_values)]
481+
pub(crate) struct UnionWithDefault {
482+
#[primary_span]
483+
pub span: Span,
484+
}

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use tracing::instrument;
1717

1818
use super::errors::{
1919
InvalidAbi, InvalidAbiSuggestion, MisplacedRelaxTraitBound, TupleStructWithDefault,
20+
UnionWithDefault,
2021
};
2122
use super::stability::{enabled_names, gate_unstable_abi};
2223
use super::{
@@ -316,7 +317,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
316317
ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
317318
|this| {
318319
this.arena.alloc_from_iter(
319-
enum_definition.variants.iter().map(|x| this.lower_variant(x)),
320+
enum_definition.variants.iter().map(|x| this.lower_variant(i, x)),
320321
)
321322
},
322323
);
@@ -328,7 +329,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
328329
generics,
329330
id,
330331
ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
331-
|this| this.lower_variant_data(hir_id, struct_def),
332+
|this| this.lower_variant_data(hir_id, i, struct_def),
332333
);
333334
hir::ItemKind::Struct(ident, generics, struct_def)
334335
}
@@ -338,7 +339,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
338339
generics,
339340
id,
340341
ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
341-
|this| this.lower_variant_data(hir_id, vdata),
342+
|this| this.lower_variant_data(hir_id, i, vdata),
342343
);
343344
hir::ItemKind::Union(ident, generics, vdata)
344345
}
@@ -714,13 +715,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
714715
}
715716
}
716717

717-
fn lower_variant(&mut self, v: &Variant) -> hir::Variant<'hir> {
718+
fn lower_variant(&mut self, item_kind: &ItemKind, v: &Variant) -> hir::Variant<'hir> {
718719
let hir_id = self.lower_node_id(v.id);
719720
self.lower_attrs(hir_id, &v.attrs, v.span);
720721
hir::Variant {
721722
hir_id,
722723
def_id: self.local_def_id(v.id),
723-
data: self.lower_variant_data(hir_id, &v.data),
724+
data: self.lower_variant_data(hir_id, item_kind, &v.data),
724725
disr_expr: v.disr_expr.as_ref().map(|e| self.lower_anon_const_to_anon_const(e)),
725726
ident: self.lower_ident(v.ident),
726727
span: self.lower_span(v.span),
@@ -730,15 +731,36 @@ impl<'hir> LoweringContext<'_, 'hir> {
730731
fn lower_variant_data(
731732
&mut self,
732733
parent_id: hir::HirId,
734+
item_kind: &ItemKind,
733735
vdata: &VariantData,
734736
) -> hir::VariantData<'hir> {
735737
match vdata {
736-
VariantData::Struct { fields, recovered } => hir::VariantData::Struct {
737-
fields: self
738+
VariantData::Struct { fields, recovered } => {
739+
let fields = self
738740
.arena
739-
.alloc_from_iter(fields.iter().enumerate().map(|f| self.lower_field_def(f))),
740-
recovered: *recovered,
741-
},
741+
.alloc_from_iter(fields.iter().enumerate().map(|f| self.lower_field_def(f)));
742+
743+
if let ItemKind::Union(..) = item_kind {
744+
for field in &fields[..] {
745+
if let Some(default) = field.default {
746+
// Unions cannot derive `Default`, and it's not clear how to use default
747+
// field values of unions if that was supported. Therefore, blanket reject
748+
// trying to use field values with unions.
749+
if self.tcx.features().default_field_values() {
750+
self.dcx().emit_err(UnionWithDefault { span: default.span });
751+
} else {
752+
let _ = self.dcx().span_delayed_bug(
753+
default.span,
754+
"expected union default field values feature gate error but none \
755+
was produced",
756+
);
757+
}
758+
}
759+
}
760+
}
761+
762+
hir::VariantData::Struct { fields, recovered: *recovered }
763+
}
742764
VariantData::Tuple(fields, id) => {
743765
let ctor_id = self.lower_node_id(*id);
744766
self.alias_attrs(ctor_id, parent_id);

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -224,20 +224,6 @@ impl<'a> AstValidator<'a> {
224224
}
225225
}
226226

227-
fn visit_struct_field_def(&mut self, field: &'a FieldDef) {
228-
if let Some(ref ident) = field.ident
229-
&& ident.name == kw::Underscore
230-
{
231-
self.visit_vis(&field.vis);
232-
self.visit_ident(ident);
233-
self.visit_ty_common(&field.ty);
234-
self.walk_ty(&field.ty);
235-
walk_list!(self, visit_attribute, &field.attrs);
236-
} else {
237-
self.visit_field_def(field);
238-
}
239-
}
240-
241227
fn dcx(&self) -> DiagCtxtHandle<'a> {
242228
self.sess.dcx()
243229
}
@@ -1135,8 +1121,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
11351121
VariantData::Struct { fields, .. } => {
11361122
self.visit_attrs_vis_ident(&item.attrs, &item.vis, ident);
11371123
self.visit_generics(generics);
1138-
// Permit `Anon{Struct,Union}` as field type.
1139-
walk_list!(self, visit_struct_field_def, fields);
1124+
walk_list!(self, visit_field_def, fields);
11401125
}
11411126
_ => visit::walk_item(self, item),
11421127
},
@@ -1148,8 +1133,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
11481133
VariantData::Struct { fields, .. } => {
11491134
self.visit_attrs_vis_ident(&item.attrs, &item.vis, ident);
11501135
self.visit_generics(generics);
1151-
// Permit `Anon{Struct,Union}` as field type.
1152-
walk_list!(self, visit_struct_field_def, fields);
1136+
walk_list!(self, visit_field_def, fields);
11531137
}
11541138
_ => visit::walk_item(self, item),
11551139
}

compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -342,10 +342,7 @@ impl<'tcx> BorrowExplanation<'tcx> {
342342
}
343343
}
344344
} else if let LocalInfo::BlockTailTemp(info) = local_decl.local_info() {
345-
let sp = info
346-
.span
347-
.find_ancestor_in_same_ctxt(local_decl.source_info.span)
348-
.unwrap_or(info.span);
345+
let sp = info.span.find_oldest_ancestor_in_same_ctxt();
349346
if info.tail_result_is_ignored {
350347
// #85581: If the first mutable borrow's scope contains
351348
// the second borrow, this suggestion isn't helpful.

compiler/rustc_codegen_ssa/src/back/link.rs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -69,23 +69,6 @@ pub fn ensure_removed(dcx: DiagCtxtHandle<'_>, path: &Path) {
6969
}
7070
}
7171

72-
fn check_link_info_print_request(sess: &Session, crate_types: &[CrateType]) {
73-
let print_native_static_libs =
74-
sess.opts.prints.iter().any(|p| p.kind == PrintKind::NativeStaticLibs);
75-
let has_staticlib = crate_types.iter().any(|ct| *ct == CrateType::Staticlib);
76-
if print_native_static_libs {
77-
if !has_staticlib {
78-
sess.dcx()
79-
.warn(format!("cannot output linkage information without staticlib crate-type"));
80-
sess.dcx()
81-
.note(format!("consider `--crate-type staticlib` to print linkage information"));
82-
} else if !sess.opts.output_types.should_link() {
83-
sess.dcx()
84-
.warn(format!("cannot output linkage information when --emit link is not passed"));
85-
}
86-
}
87-
}
88-
8972
/// Performs the linkage portion of the compilation phase. This will generate all
9073
/// of the requested outputs for this compilation session.
9174
pub fn link_binary(
@@ -208,8 +191,6 @@ pub fn link_binary(
208191
}
209192
}
210193

211-
check_link_info_print_request(sess, &codegen_results.crate_info.crate_types);
212-
213194
// Remove the temporary object file and metadata if we aren't saving temps.
214195
sess.time("link_binary_remove_temps", || {
215196
// If the user requests that temporaries are saved, don't delete any.

compiler/rustc_codegen_ssa/src/back/metadata.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,24 @@ pub(super) fn elf_e_flags(architecture: Architecture, sess: &Session) -> u32 {
379379
};
380380
e_flags
381381
}
382+
Architecture::PowerPc64 => {
383+
const EF_PPC64_ABI_UNKNOWN: u32 = 0;
384+
const EF_PPC64_ABI_ELF_V1: u32 = 1;
385+
const EF_PPC64_ABI_ELF_V2: u32 = 2;
386+
387+
match sess.target.options.llvm_abiname.as_ref() {
388+
// If the flags do not correctly indicate the ABI,
389+
// linkers such as ld.lld assume that the ppc64 object files are always ELFv2
390+
// which leads to broken binaries if ELFv1 is used for the object files.
391+
"elfv1" => EF_PPC64_ABI_ELF_V1,
392+
"elfv2" => EF_PPC64_ABI_ELF_V2,
393+
"" if sess.target.options.binary_format.to_object() == BinaryFormat::Elf => {
394+
bug!("No ABI specified for this PPC64 ELF target");
395+
}
396+
// Fall back
397+
_ => EF_PPC64_ABI_UNKNOWN,
398+
}
399+
}
382400
_ => 0,
383401
}
384402
}

compiler/rustc_mir_transform/src/simplify.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,11 @@ impl SimplifyCfg {
7474
}
7575

7676
pub(super) fn simplify_cfg<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
77-
CfgSimplifier::new(tcx, body).simplify();
77+
if CfgSimplifier::new(tcx, body).simplify() {
78+
// `simplify` returns that it changed something. We must invalidate the CFG caches as they
79+
// are not consistent with the modified CFG any more.
80+
body.basic_blocks.invalidate_cfg_cache();
81+
}
7882
remove_dead_blocks(body);
7983

8084
// FIXME: Should probably be moved into some kind of pass manager
@@ -121,19 +125,24 @@ impl<'a, 'tcx> CfgSimplifier<'a, 'tcx> {
121125
// Preserve `SwitchInt` reads on built and analysis MIR, or if `-Zmir-preserve-ub`.
122126
let preserve_switch_reads = matches!(body.phase, MirPhase::Built | MirPhase::Analysis(_))
123127
|| tcx.sess.opts.unstable_opts.mir_preserve_ub;
124-
let basic_blocks = body.basic_blocks_mut();
128+
// Do not clear caches yet. The caller to `simplify` will do it if anything changed.
129+
let basic_blocks = body.basic_blocks.as_mut_preserves_cfg();
125130

126131
CfgSimplifier { preserve_switch_reads, basic_blocks, pred_count }
127132
}
128133

129-
fn simplify(mut self) {
134+
/// Returns whether we actually simplified anything. In that case, the caller *must* invalidate
135+
/// the CFG caches of the MIR body.
136+
#[must_use]
137+
fn simplify(mut self) -> bool {
130138
self.strip_nops();
131139

132140
// Vec of the blocks that should be merged. We store the indices here, instead of the
133141
// statements itself to avoid moving the (relatively) large statements twice.
134142
// We do not push the statements directly into the target block (`bb`) as that is slower
135143
// due to additional reallocations
136144
let mut merged_blocks = Vec::new();
145+
let mut outer_changed = false;
137146
loop {
138147
let mut changed = false;
139148

@@ -177,7 +186,11 @@ impl<'a, 'tcx> CfgSimplifier<'a, 'tcx> {
177186
if !changed {
178187
break;
179188
}
189+
190+
outer_changed = true;
180191
}
192+
193+
outer_changed
181194
}
182195

183196
/// This function will return `None` if

compiler/rustc_target/src/spec/targets/powerpc64_unknown_freebsd.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub(crate) fn target() -> Target {
1010
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m64"]);
1111
base.max_atomic_width = Some(64);
1212
base.stack_probes = StackProbeType::Inline;
13+
base.llvm_abiname = "elfv2".into();
1314

1415
Target {
1516
llvm_target: "powerpc64-unknown-freebsd".into(),

compiler/rustc_target/src/spec/targets/powerpc64_unknown_linux_gnu.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub(crate) fn target() -> Target {
1010
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m64"]);
1111
base.max_atomic_width = Some(64);
1212
base.stack_probes = StackProbeType::Inline;
13+
base.llvm_abiname = "elfv1".into();
1314

1415
Target {
1516
llvm_target: "powerpc64-unknown-linux-gnu".into(),

compiler/rustc_target/src/spec/targets/powerpc64_unknown_linux_musl.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ pub(crate) fn target() -> Target {
1212
base.stack_probes = StackProbeType::Inline;
1313
// FIXME(compiler-team#422): musl targets should be dynamically linked by default.
1414
base.crt_static_default = true;
15+
base.llvm_abiname = "elfv2".into();
1516

1617
Target {
1718
llvm_target: "powerpc64-unknown-linux-musl".into(),

compiler/rustc_target/src/spec/targets/powerpc64_unknown_openbsd.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub(crate) fn target() -> Target {
1010
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m64"]);
1111
base.max_atomic_width = Some(64);
1212
base.stack_probes = StackProbeType::Inline;
13+
base.llvm_abiname = "elfv2".into();
1314

1415
Target {
1516
llvm_target: "powerpc64-unknown-openbsd".into(),

compiler/rustc_target/src/spec/targets/powerpc64_wrs_vxworks.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub(crate) fn target() -> Target {
1010
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m64"]);
1111
base.max_atomic_width = Some(64);
1212
base.stack_probes = StackProbeType::Inline;
13+
base.llvm_abiname = "elfv1".into();
1314

1415
Target {
1516
llvm_target: "powerpc64-unknown-linux-gnu".into(),

compiler/rustc_target/src/spec/targets/powerpc64le_unknown_freebsd.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ pub(crate) fn target() -> Target {
88
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m64"]);
99
base.max_atomic_width = Some(64);
1010
base.stack_probes = StackProbeType::Inline;
11+
base.llvm_abiname = "elfv2".into();
1112

1213
Target {
1314
llvm_target: "powerpc64le-unknown-freebsd".into(),

compiler/rustc_target/src/spec/targets/powerpc64le_unknown_linux_gnu.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ pub(crate) fn target() -> Target {
88
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m64"]);
99
base.max_atomic_width = Some(64);
1010
base.stack_probes = StackProbeType::Inline;
11+
base.llvm_abiname = "elfv2".into();
1112

1213
Target {
1314
llvm_target: "powerpc64le-unknown-linux-gnu".into(),

compiler/rustc_target/src/spec/targets/powerpc64le_unknown_linux_musl.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub(crate) fn target() -> Target {
1010
base.stack_probes = StackProbeType::Inline;
1111
// FIXME(compiler-team#422): musl targets should be dynamically linked by default.
1212
base.crt_static_default = true;
13+
base.llvm_abiname = "elfv2".into();
1314

1415
Target {
1516
llvm_target: "powerpc64le-unknown-linux-musl".into(),

0 commit comments

Comments
 (0)