Skip to content

Commit f21b4c0

Browse files
committed
Auto merge of #152412 - JonathanBrouwer:rollup-hShycIY, r=JonathanBrouwer
Rollup of 7 pull requests Successful merges: - #151960 (rustc_parse: improve the error diagnostic for "missing let") - #152157 (Fix error spans for `asm!()` args that are macros) - #152317 (fix: sup_trace to sub_trace) - #150897 (rustc_parse_format: improve diagnostics for unsupported debug = syntax) - #151154 (Add `s390x-unknown-none-softfloat` with `RustcAbi::Softfloat`) - #152013 (Update to Xcode 26.2) - #152326 (Remove the compiler adhoc group)
2 parents 381e9ef + 415780b commit f21b4c0

Some content is hidden

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

44 files changed

+600
-91
lines changed

compiler/rustc_builtin_macros/src/asm.rs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,18 @@ fn expand_preparsed_asm(
288288
let msg = "asm template must be a string literal";
289289
let template_sp = template_expr.span;
290290
let template_is_mac_call = matches!(template_expr.kind, ast::ExprKind::MacCall(_));
291+
292+
// Gets the span inside `template_sp` corresponding to the given range
293+
let span_in_template = |range: std::ops::Range<usize>| -> Span {
294+
if template_is_mac_call {
295+
// When the template is a macro call we can't reliably get inner spans
296+
// so just use the entire template span (see ICEs #129503, #131292)
297+
template_sp
298+
} else {
299+
template_sp.from_inner(InnerSpan::new(range.start, range.end))
300+
}
301+
};
302+
291303
let ExprToSpannedString {
292304
symbol: template_str,
293305
style: template_style,
@@ -382,13 +394,8 @@ fn expand_preparsed_asm(
382394

383395
if !parser.errors.is_empty() {
384396
let err = parser.errors.remove(0);
385-
let err_sp = if template_is_mac_call {
386-
// If the template is a macro call we can't reliably point to the error's
387-
// span so just use the template's span as the error span (fixes #129503)
388-
template_span
389-
} else {
390-
template_span.from_inner(InnerSpan::new(err.span.start, err.span.end))
391-
};
397+
398+
let err_sp = span_in_template(err.span);
392399

393400
let msg = format!("invalid asm template string: {}", err.description);
394401
let mut e = ecx.dcx().struct_span_err(err_sp, msg);
@@ -397,8 +404,7 @@ fn expand_preparsed_asm(
397404
e.note(note);
398405
}
399406
if let Some((label, span)) = err.secondary_label {
400-
let err_sp = template_span.from_inner(InnerSpan::new(span.start, span.end));
401-
e.span_label(err_sp, label);
407+
e.span_label(span_in_template(span), label);
402408
}
403409
let guar = e.emit();
404410
return ExpandResult::Ready(Err(guar));
@@ -477,8 +483,7 @@ fn expand_preparsed_asm(
477483
ecx.dcx()
478484
.create_err(errors::AsmNoMatchedArgumentName {
479485
name: name.to_owned(),
480-
span: template_span
481-
.from_inner(InnerSpan::new(span.start, span.end)),
486+
span: span_in_template(span),
482487
})
483488
.emit();
484489
None
@@ -490,11 +495,7 @@ fn expand_preparsed_asm(
490495
let mut chars = arg.format.ty.chars();
491496
let mut modifier = chars.next();
492497
if chars.next().is_some() {
493-
let span = arg
494-
.format
495-
.ty_span
496-
.map(|sp| template_sp.from_inner(InnerSpan::new(sp.start, sp.end)))
497-
.unwrap_or(template_sp);
498+
let span = arg.format.ty_span.map(span_in_template).unwrap_or(template_sp);
498499
ecx.dcx().emit_err(errors::AsmModifierInvalid { span });
499500
modifier = None;
500501
}

compiler/rustc_builtin_macros/src/errors.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,18 @@ pub(crate) enum InvalidFormatStringSuggestion {
678678
#[primary_span]
679679
span: Span,
680680
},
681+
682+
#[suggestion(
683+
"use rust debug printing macro",
684+
code = "{replacement}",
685+
style = "verbose",
686+
applicability = "machine-applicable"
687+
)]
688+
UseRustDebugPrintingMacro {
689+
#[primary_span]
690+
macro_span: Span,
691+
replacement: String,
692+
},
681693
}
682694

683695
#[derive(Diagnostic)]

compiler/rustc_builtin_macros/src/format.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ fn make_format_args(
160160
ecx: &mut ExtCtxt<'_>,
161161
input: MacroInput,
162162
append_newline: bool,
163+
macro_span: Span,
163164
) -> ExpandResult<Result<FormatArgs, ErrorGuaranteed>, ()> {
164165
let msg = "format argument must be a string literal";
165166
let unexpanded_fmt_span = input.fmtstr.span;
@@ -333,6 +334,23 @@ fn make_format_args(
333334
let span = fmt_span.from_inner(InnerSpan::new(span.start, span.end));
334335
e.sugg_ = Some(errors::InvalidFormatStringSuggestion::AddMissingColon { span });
335336
}
337+
parse::Suggestion::UseRustDebugPrintingMacro => {
338+
// This targets `println!("{=}", x);` and `println!("{0=}", x);`
339+
if let [arg] = args.all_args() {
340+
let expr_span = arg.expr.span;
341+
if let Ok(expr_snippet) = ecx.source_map().span_to_snippet(expr_span) {
342+
let replacement = format!("{}!({})", "dbg", expr_snippet);
343+
344+
let call_span = macro_span.source_callsite();
345+
e.sugg_ = Some(
346+
errors::InvalidFormatStringSuggestion::UseRustDebugPrintingMacro {
347+
macro_span: call_span,
348+
replacement,
349+
},
350+
);
351+
}
352+
}
353+
}
336354
}
337355
let guar = ecx.dcx().emit_err(e);
338356
return ExpandResult::Ready(Err(guar));
@@ -1048,7 +1066,7 @@ fn expand_format_args_impl<'cx>(
10481066
sp = ecx.with_def_site_ctxt(sp);
10491067
ExpandResult::Ready(match parse_args(ecx, sp, tts) {
10501068
Ok(input) => {
1051-
let ExpandResult::Ready(mac) = make_format_args(ecx, input, nl) else {
1069+
let ExpandResult::Ready(mac) = make_format_args(ecx, input, nl, sp) else {
10521070
return ExpandResult::Retry(());
10531071
};
10541072
match mac {

compiler/rustc_parse/src/errors.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,24 @@ pub(crate) struct ExpectedExpressionFoundLet {
573573
pub comparison: Option<MaybeComparison>,
574574
}
575575

576+
#[derive(Diagnostic)]
577+
#[diag("let-chain with missing `let`")]
578+
pub(crate) struct LetChainMissingLet {
579+
#[primary_span]
580+
pub span: Span,
581+
#[label("expected `let` expression, found assignment")]
582+
pub label_span: Span,
583+
#[label("let expression later in the condition")]
584+
pub rhs_span: Span,
585+
#[suggestion(
586+
"add `let` before the expression",
587+
applicability = "maybe-incorrect",
588+
code = "let ",
589+
style = "verbose"
590+
)]
591+
pub sug_span: Span,
592+
}
593+
576594
#[derive(Diagnostic)]
577595
#[diag("`||` operators are not supported in let chain conditions")]
578596
pub(crate) struct OrInLetChain {

compiler/rustc_parse/src/parser/expr.rs

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4282,7 +4282,52 @@ impl MutVisitor for CondChecker<'_> {
42824282
mut_visit::walk_expr(self, e);
42834283
self.forbid_let_reason = forbid_let_reason;
42844284
}
4285-
ExprKind::Assign(ref lhs, _, span) => {
4285+
ExprKind::Assign(ref lhs, ref rhs, span) => {
4286+
if let ExprKind::Call(_, _) = &lhs.kind {
4287+
fn get_path_from_rhs(e: &Expr) -> Option<(u32, &Path)> {
4288+
fn inner(e: &Expr, depth: u32) -> Option<(u32, &Path)> {
4289+
match &e.kind {
4290+
ExprKind::Binary(_, lhs, _) => inner(lhs, depth + 1),
4291+
ExprKind::Path(_, path) => Some((depth, path)),
4292+
_ => None,
4293+
}
4294+
}
4295+
4296+
inner(e, 0)
4297+
}
4298+
4299+
if let Some((depth, path)) = get_path_from_rhs(rhs) {
4300+
// For cases like if Some(_) = x && let Some(_) = y && let Some(_) = z
4301+
// This return let Some(_) = y expression
4302+
fn find_let_some(expr: &Expr) -> Option<&Expr> {
4303+
match &expr.kind {
4304+
ExprKind::Let(..) => Some(expr),
4305+
4306+
ExprKind::Binary(op, lhs, rhs) if op.node == BinOpKind::And => {
4307+
find_let_some(lhs).or_else(|| find_let_some(rhs))
4308+
}
4309+
4310+
_ => None,
4311+
}
4312+
}
4313+
4314+
let expr_span = lhs.span.to(path.span);
4315+
4316+
if let Some(later_rhs) = find_let_some(rhs)
4317+
&& depth > 0
4318+
{
4319+
let guar = self.parser.dcx().emit_err(errors::LetChainMissingLet {
4320+
span: lhs.span,
4321+
label_span: expr_span,
4322+
rhs_span: later_rhs.span,
4323+
sug_span: lhs.span.shrink_to_lo(),
4324+
});
4325+
4326+
self.found_incorrect_let_chain = Some(guar);
4327+
}
4328+
}
4329+
}
4330+
42864331
let forbid_let_reason = self.forbid_let_reason;
42874332
self.forbid_let_reason = Some(errors::ForbiddenLetReason::OtherForbidden);
42884333
let missing_let = self.missing_let;

compiler/rustc_parse_format/src/lib.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,9 @@ pub enum Suggestion {
187187
/// Add missing colon:
188188
/// `format!("{foo?}")` -> `format!("{foo:?}")`
189189
AddMissingColon(Range<usize>),
190+
/// Use Rust format string:
191+
/// `format!("{x=}")` -> `dbg!(x)`
192+
UseRustDebugPrintingMacro,
190193
}
191194

192195
/// The parser structure for interpreting the input format string. This is
@@ -462,6 +465,7 @@ impl<'input> Parser<'input> {
462465
('?', _) => self.suggest_format_debug(),
463466
('<' | '^' | '>', _) => self.suggest_format_align(c),
464467
(',', _) => self.suggest_unsupported_python_numeric_grouping(),
468+
('=', '}') => self.suggest_rust_debug_printing_macro(),
465469
_ => self.suggest_positional_arg_instead_of_captured_arg(arg),
466470
}
467471
}
@@ -871,6 +875,27 @@ impl<'input> Parser<'input> {
871875
}
872876
}
873877

878+
fn suggest_rust_debug_printing_macro(&mut self) {
879+
if let Some((range, _)) = self.consume_pos('=') {
880+
self.errors.insert(
881+
0,
882+
ParseError {
883+
description:
884+
"python's f-string debug `=` is not supported in rust, use `dbg(x)` instead"
885+
.to_owned(),
886+
note: Some(format!("to print `{{`, you can escape it using `{{{{`",)),
887+
label: "expected `}`".to_owned(),
888+
span: range,
889+
secondary_label: self
890+
.last_open_brace
891+
.clone()
892+
.map(|sp| ("because of this opening brace".to_owned(), sp)),
893+
suggestion: Suggestion::UseRustDebugPrintingMacro,
894+
},
895+
);
896+
}
897+
}
898+
874899
fn suggest_format_align(&mut self, alignment: char) {
875900
if let Some((range, _)) = self.consume_pos(alignment) {
876901
self.errors.insert(

compiler/rustc_target/src/callconv/x86_win64.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ where
2828
BackendRepr::ScalableVector { .. } => panic!("scalable vectors are unsupported"),
2929
BackendRepr::Scalar(scalar) => {
3030
if is_ret && matches!(scalar.primitive(), Primitive::Int(Integer::I128, _)) {
31-
if cx.target_spec().rustc_abi == Some(RustcAbi::X86Softfloat) {
31+
if cx.target_spec().rustc_abi == Some(RustcAbi::Softfloat) {
3232
// Use the native `i128` LLVM type for the softfloat ABI -- in other words, adjust nothing.
3333
} else {
3434
// `i128` is returned in xmm0 by Clang and GCC

compiler/rustc_target/src/lib.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ macro_rules! target_spec_enum {
7676
pub enum $Name:ident {
7777
$(
7878
$( #[$variant_attr:meta] )*
79-
$Variant:ident = $string:literal,
79+
$Variant:ident = $string:literal $(,$alias:literal)* ,
8080
)*
8181
}
8282
parse_error_type = $parse_error_type:literal;
@@ -88,6 +88,7 @@ macro_rules! target_spec_enum {
8888
$(
8989
$( #[$variant_attr] )*
9090
#[serde(rename = $string)] // for JSON schema generation only
91+
$( #[serde(alias = $alias)] )*
9192
$Variant,
9293
)*
9394
}
@@ -97,7 +98,10 @@ macro_rules! target_spec_enum {
9798

9899
fn from_str(s: &str) -> Result<Self, Self::Err> {
99100
Ok(match s {
100-
$( $string => Self::$Variant, )*
101+
$(
102+
$string => Self::$Variant,
103+
$($alias => Self::$Variant,)*
104+
)*
101105
_ => {
102106
let all = [$( concat!("'", $string, "'") ),*].join(", ");
103107
return Err(format!("invalid {}: '{s}'. allowed values: {all}", $parse_error_type));
@@ -123,7 +127,7 @@ macro_rules! target_spec_enum {
123127
pub enum $Name:ident {
124128
$(
125129
$( #[$variant_attr:meta] )*
126-
$Variant:ident = $string:literal,
130+
$Variant:ident = $string:literal $(,$alias:literal)* ,
127131
)*
128132
}
129133
$( #[$other_variant_attr:meta] )*
@@ -134,6 +138,7 @@ macro_rules! target_spec_enum {
134138
pub enum $Name {
135139
$(
136140
$( #[$variant_attr:meta] )*
141+
$( #[serde(alias = $alias)] )*
137142
$Variant,
138143
)*
139144
/// The vast majority of the time, the compiler deals with a fixed
@@ -165,7 +170,10 @@ macro_rules! target_spec_enum {
165170

166171
fn from_str(s: &str) -> Result<Self, Self::Err> {
167172
Ok(match s {
168-
$( $string => Self::$Variant, )*
173+
$(
174+
$string => Self::$Variant,
175+
$($alias => Self::$Variant,)*
176+
)*
169177
_ => Self::$OtherVariant(s.to_owned().into()),
170178
})
171179
}

compiler/rustc_target/src/spec/mod.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,8 +1005,8 @@ crate::target_spec_enum! {
10051005
pub enum RustcAbi {
10061006
/// On x86-32 only: make use of SSE and SSE2 for ABI purposes.
10071007
X86Sse2 = "x86-sse2",
1008-
/// On x86-32/64 only: do not use any FPU or SIMD registers for the ABI.
1009-
X86Softfloat = "x86-softfloat",
1008+
/// On x86-32/64 and S390x: do not use any FPU or SIMD registers for the ABI.
1009+
Softfloat = "softfloat", "x86-softfloat",
10101010
}
10111011

10121012
parse_error_type = "rustc abi";
@@ -1460,6 +1460,7 @@ supported_targets! {
14601460
("powerpc64le-unknown-linux-gnu", powerpc64le_unknown_linux_gnu),
14611461
("powerpc64le-unknown-linux-musl", powerpc64le_unknown_linux_musl),
14621462
("s390x-unknown-linux-gnu", s390x_unknown_linux_gnu),
1463+
("s390x-unknown-none-softfloat", s390x_unknown_none_softfloat),
14631464
("s390x-unknown-linux-musl", s390x_unknown_linux_musl),
14641465
("sparc-unknown-linux-gnu", sparc_unknown_linux_gnu),
14651466
("sparc64-unknown-linux-gnu", sparc64_unknown_linux_gnu),
@@ -3204,10 +3205,10 @@ impl Target {
32043205
Arch::X86,
32053206
"`x86-sse2` ABI is only valid for x86-32 targets"
32063207
),
3207-
RustcAbi::X86Softfloat => check_matches!(
3208+
RustcAbi::Softfloat => check_matches!(
32083209
self.arch,
3209-
Arch::X86 | Arch::X86_64,
3210-
"`x86-softfloat` ABI is only valid for x86 targets"
3210+
Arch::X86 | Arch::X86_64 | Arch::S390x,
3211+
"`softfloat` ABI is only valid for x86 and s390x targets"
32113212
),
32123213
}
32133214
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub(crate) fn target() -> Target {
2222
// If you initialize FP units yourself, you can override these flags with custom linker
2323
// arguments, thus giving you access to full MMX/SSE acceleration.
2424
base.features = "-mmx,-sse,+soft-float".into();
25-
base.rustc_abi = Some(RustcAbi::X86Softfloat);
25+
base.rustc_abi = Some(RustcAbi::Softfloat);
2626

2727
// Turn off DWARF. This fixes an lld warning, "section name .debug_frame is longer than 8
2828
// characters and will use a non-standard string table". That section will not be created if

0 commit comments

Comments
 (0)