Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
ee9986b
document lifetime extension for `format_args!`'s arguments
dianne Aug 27, 2025
a7bd285
cmse: use BackendRepr to determine valid 64-bit return types
folkertdev Sep 26, 2025
4787834
Fix target list of `link_section`
JonathanBrouwer Oct 6, 2025
1589c6c
Add regression test for `link_section` targets
JonathanBrouwer Oct 7, 2025
eb8d87d
avoid in-process serializing&deserializing
yotamofek Oct 6, 2025
978ab7c
nicer serde impls
yotamofek Oct 7, 2025
f8ee9f0
Print tip for human error format when check fail
chenyukang Oct 7, 2025
c5ab530
move serde impls to separate module
yotamofek Oct 7, 2025
713e0dd
Fix comments error for CtfeProvenance
chenyukang Oct 7, 2025
0a3f1d5
c-variadic: fix thir-print for `...` without a pattern
folkertdev Oct 7, 2025
fbdc685
cmse: disallow `impl Trait` in `cmse-nonsecure-entry` return types
folkertdev Oct 1, 2025
bce59ab
Rollup merge of #145943 - dianne:format-args-assign-docs, r=joboet
matthiaskrgr Oct 7, 2025
7ab1fd1
Rollup merge of #147243 - folkertdev:cmse-bail-impl-trait, r=davidtwco
matthiaskrgr Oct 7, 2025
4461dd9
Rollup merge of #147402 - yotamofek:wip/rustdoc/search_index/impl-dis…
matthiaskrgr Oct 7, 2025
0072d0c
Rollup merge of #147418 - JonathanBrouwer:link_section_targets, r=jdo…
matthiaskrgr Oct 7, 2025
2d353c3
Rollup merge of #147429 - chenyukang:yukang-fix-test-tip, r=fmease
matthiaskrgr Oct 7, 2025
883032b
Rollup merge of #147441 - chenyukang:yukang-trivial-fix-comments, r=R…
matthiaskrgr Oct 7, 2025
5f03328
Rollup merge of #147442 - folkertdev:thir-print-c-variadic, r=fmease
matthiaskrgr Oct 7, 2025
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions compiler/rustc_attr_parsing/src/attributes/link_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,8 +467,14 @@ impl<S: Stage> SingleAttributeParser<S> for LinkSectionParser {
const PATH: &[Symbol] = &[sym::link_section];
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepInnermost;
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::WarnButFutureError;
const ALLOWED_TARGETS: AllowedTargets =
AllowedTargets::AllowListWarnRest(&[Allow(Target::Static), Allow(Target::Fn)]);
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowListWarnRest(&[
Allow(Target::Static),
Allow(Target::Fn),
Allow(Target::Method(MethodKind::Inherent)),
Allow(Target::Method(MethodKind::Trait { body: false })),
Allow(Target::Method(MethodKind::Trait { body: true })),
Allow(Target::Method(MethodKind::TraitImpl)),
]);
const TEMPLATE: AttributeTemplate = template!(
NameValueStr: "name",
"https://doc.rust-lang.org/reference/abi.html#the-link_section-attribute"
Expand Down
64 changes: 34 additions & 30 deletions compiler/rustc_hir_analysis/src/hir_ty_lowering/cmse.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use rustc_abi::ExternAbi;
use rustc_abi::{BackendRepr, ExternAbi, Float, Integer, Primitive, Scalar};
use rustc_errors::{DiagCtxtHandle, E0781, struct_span_code_err};
use rustc_hir::{self as hir, HirId};
use rustc_middle::bug;
use rustc_middle::ty::layout::LayoutError;
use rustc_middle::ty::{self, TyCtxt};
use rustc_middle::ty::layout::{LayoutError, TyAndLayout};
use rustc_middle::ty::{self, TyCtxt, TypeVisitableExt};

use crate::errors;

Expand Down Expand Up @@ -164,44 +164,48 @@ fn is_valid_cmse_output<'tcx>(
) -> Result<bool, &'tcx LayoutError<'tcx>> {
// this type is only used for layout computation, which does not rely on regions
let fn_sig = tcx.instantiate_bound_regions_with_erased(fn_sig);
let fn_sig = tcx.erase_and_anonymize_regions(fn_sig);
let return_type = fn_sig.output();

// `impl Trait` is already disallowed with `cmse-nonsecure-call`, because that ABI is only
// allowed on function pointers, and function pointers cannot contain `impl Trait` in their
// signature.
//
// Here we explicitly disallow `impl Trait` in the `cmse-nonsecure-entry` return type too, to
// prevent query cycles when calculating the layout. This ABI is meant to be used with
// `#[no_mangle]` or similar, so generics in the type really don't make sense.
//
// see also https://github.com/rust-lang/rust/issues/147242.
if return_type.has_opaque_types() {
return Err(tcx.arena.alloc(LayoutError::TooGeneric(return_type)));
}

let typing_env = ty::TypingEnv::fully_monomorphized();
let layout = tcx.layout_of(typing_env.as_query_input(return_type))?;

Ok(is_valid_cmse_output_layout(layout))
}

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

if size <= 4 {
return Ok(true);
return true;
} else if size > 8 {
return Ok(false);
return false;
}

// next we need to peel any repr(transparent) layers off
'outer: loop {
let ty::Adt(adt_def, args) = ret_ty.kind() else {
break;
};

if !adt_def.repr().transparent() {
break;
}

// the first field with non-trivial size and alignment must be the data
for variant_def in adt_def.variants() {
for field_def in variant_def.fields.iter() {
let ty = field_def.ty(tcx, args);
let layout = tcx.layout_of(typing_env.as_query_input(ty))?;
// Accept scalar 64-bit types.
let BackendRepr::Scalar(scalar) = layout.layout.backend_repr else {
return false;
};

if !layout.layout.is_1zst() {
ret_ty = ty;
continue 'outer;
}
}
}
}
let Scalar::Initialized { value, .. } = scalar else {
return false;
};

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

