Skip to content

Commit

Permalink
Assorted feature gate updates / other adjustments to fix compilation …
Browse files Browse the repository at this point in the history
…on the latest nightly compiler
  • Loading branch information
slightlyoutofphase committed Mar 13, 2022
1 parent 0fcb4d8 commit 90f4d79
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 9 deletions.
1 change: 0 additions & 1 deletion demo/main_demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
// of a single program.
#![feature(
const_fn_floating_point_arithmetic,
const_fn_trait_bound,
const_mut_refs,
const_precise_live_drops,
// Weirdly named feature, as it doesn't necessarily relate to `Cell` at all.
Expand Down
10 changes: 9 additions & 1 deletion src/heap/heap_trait_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,15 @@ impl<T: Copy, const N: usize> const Clone for StaticHeap<T, N> {

#[inline(always)]
fn clone_from(&mut self, source: &Self) {
self.data.clone_from(&source.data);
// Calling `clone_from` directly through `self.data` is not accepted by the compiler currently
// for some reason in the context of this impl being `const`.
unsafe {
self
.data
.as_mut_ptr()
.copy_from_nonoverlapping(source.data.as_ptr(), source.data.length);
self.data.set_len(source.data.length);
}
}
}

Expand Down
2 changes: 0 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
const_assume,
const_eval_select,
const_fn_floating_point_arithmetic,
const_fn_fn_ptr_basics,
const_fn_trait_bound,
const_intrinsic_copy,
const_maybe_uninit_as_mut_ptr,
const_maybe_uninit_assume_init,
Expand Down
10 changes: 9 additions & 1 deletion src/string/string_trait_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,15 @@ impl<const N: usize> const Clone for StaticString<N> {

#[inline(always)]
fn clone_from(&mut self, other: &Self) {
self.vec.clone_from(&other.vec);
// Calling `clone_from` directly through `self.vec` is not accepted by the compiler currently
// for some reason in the context of this impl being `const`.
unsafe {
self
.vec
.as_mut_ptr()
.copy_from_nonoverlapping(other.vec.as_ptr(), other.vec.length);
self.vec.set_len(other.vec.length);
}
}
}

Expand Down
7 changes: 3 additions & 4 deletions test/test_staticvec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
adt_const_params,
box_syntax,
const_fn_floating_point_arithmetic,
const_fn_trait_bound,
const_trait_impl,
exact_size_is_empty,
generic_const_exprs,
Expand Down Expand Up @@ -602,7 +601,7 @@ fn extend_from_slice() {
assert_eq!(vec, [1, 2, 3, 4]);
let mut vec2 = StaticVec::<i32, 0>::new();
vec2.extend_from_slice(&[2, 3, 4]);
assert_eq!(vec2, []);
assert_eq!(vec2, []);
}

#[test]
Expand All @@ -617,10 +616,10 @@ fn filled_with() {
assert_eq!(v[1], 2);
assert_eq!(v[2], 3);
assert_eq!(v[3], 4);
let v2 = StaticVec::<i32, 0>::filled_with(|| { 0 });
let v2 = StaticVec::<i32, 0>::filled_with(|| 0);
assert_eq!(v2.len(), 0);
assert_eq!(v2.capacity(), 0);
assert_eq!(v2.remaining_capacity(), 0);
assert_eq!(v2.remaining_capacity(), 0);
}

#[test]
Expand Down

0 comments on commit 90f4d79

Please sign in to comment.