Skip to content

Commit c39b604

Browse files
committed
Auto merge of #161041 - JonathanBrouwer:rollup-WjOI7Vo, r=<try>
Rollup of 6 pull requests try-job: dist-various-1 try-job: test-various try-job: x86_64-gnu-aux try-job: x86_64-gnu-llvm-21-3 try-job: x86_64-msvc-1 try-job: aarch64-apple-1 try-job: aarch64-apple-2 try-job: x86_64-mingw-1 try-job: i686-msvc-1 try-job: i686-msvc-2
2 parents 1e5ee35 + 851e090 commit c39b604

81 files changed

Lines changed: 1073 additions & 723 deletions

File tree

Some content is hidden

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

compiler/rustc_abi/src/layout/ty.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ pub trait TyAbiInterface<'a, C>: Sized + std::fmt::Debug + std::fmt::Display {
120120
fn is_tuple(this: TyAndLayout<'a, Self>) -> bool;
121121
fn is_unit(this: TyAndLayout<'a, Self>) -> bool;
122122
fn is_transparent(this: TyAndLayout<'a, Self>) -> bool;
123+
fn is_complex_number(this: TyAndLayout<'a, Self>, cx: &C) -> bool;
123124
fn is_scalable_vector(this: TyAndLayout<'a, Self>) -> bool;
124125
/// See [`TyAndLayout::pass_indirectly_in_non_rustic_abis`] for details.
125126
fn is_pass_indirectly_in_non_rustic_abis_flag_set(this: TyAndLayout<'a, Self>) -> bool;
@@ -227,6 +228,13 @@ impl<'a, Ty> TyAndLayout<'a, Ty> {
227228
Ty::is_transparent(self)
228229
}
229230

231+
pub fn is_complex_number<C>(self, cx: &C) -> bool
232+
where
233+
Ty: TyAbiInterface<'a, C> + Copy,
234+
{
235+
Ty::is_complex_number(self.peel_transparent_wrappers(cx), cx)
236+
}
237+
230238
pub fn is_scalable_vector<C>(self) -> bool
231239
where
232240
Ty: TyAbiInterface<'a, C>,
@@ -291,6 +299,26 @@ impl<'a, Ty> TyAndLayout<'a, Ty> {
291299
found
292300
}
293301

302+
pub fn complex_float<C>(&self, cx: &C) -> Option<Float>
303+
where
304+
Ty: TyAbiInterface<'a, C> + Copy,
305+
{
306+
if !Ty::is_complex_number(*self, cx) {
307+
return None;
308+
}
309+
310+
let BackendRepr::ScalarPair { a, b, .. } = self.backend_repr else {
311+
return None;
312+
};
313+
314+
debug_assert_eq!(a, b);
315+
316+
match a.primitive() {
317+
Primitive::Float(f) => Some(f),
318+
_ => None,
319+
}
320+
}
321+
294322
/// Whether this type/layout has any padding that is dependent on a variant, i.e. has bytes that
295323
/// are padding for some, but not all, valid values of this type.
296324
pub fn has_variant_dependent_padding<C>(&self, cx: &C) -> bool

compiler/rustc_attr_ir/src/lang_items.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,8 @@ language_item_table! {
232232
VaArgSafe, sym::va_arg_safe, va_arg_safe, Target::Trait, GenericRequirement::None;
233233
VaList, sym::va_list, va_list, Target::Struct, GenericRequirement::None;
234234

235+
Complex, sym::complex, complex, Target::Struct, GenericRequirement::Exact(1);
236+
235237
Deref, sym::deref, deref_trait, Target::Trait, GenericRequirement::Exact(0);
236238
DerefMut, sym::deref_mut, deref_mut_trait, Target::Trait, GenericRequirement::Exact(0);
237239
DerefPure, sym::deref_pure, deref_pure_trait, Target::Trait, GenericRequirement::Exact(0);

compiler/rustc_attr_parsing/src/attributes/rustc_internal.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1132,7 +1132,7 @@ pub(crate) struct RustcDocPrimitiveParser;
11321132

11331133
impl SingleAttributeParser for RustcDocPrimitiveParser {
11341134
const PATH: &[Symbol] = &[sym::rustc_doc_primitive];
1135-
const ALLOWED_TARGETS: AllowedTargets<'_> = AllowedTargets::AllowList(&[Allow(Target::Mod)]);
1135+
const ALLOWED_TARGETS: AllowedTargets<'_> = AllowedTargets::AllowList(&[Allow(Target::Const)]);
11361136
const TEMPLATE: AttributeTemplate = template!(NameValueStr: "primitive name");
11371137
const STABILITY: AttributeStability = unstable!(
11381138
rustc_attrs,

compiler/rustc_codegen_llvm/src/asm.rs

Lines changed: 23 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::assert_matches;
22
use std::fmt::Write;
33

4-
use rustc_abi::{BackendRepr, Float, Integer, Primitive, Scalar, Size};
4+
use rustc_abi::{BackendRepr, Endian, Float, Integer, Primitive, Scalar, Size};
55
use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece};
66
use rustc_codegen_ssa::mir::operand::OperandValue;
77
use rustc_codegen_ssa::traits::*;
@@ -12,6 +12,7 @@ use rustc_middle::ty::layout::TyAndLayout;
1212
use rustc_middle::{bug, span_bug};
1313
use rustc_span::{Pos, Span, Symbol, sym};
1414
use rustc_target::asm::*;
15+
use rustc_target::spec::HasTargetSpec;
1516
use smallvec::SmallVec;
1617
use tracing::debug;
1718

@@ -1244,24 +1245,16 @@ fn llvm_fixup_input<'ll, 'tcx>(
12441245
(
12451246
PowerPC(PowerPCInlineAsmRegClass::vreg | PowerPCInlineAsmRegClass::vsreg),
12461247
BackendRepr::Scalar(s),
1247-
) if s.primitive() == Primitive::Float(Float::F32) => {
1248-
let value = bx.insert_element(
1249-
bx.const_undef(bx.type_vector(bx.type_f32(), 4)),
1248+
) if let Primitive::Float(float @ (Float::F32 | Float::F64)) = s.primitive() => {
1249+
let num_lanes = 16 / float.size().bytes();
1250+
bx.insert_element(
1251+
bx.const_undef(bx.type_vector(bx.type_from_float(float), num_lanes)),
12501252
value,
1251-
bx.const_usize(0),
1252-
);
1253-
bx.bitcast(value, bx.type_vector(bx.type_f32(), 4))
1254-
}
1255-
(
1256-
PowerPC(PowerPCInlineAsmRegClass::vreg | PowerPCInlineAsmRegClass::vsreg),
1257-
BackendRepr::Scalar(s),
1258-
) if s.primitive() == Primitive::Float(Float::F64) => {
1259-
let value = bx.insert_element(
1260-
bx.const_undef(bx.type_vector(bx.type_f64(), 2)),
1261-
value,
1262-
bx.const_usize(0),
1263-
);
1264-
bx.bitcast(value, bx.type_vector(bx.type_f64(), 2))
1253+
bx.const_usize(match bx.target_spec().endian {
1254+
Endian::Little => num_lanes - 1,
1255+
Endian::Big => 0,
1256+
}),
1257+
)
12651258
}
12661259
_ => value,
12671260
}
@@ -1416,16 +1409,15 @@ fn llvm_fixup_output<'ll, 'tcx>(
14161409
(
14171410
PowerPC(PowerPCInlineAsmRegClass::vreg | PowerPCInlineAsmRegClass::vsreg),
14181411
BackendRepr::Scalar(s),
1419-
) if s.primitive() == Primitive::Float(Float::F32) => {
1420-
let value = bx.bitcast(value, bx.type_vector(bx.type_f32(), 4));
1421-
bx.extract_element(value, bx.const_usize(0))
1422-
}
1423-
(
1424-
PowerPC(PowerPCInlineAsmRegClass::vreg | PowerPCInlineAsmRegClass::vsreg),
1425-
BackendRepr::Scalar(s),
1426-
) if s.primitive() == Primitive::Float(Float::F64) => {
1427-
let value = bx.bitcast(value, bx.type_vector(bx.type_f64(), 2));
1428-
bx.extract_element(value, bx.const_usize(0))
1412+
) if let Primitive::Float(float @ (Float::F32 | Float::F64)) = s.primitive() => {
1413+
let num_lanes = 16 / float.size().bytes();
1414+
bx.extract_element(
1415+
value,
1416+
bx.const_usize(match bx.target_spec().endian {
1417+
Endian::Little => num_lanes - 1,
1418+
Endian::Big => 0,
1419+
}),
1420+
)
14291421
}
14301422
_ => value,
14311423
}
@@ -1566,11 +1558,9 @@ fn llvm_fixup_output_type<'ll, 'tcx>(
15661558
(
15671559
PowerPC(PowerPCInlineAsmRegClass::vreg | PowerPCInlineAsmRegClass::vsreg),
15681560
BackendRepr::Scalar(s),
1569-
) if s.primitive() == Primitive::Float(Float::F32) => cx.type_vector(cx.type_f32(), 4),
1570-
(
1571-
PowerPC(PowerPCInlineAsmRegClass::vreg | PowerPCInlineAsmRegClass::vsreg),
1572-
BackendRepr::Scalar(s),
1573-
) if s.primitive() == Primitive::Float(Float::F64) => cx.type_vector(cx.type_f64(), 2),
1561+
) if let Primitive::Float(float @ (Float::F32 | Float::F64)) = s.primitive() => {
1562+
cx.type_vector(cx.type_from_float(float), 16 / float.size().bytes())
1563+
}
15741564
_ => layout.llvm_type(cx),
15751565
}
15761566
}

compiler/rustc_codegen_llvm/src/llvm_util.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,8 @@ fn update_target_reliable_float_cfg(sess: &Session, cfg: &mut TargetConfig) {
374374
cfg.has_reliable_f16 = match (target_arch, target_os) {
375375
// Unsupported <https://github.com/llvm/llvm-project/issues/94434> (fixed in llvm22)
376376
(Arch::Arm64EC, _) if major < 22 => false,
377-
// MinGW ABI bugs <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115054>
377+
// MinGW ABI bugs <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115054> resolved in GCC 16
378+
// but our toolchain hasn't been updated.
378379
(Arch::X86_64, Os::Windows) if *target_env == Env::Gnu && *target_abi != CfgAbi::Llvm => {
379380
false
380381
}
@@ -401,8 +402,10 @@ fn update_target_reliable_float_cfg(sess: &Session, cfg: &mut TargetConfig) {
401402
(Arch::PowerPC | Arch::PowerPC64, _) => false,
402403
// ABI unsupported <https://github.com/llvm/llvm-project/issues/41838> (fixed in llvm22)
403404
(Arch::Sparc, _) if major < 22 => false,
404-
// MinGW ABI bugs <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115054>
405-
(Arch::X86_64, Os::Windows) if *target_env == Env::Gnu && *target_abi != CfgAbi::Llvm => {
405+
// MinGW ABI bugs <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115054> (fixed in llvm23)
406+
(Arch::X86_64, Os::Windows)
407+
if *target_env == Env::Gnu && *target_abi != CfgAbi::Llvm && major < 23 =>
408+
{
406409
false
407410
}
408411
// There are no known problems on other platforms, so the only requirement is that symbols

compiler/rustc_hir_typeck/src/diagnostics.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -819,10 +819,13 @@ pub(crate) struct OutsideLoop<'a> {
819819
applicability = "maybe-incorrect"
820820
)]
821821
pub(crate) struct OutsideLoopSuggestion {
822-
#[suggestion_part(code = "'block: ")]
822+
#[suggestion_part(code = "{block_prefix}")]
823823
pub block_span: Span,
824824
#[suggestion_part(code = " 'block")]
825825
pub break_spans: Vec<Span>,
826+
#[suggestion_part(code = " }}")]
827+
pub wrap_end: Option<Span>,
828+
pub block_prefix: &'static str,
826829
}
827830

828831
#[derive(Diagnostic)]

compiler/rustc_hir_typeck/src/loops.rs

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ enum Context {
3131
kind: hir::CoroutineDesugaring,
3232
source: hir::CoroutineSource,
3333
},
34-
UnlabeledBlock(Span),
34+
UnlabeledBlock {
35+
label_span: Span,
36+
wrap_end: Option<Span>,
37+
},
3538
UnlabeledIfBlock(Span),
3639
LabeledBlock,
3740
/// E.g. The labeled block inside `['_'; 'block: { break 'block 1 + 2; }]`.
@@ -50,6 +53,7 @@ struct BlockInfo {
5053
name: String,
5154
spans: Vec<Span>,
5255
suggs: Vec<Span>,
56+
wrap_end: Option<Span>,
5357
}
5458

5559
#[derive(PartialEq)]
@@ -118,7 +122,7 @@ impl<'hir> Visitor<'hir> for CheckLoopVisitor<'hir> {
118122
ck_loop.cx_stack.last(),
119123
Some(&Normal)
120124
| Some(&AnonConst)
121-
| Some(&UnlabeledBlock(_))
125+
| Some(&UnlabeledBlock { .. })
122126
| Some(&UnlabeledIfBlock(_))
123127
)
124128
{
@@ -177,10 +181,16 @@ impl<'hir> Visitor<'hir> for CheckLoopVisitor<'hir> {
177181
None,
178182
) if matches!(
179183
self.cx_stack.last(),
180-
Some(&Normal) | Some(&AnonConst) | Some(&UnlabeledBlock(_))
184+
Some(&Normal) | Some(&AnonConst) | Some(&UnlabeledBlock { .. })
181185
) =>
182186
{
183-
self.with_context(UnlabeledBlock(b.span.shrink_to_lo()), |v| v.visit_block(b));
187+
// An unlabeled block targeted by `break` may comes from a `try` block.
188+
// Since `try 'block: {}` is invalid, nest a labeled block inside its body.
189+
let wrap_end = b.targeted_by_break.then(|| b.span.shrink_to_hi());
190+
self.with_context(
191+
UnlabeledBlock { label_span: b.span.shrink_to_lo(), wrap_end },
192+
|v| v.visit_block(b),
193+
);
184194
}
185195
hir::ExprKind::Break(break_destination, ref opt_expr) => {
186196
if let Some(e) = opt_expr {
@@ -365,21 +375,22 @@ impl<'hir> CheckLoopVisitor<'hir> {
365375
source,
366376
});
367377
}
368-
UnlabeledBlock(block_span)
369-
if br_cx_kind == BreakContextKind::Break && block_span.eq_ctxt(break_span) =>
378+
UnlabeledBlock { label_span, wrap_end }
379+
if br_cx_kind == BreakContextKind::Break && label_span.eq_ctxt(break_span) =>
370380
{
371-
let block = self.block_breaks.entry(block_span).or_insert_with(|| BlockInfo {
381+
let block = self.block_breaks.entry(label_span).or_insert_with(|| BlockInfo {
372382
name: br_cx_kind.to_string(),
373383
spans: vec![],
374384
suggs: vec![],
385+
wrap_end,
375386
});
376387
block.spans.push(span);
377388
block.suggs.push(break_span);
378389
}
379390
UnlabeledIfBlock(_) if br_cx_kind == BreakContextKind::Break => {
380391
self.require_break_cx(br_cx_kind, span, break_span, cx_pos - 1);
381392
}
382-
Normal | AnonConst | Fn | UnlabeledBlock(_) | UnlabeledIfBlock(_) | ConstBlock => {
393+
Normal | AnonConst | Fn | UnlabeledBlock { .. } | UnlabeledIfBlock(_) | ConstBlock => {
383394
self.tcx.dcx().emit_err(OutsideLoop {
384395
spans: vec![span],
385396
name: &br_cx_kind.to_string(),
@@ -415,6 +426,8 @@ impl<'hir> CheckLoopVisitor<'hir> {
415426
suggestion: Some(OutsideLoopSuggestion {
416427
block_span: *s,
417428
break_spans: block.suggs.clone(),
429+
block_prefix: if block.wrap_end.is_some() { "{ 'block: " } else { "'block: " },
430+
wrap_end: block.wrap_end,
418431
}),
419432
});
420433
}

compiler/rustc_middle/src/ty/layout.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,6 +1213,20 @@ where
12131213
matches!(this.ty.kind(), ty::Adt(def, _) if def.repr().transparent())
12141214
}
12151215

1216+
/// Does this type have a layout compatible with C `_Complex`?
1217+
///
1218+
/// The value must be of type `core::num::Complex<T>` where `T` is numeric.
1219+
fn is_complex_number(this: TyAndLayout<'tcx>, cx: &C) -> bool {
1220+
let ty::Adt(def, generic_args) = this.ty.kind() else { return false };
1221+
1222+
if !cx.tcx().is_lang_item(def.did(), LangItem::Complex) {
1223+
return false;
1224+
}
1225+
1226+
// Only Complex<{ float }> and Complex<{ integer }> have special layout.
1227+
generic_args.type_at(0).is_numeric()
1228+
}
1229+
12161230
fn is_scalable_vector(this: TyAndLayout<'tcx>) -> bool {
12171231
this.ty.is_scalable_vector()
12181232
}

compiler/rustc_passes/src/check_attr.rs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ use rustc_session::lint::builtin::{
4444
MALFORMED_DIAGNOSTIC_FORMAT_LITERALS, MISPLACED_DIAGNOSTIC_ATTRIBUTES, UNUSED_ATTRIBUTES,
4545
};
4646
use rustc_span::edition::Edition;
47-
use rustc_span::{DUMMY_SP, Ident, Span, Symbol, sym};
47+
use rustc_span::{DUMMY_SP, Ident, Span, Symbol, kw, sym};
4848
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
4949
use rustc_trait_selection::infer::{TyCtxtInferExt, ValuePairs};
5050
use rustc_trait_selection::traits::{ObligationCtxt, TraitErrors};
@@ -1024,18 +1024,11 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
10241024
hir::Node::Item(item) => Some(&item.kind),
10251025
_ => None,
10261026
};
1027-
match item_kind {
1028-
Some(ItemKind::Mod(_, module)) => {
1029-
if !module.item_ids.is_empty() {
1030-
self.dcx()
1031-
.emit_err(diagnostics::DocKeywordAttributeEmptyMod { span, attr_name });
1032-
return;
1033-
}
1034-
}
1035-
_ => {
1036-
self.dcx().emit_err(diagnostics::DocKeywordAttributeNotMod { span, attr_name });
1037-
return;
1038-
}
1027+
if let Some(ItemKind::Const(ident, _gen, _ty, _rhs)) = item_kind
1028+
&& ident.name == kw::Underscore
1029+
{
1030+
} else {
1031+
self.dcx().emit_err(diagnostics::DocKeywordAttributeNotAnonConst { span, attr_name });
10391032
}
10401033
}
10411034

compiler/rustc_passes/src/diagnostics.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,8 @@ pub(crate) struct DocAliasNotAnAlias {
7373
}
7474

7575
#[derive(Diagnostic)]
76-
#[diag("`#[doc({$attr_name} = \"...\")]` should be used on empty modules")]
77-
pub(crate) struct DocKeywordAttributeEmptyMod {
78-
#[primary_span]
79-
pub span: Span,
80-
pub attr_name: &'static str,
81-
}
82-
83-
#[derive(Diagnostic)]
84-
#[diag("`#[doc({$attr_name} = \"...\")]` should be used on modules")]
85-
pub(crate) struct DocKeywordAttributeNotMod {
76+
#[diag("`#[doc({$attr_name} = \"...\")]` should be used on anonymous constants")]
77+
pub(crate) struct DocKeywordAttributeNotAnonConst {
8678
#[primary_span]
8779
pub span: Span,
8880
pub attr_name: &'static str,

0 commit comments

Comments
 (0)