Skip to content

Commit d62f33a

Browse files
committed
Auto merge of #147449 - matthiaskrgr:rollup-njyi5yr, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - #145943 (stdlib docs: document lifetime extension for `format_args!`'s arguments) - #147243 (cmse: disallow `impl Trait` in `cmse-nonsecure-entry` return types) - #147402 ([rustdoc] Don't serialize & deserialize data that doesn't go OTW) - #147418 (Fix target list of `link_section`) - #147429 (Print tip for human error format in runtest) - #147441 (Fix comments error for Provenance impls) - #147442 (c-variadic: fix thir-print for `...` without a pattern) r? `@ghost` `@rustbot` modify labels: rollup
2 parents fed46ff + 5f03328 commit d62f33a

File tree

18 files changed

+519
-311
lines changed

18 files changed

+519
-311
lines changed

compiler/rustc_attr_parsing/src/attributes/link_attrs.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,8 +467,14 @@ impl<S: Stage> SingleAttributeParser<S> for LinkSectionParser {
467467
const PATH: &[Symbol] = &[sym::link_section];
468468
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepInnermost;
469469
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::WarnButFutureError;
470-
const ALLOWED_TARGETS: AllowedTargets =
471-
AllowedTargets::AllowListWarnRest(&[Allow(Target::Static), Allow(Target::Fn)]);
470+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowListWarnRest(&[
471+
Allow(Target::Static),
472+
Allow(Target::Fn),
473+
Allow(Target::Method(MethodKind::Inherent)),
474+
Allow(Target::Method(MethodKind::Trait { body: false })),
475+
Allow(Target::Method(MethodKind::Trait { body: true })),
476+
Allow(Target::Method(MethodKind::TraitImpl)),
477+
]);
472478
const TEMPLATE: AttributeTemplate = template!(
473479
NameValueStr: "name",
474480
"https://doc.rust-lang.org/reference/abi.html#the-link_section-attribute"

compiler/rustc_hir_analysis/src/hir_ty_lowering/cmse.rs

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
use rustc_abi::ExternAbi;
1+
use rustc_abi::{BackendRepr, ExternAbi, Float, Integer, Primitive, Scalar};
22
use rustc_errors::{DiagCtxtHandle, E0781, struct_span_code_err};
33
use rustc_hir::{self as hir, HirId};
44
use rustc_middle::bug;
5-
use rustc_middle::ty::layout::LayoutError;
6-
use rustc_middle::ty::{self, TyCtxt};
5+
use rustc_middle::ty::layout::{LayoutError, TyAndLayout};
6+
use rustc_middle::ty::{self, TyCtxt, TypeVisitableExt};
77

88
use crate::errors;
99

@@ -164,44 +164,48 @@ fn is_valid_cmse_output<'tcx>(
164164
) -> Result<bool, &'tcx LayoutError<'tcx>> {
165165
// this type is only used for layout computation, which does not rely on regions
166166
let fn_sig = tcx.instantiate_bound_regions_with_erased(fn_sig);
167+
let fn_sig = tcx.erase_and_anonymize_regions(fn_sig);
168+
let return_type = fn_sig.output();
169+
170+
// `impl Trait` is already disallowed with `cmse-nonsecure-call`, because that ABI is only
171+
// allowed on function pointers, and function pointers cannot contain `impl Trait` in their
172+
// signature.
173+
//
174+
// Here we explicitly disallow `impl Trait` in the `cmse-nonsecure-entry` return type too, to
175+
// prevent query cycles when calculating the layout. This ABI is meant to be used with
176+
// `#[no_mangle]` or similar, so generics in the type really don't make sense.
177+
//
178+
// see also https://github.com/rust-lang/rust/issues/147242.
179+
if return_type.has_opaque_types() {
180+
return Err(tcx.arena.alloc(LayoutError::TooGeneric(return_type)));
181+
}
167182

168183
let typing_env = ty::TypingEnv::fully_monomorphized();
184+
let layout = tcx.layout_of(typing_env.as_query_input(return_type))?;
185+
186+
Ok(is_valid_cmse_output_layout(layout))
187+
}
169188

170-
let mut ret_ty = fn_sig.output();
171-
let layout = tcx.layout_of(typing_env.as_query_input(ret_ty))?;
189+
/// Returns whether the output will fit into the available registers
190+
fn is_valid_cmse_output_layout<'tcx>(layout: TyAndLayout<'tcx>) -> bool {
172191
let size = layout.layout.size().bytes();
173192

174193
if size <= 4 {
175-
return Ok(true);
194+
return true;
176195
} else if size > 8 {
177-
return Ok(false);
196+
return false;
178197
}
179198

180-
// next we need to peel any repr(transparent) layers off
181-
'outer: loop {
182-
let ty::Adt(adt_def, args) = ret_ty.kind() else {
183-
break;
184-
};
185-
186-
if !adt_def.repr().transparent() {
187-
break;
188-
}
189-
190-
// the first field with non-trivial size and alignment must be the data
191-
for variant_def in adt_def.variants() {
192-
for field_def in variant_def.fields.iter() {
193-
let ty = field_def.ty(tcx, args);
194-
let layout = tcx.layout_of(typing_env.as_query_input(ty))?;
199+
// Accept scalar 64-bit types.
200+
let BackendRepr::Scalar(scalar) = layout.layout.backend_repr else {
201+
return false;
202+
};
195203

196-
if !layout.layout.is_1zst() {
197-
ret_ty = ty;
198-
continue 'outer;
199-
}
200-
}
201-
}
202-
}
204+
let Scalar::Initialized { value, .. } = scalar else {
205+
return false;
206+
};
203207

