diff options
| author | Aapo Alasuutari <aapo.alasuutari@gmail.com> | 2025-09-15 20:32:06 +0300 |
|---|---|---|
| committer | Aapo Alasuutari <aapo.alasuutari@gmail.com> | 2025-09-15 20:50:00 +0300 |
| commit | c4a87eb62cd74e31e5d3889741a76a4bb2a48ed6 (patch) | |
| tree | 4ecff737192aec670c2ccb0f522ca66ca2d74c4c | |
| parent | 35bae9df1dfb164de7be95180a0982312128d559 (diff) | |
| download | rust-c4a87eb62cd74e31e5d3889741a76a4bb2a48ed6.tar.gz rust-c4a87eb62cd74e31e5d3889741a76a4bb2a48ed6.zip | |
fix: Move CoerceShared into ops
| -rw-r--r-- | library/core/src/marker.rs | 9 | ||||
| -rw-r--r-- | library/core/src/ops/mod.rs | 3 | ||||
| -rw-r--r-- | library/core/src/ops/reborrow.rs | 10 | ||||
| -rw-r--r-- | tests/ui/feature-gates/feature-gate-reborrow-coerce-shared.rs | 2 | ||||
| -rw-r--r-- | tests/ui/feature-gates/feature-gate-reborrow-coerce-shared.stderr | 4 | ||||
| -rw-r--r-- | tests/ui/reborrow/custom_mut_coerce_shared.rs | 3 | ||||
| -rw-r--r-- | tests/ui/reborrow/custom_mut_coerce_shared.stderr | 4 |
7 files changed, 20 insertions, 15 deletions
diff --git a/library/core/src/marker.rs b/library/core/src/marker.rs index 8541a5b91cd..d03d7a43469 100644 --- a/library/core/src/marker.rs +++ b/library/core/src/marker.rs @@ -1372,12 +1372,3 @@ pub trait CoercePointeeValidated { pub trait Reborrow { // Empty. } - -/// Allows reborrowable value to be reborrowed as shared, creating a copy of -/// that disables the source for writes for the lifetime of the copy. -#[lang = "coerce_shared"] -#[unstable(feature = "reborrow", issue = "145612")] -pub trait CoerceShared: Reborrow { - /// The type of this value when reborrowed as shared. - type Target: Copy; -} diff --git a/library/core/src/ops/mod.rs b/library/core/src/ops/mod.rs index 87dd873fdb5..9814f5d5795 100644 --- a/library/core/src/ops/mod.rs +++ b/library/core/src/ops/mod.rs @@ -149,6 +149,7 @@ mod function; mod index; mod index_range; mod range; +mod reborrow; mod try_trait; mod unsize; @@ -189,6 +190,8 @@ pub use self::range::{Bound, RangeBounds, RangeInclusive, RangeToInclusive}; 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; #[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 new file mode 100644 index 00000000000..90288f766d5 --- /dev/null +++ b/library/core/src/ops/reborrow.rs @@ -0,0 +1,10 @@ +use crate::marker::Reborrow; + +/// Allows reborrowable value to be reborrowed as shared, creating a copy +/// that disables the source for writes for the lifetime of the copy. +#[lang = "coerce_shared"] +#[unstable(feature = "reborrow", issue = "145612")] +pub trait CoerceShared: Reborrow { + /// The type of this value when reborrowed as shared. + type Target: Copy; +} diff --git a/tests/ui/feature-gates/feature-gate-reborrow-coerce-shared.rs b/tests/ui/feature-gates/feature-gate-reborrow-coerce-shared.rs index 48a14959d8d..c8ca4537089 100644 --- a/tests/ui/feature-gates/feature-gate-reborrow-coerce-shared.rs +++ b/tests/ui/feature-gates/feature-gate-reborrow-coerce-shared.rs @@ -1,3 +1,3 @@ -use std::marker::CoerceShared; //~ ERROR use of unstable library feature `reborrow` +use std::ops::CoerceShared; //~ ERROR use of unstable library feature `reborrow` fn main() {} diff --git a/tests/ui/feature-gates/feature-gate-reborrow-coerce-shared.stderr b/tests/ui/feature-gates/feature-gate-reborrow-coerce-shared.stderr index c4c5e06778a..dbbbcdf2fd5 100644 --- a/tests/ui/feature-gates/feature-gate-reborrow-coerce-shared.stderr +++ b/tests/ui/feature-gates/feature-gate-reborrow-coerce-shared.stderr @@ -1,8 +1,8 @@ error[E0658]: use of unstable library feature `reborrow` --> $DIR/feature-gate-reborrow-coerce-shared.rs:1:5 | -LL | use std::marker::CoerceShared; - | ^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | use std::ops::CoerceShared; + | ^^^^^^^^^^^^^^^^^^^^^^ | = note: see issue #145612 <https://github.com/rust-lang/rust/issues/145612> for more information = help: add `#![feature(reborrow)]` to the crate attributes to enable diff --git a/tests/ui/reborrow/custom_mut_coerce_shared.rs b/tests/ui/reborrow/custom_mut_coerce_shared.rs index b292b5b073c..28d802aabff 100644 --- a/tests/ui/reborrow/custom_mut_coerce_shared.rs +++ b/tests/ui/reborrow/custom_mut_coerce_shared.rs @@ -1,5 +1,6 @@ #![feature(reborrow)] -use std::marker::{Reborrow, CoerceShared}; +use std::marker::Reborrow; +use std::ops::CoerceShared; 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 508651badc0..90d8a981605 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:23:12 + --> $DIR/custom_mut_coerce_shared.rs:24: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:19:4 + --> $DIR/custom_mut_coerce_shared.rs:20:4 | LL | fn method(a: CustomRef<'_, ()>) {} | ^^^^^^ -------------------- |
