Skip to content

Commit 896d9e4

Browse files
committed
Auto merge of #142604 - jhpratt:rollup-77fsgte, r=jhpratt
Rollup of 11 pull requests Successful merges: - #140809 (Reduce special casing for the panic runtime) - #141608 (Add support for repetition to `proc_macro::quote`) - #141864 (Handle win32 separator for cygwin paths) - #142216 (Miscellaneous RefCell cleanups) - #142517 (Windows: Use anonymous pipes in Command) - #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) - #142595 (Revert overeager warning for misuse of `--print native-static-libs`) - #142598 (Set elf e_flags on ppc64 targets according to abi) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 55d4364 + 5d62529 commit 896d9e4

File tree

70 files changed

+1718
-716
lines changed

Some content is hidden

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

70 files changed

+1718
-716
lines changed

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/linker.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1829,6 +1829,7 @@ pub(crate) fn linked_symbols(
18291829
for_each_exported_symbols_include_dep(tcx, crate_type, |symbol, info, cnum| {
18301830
if info.level.is_below_threshold(export_threshold) && !tcx.is_compiler_builtins(cnum)
18311831
|| info.used
1832+
|| info.rustc_std_internal_symbol
18321833
{
18331834
symbols.push((
18341835
symbol_export::linking_symbol_name_for_instance_in_crate(tcx, symbol, cnum),

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_codegen_ssa/src/back/symbol_export.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ fn reachable_non_generics_provider(tcx: TyCtxt<'_>, _: LocalCrate) -> DefIdMap<S
131131
used: codegen_attrs.flags.contains(CodegenFnAttrFlags::USED_COMPILER)
132132
|| codegen_attrs.flags.contains(CodegenFnAttrFlags::USED_LINKER)
133133
|| used,
134+
rustc_std_internal_symbol: codegen_attrs
135+
.flags
136+
.contains(CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL),
134137
};
135138
(def_id.to_def_id(), info)
136139
})
@@ -143,6 +146,7 @@ fn reachable_non_generics_provider(tcx: TyCtxt<'_>, _: LocalCrate) -> DefIdMap<S
143146
level: SymbolExportLevel::C,
144147
kind: SymbolExportKind::Data,
145148
used: false,
149+
rustc_std_internal_symbol: false,
146150
},
147151
);
148152
}
@@ -191,6 +195,7 @@ fn exported_symbols_provider_local<'tcx>(
191195
level: info.level,
192196
kind: SymbolExportKind::Text,
193197
used: info.used,
198+
rustc_std_internal_symbol: info.rustc_std_internal_symbol,
194199
},
195200
)
196201
})
@@ -207,6 +212,7 @@ fn exported_symbols_provider_local<'tcx>(
207212
level: SymbolExportLevel::C,
208213
kind: SymbolExportKind::Text,
209214
used: false,
215+
rustc_std_internal_symbol: false,
210216
},
211217
));
212218
}
@@ -229,6 +235,7 @@ fn exported_symbols_provider_local<'tcx>(
229235
level: SymbolExportLevel::Rust,
230236
kind: SymbolExportKind::Text,
231237
used: false,
238+
rustc_std_internal_symbol: true,
232239
},
233240
));
234241
}
@@ -243,6 +250,7 @@ fn exported_symbols_provider_local<'tcx>(
243250
level: SymbolExportLevel::Rust,
244251
kind: SymbolExportKind::Data,
245252
used: false,
253+
rustc_std_internal_symbol: true,
246254
},
247255
))
248256
}
@@ -262,6 +270,7 @@ fn exported_symbols_provider_local<'tcx>(
262270
level: SymbolExportLevel::C,
263271
kind: SymbolExportKind::Data,
264272
used: false,
273+
rustc_std_internal_symbol: false,
265274
},
266275
)
267276
}));
@@ -287,6 +296,7 @@ fn exported_symbols_provider_local<'tcx>(
287296
level: SymbolExportLevel::C,
288297
kind: SymbolExportKind::Data,
289298
used: false,
299+
rustc_std_internal_symbol: false,
290300
},
291301
)
292302
}));
@@ -304,6 +314,7 @@ fn exported_symbols_provider_local<'tcx>(
304314
level: SymbolExportLevel::C,
305315
kind: SymbolExportKind::Data,
306316
used: true,
317+
rustc_std_internal_symbol: false,
307318
},
308319
));
309320
}
@@ -379,6 +390,8 @@ fn exported_symbols_provider_local<'tcx>(
379390
}
380391
}
381392

