Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ambiguous associated type usage on top of 0.20.1 #110

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/tour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ are dominant."
println!("{:?}", bs.domain());
println!("Show the bits in memory");
for elt in bs.domain() {
println!("{:0w$b} ", elt, w = T::Mem::BITS as usize);
println!("{:0w$b} ", elt, w = <T::Mem as BitMemory>::BITS as usize);
}
println!();
}
Expand Down
21 changes: 18 additions & 3 deletions src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ behavior of ordinary arrays `[T; N]` as they stand today.
[`.as_bitslice()`]: Self::as_bitslice
**/
#[repr(transparent)]
#[derive(Copy)]
pub struct BitArray<O = Lsb0, V = [usize; 1]>
where
O: BitOrder,
Expand Down Expand Up @@ -227,7 +226,7 @@ where

/// Views the array as a slice of its underlying memory registers.
#[inline]
pub fn as_slice(&self) -> &[V::Store] {
pub fn as_raw_slice(&self) -> &[V::Store] {
unsafe {
slice::from_raw_parts(
&self.data as *const V as *const V::Store,
Expand All @@ -238,7 +237,7 @@ where

/// Views the array as a mutable slice of its underlying memory registers.
#[inline]
pub fn as_mut_slice(&mut self) -> &mut [V::Store] {
pub fn as_mut_raw_slice(&mut self) -> &mut [V::Store] {
unsafe {
slice::from_raw_parts_mut(
&mut self.data as *mut V as *mut V::Store,
Expand All @@ -247,6 +246,22 @@ where
}
}

#[doc(hidden)]
#[inline(always)]
#[cfg(not(tarpaulin_include))]
#[deprecated = "This is renamed to `as_raw_slice`"]
pub fn as_slice(&self) -> &[V::Store] {
self.as_raw_slice()
}

#[doc(hidden)]
#[inline(always)]
#[cfg(not(tarpaulin_include))]
#[deprecated = "This is renamed to `as_mut_raw_slice`"]
pub fn as_mut_slice(&mut self) -> &mut [V::Store] {
self.as_mut_raw_slice()
}

/// Views the interior buffer.
#[inline(always)]
#[cfg(not(tarpaulin_include))]
Expand Down
2 changes: 1 addition & 1 deletion src/array/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ where
fn get(&self, index: usize) -> bool {
unsafe {
self.array
.as_slice()
.as_raw_slice()
.pipe(BitPtr::<Const, O, V::Store>::from_slice)
.add(index)
.read()
Expand Down
2 changes: 1 addition & 1 deletion src/array/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ where

#[inline]
fn not(mut self) -> Self::Output {
for elem in self.as_mut_slice() {
for elem in self.as_mut_raw_slice() {
elem.store_value(!elem.load_value());
}
self
Expand Down
4 changes: 2 additions & 2 deletions src/array/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ fn wrap_unwrap() {
fn views() {
let mut arr = bitarr![Msb0, u8; 0; 20];

let s: &mut [u8] = arr.as_mut_slice();
let s: &mut [u8] = arr.as_mut_raw_slice();
s[0] = !0u8;
let s: &[u8] = arr.as_slice();
let s: &[u8] = arr.as_raw_slice();
assert_eq!(s, &[!0, 0, 0]);

let a: &mut [u8; 3] = arr.as_mut_buffer();
Expand Down
11 changes: 10 additions & 1 deletion src/array/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ where
#[inline]
fn clone(&self) -> Self {
let mut out = Self::zeroed();
for (dst, src) in out.as_mut_slice().iter_mut().zip(self.as_slice()) {
for (dst, src) in
out.as_mut_raw_slice().iter_mut().zip(self.as_raw_slice())
{
dst.store_value(src.load_value());
}
out
Expand Down Expand Up @@ -377,6 +379,13 @@ where
}
}

impl<O, V> Copy for BitArray<O, V>
where
O: BitOrder,
V: BitView + Copy,
{
}

impl<O, V> Unpin for BitArray<O, V>
where
O: BitOrder,
Expand Down
4 changes: 2 additions & 2 deletions src/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ where
let mut boxed = ManuallyDrop::new(boxed);

BitPtr::from_mut_slice(&mut boxed[..])
.span(boxed.len() * T::Mem::BITS as usize)
.span(boxed.len() * <T::Mem as BitMemory>::BITS as usize)
.map(|bitspan| Self { bitspan })
.map_err(|_| ManuallyDrop::into_inner(boxed))
}
Expand Down Expand Up @@ -438,7 +438,7 @@ where
let (_, head, bits) = bp.raw_parts();
let head = head.value() as usize;
let tail = head + bits;
let full = crate::mem::elts::<T::Mem>(tail) * T::Mem::BITS as usize;
let full = crate::mem::elts::<T::Mem>(tail) * <T::Mem as BitMemory>::BITS as usize;
unsafe {
bp.set_head(BitIdx::ZERO);
bp.set_len(full);
Expand Down
44 changes: 40 additions & 4 deletions src/devel.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
//! Internal support utilities.

use core::ops::{
Bound,
Range,
RangeBounds,
use crate::{
order::BitOrder,
store::BitStore,
};

use core::{
any::TypeId,
ops::{
Bound,
Range,
RangeBounds,
},
};

/** Normalizes any range into a basic `Range`.
Expand All @@ -29,6 +37,7 @@ the function, and must be inspected by the caller.

`bounds` normalized to an ordinary `Range`, optionally clamped to `end`.
**/
#[inline]
pub fn normalize_range<R>(bounds: R, end: usize) -> Range<usize>
where R: RangeBounds<usize> {
let min = match bounds.start_bound() {
Expand Down Expand Up @@ -58,6 +67,7 @@ range end be not greater than the ending marker (if provided).

This panics if the range fails a requirement.
**/
#[inline]
pub fn assert_range(range: Range<usize>, end: impl Into<Option<usize>>) {
if range.start > range.end {
panic!(
Expand All @@ -75,6 +85,32 @@ pub fn assert_range(range: Range<usize>, end: impl Into<Option<usize>>) {
}
}

/// Tests if two `BitOrder` type parameters match each other.
///
/// This evaluates to a compile-time constant, and is removed during codegen.
#[inline(always)]
pub fn match_order<O1, O2>() -> bool
where
O1: BitOrder,
O2: BitOrder,
{
TypeId::of::<O1>() == TypeId::of::<O2>()
}

/// Tests if two `<O, T>` type parameter pairs match each other.
///
/// This evaluates to a compile-time constant, and is removed during codegen.
#[inline(always)]
pub fn match_types<O1, T1, O2, T2>() -> bool
where
O1: BitOrder,
T1: BitStore,
O2: BitOrder,
T2: BitStore,
{
match_order::<O1, O2>() && TypeId::of::<T1>() == TypeId::of::<T2>()
}

#[cfg(all(test, feature = "std"))]
mod tests {
use super::*;
Expand Down
8 changes: 4 additions & 4 deletions src/domain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ macro_rules! bit_domain {
let bitspan = slice.as_bitspan();
let h = bitspan.head();
let (e, t) = h.span(bitspan.len());
let w = T::Mem::BITS;
let w = <T::Mem as BitMemory>::BITS;

match (h.value(), e, t.value()) {
(_, 0, _) => Self::empty(),
Expand All @@ -258,7 +258,7 @@ macro_rules! bit_domain {
) -> Self {
let (head, rest) = bit_domain!(split $($m)?
slice,
(T::Mem::BITS - head.value()) as usize,
(<T::Mem as BitMemory>::BITS - head.value()) as usize,
);
let (body, tail) = bit_domain!(split $($m)?
rest,
Expand Down Expand Up @@ -289,7 +289,7 @@ macro_rules! bit_domain {
) -> Self {
let (head, rest) = bit_domain!(split $($m)?
slice,
(T::Mem::BITS - head.value()) as usize,
(<T::Mem as BitMemory>::BITS - head.value()) as usize,
);
let (head, body) = (
bit_domain!(retype $($m)? head),
Expand Down Expand Up @@ -537,7 +537,7 @@ macro_rules! domain {
let head = bitspan.head();
let elts = bitspan.elements();
let tail = bitspan.tail();
let bits = T::Mem::BITS;
let bits = <T::Mem as BitMemory>::BITS;
let base = bitspan.address().to_const() as *const _;
match (head.value(), elts, tail.value()) {
(_, 0, _) => Self::empty(),
Expand Down
Loading