Skip to content

Commit 510f5c7

Browse files
committed
Merge branch '⬆️-nightly-2022-03-21' into 🦆
2 parents 97d7f0e + 388d3ce commit 510f5c7

File tree

12 files changed

+20
-135
lines changed

12 files changed

+20
-135
lines changed

doc/toolchain_limitations.md

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -376,21 +376,6 @@ const fn f(_: usize) {}
376376
```
377377

378378

379-
### `[tag:const_slice_get]` `<[T]>::get` is not `const fn`
380-
381-
```rust
382-
assert!(matches!(b"a".get(0), Some(b'a')));
383-
assert!(matches!(b"a".get(1), None));
384-
```
385-
386-
```rust,compile_fail,E0015
387-
// `assert!` is used here due to [ref:const_assert_eq]
388-
// `matches!` is used here due to [ref:option_const_partial_eq]
389-
const _: () = assert!(matches!(b"a".get(0), Some(b'a')));
390-
const _: () = assert!(matches!(b"a".get(1), None));
391-
```
392-
393-
394379
### `[tag:const_slice_sort_unstable]` `<[T]>::sort_unstable*` is not `const fn`
395380

396381
```rust
@@ -442,20 +427,6 @@ const _: () = { Ok::<(), ()>(()).map(identity); };
442427
```
443428

444429

445-
### `[tag:const_slice_get_unchecked]` `<[T]>::get_unchecked` is not `const fn`
446-
447-
```rust
448-
assert!(unsafe { *b"a".get_unchecked(0) } == b'a');
449-
```
450-
451-
```rust,compile_fail,E0015
452-
// `assert!` is used here due to [ref:const_assert_eq]
453-
// error[E0015]: cannot call non-const fn `core::slice::<impl [u8]>::
454-
// get_unchecked::<usize>` in constants
455-
const _: () = assert!(unsafe { *b"a".get_unchecked(0) } == b'a');
456-
```
457-
458-
459430
### `[tag:const_slice_iter]` `<[T]>::iter` is not `const fn`
460431

461432
```rust
@@ -661,30 +632,6 @@ const _: () = assert!(matches!((2..4).next(), Some(2)));
661632
```
662633

663634

664-
### `[tag:clone_from_default]` `Clone::clone_from` lacks `#[default_method_body_is_const]`
665-
666-
When implementing `const Clone`, you can't use the provided implementation of `Clone::clone_from`.
667-
668-
```rust
669-
#![feature(const_trait_impl)]
670-
#![feature(const_mut_refs)]
671-
struct A;
672-
impl const Clone for A {
673-
fn clone(&self) -> Self { A }
674-
fn clone_from(&mut self, source: &Self) {}
675-
}
676-
```
677-
678-
```rust,compile_fail
679-
#![feature(const_trait_impl)]
680-
struct A;
681-
impl const Clone for A {
682-
fn clone(&self) -> Self { A }
683-
// error: const trait implementations may not use non-const default functions
684-
}
685-
```
686-
687-
688635
### `[tag:iterator_const_default]` `Iterator`'s methods lack `#[default_method_body_is_const]`
689636

690637
Implementing `const Iterator` requires you to implement all of its methods, which is impossible to do correctly.

rust-toolchain

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
nightly-2022-03-10
1+
nightly-2022-03-21

src/r3_core/src/bind.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -235,12 +235,6 @@ impl<System, T> const Clone for Bind<'_, System, T> {
235235
fn clone(&self) -> Self {
236236
*self
237237
}
238-
239-
// `clone_from` needed due to [ref:clone_from_default]
240-
#[inline]
241-
fn clone_from(&mut self, source: &Self) {
242-
*self = *source;
243-
}
244238
}
245239

246240
/// A [binder][1] that gives `&T` to a bound function.
@@ -296,12 +290,6 @@ impl<System, T> const Clone for BindRef<System, T> {
296290
fn clone(&self) -> Self {
297291
*self
298292
}
299-
300-
// `clone_from` needed due to [ref:clone_from_default]
301-
#[inline]
302-
fn clone_from(&mut self, source: &Self) {
303-
*self = *source;
304-
}
305293
}
306294

307295
// `BindDefiner` doesn't contain `T`, so this `impl` must use a concrete `T`