393+
// Note: These all set rustc_std_internal_symbol to false as generic functions must not
394+
// be marked with this attribute and we are only handling generic functions here.
382395
match *mono_item {
383396
MonoItem::Fn(Instance { def: InstanceKind::Item(def), args }) => {
384397
let has_generics = args.non_erasable_generics().next().is_some();
@@ -394,6 +407,7 @@ fn exported_symbols_provider_local<'tcx>(
394407
level: SymbolExportLevel::Rust,
395408
kind: SymbolExportKind::Text,
396409
used: false,
410+
rustc_std_internal_symbol: false,
397411
},
398412
));
399413
}
@@ -416,6 +430,7 @@ fn exported_symbols_provider_local<'tcx>(
416430
level: SymbolExportLevel::Rust,
417431
kind: SymbolExportKind::Text,
418432
used: false,
433+
rustc_std_internal_symbol: false,
419434
},
420435
));
421436
}
@@ -432,6 +447,7 @@ fn exported_symbols_provider_local<'tcx>(
432447
level: SymbolExportLevel::Rust,
433448
kind: SymbolExportKind::Text,
434449
used: false,
450+
rustc_std_internal_symbol: false,
435451
},
436452
));
437453
}
@@ -442,6 +458,7 @@ fn exported_symbols_provider_local<'tcx>(
442458
level: SymbolExportLevel::Rust,
443459
kind: SymbolExportKind::Text,
444460
used: false,
461+
rustc_std_internal_symbol: false,
445462
},
446463
));
447464
}

compiler/rustc_codegen_ssa/src/base.rs

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::time::{Duration, Instant};
66
use itertools::Itertools;
77
use rustc_abi::FIRST_VARIANT;
88
use rustc_ast as ast;
9-
use rustc_ast::expand::allocator::{ALLOCATOR_METHODS, AllocatorKind, global_fn_name};
9+
use rustc_ast::expand::allocator::AllocatorKind;
1010
use rustc_attr_data_structures::OptimizeAttr;
1111
use rustc_data_structures::fx::{FxHashMap, FxIndexSet};
1212
use rustc_data_structures::profiling::{get_resident_set_size, print_time_passes_entry};
@@ -1039,26 +1039,6 @@ impl CrateInfo {
10391039
.collect::<Vec<_>>();
10401040
symbols.sort_unstable_by(|a, b| a.0.cmp(&b.0));
10411041
linked_symbols.extend(symbols);
1042-
if tcx.allocator_kind(()).is_some() {
1043-
// At least one crate needs a global allocator. This crate may be placed
1044-
// after the crate that defines it in the linker order, in which case some
1045-
// linkers return an error. By adding the global allocator shim methods to
1046-
// the linked_symbols list, linking the generated symbols.o will ensure that
1047-
// circular dependencies involving the global allocator don't lead to linker
1048-
// errors.
1049-
linked_symbols.extend(ALLOCATOR_METHODS.iter().map(|method| {
1050-
(
1051-
format!(
1052-
"{prefix}{}",
1053-
mangle_internal_symbol(
1054-
tcx,
1055-
global_fn_name(method.name).as_str()
1056-
)
1057-
),
1058-
SymbolExportKind::Text,
1059-
)
1060-
}));
1061-
}
10621042
});
10631043
}
10641044

0 commit comments

Comments
 (0)