From e88fa086fb597041a207a9bb5df0654628d57b1a Mon Sep 17 00:00:00 2001 From: Aapo Alasuutari Date: Sat, 27 Sep 2025 01:11:01 +0300 Subject: [PATCH] move Reborrow to ops, fix fmt issues --- library/core/src/marker.rs | 8 -------- library/core/src/ops/mod.rs | 2 +- library/core/src/ops/reborrow.rs | 8 +++++++- tests/ui/feature-gates/feature-gate-reborrow.rs | 2 +- tests/ui/feature-gates/feature-gate-reborrow.stderr | 4 ++-- tests/ui/reborrow/custom_mut.rs | 2 +- tests/ui/reborrow/custom_mut_coerce_shared.rs | 3 +-- tests/ui/reborrow/custom_mut_coerce_shared.stderr | 4 ++-- tests/ui/reborrow/option_mut.rs | 2 +- tests/ui/reborrow/option_mut.stderr | 4 ++-- tests/ui/reborrow/pin_mut.rs | 2 +- tests/ui/reborrow/pin_mut.stderr | 4 ++-- tests/ui/reborrow/pin_mut_coerce_shared.rs | 1 - 13 files changed, 21 insertions(+), 25 deletions(-) diff --git a/library/core/src/marker.rs b/library/core/src/marker.rs index d03d7a43469a..fc715207d5da 100644 --- a/library/core/src/marker.rs +++ b/library/core/src/marker.rs @@ -1364,11 +1364,3 @@ 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. -} diff --git a/library/core/src/ops/mod.rs b/library/core/src/ops/mod.rs index 9814f5d5795c..ab1ad407ee28 100644 --- a/library/core/src/ops/mod.rs +++ b/library/core/src/ops/mod.rs @@ -191,7 +191,7 @@ pub use self::range::{OneSidedRange, OneSidedRangeBound}; #[stable(feature = "rust1", since = "1.0.0")] pub use self::range::{Range, RangeFrom, RangeFull, RangeTo}; #[unstable(feature = "reborrow", issue = "145612")] -pub use self::reborrow::CoerceShared; +pub use self::reborrow::{CoerceShared, Reborrow}; #[unstable(feature = "try_trait_v2_residual", issue = "91285")] pub use self::try_trait::Residual; #[unstable(feature = "try_trait_v2_yeet", issue = "96374")] diff --git a/library/core/src/ops/reborrow.rs b/library/core/src/ops/reborrow.rs index 90288f766d50..f83f4233a4de 100644 --- a/library/core/src/ops/reborrow.rs +++ b/library/core/src/ops/reborrow.rs @@ -1,4 +1,10 @@ -use crate::marker::Reborrow; +/// 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. +} /// Allows reborrowable value to be reborrowed as shared, creating a copy /// that disables the source for writes for the lifetime of the copy. diff --git a/tests/ui/feature-gates/feature-gate-reborrow.rs b/tests/ui/feature-gates/feature-gate-reborrow.rs index f016f6c6bfa5..96eecfb28a10 100644 --- a/tests/ui/feature-gates/feature-gate-reborrow.rs +++ b/tests/ui/feature-gates/feature-gate-reborrow.rs @@ -1,3 +1,3 @@ -use std::marker::Reborrow; //~ ERROR use of unstable library feature `reborrow` +use std::ops::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 index 5e3033f3bf1f..1224909f564b 100644 --- a/tests/ui/feature-gates/feature-gate-reborrow.stderr +++ b/tests/ui/feature-gates/feature-gate-reborrow.stderr @@ -1,8 +1,8 @@ error[E0658]: use of unstable library feature `reborrow` --> $DIR/feature-gate-reborrow.rs:1:5 | -LL | use std::marker::Reborrow; - | ^^^^^^^^^^^^^^^^^^^^^ +LL | use std::ops::Reborrow; + | ^^^^^^^^^^^^^^^^^^ | = note: see issue #145612 for more information = help: add `#![feature(reborrow)]` to the crate attributes to enable diff --git a/tests/ui/reborrow/custom_mut.rs b/tests/ui/reborrow/custom_mut.rs index b55a5e6faa3d..1e7c46932382 100644 --- a/tests/ui/reborrow/custom_mut.rs +++ b/tests/ui/reborrow/custom_mut.rs @@ -1,5 +1,5 @@ #![feature(reborrow)] -use std::marker::Reborrow; +use std::ops::Reborrow; struct CustomMut<'a, T>(&'a mut T); impl<'a, T> Reborrow for CustomMut<'a, T> {} diff --git a/tests/ui/reborrow/custom_mut_coerce_shared.rs b/tests/ui/reborrow/custom_mut_coerce_shared.rs index 28d802aabffe..e2d25835c093 100644 --- a/tests/ui/reborrow/custom_mut_coerce_shared.rs +++ b/tests/ui/reborrow/custom_mut_coerce_shared.rs @@ -1,6 +1,5 @@ #![feature(reborrow)] -use std::marker::Reborrow; -use std::ops::CoerceShared; +use std::ops::{CoerceShared, Reborrow}; struct CustomMut<'a, T>(&'a mut T); impl<'a, T> Reborrow for CustomMut<'a, T> {} diff --git a/tests/ui/reborrow/custom_mut_coerce_shared.stderr b/tests/ui/reborrow/custom_mut_coerce_shared.stderr index 90d8a9816054..508651badc0a 100644 --- a/tests/ui/reborrow/custom_mut_coerce_shared.stderr +++ b/tests/ui/reborrow/custom_mut_coerce_shared.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/custom_mut_coerce_shared.rs:24:12 + --> $DIR/custom_mut_coerce_shared.rs:23:12 | LL | method(a); | ------ ^ expected `CustomRef<'_, ()>`, found `CustomMut<'_, ()>` @@ -9,7 +9,7 @@ LL | method(a); = note: expected struct `CustomRef<'_, ()>` found struct `CustomMut<'_, ()>` note: function defined here - --> $DIR/custom_mut_coerce_shared.rs:20:4 + --> $DIR/custom_mut_coerce_shared.rs:19:4 | LL | fn method(a: CustomRef<'_, ()>) {} | ^^^^^^ -------------------- diff --git a/tests/ui/reborrow/option_mut.rs b/tests/ui/reborrow/option_mut.rs index 60b7145a7b2e..04d8301772de 100644 --- a/tests/ui/reborrow/option_mut.rs +++ b/tests/ui/reborrow/option_mut.rs @@ -1,4 +1,4 @@ -fn method(a: Option<& mut ()>) {} +fn method(a: Option<&mut ()>) {} fn main() { let a = Some(&mut ()); diff --git a/tests/ui/reborrow/option_mut.stderr b/tests/ui/reborrow/option_mut.stderr index 497319d2e903..d665e266079e 100644 --- a/tests/ui/reborrow/option_mut.stderr +++ b/tests/ui/reborrow/option_mut.stderr @@ -11,8 +11,8 @@ LL | let _ = method(a); note: consider changing this parameter type in function `method` to borrow instead if owning the value isn't necessary --> $DIR/option_mut.rs:1:14 | -LL | fn method(a: Option<& mut ()>) {} - | ------ ^^^^^^^^^^^^^^^^ this parameter takes ownership of the value +LL | fn method(a: Option<&mut ()>) {} + | ------ ^^^^^^^^^^^^^^^ this parameter takes ownership of the value | | | in this function diff --git a/tests/ui/reborrow/pin_mut.rs b/tests/ui/reborrow/pin_mut.rs index 966106969943..959cb14f8c9a 100644 --- a/tests/ui/reborrow/pin_mut.rs +++ b/tests/ui/reborrow/pin_mut.rs @@ -1,6 +1,6 @@ use std::pin::Pin; -fn method(a: Pin<& mut ()>) {} +fn method(a: Pin<&mut ()>) {} fn main() { let a = &mut (); diff --git a/tests/ui/reborrow/pin_mut.stderr b/tests/ui/reborrow/pin_mut.stderr index 8a10e2d9af26..64e3f603e111 100644 --- a/tests/ui/reborrow/pin_mut.stderr +++ b/tests/ui/reborrow/pin_mut.stderr @@ -11,8 +11,8 @@ LL | let _ = method(a); note: consider changing this parameter type in function `method` to borrow instead if owning the value isn't necessary --> $DIR/pin_mut.rs:3:14 | -LL | fn method(a: Pin<& mut ()>) {} - | ------ ^^^^^^^^^^^^^ this parameter takes ownership of the value +LL | fn method(a: Pin<&mut ()>) {} + | ------ ^^^^^^^^^^^^ this parameter takes ownership of the value | | | in this function diff --git a/tests/ui/reborrow/pin_mut_coerce_shared.rs b/tests/ui/reborrow/pin_mut_coerce_shared.rs index fd529195fe01..06af0b765d04 100644 --- a/tests/ui/reborrow/pin_mut_coerce_shared.rs +++ b/tests/ui/reborrow/pin_mut_coerce_shared.rs @@ -10,5 +10,4 @@ fn main() { //~| NOTE arguments to this function are incorrect //~| NOTE types differ in mutability //~| NOTE expected struct `Pin<&()>` - //~| NOTE found struct `Pin<&mut ()>` }