Skip to content

Rollup of 13 pull requests #142613

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 32 commits into from
Jun 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
8713973
std: simplify `NonNull` variance documentation
xizheyin Jun 3, 2025
a16b49b
Manually invalidate caches in SimplifyCfg.
cjgillot Jun 15, 2025
32c0cb0
Add union with default field values case test
jieyouxu Jun 16, 2025
a2d9687
Add comment.
cjgillot Jun 16, 2025
718df66
Two changes: Have BorrowError & BorrowMutError derive Debug and add
nealsid Jun 14, 2025
2fca05a
Rename BorrowFlag type to BorrowCounter
nealsid Jun 14, 2025
7cfc51b
Update books
rustbot Jun 16, 2025
8a7b50a
Fold unnecessary visit_struct_field_def in AstValidator
compiler-errors Jun 16, 2025
ad60d8e
Make sure to propagate result from visit_expr_fields
compiler-errors Jun 16, 2025
994794a
Handle same-crate macro for borrowck semicolon suggestion
Urgau Jun 16, 2025
ac8b506
Fix some unused fields in AST visitor
compiler-errors Jun 16, 2025
7b29a5d
Revert overeager warning for misuse of `--print native-static-libs`
workingjubilee Jun 16, 2025
7859a37
explicitly set llvm_abiname option on existing ppc64 targets
ostylk Jun 11, 2025
9c1180b
indicate ppc64 elf abi in e_flags
ostylk Jun 11, 2025
2dd9cc1
Reject union default field values
jieyouxu Jun 16, 2025
fb75e09
Add a comment to `FORMAT_VERSION`.
nnethercote Jun 16, 2025
1dbedaf
Refine run-make test ignores due to unpredictable `i686-pc-windows-gn…
jieyouxu Jun 16, 2025
aa8c6f8
Don't match on platform-specific directory not found message
jieyouxu Jun 17, 2025
0348a4a
Make performance of String::insert_str more precise
hkBst Mar 15, 2025
346adce
Rollup merge of #138538 - hkBst:patch-4, r=tgross35
workingjubilee Jun 17, 2025
94ce4b5
Rollup merge of #141946 - xizheyin:141933, r=jhpratt
workingjubilee Jun 17, 2025
a2a767a
Rollup merge of #142216 - nealsid:refcell-logging, r=tgross35
workingjubilee Jun 17, 2025
725d829
Rollup merge of #142542 - cjgillot:invalidate-simplify-cfg, r=SparrowLii
workingjubilee Jun 17, 2025
f2e9e2a
Rollup merge of #142563 - jieyouxu:no-more-i686-mingw, r=mati865
workingjubilee Jun 17, 2025
d4f23cd
Rollup merge of #142570 - jieyouxu:disunion, r=estebank
workingjubilee Jun 17, 2025
b27b74f
Rollup merge of #142584 - Urgau:span-borrowck-139049, r=fmease
workingjubilee Jun 17, 2025
bb3a273
Rollup merge of #142585 - rustbot:docs-update, r=ehuss
workingjubilee Jun 17, 2025
3018154
Rollup merge of #142586 - compiler-errors:remove-visit-struct-field-d…
workingjubilee Jun 17, 2025
5df2389
Rollup merge of #142587 - compiler-errors:try-visit-expr-fields, r=ji…
workingjubilee Jun 17, 2025
99c8475
Rollup merge of #142595 - workingjubilee:revert-warning-138139, r=Chr…
workingjubilee Jun 17, 2025
3800083
Rollup merge of #142598 - ostylk:fix/ppc64_llvmabi, r=nikic,workingju…
workingjubilee Jun 17, 2025
68ebae9
Rollup merge of #142601 - nnethercote:format_version-comment, r=aDotI…
workingjubilee Jun 17, 2025
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
6 changes: 3 additions & 3 deletions compiler/rustc_ast/src/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,7 @@ macro_rules! common_visitor_and_walkers {
TyKind::BareFn(function_declaration) => {
let BareFnTy { safety, ext: _, generic_params, decl, decl_span } =
&$($mut)? **function_declaration;
visit_safety(vis, safety);
try_visit!(visit_safety(vis, safety));
try_visit!(visit_generic_params(vis, generic_params));
try_visit!(vis.visit_fn_decl(decl));
try_visit!(visit_span(vis, decl_span));
Expand Down Expand Up @@ -1235,7 +1235,7 @@ macro_rules! common_visitor_and_walkers {
bounds,
bound_generic_params,
}) => {
visit_generic_params(vis, bound_generic_params);
try_visit!(visit_generic_params(vis, bound_generic_params));
try_visit!(vis.visit_ty(bounded_ty));
walk_list!(vis, visit_param_bound, bounds, BoundKind::Bound);
}
Expand Down Expand Up @@ -1420,7 +1420,7 @@ macro_rules! common_visitor_and_walkers {
let StructExpr { qself, path, fields, rest } = &$($mut)?**se;
try_visit!(vis.visit_qself(qself));
try_visit!(vis.visit_path(path));
visit_expr_fields(vis, fields);
try_visit!(visit_expr_fields(vis, fields));
match rest {
StructRest::Base(expr) => try_visit!(vis.visit_expr(expr)),
StructRest::Rest(_span) => {}
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_ast_lowering/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ ast_lowering_underscore_expr_lhs_assign =
in expressions, `_` can only be used on the left-hand side of an assignment
.label = `_` not allowed here
ast_lowering_union_default_field_values = unions cannot have default field values
ast_lowering_unstable_inline_assembly = inline assembly is not stable yet on this architecture
ast_lowering_unstable_inline_assembly_label_operand_with_outputs =
using both label and output operands for inline assembly is unstable
Expand Down
7 changes: 7 additions & 0 deletions compiler/rustc_ast_lowering/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,3 +475,10 @@ pub(crate) struct UseConstGenericArg {
#[suggestion_part(code = "{other_args}")]
pub call_args: Span,
}

#[derive(Diagnostic)]
#[diag(ast_lowering_union_default_field_values)]
pub(crate) struct UnionWithDefault {
#[primary_span]
pub span: Span,
}
42 changes: 32 additions & 10 deletions compiler/rustc_ast_lowering/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use tracing::instrument;

use super::errors::{
InvalidAbi, InvalidAbiSuggestion, MisplacedRelaxTraitBound, TupleStructWithDefault,
UnionWithDefault,
};
use super::stability::{enabled_names, gate_unstable_abi};
use super::{
Expand Down Expand Up @@ -316,7 +317,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
|this| {
this.arena.alloc_from_iter(
enum_definition.variants.iter().map(|x| this.lower_variant(x)),
enum_definition.variants.iter().map(|x| this.lower_variant(i, x)),
)
},
);
Expand All @@ -328,7 +329,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
generics,
id,
ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
|this| this.lower_variant_data(hir_id, struct_def),
|this| this.lower_variant_data(hir_id, i, struct_def),
);
hir::ItemKind::Struct(ident, generics, struct_def)
}
Expand All @@ -338,7 +339,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
generics,
id,
ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
|this| this.lower_variant_data(hir_id, vdata),
|this| this.lower_variant_data(hir_id, i, vdata),
);
hir::ItemKind::Union(ident, generics, vdata)
}
Expand Down Expand Up @@ -714,13 +715,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
}
}

fn lower_variant(&mut self, v: &Variant) -> hir::Variant<'hir> {
fn lower_variant(&mut self, item_kind: &ItemKind, v: &Variant) -> hir::Variant<'hir> {
let hir_id = self.lower_node_id(v.id);
self.lower_attrs(hir_id, &v.attrs, v.span);
hir::Variant {
hir_id,
def_id: self.local_def_id(v.id),
data: self.lower_variant_data(hir_id, &v.data),
data: self.lower_variant_data(hir_id, item_kind, &v.data),
disr_expr: v.disr_expr.as_ref().map(|e| self.lower_anon_const_to_anon_const(e)),
ident: self.lower_ident(v.ident),
span: self.lower_span(v.span),
Expand All @@ -730,15 +731,36 @@ impl<'hir> LoweringContext<'_, 'hir> {
fn lower_variant_data(
&mut self,
parent_id: hir::HirId,
item_kind: &ItemKind,
vdata: &VariantData,
) -> hir::VariantData<'hir> {
match vdata {
VariantData::Struct { fields, recovered } => hir::VariantData::Struct {
fields: self
VariantData::Struct { fields, recovered } => {
let fields = self
.arena
.alloc_from_iter(fields.iter().enumerate().map(|f| self.lower_field_def(f))),
recovered: *recovered,
},
.alloc_from_iter(fields.iter().enumerate().map(|f| self.lower_field_def(f)));

if let ItemKind::Union(..) = item_kind {
for field in &fields[..] {
if let Some(default) = field.default {
// Unions cannot derive `Default`, and it's not clear how to use default
// field values of unions if that was supported. Therefore, blanket reject
// trying to use field values with unions.
if self.tcx.features().default_field_values() {
self.dcx().emit_err(UnionWithDefault { span: default.span });
} else {
let _ = self.dcx().span_delayed_bug(
default.span,
"expected union default field values feature gate error but none \
was produced",
);
}
}
}
}

hir::VariantData::Struct { fields, recovered: *recovered }
}
VariantData::Tuple(fields, id) => {
let ctor_id = self.lower_node_id(*id);
self.alias_attrs(ctor_id, parent_id);
Expand Down
20 changes: 2 additions & 18 deletions compiler/rustc_ast_passes/src/ast_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,20 +224,6 @@ impl<'a> AstValidator<'a> {
}
}

fn visit_struct_field_def(&mut self, field: &'a FieldDef) {
if let Some(ref ident) = field.ident
&& ident.name == kw::Underscore
{
self.visit_vis(&field.vis);
self.visit_ident(ident);
self.visit_ty_common(&field.ty);
self.walk_ty(&field.ty);
walk_list!(self, visit_attribute, &field.attrs);
} else {
self.visit_field_def(field);
}
}

fn dcx(&self) -> DiagCtxtHandle<'a> {
self.sess.dcx()
}
Expand Down Expand Up @@ -1135,8 +1121,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
VariantData::Struct { fields, .. } => {
self.visit_attrs_vis_ident(&item.attrs, &item.vis, ident);
self.visit_generics(generics);
// Permit `Anon{Struct,Union}` as field type.
walk_list!(self, visit_struct_field_def, fields);
walk_list!(self, visit_field_def, fields);
}
_ => visit::walk_item(self, item),
},
Expand All @@ -1148,8 +1133,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
VariantData::Struct { fields, .. } => {
self.visit_attrs_vis_ident(&item.attrs, &item.vis, ident);
self.visit_generics(generics);
// Permit `Anon{Struct,Union}` as field type.
walk_list!(self, visit_struct_field_def, fields);
walk_list!(self, visit_field_def, fields);
}
_ => visit::walk_item(self, item),
}
Expand Down
5 changes: 1 addition & 4 deletions compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,10 +342,7 @@ impl<'tcx> BorrowExplanation<'tcx> {
}
}
} else if let LocalInfo::BlockTailTemp(info) = local_decl.local_info() {
let sp = info
.span
.find_ancestor_in_same_ctxt(local_decl.source_info.span)
.unwrap_or(info.span);
let sp = info.span.find_oldest_ancestor_in_same_ctxt();
if info.tail_result_is_ignored {
// #85581: If the first mutable borrow's scope contains
// the second borrow, this suggestion isn't helpful.
Expand Down
19 changes: 0 additions & 19 deletions compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,23 +69,6 @@ pub fn ensure_removed(dcx: DiagCtxtHandle<'_>, path: &Path) {
}
}

fn check_link_info_print_request(sess: &Session, crate_types: &[CrateType]) {
let print_native_static_libs =
sess.opts.prints.iter().any(|p| p.kind == PrintKind::NativeStaticLibs);
let has_staticlib = crate_types.iter().any(|ct| *ct == CrateType::Staticlib);
if print_native_static_libs {
if !has_staticlib {
sess.dcx()
.warn(format!("cannot output linkage information without staticlib crate-type"));
sess.dcx()
.note(format!("consider `--crate-type staticlib` to print linkage information"));
} else if !sess.opts.output_types.should_link() {
sess.dcx()
.warn(format!("cannot output linkage information when --emit link is not passed"));
}
}
}

/// Performs the linkage portion of the compilation phase. This will generate all
/// of the requested outputs for this compilation session.
pub fn link_binary(
Expand Down Expand Up @@ -208,8 +191,6 @@ pub fn link_binary(
}
}

check_link_info_print_request(sess, &codegen_results.crate_info.crate_types);

// Remove the temporary object file and metadata if we aren't saving temps.
sess.time("link_binary_remove_temps", || {
// If the user requests that temporaries are saved, don't delete any.
Expand Down
18 changes: 18 additions & 0 deletions compiler/rustc_codegen_ssa/src/back/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,24 @@ pub(super) fn elf_e_flags(architecture: Architecture, sess: &Session) -> u32 {
};
e_flags
}
Architecture::PowerPc64 => {
const EF_PPC64_ABI_UNKNOWN: u32 = 0;
const EF_PPC64_ABI_ELF_V1: u32 = 1;
const EF_PPC64_ABI_ELF_V2: u32 = 2;

match sess.target.options.llvm_abiname.as_ref() {
// If the flags do not correctly indicate the ABI,
// linkers such as ld.lld assume that the ppc64 object files are always ELFv2
// which leads to broken binaries if ELFv1 is used for the object files.
"elfv1" => EF_PPC64_ABI_ELF_V1,
"elfv2" => EF_PPC64_ABI_ELF_V2,
"" if sess.target.options.binary_format.to_object() == BinaryFormat::Elf => {
bug!("No ABI specified for this PPC64 ELF target");
}
// Fall back
_ => EF_PPC64_ABI_UNKNOWN,
}
}
_ => 0,
}
}
Expand Down
19 changes: 16 additions & 3 deletions compiler/rustc_mir_transform/src/simplify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ impl SimplifyCfg {
}

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

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

CfgSimplifier { preserve_switch_reads, basic_blocks, pred_count }
}

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

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

Expand Down Expand Up @@ -177,7 +186,11 @@ impl<'a, 'tcx> CfgSimplifier<'a, 'tcx> {
if !changed {
break;
}

outer_changed = true;
}

outer_changed
}

/// This function will return `None` if
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub(crate) fn target() -> Target {
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m64"]);
base.max_atomic_width = Some(64);
base.stack_probes = StackProbeType::Inline;
base.llvm_abiname = "elfv2".into();

Target {
llvm_target: "powerpc64-unknown-freebsd".into(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub(crate) fn target() -> Target {
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m64"]);
base.max_atomic_width = Some(64);
base.stack_probes = StackProbeType::Inline;
base.llvm_abiname = "elfv1".into();

Target {
llvm_target: "powerpc64-unknown-linux-gnu".into(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub(crate) fn target() -> Target {
base.stack_probes = StackProbeType::Inline;
// FIXME(compiler-team#422): musl targets should be dynamically linked by default.
base.crt_static_default = true;
base.llvm_abiname = "elfv2".into();

Target {
llvm_target: "powerpc64-unknown-linux-musl".into(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub(crate) fn target() -> Target {
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m64"]);
base.max_atomic_width = Some(64);
base.stack_probes = StackProbeType::Inline;
base.llvm_abiname = "elfv2".into();

Target {
llvm_target: "powerpc64-unknown-openbsd".into(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub(crate) fn target() -> Target {
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m64"]);
base.max_atomic_width = Some(64);
base.stack_probes = StackProbeType::Inline;
base.llvm_abiname = "elfv1".into();

Target {
llvm_target: "powerpc64-unknown-linux-gnu".into(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub(crate) fn target() -> Target {
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m64"]);
base.max_atomic_width = Some(64);
base.stack_probes = StackProbeType::Inline;
base.llvm_abiname = "elfv2".into();

Target {
llvm_target: "powerpc64le-unknown-freebsd".into(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub(crate) fn target() -> Target {
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m64"]);
base.max_atomic_width = Some(64);
base.stack_probes = StackProbeType::Inline;
base.llvm_abiname = "elfv2".into();

Target {
llvm_target: "powerpc64le-unknown-linux-gnu".into(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub(crate) fn target() -> Target {
base.stack_probes = StackProbeType::Inline;
// FIXME(compiler-team#422): musl targets should be dynamically linked by default.
base.crt_static_default = true;
base.llvm_abiname = "elfv2".into();

Target {
llvm_target: "powerpc64le-unknown-linux-musl".into(),
Expand Down
Loading
Loading