fn should_emit_generic_error<'tcx>(abi: ExternAbi, layout_err: &'tcx LayoutError<'tcx>) -> bool {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/mir/interpret/pointer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ impl CtfeProvenance {
}

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

Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_mir_build/src/thir/print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,9 @@ impl<'a, 'tcx> ThirPrinter<'a, 'tcx> {
print_indented!(self, "kind: PatKind {", depth_lvl);

match pat_kind {
PatKind::Missing => unreachable!(),
PatKind::Missing => {
print_indented!(self, "Missing", depth_lvl + 1);
}
PatKind::Wild => {
print_indented!(self, "Wild", depth_lvl + 1);
}
Expand Down
19 changes: 12 additions & 7 deletions library/core/src/macros/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -951,8 +951,9 @@ pub(crate) mod builtin {
/// format string in `format_args!`.
///
/// ```rust
/// let debug = format!("{:?}", format_args!("{} foo {:?}", 1, 2));
/// let display = format!("{}", format_args!("{} foo {:?}", 1, 2));
/// let args = format_args!("{} foo {:?}", 1, 2);
/// let debug = format!("{args:?}");
/// let display = format!("{args}");
/// assert_eq!("1 foo 2", display);
/// assert_eq!(display, debug);
/// ```
Expand All @@ -976,13 +977,17 @@ pub(crate) mod builtin {
/// assert_eq!(s, format!("hello {}", "world"));
/// ```
///
/// # Lifetime limitation
/// # Argument lifetimes
///
/// Except when no formatting arguments are used,
/// the produced `fmt::Arguments` value borrows temporary values,
/// which means it can only be used within the same expression
/// and cannot be stored for later use.
/// This is a known limitation, see [#92698](https://github.com/rust-lang/rust/issues/92698).
/// the produced `fmt::Arguments` value borrows temporary values.
/// To allow it to be stored for later use, the arguments' lifetimes, as well as those of
/// temporaries they borrow, may be [extended] when `format_args!` appears in the initializer
/// expression of a `let` statement. The syntactic rules used to determine when temporaries'
/// lifetimes are extended are documented in the [Reference].
///
/// [extended]: ../reference/destructors.html#temporary-lifetime-extension
/// [Reference]: ../reference/destructors.html#extending-based-on-expressions
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_diagnostic_item = "format_args_macro"]
#[allow_internal_unsafe]
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/html/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ pub(crate) struct IndexItem {
}

/// A type used for the search index.
#[derive(Debug, Eq, PartialEq)]
#[derive(Clone, Debug, Eq, PartialEq)]
struct RenderType {
id: Option<RenderTypeId>,
generics: Option<Vec<RenderType>>,
Expand Down Expand Up @@ -301,7 +301,7 @@ impl RenderTypeId {
}

/// Full type of functions/methods in the search index.
#[derive(Debug, Eq, PartialEq)]
#[derive(Clone, Debug, Eq, PartialEq)]
pub(crate) struct IndexItemFunctionType {
inputs: Vec<RenderType>,
output: Vec<RenderType>,
Expand Down
Loading
Loading