8000 Auto merge of #130390 - matthiaskrgr:rollup-evbfwe2, r=matthiaskrgr · rust-lang-ci/rust@dde7d66 · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit dde7d66

Browse files
committed
Auto merge of rust-lang#130390 - matthiaskrgr:rollup-evbfwe2, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - rust-lang#129195 (Stabilize `&mut` (and `*mut`) as well as `&Cell` (and `*const Cell`) in const) - rust-lang#130118 (move Option::unwrap_unchecked into const_option feature gate) - rust-lang#130295 (Fix target-cpu fpu features on Armv8-R.) - rust-lang#130371 (Correctly account for niche-optimized tags in rustc_transmute) - rust-lang#130381 (library: Compute Rust exception class from its string repr) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 1ae2688 + 729aa49 commit dde7d66

File tree

181 files changed

+426
-1738
lines changed
  • rustc_error_codes/src/error_codes
  • rustc_feature/src
  • rustc_target/src/spec/targets
  • rustc_transmute/src/layout
  • library
  • src/tools
  • tests
  • Some content is hidden

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

    181 files changed

    +426
    -1738
    lines changed

    compiler/rustc_const_eval/messages.ftl

    Lines changed: 0 additions & 10 deletions
    Original file line numberDiff line numberDiff line change
    @@ -134,9 +134,6 @@ const_eval_incompatible_return_types =
    134134
    const_eval_incompatible_types =
    135135
    calling a function with argument of type {$callee_ty} passing data of type {$caller_ty}
    136136
    137-
    const_eval_interior_mutability_borrow =
    138-
    cannot borrow here, since the borrowed element may contain interior mutability
    139-
    140137
    const_eval_interior_mutable_data_refer =
    141138
    {const_eval_const_context}s cannot refer to interior mutable data
    142139
    .label = this borrow of an interior mutable value may end up in the final value
    @@ -230,9 +227,6 @@ const_eval_memory_exhausted =
    230227
    const_eval_modified_global =
    231228
    modifying a static's initial value from another static's initializer
    232229
    233-
    const_eval_mut_deref =
    234-
    mutation through a reference is not allowed in {const_eval_const_context}s
    235-
    236230
    const_eval_mutable_ptr_in_final = encountered mutable pointer in final value of {const_eval_intern_kind}
    237231
    238232
    const_eval_nested_static_in_thread_local = #[thread_local] does not support implicit nested statics, please create explicit static items and refer to them instead
    @@ -363,10 +357,6 @@ const_eval_too_generic =
    363357
    const_eval_too_many_caller_args =
    364358
    calling a function with more arguments than it expected
    365359
    366-
    const_eval_transient_mut_borrow = mutable references are not allowed in {const_eval_const_context}s
    367-
    368-
    const_eval_transient_mut_raw = raw mutable pointers are not allowed in {const_eval_const_context}s
    369-
    370360
    const_eval_try_block_from_output_non_const =
    371361
    `try` block cannot convert `{$ty}` to the result in {const_eval_const_context}s
    372362
    const_eval_unallowed_fn_pointer_call = function pointer calls are not allowed in {const_eval_const_context}s

    compiler/rustc_const_eval/src/check_consts/check.rs

    Lines changed: 25 additions & 229 deletions
    Large diffs are not rendered by default.

    compiler/rustc_const_eval/src/check_consts/ops.rs

    Lines changed: 5 additions & 111 deletions
    Original file line numberDiff line numberDiff line change
    @@ -8,7 +8,7 @@ use rustc_hir as hir;
    88
    use rustc_hir::def_id::DefId;
    99
    use rustc_infer::infer::TyCtxtInferExt;
    1010
    use rustc_infer::traits::{ImplSource, Obligation, ObligationCause};
    11-
    use rustc_middle::mir::{self, CallSource};
    11+
    use rustc_middle::mir::CallSource;
    1212
    use rustc_middle::span_bug;
    1313
    use rustc_middle::ty::print::{with_no_trimmed_paths, PrintTraitRefExt as _};
    1414
    use rustc_middle::ty::{
    @@ -391,27 +391,12 @@ impl<'tcx> NonConstOp<'tcx> for LiveDrop<'tcx> {
    391391
    }
    392392
    }
    393393

    394-
    #[derive(Debug)]
    395-
    /// A borrow of a type that contains an `UnsafeCell` somewhere. The borrow never escapes to
    396-
    /// the final value of the constant.
    397-
    pub(crate) struct TransientCellBorrow;
    398-
    impl<'tcx> NonConstOp<'tcx> for TransientCellBorrow {
    399-
    fn status_in_item(&self, _: &ConstCx<'_, 'tcx>) -> Status {
    400-
    Status::Unstable(sym::const_refs_to_cell)
    401-
    }
    402-
    fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
    403-
    ccx.tcx
    404-
    .sess
    405-
    .create_feature_err(errors::InteriorMutabilityBorrow { span }, sym::const_refs_to_cell)
    406-
    }
    407-
    }
    408-
    409394
    #[derive(Debug)]
    410395
    /// A borrow of a type that contains an `UnsafeCell` somewhere. The borrow might escape to
    411396
    /// the final value of the constant, and thus we cannot allow this (for now). We may allow
    412397
    /// it in the future for static items.
    413-
    pub(crate) struct CellBorrow;
    414-
    impl<'tcx> NonConstOp<'tcx> for CellBorrow {
    398+
    pub(crate) struct EscapingCellBorrow;
    399+
    impl<'tcx> NonConstOp<'tcx> for EscapingCellBorrow {
    415400
    fn importance(&self) -> DiagImportance {
    416401
    // Most likely the code will try to do mutation with these borrows, which
    417402
    // triggers its own errors. Only show this one if that does not happen.
    @@ -431,9 +416,9 @@ impl<'tcx> NonConstOp<'tcx> for CellBorrow {
    431416
    /// This op is for `&mut` borrows in the trailing expression of a constant
    432417
    /// which uses the "enclosing scopes rule" to leak its locals into anonymous
    433418
    /// static or const items.
    434-
    pub(crate) struct MutBorrow(pub hir::BorrowKind);
    419+
    pub(crate) struct EscapingMutBorrow(pub hir::BorrowKind);
    435420

    436-
    impl<'tcx> NonConstOp<'tcx> for MutBorrow {
    421+
    impl<'tcx> NonConstOp<'tcx> for EscapingMutBorrow {
    437422
    fn status_in_item(&self, _ccx: &ConstCx<'_, 'tcx>) -> Status {
    438423
    Status::Forbidden
    439424
    }
    @@ -460,49 +445,6 @@ impl<'tcx> NonConstOp<'tcx> for MutBorrow {
    460445
    }
    461446
    }
    462447

    463-
    #[derive(Debug)]
    464-
    pub(crate) struct TransientMutBorrow(pub hir::BorrowKind);
    465-
    466-
    impl<'tcx> NonConstOp<'tcx> for TransientMutBorrow {
    467-
    fn status_in_item(&self, _: &ConstCx<'_, 'tcx>) -> Status {
    468-
    Status::Unstable(sym::const_mut_refs)
    469-
    }
    470-
    471-
    fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
    472-
    let kind = ccx.const_kind();
    473-
    match self.0 {
    474-
    hir::BorrowKind::Raw => ccx
    475-
    .tcx
    476-
    .sess
    477-
    .create_feature_err(errors::TransientMutRawErr { span, kind }, sym::const_mut_refs),
    478-
    hir::BorrowKind::Ref => ccx.tcx.sess.create_feature_err(
    479-
    errors::TransientMutBorrowErr { span, kind },
    480-
    sym::const_mut_refs,
    481-
    ),
    482-
    }
    483-
    }
    484-
    }
    485-
    486-
    #[derive(Debug)]
    487-
    pub(crate) struct MutDeref;
    488-
    impl<'tcx> NonConstOp<'tcx> for MutDeref {
    489-
    fn status_in_item(&self, _: &ConstCx<'_, 'tcx>) -> Status {
    490-
    Status::Unstable(sym::const_mut_refs)
    491-
    }
    492-
    493-
    fn importance(&self) -> DiagImportance {
    494-
    // Usually a side-effect of a `TransientMutBorrow` somewhere.
    495-
    DiagImportance::Secondary
    496-
    }
    497-
    498-
    fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
    499-
    ccx.tcx.sess.create_feature_err(
    500-
    errors::MutDerefErr { span, kind: ccx.const_kind() },
    501-
    sym::const_mut_refs,
    502-
    )
    503-
    }
    504-
    }
    505-
    506448
    /// A call to a `panic()` lang item where the first argument is _not_ a `&str`.
    507449
    #[derive(Debug)]
    508450
    pub(crate) struct PanicNonStr;
    @@ -524,24 +466,6 @@ impl<'tcx> NonConstOp<'tcx> for RawPtrComparison {
    524466
    }
    525467
    }
    526468

    527-
    #[derive(Debug)]
    528-
    pub(crate) struct RawMutPtrDeref;
    529-
    impl<'tcx> NonConstOp<'tcx> for RawMutPtrDeref {
    530-
    fn status_in_item(&self, _: &ConstCx<'_, '_>) -> Status {
    531-
    Status::Unstable(sym::const_mut_refs)
    532-
    }
    533-
    534-
    #[allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable
    535-
    fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
    536-
    feature_err(
    537-
    &ccx.tcx.sess,
    538-
    sym::const_mut_refs,
    539-
    span,
    540-
    format!("dereferencing raw mutable pointers in {}s is unstable", ccx.const_kind(),),
    541-
    )
    542-
    }
    543-
    }
    544-
    545469
    /// Casting raw pointer or function pointer to an integer.
    546470
    /// Not currently intended to ever be allowed, even behind a feature gate: operation depends on
    547471
    /// allocation base addresses that are not known at compile-time.
    @@ -588,33 +512,3 @@ impl<'tcx> NonConstOp<'tcx> for ThreadLocalAccess {
    588512
    ccx.dcx().create_err(errors::ThreadLocalAccessErr { span })
    589513
    }
    590514
    }
    591-
    592-
    /// Types that cannot appear in the signature or locals of a `const fn`.
    593-
    pub(crate) mod mut_ref {
    594-
    use super::*;
    595-
    596-
    #[derive(Debug)]
    597-
    pub(crate) struct MutRef(pub mir::LocalKind);
    598-
    impl<'tcx> NonConstOp<'tcx> for MutRef {
    599-
    fn status_in_item(&self, _ccx: &ConstCx<'_, 'tcx>) -> Status {
    600-
    Status::Unstable(sym::const_mut_refs)
    601-
    }
    602-
    603-
    fn importance(&self) -> DiagImportance {
    604-
    match self.0 {
    605-
    mir::LocalKind::Temp => DiagImportance::Secondary,
    606-
    mir::LocalKind::ReturnPointer | mir::LocalKind::Arg => DiagImportance::Primary,
    607-
    }
    608-
    }
    609-
    610-
    #[allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable
    611-
    fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
    612-
    feature_err(
    613-
    &ccx.tcx.sess,
    614-
    sym::const_mut_refs,
    615-
    span,
    616-
    format!("mutable references are not allowed in {}s", ccx.const_kind()),
    617-
    )
    618-
    }
    619-
    }
    620-
    }

    compiler/rustc_const_eval/src/errors.rs

    Lines changed: 0 additions & 31 deletions
    Original file line numberDiff line numberDiff line change
    @@ -93,30 +93,6 @@ pub(crate) struct PanicNonStrErr {
    9393
    pub span: Span,
    9494
    }
    9595

    96-
    #[derive(Diagnostic)]
    97-
    #[diag(const_eval_mut_deref, code = E0658)]
    98-
    pub(crate) struct MutDerefErr {
    99-
    #[primary_span]
    100-
    pub span: Span,
    101-
    pub kind: ConstContext,
    102-
    }
    103-
    104-
    #[derive(Diagnostic)]
    105-
    #[diag(const_eval_transient_mut_borrow, code = E0658)]
    106-
    pub(crate) struct TransientMutBorrowErr {
    107-
    #[primary_span]
    108-
    pub span: Span,
    109-
    pub kind: ConstContext,
    110-
    }
    111-
    112-
    #[derive(Diagnostic)]
    113-
    #[diag(const_eval_transient_mut_raw, code = E0658)]
    114-
    pub(crate) struct TransientMutRawErr {
    115-
    #[primary_span]
    116-
    pub span: Span,
    117-
    pub kind: ConstContext,
    118-
    }
    119-
    12096
    #[derive(Diagnostic)]
    12197
    #[diag(const_eval_max_num_nodes_in_const)]
    12298
    pub(crate) struct MaxNumNodesInConstErr {
    @@ -217,13 +193,6 @@ pub(crate) struct InteriorMutableDataRefer {
    217193
    pub teach: bool,
    218194
    }
    219195

    220-
    #[derive(Diagnostic)]
    221-
    #[diag(const_eval_interior_mutability_borrow)]
    222-
    pub(crate) struct InteriorMutabilityBorrow {
    223-
    #[primary_span]
    224-
    pub span: Span,
    225-
    }
    226-
    227196
    #[derive(LintDiagnostic)]
    228197
    #[diag(const_eval_long_running)]
    229198
    #[note]

    compiler/rustc_error_codes/src/error_codes/E0764.md

    Lines changed: 0 additions & 4 deletions
    Original file line numberDiff line numberDiff line change
    @@ -3,8 +3,6 @@ A mutable reference was used in a constant.
    33
    Erroneous code example:
    44

    55
    ```compile_fail,E0764
    6-
    #![feature(const_mut_refs)]
    7-
    86
    fn main() {
    97
    const OH_NO: &'static mut usize = &mut 1; // error!
    108
    }
    @@ -26,8 +24,6 @@ Remember: you cannot use a function call inside a constant or static. However,
    2624
    you can totally use it in constant functions:
    2725

    2826
    ```
    29-
    #![feature(const_mut_refs)]
    30-
    3127
    const fn foo(x: usize) -> usize {
    3228
    let mut y = 1;
    3329
    let z = &mut y;

    compiler/rustc_feature/src/accepted.rs

    Lines changed: 4 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -143,10 +143,14 @@ declare_features! (
    143143
    (accepted, const_let, "1.33.0", Some(48821)),
    144144
    /// Allows the use of `loop` and `while` in constants.
    145145
    (accepted, const_loop, "1.46.0", Some(52000)),
    146+
    /// Allows using `&mut` in constant functions.
    147+
    (accepted, const_mut_refs, "CURRENT_RUSTC_VERSION", Some(57349)),
    146148
    /// Allows panicking during const eval (producing compile-time errors).
    147149
    (accepted, const_panic, "1.57.0", Some(51999)),
    148150
    /// Allows dereferencing raw pointers during const eval.
    149151
    (accepted, const_raw_ptr_deref, "1.58.0", Some(51911)),
    152+
    /// Allows references to types with interior mutability within constants
    153+
    (accepted, const_refs_to_cell, "CURRENT_RUSTC_VERSION", Some(80384)),
    150154
    /// Allows implementing `Copy` for closures where possible (RFC 2132).
    151155
    (accepted, copy_closures, "1.26.0", Some(44490)),
    152156
    /// Allows `crate` in paths.

    compiler/rustc_feature/src/unstable.rs

    Lines changed: 0 additions & 4 deletions
    Original file line numberDiff line numberDiff line change
    @@ -403,12 +403,8 @@ declare_features! (
    403403
    (incomplete, const_closures, "1.68.0", Some(106003)),
    404404
    /// Allows `for _ in _` loops in const contexts.
    405405
    (unstable, const_for, "1.56.0", Some(87575)),
    406-
    /// Allows using `&mut` in constant functions.
    407-
    (unstable, const_mut_refs, "1.41.0", Some(57349)),
    408406
    /// Be more precise when looking for live drops in a const context.
    409407
    (unstable, const_precise_live_drops, "1.46.0", Some(73255)),
    410-
    /// Allows references to types with interior mutability within constants
    411-
    (unstable, const_refs_to_cell, "1.51.0", Some(80384)),
    412408
    /// Allows creating pointers and references to `static` items in constants.
    413409
    (unstable, const_refs_to_static, "1.78.0", Some(119618)),
    414410
    /// Allows `impl const Trait for T` syntax.

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

    Lines changed: 6 additions & 6 deletions
    Original file line numberDiff line numberDiff line change
    @@ -21,16 +21,16 @@ pub(crate) fn target() -> Target {
    2121
    linker: Some("rust-lld".into()),
    2222
    relocation_model: RelocModel::Static,
    2323
    panic_strategy: PanicStrategy::Abort,
    24-
    // The Cortex-R52 has two variants with respect to floating-point support:
    25-
    // 1. fp-armv8, SP-only, with 16 DP (32 SP) registers
    26-
    // 2. neon-fp-armv8, SP+DP, with 32 DP registers
    27-
    // Use the lesser of these two options as the default, as it will produce code
    28-
    // compatible with either variant.
    24+
    // Armv8-R requires a minimum set of floating-point features equivalent to:
    25+
    // fp-armv8, SP-only, with 16 DP (32 SP) registers
    26+
    // LLVM defines Armv8-R to include these features automatically.
    27+
    //
    28+
    // The Cortex-R52 supports these default features and optionally includes:
    29+
    // neon-fp-armv8, SP+DP, with 32 DP registers
    2930
    //
    3031
    // Reference:
    3132
    // Arm Cortex-R52 Processor Technical Reference Manual
    3233
    // - Chapter 15 Advanced SIMD and floating-point support
    33-
    features: "+fp-armv8,-fp64,-d32".into(),
    3434
    max_atomic_width: Some(64),
    3535
    emit_debug_gdb_scripts: false,
    3636
    // GCC defaults to 8 for arm-none here.

    compiler/rustc_transmute/src/layout/tree.rs

    Lines changed: 25 additions & 10 deletions
    Original file line numberDiff line numberDiff line change
    @@ -175,7 +175,7 @@ pub(crate) mod rustc {
    175175
    use rustc_middle::ty::{self, AdtDef, AdtKind, List, ScalarInt, Ty, TyCtxt, TypeVisitableExt};
    176176
    use rustc_span::ErrorGuaranteed;
    177177
    use rustc_target::abi::{
    178-
    FieldIdx, Fields F438 Shape, Layout, Size, TyAndLayout, VariantIdx, Variants,
    178+
    FieldIdx, FieldsShape, Layout, Size, TagEncoding, TyAndLayout, VariantIdx, Variants,
    179179
    };
    180180

    181181
    use super::Tree;
    @@ -319,11 +319,17 @@ pub(crate) mod rustc {
    319319
    assert!(def.is_enum());
    320320

    321321
    // Computes the variant of a given index.
    322-
    let layout_of_variant = |index| {
    322+
    let layout_of_variant = |index, encoding: Option<TagEncoding<VariantIdx>>| {
    323323
    let tag = cx.tcx.tag_for_variant((cx.tcx.erase_regions(ty), index));
    324324
    let variant_def = Def::Variant(def.variant(index));
    325325
    let variant_layout = ty_variant(cx, (ty, layout), index);
    326-
    Self::from_variant(variant_def, tag, (ty, variant_layout), layout.size, cx)
    326+
    Self::from_variant(
    327+
    variant_def,
    328+
    tag.map(|tag| (tag, index, encoding.unwrap())),
    329+
    (ty, variant_layout),
    330+
    layout.size,
    331+
    cx,
    332+
    )
    327333
    };
    328334

    329335
    // We consider three kinds of enums, each demanding a different
    @@ -345,9 +351,9 @@ pub(crate) mod rustc {
    345351
    Variants::Single { index } => {
    346352
    // `Variants::Single` on enums with variants denotes that
    347353
    // the enum delegates its layout to the variant at `index`.
    348-
    layout_of_variant(*index)
    354+
    layout_of_variant(*index, None)
    349355
    }
    350-
    Variants::Multiple { tag_field, .. } => {
    356+
    Variants::Multiple { tag, tag_encoding, tag_field, .. } => {
    351357
    // `Variants::Multiple` denotes an enum with multiple
    352358
    // variants. The layout of such an enum is the disjunction
    353359
    // of the layouts of its tagged variants.
    @@ -359,7 +365,7 @@ pub(crate) mod rustc {
    359365
    let variants = def.discriminants(cx.tcx()).try_fold(
    360366
    Self::uninhabited(),
    361367
    |variants, (idx, ref discriminant)| {
    362-
    let variant = layout_of_variant(idx)?;
    368+
    let variant = layout_of_variant(idx, Some(tag_encoding.clone()))?;
    363369
    Result::<Self, Err>::Ok(variants.or(variant))
    364370
    },
    365371
    )?;
    @@ -380,7 +386,7 @@ pub(crate) mod rustc {
    380386
    /// `0`.
    381387
    fn from_variant(
    382388
    def: Def<'tcx>,
    383-
    tag: Option<ScalarInt>,
    389+
    tag: Option<(ScalarInt, VariantIdx, TagEncoding<VariantIdx>)>,
    384390
    (ty, layout): (Ty<'tcx>, Layout<'tcx>),
    385391
    total_size: Size,
    386392
    cx: LayoutCx<'tcx, TyCtxt<'tcx>>,
    @@ -400,9 +406,18 @@ pub(crate) mod rustc {
    400406
    let mut struct_tree = Self::def(def);
    401407

    402408
    // If a `tag` is provided, place it at the start of the layout.
    403-
    if let Some(tag) = tag {
    404-
    size += tag.size();
    405-
    struct_tree = struct_tree.then(Self::from_tag(tag, cx.tcx));
    409+
    if let Some((tag, index, encoding)) = &tag {
    410+
    match encoding {
    411+
    TagEncoding::Direct => {
    412+
    size += tag.size();
    413+
    }
    414+
    TagEncoding::Niche { niche_variants, .. } => {
    415+
    if !niche_variants.contains(index) {
    416+
    size += tag.size();
    417+
    }
    418+
    }
    419+
    }
    420+
    struct_tree = struct_tree.then(Self::from_tag(*tag, cx.tcx));
    406421
    }
    407422

    408423
    // Append the fields, in memory order, to the layout.

    0 commit comments

    Comments
     (0)
    0