Rollup merge of #90270 - woppopo:const_borrow_trait, r=dtolnay

Make `Borrow` and `BorrowMut` impls `const`

Tracking issue: #91522
This commit is contained in:
Matthias Krüger 2021-12-11 17:35:24 +01:00 committed by GitHub
commit 40482bb539
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 7 deletions

View file

@ -162,14 +162,16 @@ impl<T, const N: usize> AsMut<[T]> for [T; N] {
}
#[stable(feature = "array_borrow", since = "1.4.0")]
impl<T, const N: usize> Borrow<[T]> for [T; N] {
#[rustc_const_unstable(feature = "const_borrow", issue = "91522")]
impl<T, const N: usize> const Borrow<[T]> for [T; N] {
fn borrow(&self) -> &[T] {
self
}
}
#[stable(feature = "array_borrow", since = "1.4.0")]
impl<T, const N: usize> BorrowMut<[T]> for [T; N] {
#[rustc_const_unstable(feature = "const_borrow", issue = "91522")]
impl<T, const N: usize> const BorrowMut<[T]> for [T; N] {
fn borrow_mut(&mut self) -> &mut [T] {
self
}

View file

@ -205,7 +205,8 @@ pub trait BorrowMut<Borrowed: ?Sized>: Borrow<Borrowed> {
}
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: ?Sized> Borrow<T> for T {
#[rustc_const_unstable(feature = "const_borrow", issue = "91522")]
impl<T: ?Sized> const Borrow<T> for T {
#[rustc_diagnostic_item = "noop_method_borrow"]
fn borrow(&self) -> &T {
self
@ -213,28 +214,32 @@ impl<T: ?Sized> Borrow<T> for T {
}
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: ?Sized> BorrowMut<T> for T {
#[rustc_const_unstable(feature = "const_borrow", issue = "91522")]
impl<T: ?Sized> const BorrowMut<T> for T {
fn borrow_mut(&mut self) -> &mut T {
self
}
}
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: ?Sized> Borrow<T> for &T {
#[rustc_const_unstable(feature = "const_borrow", issue = "91522")]
impl<T: ?Sized> const Borrow<T> for &T {
fn borrow(&self) -> &T {
&**self
}
}
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: ?Sized> Borrow<T> for &mut T {
#[rustc_const_unstable(feature = "const_borrow", issue = "91522")]
impl<T: ?Sized> const Borrow<T> for &mut T {
fn borrow(&self) -> &T {
&**self
}
}
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: ?Sized> BorrowMut<T> for &mut T {
#[rustc_const_unstable(feature = "const_borrow", issue = "91522")]
impl<T: ?Sized> const BorrowMut<T> for &mut T {
fn borrow_mut(&mut self) -> &mut T {
&mut **self
}