Skip to content

Commit 9b4d7c6

Browse files
committed
Auto merge of #133568 - GuillaumeGomez:rollup-js22ovb, r=GuillaumeGomez
Rollup of 7 pull requests Successful merges: - #133358 (Don't type error if we fail to coerce `Pin<T>` because it doesnt contain a ref) - #133422 (Fix clobber_abi in RV32E and RV64E inline assembly) - #133452 (Support predicate registers (clobber-only) in Hexagon inline assembly) - #133463 (Fix handling of x18 in AArch64 inline assembly on ohos/trusty or with -Zfixed-x18) - #133487 (fix confusing diagnostic for reserved `##`) - #133557 (Small doc fixes in `rustc_codegen_ssa`) - #133560 (Trim extra space in 'repeated `mut`' diagnostic) r? `@ghost` `@rustbot` modify labels: rollup
2 parents c1cfab2 + 22c5bb0 commit 9b4d7c6

Some content is hidden

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

50 files changed

+438
-186
lines changed

compiler/rustc_ast_lowering/src/asm.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
8282
let mut clobber_abis = FxIndexMap::default();
8383
if let Some(asm_arch) = asm_arch {
8484
for (abi_name, abi_span) in &asm.clobber_abis {
85-
match asm::InlineAsmClobberAbi::parse(asm_arch, &self.tcx.sess.target, *abi_name) {
85+
match asm::InlineAsmClobberAbi::parse(
86+
asm_arch,
87+
&self.tcx.sess.target,
88+
&self.tcx.sess.unstable_target_features,
89+
*abi_name,
90+
) {
8691
Ok(abi) => {
8792
// If the abi was already in the list, emit an error
8893
match clobber_abis.get(&abi) {

compiler/rustc_codegen_cranelift/src/inline_asm.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -476,9 +476,14 @@ impl<'tcx> InlineAssemblyGenerator<'_, 'tcx> {
476476
let mut new_slot = |x| new_slot_fn(&mut slot_size, x);
477477

478478
// Allocate stack slots for saving clobbered registers
479-
let abi_clobber = InlineAsmClobberAbi::parse(self.arch, &self.tcx.sess.target, sym::C)
480-
.unwrap()
481-
.clobbered_regs();
479+
let abi_clobber = InlineAsmClobberAbi::parse(
480+
self.arch,
481+
&self.tcx.sess.target,
482+
&self.tcx.sess.unstable_target_features,
483+
sym::C,
484+
)
485+
.unwrap()
486+
.clobbered_regs();
482487
for (i, reg) in self.registers.iter().enumerate().filter_map(|(i, r)| r.map(|r| (i, r))) {
483488
let mut need_save = true;
484489
// If the register overlaps with a register clobbered by function call, then

compiler/rustc_codegen_gcc/src/asm.rs

+6
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,9 @@ fn reg_to_gcc(reg: InlineAsmRegOrRegClass) -> ConstraintOrRegister {
634634
InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::reg) => "r",
635635
InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::wreg) => "w",
636636
InlineAsmRegClass::Hexagon(HexagonInlineAsmRegClass::reg) => "r",
637+
InlineAsmRegClass::Hexagon(HexagonInlineAsmRegClass::preg) => {
638+
unreachable!("clobber-only")
639+
}
637640
InlineAsmRegClass::LoongArch(LoongArchInlineAsmRegClass::reg) => "r",
638641
InlineAsmRegClass::LoongArch(LoongArchInlineAsmRegClass::freg) => "f",
639642
InlineAsmRegClass::M68k(M68kInlineAsmRegClass::reg) => "r",
@@ -720,6 +723,9 @@ fn dummy_output_type<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, reg: InlineAsmRegCl
720723
cx.type_vector(cx.type_i64(), 2)
721724
}
722725
InlineAsmRegClass::Hexagon(HexagonInlineAsmRegClass::reg) => cx.type_i32(),
726+
InlineAsmRegClass::Hexagon(HexagonInlineAsmRegClass::preg) => {
727+
unreachable!("clobber-only")
728+
}
723729
InlineAsmRegClass::LoongArch(LoongArchInlineAsmRegClass::reg) => cx.type_i32(),
724730
InlineAsmRegClass::LoongArch(LoongArchInlineAsmRegClass::freg) => cx.type_f32(),
725731
InlineAsmRegClass::Mips(MipsInlineAsmRegClass::reg) => cx.type_i32(),

compiler/rustc_codegen_llvm/src/asm.rs

+2
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,7 @@ fn reg_to_llvm(reg: InlineAsmRegOrRegClass, layout: Option<&TyAndLayout<'_>>) ->
645645
| Arm(ArmInlineAsmRegClass::qreg_low4) => "x",
646646
Arm(ArmInlineAsmRegClass::dreg) | Arm(ArmInlineAsmRegClass::qreg) => "w",
647647
Hexagon(HexagonInlineAsmRegClass::reg) => "r",
648+
Hexagon(HexagonInlineAsmRegClass::preg) => unreachable!("clobber-only"),
648649
LoongArch(LoongArchInlineAsmRegClass::reg) => "r",
649650
LoongArch(LoongArchInlineAsmRegClass::freg) => "f",
650651
Mips(MipsInlineAsmRegClass::reg) => "r",
@@ -813,6 +814,7 @@ fn dummy_output_type<'ll>(cx: &CodegenCx<'ll, '_>, reg: InlineAsmRegClass) -> &'
813814
| Arm(ArmInlineAsmRegClass::qreg_low8)
814815
| Arm(ArmInlineAsmRegClass::qreg_low4) => cx.type_vector(cx.type_i64(), 2),
815816
Hexagon(HexagonInlineAsmRegClass::reg) => cx.type_i32(),
817+
Hexagon(HexagonInlineAsmRegClass::preg) => unreachable!("clobber-only"),
816818
LoongArch(LoongArchInlineAsmRegClass::reg) => cx.type_i32(),
817819
LoongArch(LoongArchInlineAsmRegClass::freg) => cx.type_f32(),
818820
Mips(MipsInlineAsmRegClass::reg) => cx.type_i32(),

compiler/rustc_codegen_ssa/src/traits/backend.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -71,19 +71,19 @@ pub trait CodegenBackend {
7171
need_metadata_module: bool,
7272
) -> Box<dyn Any>;
7373

74-
/// This is called on the returned `Box<dyn Any>` from `codegen_backend`
74+
/// This is called on the returned `Box<dyn Any>` from [`codegen_crate`](Self::codegen_crate)
7575
///
7676
/// # Panics
7777
///
78-
/// Panics when the passed `Box<dyn Any>` was not returned by `codegen_backend`.
78+
/// Panics when the passed `Box<dyn Any>` was not returned by [`codegen_crate`](Self::codegen_crate).
7979
fn join_codegen(
8080
&self,
8181
ongoing_codegen: Box<dyn Any>,
8282
sess: &Session,
8383
outputs: &OutputFilenames,
8484
) -> (CodegenResults, FxIndexMap<WorkProductId, WorkProduct>);
8585

86-
/// This is called on the returned `CodegenResults` from `join_codegen`
86+
/// This is called on the returned [`CodegenResults`] from [`join_codegen`](Self::join_codegen).
8787
fn link(
8888
&self,
8989
sess: &Session,

compiler/rustc_hir_typeck/src/coercion.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,9 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
215215
}
216216
}
217217

218-
// Examine the supertype and consider auto-borrowing.
218+
// Examine the supertype and consider type-specific coercions, such
219+
// as auto-borrowing, coercing pointer mutability, a `dyn*` coercion,
220+
// or pin-ergonomics.
219221
match *b.kind() {
220222
ty::RawPtr(_, b_mutbl) => {
221223
return self.coerce_unsafe_ptr(a, b, b_mutbl);
@@ -230,7 +232,10 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
230232
if self.tcx.features().pin_ergonomics()
231233
&& self.tcx.is_lang_item(pin.did(), hir::LangItem::Pin) =>
232234
{
233-
return self.coerce_pin(a, b);
235+
let pin_coerce = self.commit_if_ok(|_| self.coerce_pin_ref(a, b));
236+
if pin_coerce.is_ok() {
237+
return pin_coerce;
238+
}
234239
}
235240
_ => {}
236241
}
@@ -797,7 +802,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
797802
/// - `Pin<Box<T>>` as `Pin<&T>`
798803
/// - `Pin<Box<T>>` as `Pin<&mut T>`
799804
#[instrument(skip(self), level = "trace")]
800-
fn coerce_pin(&self, a: Ty<'tcx>, b: Ty<'tcx>) -> CoerceResult<'tcx> {
805+
fn coerce_pin_ref(&self, a: Ty<'tcx>, b: Ty<'tcx>) -> CoerceResult<'tcx> {
801806
// We need to make sure the two types are compatible for coercion.
802807
// Then we will build a ReborrowPin adjustment and return that as an InferOk.
803808

compiler/rustc_lint/messages.ftl

+3
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,9 @@ lint_renamed_lint = lint `{$name}` has been renamed to `{$replace}`
733733
734734
lint_requested_level = requested on the command line with `{$level} {$lint_name}`
735735
736+
lint_reserved_multihash = reserved token in Rust 2024
737+
.suggestion = insert whitespace here to avoid this being parsed as a forbidden token in Rust 2024
738+
736739
lint_reserved_prefix = prefix `{$prefix}` is unknown
737740
.label = unknown prefix
738741
.suggestion = insert whitespace here to avoid this being parsed as a prefix in Rust 2021

compiler/rustc_lint/src/context/diagnostics.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,12 @@ pub(super) fn decorate_lint(sess: &Session, diagnostic: BuiltinLintDiag, diag: &
176176
lints::RawPrefix { label: label_span, suggestion: label_span.shrink_to_hi() }
177177
.decorate_lint(diag);
178178
}
179-
BuiltinLintDiag::ReservedString(suggestion) => {
180-
lints::ReservedString { suggestion }.decorate_lint(diag);
179+
BuiltinLintDiag::ReservedString { is_string, suggestion } => {
180+
if is_string {
181+
lints::ReservedString { suggestion }.decorate_lint(diag);
182+
} else {
183+
lints::ReservedMultihash { suggestion }.decorate_lint(diag);
184+
}
181185
}
182186
BuiltinLintDiag::UnusedBuiltinAttribute { attr_name, macro_name, invoc_span } => {
183187
lints::UnusedBuiltinAttribute { invoc_span, attr_name, macro_name }.decorate_lint(diag);

compiler/rustc_lint/src/lints.rs

+7
Original file line numberDiff line numberDiff line change
@@ -3059,3 +3059,10 @@ pub(crate) struct ReservedString {
30593059
#[suggestion(code = " ", applicability = "machine-applicable")]
30603060
pub suggestion: Span,
30613061
}
3062+
3063+
#[derive(LintDiagnostic)]
3064+
#[diag(lint_reserved_multihash)]
3065+
pub(crate) struct ReservedMultihash {
3066+
#[suggestion(code = " ", applicability = "machine-applicable")]
3067+
pub suggestion: Span,
3068+
}

compiler/rustc_lint_defs/src/lib.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -663,8 +663,11 @@ pub enum BuiltinLintDiag {
663663
ReservedPrefix(Span, String),
664664
/// `'r#` in edition < 2021.
665665
RawPrefix(Span),
666-
/// `##` or `#"` is edition < 2024.
667-
ReservedString(Span),
666+
/// `##` or `#"` in edition < 2024.
667+
ReservedString {
668+
is_string: bool,
669+
suggestion: Span,
670+
},
668671
TrailingMacro(bool, Ident),
669672
BreakWithLabelAndLoop(Span),
670673
UnicodeTextFlow(Span, String),

compiler/rustc_parse/messages.ftl

+4
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,10 @@ parse_require_colon_after_labeled_expression = labeled expression must be follow
716716
.label = the label
717717
.suggestion = add `:` after the label
718718
719+
parse_reserved_multihash = reserved multi-hash token is forbidden
720+
.note = sequences of two or more # are reserved for future use since Rust 2024
721+
.suggestion_whitespace = consider inserting whitespace here
722+
719723
parse_reserved_string = invalid string literal
720724
.note = unprefixed guarded string literals are reserved for future use since Rust 2024
721725
.suggestion_whitespace = consider inserting whitespace here

compiler/rustc_parse/src/errors.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -2151,6 +2151,15 @@ pub(crate) enum UnknownPrefixSugg {
21512151
},
21522152
}
21532153

2154+
#[derive(Diagnostic)]
2155+
#[diag(parse_reserved_multihash)]
2156+
#[note]
2157+
pub(crate) struct ReservedMultihash {
2158+
#[primary_span]
2159+
pub span: Span,
2160+
#[subdiagnostic]
2161+
pub sugg: Option<GuardedStringSugg>,
2162+
}
21542163
#[derive(Diagnostic)]
21552164
#[diag(parse_reserved_string)]
21562165
#[note]
@@ -2611,8 +2620,9 @@ pub(crate) enum InvalidMutInPattern {
26112620
#[diag(parse_repeated_mut_in_pattern)]
26122621
pub(crate) struct RepeatedMutInPattern {
26132622
#[primary_span]
2614-
#[suggestion(code = "", applicability = "machine-applicable", style = "verbose")]
26152623
pub span: Span,
2624+
#[suggestion(code = "", applicability = "machine-applicable", style = "verbose")]
2625+
pub suggestion: Span,
26162626
}
26172627

26182628
#[derive(Diagnostic)]

compiler/rustc_parse/src/lexer/mod.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,7 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
816816

817817
let mut cursor = Cursor::new(str_before);
818818

819-
let (span, unterminated) = match cursor.guarded_double_quoted_string() {
819+
let (is_string, span, unterminated) = match cursor.guarded_double_quoted_string() {
820820
Some(rustc_lexer::GuardedStr { n_hashes, terminated, token_len }) => {
821821
let end = start + BytePos(token_len);
822822
let span = self.mk_sp(start, end);
@@ -829,13 +829,13 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
829829

830830
let unterminated = if terminated { None } else { Some(str_start) };
831831

832-
(span, unterminated)
832+
(true, span, unterminated)
833833
}
834-
_ => {
834+
None => {
835835
// We should only get here in the `##+` case.
836836
debug_assert_eq!(self.str_from_to(start, start + BytePos(2)), "##");
837837

838-
(span, None)
838+
(false, span, None)
839839
}
840840
};
841841
if edition2024 {
@@ -857,7 +857,11 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
857857
};
858858

859859
// In Edition 2024 and later, emit a hard error.
860-
let err = self.dcx().emit_err(errors::ReservedString { span, sugg });
860+
let err = if is_string {
861+
self.dcx().emit_err(errors::ReservedString { span, sugg })
862+
} else {
863+
self.dcx().emit_err(errors::ReservedMultihash { span, sugg })
864+
};
861865

862866
token::Literal(token::Lit {
863867
kind: token::Err(err),
@@ -870,7 +874,7 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
870874
RUST_2024_GUARDED_STRING_INCOMPATIBLE_SYNTAX,
871875
span,
872876
ast::CRATE_NODE_ID,
873-
BuiltinLintDiag::ReservedString(space_span),
877+
BuiltinLintDiag::ReservedString { is_string, suggestion: space_span },
874878
);
875879

876880
// For backwards compatibility, roll back to after just the first `#`

compiler/rustc_parse/src/parser/pat.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1089,7 +1089,9 @@ impl<'a> Parser<'a> {
10891089
return;
10901090
}
10911091

1092-
self.dcx().emit_err(RepeatedMutInPattern { span: lo.to(self.prev_token.span) });
1092+
let span = lo.to(self.prev_token.span);
1093+
let suggestion = span.with_hi(self.token.span.lo());
1094+
self.dcx().emit_err(RepeatedMutInPattern { span, suggestion });
10931095
}
10941096

10951097
/// Parse macro invocation

compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1611,6 +1611,7 @@ symbols! {
16111611
repr_simd,
16121612
repr_transparent,
16131613
require,
1614+
reserve_x18: "reserve-x18",
16141615
residual,
16151616
result,
16161617
result_ffi_guarantees,

compiler/rustc_target/src/asm/aarch64.rs

+13-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::fmt;
22

33
use rustc_data_structures::fx::FxIndexSet;
4-
use rustc_span::Symbol;
4+
use rustc_span::{Symbol, sym};
55

66
use super::{InlineAsmArch, InlineAsmType, ModifierInfo};
77
use crate::spec::{RelocModel, Target};
@@ -71,18 +71,26 @@ impl AArch64InlineAsmRegClass {
7171
}
7272
}
7373

74-
pub(crate) fn target_reserves_x18(target: &Target) -> bool {
75-
target.os == "android" || target.os == "fuchsia" || target.is_like_osx || target.is_like_windows
74+
pub(crate) fn target_reserves_x18(target: &Target, target_features: &FxIndexSet<Symbol>) -> bool {
75+
// See isX18ReservedByDefault in LLVM for targets reserve x18 by default:
76+
// https://github.com/llvm/llvm-project/blob/llvmorg-19.1.0/llvm/lib/TargetParser/AArch64TargetParser.cpp#L102-L105
77+
// Note that +reserve-x18 is currently not set for the above targets.
78+
target.os == "android"
79+
|| target.os == "fuchsia"
80+
|| target.env == "ohos"
81+
|| target.is_like_osx
82+
|| target.is_like_windows
83+
|| target_features.contains(&sym::reserve_x18)
7684
}
7785

7886
fn reserved_x18(
7987
_arch: InlineAsmArch,
8088
_reloc_model: RelocModel,
81-
_target_features: &FxIndexSet<Symbol>,
89+
target_features: &FxIndexSet<Symbol>,
8290
target: &Target,
8391
_is_clobber: bool,
8492
) -> Result<(), &'static str> {
85-
if target_reserves_x18(target) {
93+
if target_reserves_x18(target, target_features) {
8694
Err("x18 is a reserved register on this target")
8795
} else {
8896
Ok(())

compiler/rustc_target/src/asm/hexagon.rs

+6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use super::{InlineAsmArch, InlineAsmType, ModifierInfo};
77
def_reg_class! {
88
Hexagon HexagonInlineAsmRegClass {
99
reg,
10+
preg,
1011
}
1112
}
1213

@@ -37,6 +38,7 @@ impl HexagonInlineAsmRegClass {
3738
) -> &'static [(InlineAsmType, Option<Symbol>)] {
3839
match self {
3940
Self::reg => types! { _: I8, I16, I32, F32; },
41+
Self::preg => &[],
4042
}
4143
}
4244
}
@@ -71,6 +73,10 @@ def_regs! {
7173
r26: reg = ["r26"],
7274
r27: reg = ["r27"],
7375
r28: reg = ["r28"],
76+
p0: preg = ["p0"],
77+
p1: preg = ["p1"],
78+
p2: preg = ["p2"],
79+
p3: preg = ["p3"],
7480
#error = ["r19"] =>
7581
"r19 is used internally by LLVM and cannot be used as an operand for inline asm",
7682
#error = ["r29", "sp"] =>

0 commit comments

Comments
 (0)