Skip to content

Commit 15902ef

Browse files
committed
Auto merge of #155824 - JonathanBrouwer:rollup-phz8QVJ, r=<try>
Rollup of 7 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 try-job: x86_64-mingw-1 try-job: i686-msvc-2
2 parents c7fe5e9 + 48e67fa commit 15902ef

43 files changed

Lines changed: 667 additions & 296 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_borrowck/src/diagnostics/conflict_errors.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
156156
.collect();
157157
generic_args.push((kw::SelfUpper, this.clone()));
158158

159-
let args = FormatArgs {
160-
this,
161-
// Unused
162-
this_sugared: String::new(),
163-
// Unused
164-
item_context: "",
165-
generic_args,
166-
};
159+
let args = FormatArgs { this, generic_args, .. };
167160
let CustomDiagnostic { message, label, notes, parent_label: _ } =
168161
directive.eval(None, &args);
169162

compiler/rustc_builtin_macros/src/format.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,16 @@ fn make_format_args(
173173
style: fmt_style,
174174
uncooked_symbol: uncooked_fmt_str,
175175
} = {
176+
// Extract snippet so that we can check cases `{}`, `{:?}` and `{:#?}` and emit help for
177+
// them later.
178+
let snippet = if let ExprKind::Block(b, None) = &efmt.kind
179+
&& b.stmts.len() <= 1
180+
{
181+
Some(ecx.sess.source_map().span_to_snippet(unexpanded_fmt_span))
182+
} else {
183+
None
184+
};
185+
176186
let ExpandResult::Ready(mac) = expr_to_spanned_string(ecx, efmt.clone(), msg) else {
177187
return ExpandResult::Retry(());
178188
};
@@ -222,12 +232,26 @@ fn make_format_args(
222232
});
223233
}
224234
sugg_fmt = sugg_fmt.trim_end().to_string();
225-
err.span_suggestion(
235+
err.span_suggestion_verbose(
226236
unexpanded_fmt_span.shrink_to_lo(),
227237
"you might be missing a string literal to format with",
228238
format!("\"{sugg_fmt}\", "),
229239
Applicability::MaybeIncorrect,
230240
);
241+
242+
if let Some(Ok(snippet)) = snippet.as_ref() {
243+
match snippet.as_str() {
244+
"{}" | "{:?}" | "{:#?}" => {
245+
err.span_suggestion_verbose(
246+
unexpanded_fmt_span,
247+
format!("you might want to enclose `{snippet}` with `\"\"`"),
248+
format!("\"{snippet}\""),
249+
Applicability::MaybeIncorrect,
250+
);
251+
}
252+
_ => {}
253+
};
254+
}
231255
}
232256
}
233257
err.emit()

compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1529,6 +1529,12 @@ fn codegen_regular_intrinsic_call<'tcx>(
15291529
fx.bcx.set_cold_block(fx.bcx.current_block().unwrap());
15301530
}
15311531

1532+
sym::return_address => {
1533+
let val = fx.bcx.ins().get_return_address(fx.pointer_type);
1534+
let val = CValue::by_val(val, ret.layout());
1535+
ret.write_cvalue(fx, val);
1536+
}
1537+
15321538
// Unimplemented intrinsics must have a fallback body. The fallback body is obtained
15331539
// by converting the `InstanceKind::Intrinsic` to an `InstanceKind::Item`.
15341540
_ => {

compiler/rustc_codegen_llvm/src/intrinsic.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,22 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
838838
}
839839
}
840840

