From: woppopo Date: Sat, 4 Dec 2021 12:57:39 +0000 (+0900) Subject: Make `Borrow` and `BorrowMut` impls `const` X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=8f68bdc38024c471f925ce8b6572ec41546229e1;hp=68a698baf6bfc61d85ce6e25122a092c60c7f21a;p=rust.git Make `Borrow` and `BorrowMut` impls `const` --- diff --git a/library/core/src/array/mod.rs b/library/core/src/array/mod.rs index b27c36baf37..e89659c41ea 100644 --- a/library/core/src/array/mod.rs +++ b/library/core/src/array/mod.rs @@ -149,14 +149,16 @@ fn as_mut(&mut self) -> &mut [T] { } #[stable(feature = "array_borrow", since = "1.4.0")] -impl Borrow<[T]> for [T; N] { +#[rustc_const_unstable(feature = "const_borrow", issue = "91522")] +impl const Borrow<[T]> for [T; N] { fn borrow(&self) -> &[T] { self } } #[stable(feature = "array_borrow", since = "1.4.0")] -impl BorrowMut<[T]> for [T; N] { +#[rustc_const_unstable(feature = "const_borrow", issue = "91522")] +impl const BorrowMut<[T]> for [T; N] { fn borrow_mut(&mut self) -> &mut [T] { self } diff --git a/library/core/src/borrow.rs b/library/core/src/borrow.rs index f28be20aaa1..58eabecf3f0 100644 --- a/library/core/src/borrow.rs +++ b/library/core/src/borrow.rs @@ -205,7 +205,8 @@ pub trait BorrowMut: Borrow { } #[stable(feature = "rust1", since = "1.0.0")] -impl Borrow for T { +#[rustc_const_unstable(feature = "const_borrow", issue = "91522")] +impl const Borrow for T { #[rustc_diagnostic_item = "noop_method_borrow"] fn borrow(&self) -> &T { self @@ -213,28 +214,32 @@ fn borrow(&self) -> &T { } #[stable(feature = "rust1", since = "1.0.0")] -impl BorrowMut for T { +#[rustc_const_unstable(feature = "const_borrow", issue = "91522")] +impl const BorrowMut for T { fn borrow_mut(&mut self) -> &mut T { self } } #[stable(feature = "rust1", since = "1.0.0")] -impl Borrow for &T { +#[rustc_const_unstable(feature = "const_borrow", issue = "91522")] +impl const Borrow for &T { fn borrow(&self) -> &T { &**self } } #[stable(feature = "rust1", since = "1.0.0")] -impl Borrow for &mut T { +#[rustc_const_unstable(feature = "const_borrow", issue = "91522")] +impl const Borrow for &mut T { fn borrow(&self) -> &T { &**self } } #[stable(feature = "rust1", since = "1.0.0")] -impl BorrowMut for &mut T { +#[rustc_const_unstable(feature = "const_borrow", issue = "91522")] +impl const BorrowMut for &mut T { fn borrow_mut(&mut self) -> &mut T { &mut **self }