204-
Ok(ret_ty == tcx.types.i64 || ret_ty == tcx.types.u64 || ret_ty == tcx.types.f64)
208+
matches!(value, Primitive::Int(Integer::I64, _) | Primitive::Float(Float::F64))
205209
}
206210

207211
fn should_emit_generic_error<'tcx>(abi: ExternAbi, layout_err: &'tcx LayoutError<'tcx>) -> bool {

compiler/rustc_middle/src/mir/interpret/pointer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ impl CtfeProvenance {
167167
}
168168

169169
impl Provenance for CtfeProvenance {
170-
// With the `AllocId` as provenance, the `offset` is interpreted *relative to the allocation*,
170+
// With the `CtfeProvenance` as provenance, the `offset` is interpreted *relative to the allocation*,
171171
// so ptr-to-int casts are not possible (since we do not know the global physical offset).
172172
const OFFSET_IS_ADDR: bool = false;
173173

compiler/rustc_mir_build/src/thir/print.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,9 @@ impl<'a, 'tcx> ThirPrinter<'a, 'tcx> {
689689
print_indented!(self, "kind: PatKind {", depth_lvl);
690690

691691
match pat_kind {
692-
PatKind::Missing => unreachable!(),
692+
PatKind::Missing => {
693+
print_indented!(self, "Missing", depth_lvl + 1);
694+
}
693695
PatKind::Wild => {
694696
print_indented!(self, "Wild", depth_lvl + 1);
695697
}

library/core/src/macros/mod.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -951,8 +951,9 @@ pub(crate) mod builtin {
951951
/// format string in `format_args!`.
952952
///
953953
/// ```rust
954-
/// let debug = format!("{:?}", format_args!("{} foo {:?}", 1, 2));
955-
/// let display = format!("{}", format_args!("{} foo {:?}", 1, 2));
954+
/// let args = format_args!("{} foo {:?}", 1, 2);
955+
/// let debug = format!("{args:?}");
956+
/// let display = format!("{args}");
956957
/// assert_eq!("1 foo 2", display);
957958
/// assert_eq!(display, debug);
958959
/// ```
@@ -976,13 +977,17 @@ pub(crate) mod builtin {
976977
/// assert_eq!(s, format!("hello {}", "world"));
977978
/// ```
978979
///
979-
/// # Lifetime limitation
980+
/// # Argument lifetimes
980981
///
981982
/// Except when no formatting arguments are used,
982-
/// the produced `fmt::Arguments` value borrows temporary values,
983-
/// which means it can only be used within the same expression
984-
/// and cannot be stored for later use.
985-
/// This is a known limitation, see [#92698](https://github.com/rust-lang/rust/issues/92698).
983+
/// the produced `fmt::Arguments` value borrows temporary values.
984+
/// To allow it to be stored for later use, the arguments' lifetimes, as well as those of
985+
/// temporaries they borrow, may be [extended] when `format_args!` appears in the initializer
986+
/// expression of a `let` statement. The syntactic rules used to determine when temporaries'
987+
/// lifetimes are extended are documented in the [Reference].
988+
///
989+
/// [extended]: ../reference/destructors.html#temporary-lifetime-extension
990+
/// [Reference]: ../reference/destructors.html#extending-based-on-expressions
986991
#[stable(feature = "rust1", since = "1.0.0")]
987992
#[rustc_diagnostic_item = "format_args_macro"]
988993
#[allow_internal_unsafe]

src/librustdoc/html/render/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ pub(crate) struct IndexItem {
144144
}
145145

146146
/// A type used for the search index.
147-
#[derive(Debug, Eq, PartialEq)]
147+
#[derive(Clone, Debug, Eq, PartialEq)]
148148
struct RenderType {
149149
id: Option<RenderTypeId>,
150150
generics: Option<Vec<RenderType>>,
@@ -301,7 +301,7 @@ impl RenderTypeId {
301301
}
302302

303303
/// Full type of functions/methods in the search index.
304-
#[derive(Debug, Eq, PartialEq)]
304+
#[derive(Clone, Debug, Eq, PartialEq)]
305305
pub(crate) struct IndexItemFunctionType {
306306
inputs: Vec<RenderType>,
307307
output: Vec<RenderType>,

0 commit comments

Comments
 (0)