src/r3_core/src/bind/sorter.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -378,17 +378,16 @@ pub(super) const fn sort_bindings<Callback, SorterUseInfoList, VertexList>(
378378
SuccessorIterState::BindInitToBorrowingUser(bind_i, bind_user_i) => {
379379
let cb = self.cb.borrow();
380380
let bind_users = cb.bind_users(bind_i);
381-
// `[T]::get` is not `const fn` yet [ref:const_slice_get]
382-
if bind_user_i < bind_users.len() {
381+
if let Some(bind_user) = bind_users.get(bind_user_i) {
383382
self.st = SuccessorIterState::BindInitToBorrowingUser(
384383
bind_i,
385384
bind_user_i + 1,
386385
);
387386
if matches!(
388-
bind_users[bind_user_i].1,
387+
bind_user.1,
389388
BindBorrowType::Borrow | BindBorrowType::BorrowMut
390389
) {
391-
return Some(match bind_users[bind_user_i].0 {
390+
return Some(match bind_user.0 {
392391
BindUsage::Executable => Vertex::Executable,
393392
BindUsage::Bind(user_bind_i) => Vertex::BindInit(user_bind_i),
394393
});
@@ -434,17 +433,16 @@ pub(super) const fn sort_bindings<Callback, SorterUseInfoList, VertexList>(
434433
SuccessorIterState::BindDisownToTakingUser(bind_i, bind_user_i) => {
435434
let cb = self.cb.borrow();
436435
let bind_users = cb.bind_users(bind_i);
437-
// `[T]::get` is not `const fn` yet [ref:const_slice_get]
438-
if bind_user_i < bind_users.len() {
436+
if let Some(bind_user) = bind_users.get(bind_user_i) {
439437
self.st =
440438
SuccessorIterState::BindDisownToTakingUser(bind_i, bind_user_i + 1);
441439
if matches!(
442-
bind_users[bind_user_i].1,
440+
bind_user.1,
443441
BindBorrowType::Take
444442
| BindBorrowType::TakeRef
445443
| BindBorrowType::TakeMut
446444
) {
447-
return Some(match bind_users[bind_user_i].0 {
445+
return Some(match bind_user.0 {
448446
BindUsage::Executable => Vertex::Executable,
449447
BindUsage::Bind(user_bind_i) => Vertex::BindInit(user_bind_i),
450448
});

src/r3_core/src/kernel/cfg.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -212,12 +212,10 @@ impl<'c, C: raw_cfg::CfgBase> Cfg<'c, C> {
212212
let mut i = 0;
213213
while i < self.interrupt_lines.len() {
214214
let interrupt_line = &self.interrupt_lines[i];
215-
// `<[T]>::get` is not `const fn` yet [ref:const_slice_get]
216-
let start = if interrupt_line.num < C::System::CFG_INTERRUPT_HANDLERS.len() {
217-
C::System::CFG_INTERRUPT_HANDLERS[interrupt_line.num]
218-
} else {
219-
None
220-
};
215+
let start = C::System::CFG_INTERRUPT_HANDLERS
216+
.get(interrupt_line.num)
217+
.copied()
218+
.flatten();
221219
self.raw.interrupt_line_define(
222220
raw_cfg::InterruptLineDescriptor {
223221
phantom: Init::INIT,

src/r3_core/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#![feature(maybe_uninit_slice)]
2424
#![feature(const_nonnull_new)]
2525
#![feature(const_result_drop)]
26+
#![feature(const_slice_index)]
2627
#![feature(const_option_ext)]
2728
#![feature(const_ptr_offset)]
2829
#![feature(const_trait_impl)]

src/r3_core/src/utils/alloc.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,6 @@ impl const Clone for ConstAllocator {
193193
ref_count: self.ref_count,
194194
}
195195
}
196-
197-
fn clone_from(&mut self, source: &Self) {
198-
*self = source.clone();
199-
}
200196
}
201197

202198
impl const Drop for ConstAllocator {

src/r3_core/src/utils/binary_heap/helpers.rs

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ impl<'a, T> Hole<'a, T> {
2020
pub(super) const unsafe fn new(data: &'a mut [T], pos: usize) -> Self {
2121
debug_assert!(pos < data.len());
2222
// SAFE: pos should be inside the slice
23-
let elt = unsafe { ptr::read(data.get_unchecked2(pos)) };
23+
let elt = unsafe { ptr::read(data.get_unchecked(pos)) };
2424
Hole {
2525
data,
2626
elt: ManuallyDrop::new(elt),
@@ -52,7 +52,7 @@ impl<'a, T> Hole<'a, T> {
5252
pub(super) const unsafe fn get(&self, index: usize) -> &T {
5353
debug_assert!(index != self.pos);
5454
debug_assert!(index < self.data.len());
55-
unsafe { self.data.get_unchecked2(index) }
55+
unsafe { self.data.get_unchecked(index) }
5656
}
5757

5858
/// Returns a mutable reference to the element at `index`.
@@ -62,7 +62,7 @@ impl<'a, T> Hole<'a, T> {
6262
pub(super) const unsafe fn get_mut(&mut self, index: usize) -> &mut T {
6363
debug_assert!(index != self.pos);
6464
debug_assert!(index < self.data.len());
65-
unsafe { self.data.get_unchecked_mut2(index) }
65+
unsafe { self.data.get_unchecked_mut(index) }
6666
}
6767

6868
/// Move hole to new location
@@ -73,8 +73,8 @@ impl<'a, T> Hole<'a, T> {
7373
debug_assert!(index != self.pos);
7474
debug_assert!(index < self.data.len());
7575
unsafe {
76-
let index_ptr: *const _ = self.data.get_unchecked2(index);
77-
let hole_ptr = self.data.get_unchecked_mut2(self.pos);
76+
let index_ptr: *const _ = self.data.get_unchecked(index);
77+
let hole_ptr = self.data.get_unchecked_mut(self.pos);
7878
ptr::copy_nonoverlapping(index_ptr, hole_ptr, 1);
7979
}
8080
self.pos = index;
@@ -87,37 +87,7 @@ impl<T> const Drop for Hole<'_, T> {
8787
// fill the hole again
8888
unsafe {
8989
let pos = self.pos;
90-
ptr::copy_nonoverlapping(&*self.elt, self.data.get_unchecked_mut2(pos), 1);
90+
ptr::copy_nonoverlapping(&*self.elt, self.data.get_unchecked_mut(pos), 1);
9191
}
9292
}
9393
}
94-
95-
// `[T]::get_unchecked<usize>` is not `const fn` yet [ref:const_slice_get_unchecked]
96-
trait GetUnchecked {
97-
type Element;
98-
unsafe fn get_unchecked2(&self, i: usize) -> &Self::Element;
99-
}
100-
101-
impl<Element> const GetUnchecked for [Element] {
102-
type Element = Element;
103-
104-
#[inline]
105-
unsafe fn get_unchecked2(&self, i: usize) -> &Self::Element {
106-
unsafe { &*self.as_ptr().add(i) }
107-
}
108-
}
109-
110-
// `[T]::get_unchecked_mut<usize>` is not `const fn` yet [ref:const_slice_get_unchecked]
111-
trait GetUncheckedMut {
112-
type Element;
113-
unsafe fn get_unchecked_mut2(&mut self, i: usize) -> &mut Self::Element;
114-
}
115-
116-
impl<Element> const GetUncheckedMut for [Element] {
117-
type Element = Element;
118-
119-
#[inline]
120-
unsafe fn get_unchecked_mut2(&mut self, i: usize) -> &mut Self::Element {
121-
unsafe { &mut *self.as_mut_ptr().add(i) }
122-
}
123-
}

src/r3_core/src/utils/freeze.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,6 @@ impl<T: Copy> const Clone for Frozen<T> {
8282
// Don't use `T as Clone` because it could expose interior mutability.
8383
*self
8484
}
85-
86-
#[inline]
87-
fn clone_from(&mut self, source: &Self) {
88-
*self = *source;
89-
}
9085
}
9186

9287
impl<T: Copy + ~const fmt::Debug> const fmt::Debug for Frozen<T> {

src/r3_core/src/utils/vec.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ impl<T: ~const Clone + ~const Drop> const Clone for ComptimeVec<T> {
3535
}
3636
self.map(clone_shim)
3737
}
38-
39-
fn clone_from(&mut self, source: &Self) {
40-
*self = source.clone();
41-
}
4238
}
4339

4440
impl<T> const Drop for ComptimeVec<T>

0 commit comments

Comments
 (0)