Skip to content

Commit ae9dafc

Browse files
authored
Rollup merge of rust-lang#90270 - woppopo:const_borrow_trait, r=dtolnay
Make `Borrow` and `BorrowMut` impls `const` Tracking issue: rust-lang#91522
2 parents d9df1a8 + 8f68bdc commit ae9dafc

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

Diff for: library/core/src/array/mod.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -162,14 +162,16 @@ impl<T, const N: usize> AsMut<[T]> for [T; N] {
162162
}
163163

164164
#[stable(feature = "array_borrow", since = "1.4.0")]
165-
impl<T, const N: usize> Borrow<[T]> for [T; N] {
165+
#[rustc_const_unstable(feature = "const_borrow", issue = "91522")]
166+
impl<T, const N: usize> const Borrow<[T]> for [T; N] {
166167
fn borrow(&self) -> &[T] {
167168
self
168169
}
169170
}
170171

171172
#[stable(feature = "array_borrow", since = "1.4.0")]
172-
impl<T, const N: usize> BorrowMut<[T]> for [T; N] {
173+
#[rustc_const_unstable(feature = "const_borrow", issue = "91522")]
174+
impl<T, const N: usize> const BorrowMut<[T]> for [T; N] {
173175
fn borrow_mut(&mut self) -> &mut [T] {
174176
self
175177
}

Diff for: library/core/src/borrow.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -205,36 +205,41 @@ pub trait BorrowMut<Borrowed: ?Sized>: Borrow<Borrowed> {
205205
}
206206

207207
#[stable(feature = "rust1", since = "1.0.0")]
208-
impl<T: ?Sized> Borrow<T> for T {
208+
#[rustc_const_unstable(feature = "const_borrow", issue = "91522")]
209+
impl<T: ?Sized> const Borrow<T> for T {
209210
#[rustc_diagnostic_item = "noop_method_borrow"]
210211
fn borrow(&self) -> &T {
211212
self
212213
}
213214
}
214215

215216
#[stable(feature = "rust1", since = "1.0.0")]
216-
impl<T: ?Sized> BorrowMut<T> for T {
217+
#[rustc_const_unstable(feature = "const_borrow", issue = "91522")]
218+
impl<T: ?Sized> const BorrowMut<T> for T {
217219
fn borrow_mut(&mut self) -> &mut T {
218220
self
219221
}
220222
}
221223

222224
#[stable(feature = "rust1", since = "1.0.0")]
223-
impl<T: ?Sized> Borrow<T> for &T {
225+
#[rustc_const_unstable(feature = "const_borrow", issue = "91522")]
226+
impl<T: ?Sized> const Borrow<T> for &T {
224227
fn borrow(&self) -> &T {
225228
&**self
226229
}
227230
}
228231

229232
#[stable(feature = "rust1", since = "1.0.0")]
230-
impl<T: ?Sized> Borrow<T> for &mut T {
233+
#[rustc_const_unstable(feature = "const_borrow", issue = "91522")]
234+
impl<T: ?Sized> const Borrow<T> for &mut T {
231235
fn borrow(&self) -> &T {
232236
&**self
233237
}
234238
}
235239

236240
#[stable(feature = "rust1", since = "1.0.0")]
237-
impl<T: ?Sized> BorrowMut<T> for &mut T {
241+
#[rustc_const_unstable(feature = "const_borrow", issue = "91522")]
242+
impl<T: ?Sized> const BorrowMut<T> for &mut T {
238243
fn borrow_mut(&mut self) -> &mut T {
239244
&mut **self
240245
}

0 commit comments

Comments
 (0)