From 719880dd2a3081ca69fd41eac82f45d84b90bb06 Mon Sep 17 00:00:00 2001 From: Aapo Alasuutari Date: Thu, 21 Aug 2025 23:36:21 +0300 Subject: [PATCH 1/3] Introduce reborrow unstable feature --- compiler/rustc_feature/src/unstable.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/compiler/rustc_feature/src/unstable.rs b/compiler/rustc_feature/src/unstable.rs index 746871982ce80..6a7370c24729e 100644 --- a/compiler/rustc_feature/src/unstable.rs +++ b/compiler/rustc_feature/src/unstable.rs @@ -614,6 +614,7 @@ declare_features! ( (unstable, proc_macro_hygiene, "1.30.0", Some(54727)), /// Allows the use of raw-dylibs on ELF platforms (incomplete, raw_dylib_elf, "1.87.0", Some(135694)), + (unstable, reborrow, "CURRENT_RUSTC_VERSION", None), /// Makes `&` and `&mut` patterns eat only one layer of references in Rust 2024. (incomplete, ref_pat_eat_one_layer_2024, "1.79.0", Some(123076)), /// Makes `&` and `&mut` patterns eat only one layer of references in Rust 2024—structural variant From 5af359162e5ebf6c9ad318e7e45ac2f2b47b4b74 Mon Sep 17 00:00:00 2001 From: Aapo Alasuutari Date: Thu, 21 Aug 2025 23:42:46 +0300 Subject: [PATCH 2/3] Introduce Reborrow lang item and trait --- compiler/rustc_feature/src/unstable.rs | 2 +- compiler/rustc_hir/src/lang_items.rs | 3 +++ compiler/rustc_span/src/symbol.rs | 1 + library/core/src/lib.rs | 1 + library/core/src/marker.rs | 8 ++++++++ 5 files changed, 14 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_feature/src/unstable.rs b/compiler/rustc_feature/src/unstable.rs index 6a7370c24729e..d70d15b681546 100644 --- a/compiler/rustc_feature/src/unstable.rs +++ b/compiler/rustc_feature/src/unstable.rs @@ -614,7 +614,7 @@ declare_features! ( (unstable, proc_macro_hygiene, "1.30.0", Some(54727)), /// Allows the use of raw-dylibs on ELF platforms (incomplete, raw_dylib_elf, "1.87.0", Some(135694)), - (unstable, reborrow, "CURRENT_RUSTC_VERSION", None), + (unstable, reborrow, "CURRENT_RUSTC_VERSION", Some(145612)), /// Makes `&` and `&mut` patterns eat only one layer of references in Rust 2024. (incomplete, ref_pat_eat_one_layer_2024, "1.79.0", Some(123076)), /// Makes `&` and `&mut` patterns eat only one layer of references in Rust 2024—structural variant diff --git a/compiler/rustc_hir/src/lang_items.rs b/compiler/rustc_hir/src/lang_items.rs index 905b84a8cbeb6..0464665b41fc5 100644 --- a/compiler/rustc_hir/src/lang_items.rs +++ b/compiler/rustc_hir/src/lang_items.rs @@ -437,6 +437,9 @@ language_item_table! { DefaultTrait1, sym::default_trait1, default_trait1_trait, Target::Trait, GenericRequirement::None; ContractCheckEnsures, sym::contract_check_ensures, contract_check_ensures_fn, Target::Fn, GenericRequirement::None; + + // Reborrowing related lang-items + Reborrow, sym::reborrow, reborrow, Target::Trait, GenericRequirement::Exact(0); } /// The requirement imposed on the generics of a lang item diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index dcb1becc957db..8465845d792f2 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -1754,6 +1754,7 @@ symbols! { readonly, realloc, reason, + reborrow, receiver, receiver_target, recursion_limit, diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index 71abd707374cf..f69d6a98592ae 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -172,6 +172,7 @@ #![feature(no_core)] #![feature(optimize_attribute)] #![feature(prelude_import)] +#![feature(reborrow)] #![feature(repr_simd)] #![feature(rustc_allow_const_fn_unstable)] #![feature(rustc_attrs)] diff --git a/library/core/src/marker.rs b/library/core/src/marker.rs index ba00ee17b6528..8ad58599c6815 100644 --- a/library/core/src/marker.rs +++ b/library/core/src/marker.rs @@ -1365,3 +1365,11 @@ pub macro CoercePointee($item:item) { pub trait CoercePointeeValidated { /* compiler built-in */ } + +/// Allows value to be reborrowed as exclusive, creating a copy of the value +/// that disables the source for reads and writes for the lifetime of the copy. +#[lang = "reborrow"] +#[unstable(feature = "reborrow", issue = "145612")] +pub trait Reborrow { + // Empty. +} From fd44708aa33e92fb165b35916bb120033bce9f23 Mon Sep 17 00:00:00 2001 From: Aapo Alasuutari Date: Fri, 22 Aug 2025 00:15:59 +0300 Subject: [PATCH 3/3] Add reborrow feature gate test --- tests/ui/feature-gates/feature-gate-reborrow.rs | 3 +++ tests/ui/feature-gates/feature-gate-reborrow.stderr | 13 +++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 tests/ui/feature-gates/feature-gate-reborrow.rs create mode 100644 tests/ui/feature-gates/feature-gate-reborrow.stderr diff --git a/tests/ui/feature-gates/feature-gate-reborrow.rs b/tests/ui/feature-gates/feature-gate-reborrow.rs new file mode 100644 index 0000000000000..f016f6c6bfa59 --- /dev/null +++ b/tests/ui/feature-gates/feature-gate-reborrow.rs @@ -0,0 +1,3 @@ +use std::marker::Reborrow; //~ ERROR use of unstable library feature `reborrow` + +fn main() {} diff --git a/tests/ui/feature-gates/feature-gate-reborrow.stderr b/tests/ui/feature-gates/feature-gate-reborrow.stderr new file mode 100644 index 0000000000000..5e3033f3bf1fe --- /dev/null +++ b/tests/ui/feature-gates/feature-gate-reborrow.stderr @@ -0,0 +1,13 @@ +error[E0658]: use of unstable library feature `reborrow` + --> $DIR/feature-gate-reborrow.rs:1:5 + | +LL | use std::marker::Reborrow; + | ^^^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #145612 for more information + = help: add `#![feature(reborrow)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0658`.