841+
sym::return_address => {
842+
match self.sess().target.arch {
843+
// Expand this list as needed
844+
| Arch::Wasm32
845+
| Arch::Wasm64 => {
846+
let ty = self.type_ptr();
847+
self.const_null(ty)
848+
}
849+
_ => {
850+
let ty = self.type_ix(32);
851+
let val = self.const_int(ty, 0);
852+
self.call_intrinsic("llvm.returnaddress", &[], &[val])
853+
}
854+
}
855+
}
856+
841857
_ => {
842858
debug!("unknown intrinsic '{}' -- falling back to default body", name);
843859
// Call the fallback body instead of generating the intrinsic code

compiler/rustc_codegen_ssa/src/mir/intrinsic.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
121121
| sym::contract_checks
122122
| sym::atomic_fence
123123
| sym::atomic_singlethreadfence
124-
| sym::caller_location => {}
124+
| sym::caller_location
125+
| sym::return_address => {}
125126
_ => {
126127
span_bug!(
127128
span,

compiler/rustc_expand/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// tidy-alphabetical-start
22
#![allow(internal_features)]
33
#![feature(associated_type_defaults)]
4+
#![feature(default_field_values)]
45
#![feature(macro_metavar_expr)]
56
#![feature(proc_macro_diagnostic)]
67
#![feature(proc_macro_internals)]

compiler/rustc_expand/src/mbe/diagnostics.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -77,19 +77,8 @@ pub(super) fn failed_to_match_macro(
7777
let CustomDiagnostic {
7878
message: custom_message, label: custom_label, notes: custom_notes, ..
7979
} = {
80-
let macro_name = name.to_string();
8180
on_unmatch_args
82-
.map(|directive| {
83-
directive.eval(
84-
None,
85-
&FormatArgs {
86-
this: macro_name.clone(),
87-
this_sugared: macro_name,
88-
item_context: "macro invocation",
89-
generic_args: Vec::new(),
90-
},
91-
)
92-
})
81+
.map(|directive| directive.eval(None, &FormatArgs { this: name.to_string(), .. }))
9382
.unwrap_or_default()
9483
};
9584

compiler/rustc_hir/src/attrs/diagnostic.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,10 +218,11 @@ impl FormatString {
218218
/// ```
219219
#[derive(Debug)]
220220
pub struct FormatArgs {
221+
/// The name of the item the attribute is on.
221222
pub this: String,
222-
pub this_sugared: String,
223-
pub item_context: &'static str,
224-
pub generic_args: Vec<(Symbol, String)>,
223+
pub this_sugared: String = String::new(),
224+
pub item_context: &'static str = "",
225+
pub generic_args: Vec<(Symbol, String)> = Vec::new(),
225226
}
226227

227228
#[derive(Clone, Debug, HashStable_Generic, Encodable, Decodable, PrintAttribute)]

compiler/rustc_hir/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#![feature(closure_track_caller)]
88
#![feature(const_default)]
99
#![feature(const_trait_impl)]
10+
#![feature(default_field_values)]
1011
#![feature(derive_const)]
1112
#![feature(exhaustive_patterns)]
1213
#![feature(never_type)]

compiler/rustc_hir_analysis/src/check/intrinsic.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ fn intrinsic_operation_unsafety(tcx: TyCtxt<'_>, intrinsic_id: LocalDefId) -> hi
180180
| sym::ptr_guaranteed_cmp
181181
| sym::ptr_mask
182182
| sym::ptr_metadata
183+
| sym::return_address
183184
| sym::rotate_left
184185
| sym::rotate_right
185186
| sym::round_ties_even_f16
@@ -803,6 +804,8 @@ pub(crate) fn check_intrinsic_type(
803804
| sym::atomic_xor => (2, 1, vec![Ty::new_mut_ptr(tcx, param(0)), param(1)], param(0)),
804805
sym::atomic_fence | sym::atomic_singlethreadfence => (0, 1, Vec::new(), tcx.types.unit),
805806

807+
sym::return_address => (0, 0, vec![], Ty::new_imm_ptr(tcx, tcx.types.unit)),
808+
806809
other => {
807810
tcx.dcx().emit_err(UnrecognizedIntrinsicFunction { span, name: other });
808811
return;

0 commit comments

Comments
 (0)