Skip to content

Commit d824f85

Browse files
Bumped version to 1.10.0, turned BoolWit into more generic `BoolWit… (#13)
* Bumped version to 1.10.0, turned `BoolWit` into more generic `BoolWitG` enum Replaced `typewit::const_marker::BoolWit` enum with type alias to `BoolWitG`` Added `Copy + Clone + Debug` impls to `BoolWit` Fixed broken reference to array::from_fn Fixed `"adt_const_marker"` crate feature Disabled UI tests because they can't be locally replicated (must be a version-by-version nightly difference) Made trybuild optional to fix MSRV of tests
1 parent 2d79ba0 commit d824f85

File tree

13 files changed

+145
-14
lines changed

13 files changed

+145
-14
lines changed

.github/workflows/rust.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,12 @@ jobs:
6464
"rust_stable adt_const_marker alloc nightly_mut_refs"
6565
6666
cargo test --no-default-features --features \
67-
"rust_stable adt_const_marker proc_macros __ui_tests alloc nightly_mut_refs"
67+
"rust_stable adt_const_marker proc_macros alloc nightly_mut_refs"
68+
# "rust_stable adt_const_marker proc_macros __ui_tests alloc nightly_mut_refs"
6869
6970
cargo test --no-default-features --features \
70-
"rust_stable adt_const_marker __ui_tests alloc nightly_mut_refs"
71+
"rust_stable adt_const_marker alloc nightly_mut_refs"
72+
# "rust_stable adt_const_marker __ui_tests alloc nightly_mut_refs"
7173
7274
MIRI_NIGHTLY=nightly-$(curl -s https://rust-lang.github.io/rustup-components-history/x86_64-unknown-linux-gnu/miri)
7375
echo "Installing latest nightly with Miri"

Cargo.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "typewit"
3-
version = "1.9.0"
3+
version = "1.10.0"
44
authors = ["rodrimati1992 <rodrimatt1985@gmail.com>"]
55
rust-version = "1.57.0"
66
edition = "2021"
@@ -29,8 +29,10 @@ optional = true
2929
version = "0.7"
3030
default-features = false
3131

32-
[dev-dependencies.trybuild]
32+
# no such thing as optional dev-dependencies, aaaaaaah
33+
[dependencies.trybuild]
3334
version = "1.0"
35+
optional = true
3436

3537
[features]
3638
default = ["proc_macros"]
@@ -44,7 +46,7 @@ alloc = []
4446
mut_refs = ["rust_stable"]
4547
nightly_mut_refs = ["mut_refs"]
4648
docsrs = []
47-
__ui_tests = []
49+
__ui_tests = ["trybuild"]
4850

4951
[package.metadata.docs.rs]
5052
features = ["alloc", "rust_stable", "nightly_mut_refs", "adt_const_marker", "docsrs"]

Changelog.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@ This is the changelog, summarising changes in each version(some minor changes ma
22

33
# 1.0
44

5+
### 1.10.0
6+
7+
Added `typewit::const_marker::BoolWitG` enum
8+
9+
Replaced `typewit::const_marker::BoolWit` enum with type alias to `BoolWitG``
10+
11+
Added `Copy + Clone + Debug` impls to `BoolWit`
12+
13+
Fixed `"adt_const_marker"` crate feature
14+
515
### 1.9.0
616

717
Deprecated `{TypeCmp, TypeNe}::with_any` due to unsoundness: both constructors rely on `TypeId::of::<L>() != TypeId::of::<R>()` implying `L != R`, which is not true in the general case.

src/const_marker.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@ use crate::{
3838
TypeNe,
3939
};
4040

41-
mod const_witnesses;
41+
mod boolwit;
42+
43+
pub use boolwit::*;
4244

43-
pub use const_witnesses::*;
4445

4546
#[cfg(feature = "adt_const_marker")]
4647
mod slice_const_markers;

src/const_marker/const_witnesses.rs renamed to src/const_marker/boolwit.rs

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use core::fmt::{self, Debug};
2+
13
use crate::{
24
const_marker::Bool,
35
TypeCmp,
@@ -6,9 +8,10 @@ use crate::{
68
};
79

810

9-
1011
/// Type Witness that [`Bool<B>`](Bool) is either `Bool<true>` or `Bool<false>`.
1112
///
13+
/// Use this over [`BoolWitG`] if you have a `const B: bool` parameter already.
14+
///
1215
/// # Example
1316
///
1417
/// Making a function that takes a generic `Foo<B>` and calls methods on
@@ -160,18 +163,45 @@ use crate::{
160163
/// ```
161164
///
162165
///
163-
pub enum BoolWit<const B: bool> {
166+
pub type BoolWit<const B: bool> = BoolWitG<Bool<B>>;
167+
168+
169+
/// Type witness that `B` is either [`Bool`]`<true>` or [`Bool`]`<false>`
170+
///
171+
/// Use this over [`BoolWit`] if you want to write a [`HasTypeWitness`] bound
172+
/// and adding a `const B: bool` parameter would be impossible.
173+
///
174+
///
175+
/// [`HasTypeWitness`]: crate::HasTypeWitness
176+
pub enum BoolWitG<B> {
164177
/// Witnesses that `B == true`
165-
True(TypeEq<Bool<B>, Bool<true>>),
178+
True(TypeEq<B, Bool<true>>),
166179
/// Witnesses that `B == false`
167-
False(TypeEq<Bool<B>, Bool<false>>),
180+
False(TypeEq<B, Bool<false>>),
181+
}
182+
183+
impl<const B: bool> Copy for BoolWitG<Bool<B>> {}
184+
185+
impl<const B: bool> Clone for BoolWitG<Bool<B>> {
186+
fn clone(&self) -> Self {
187+
*self
188+
}
189+
}
190+
191+
impl<const B: bool> Debug for BoolWitG<Bool<B>> {
192+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
193+
f.write_str(match self {
194+
Self::True{..} => "True",
195+
Self::False{..} => "False",
196+
})
197+
}
168198
}
169199

170-
impl<const B: bool> TypeWitnessTypeArg for BoolWit<B> {
200+
impl<const B: bool> TypeWitnessTypeArg for BoolWitG<Bool<B>> {
171201
type Arg = Bool<B>;
172202
}
173203

174-
impl<const B: bool> MakeTypeWitness for BoolWit<B> {
204+
impl<const B: bool> MakeTypeWitness for BoolWitG<Bool<B>> {
175205
const MAKE: Self = {
176206
if let TypeCmp::Eq(te) = Bool.equals(Bool) {
177207
BoolWit::True(te)

src/const_marker/slice_const_markers.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ super::declare_const_param_type! {
1616
///
1717
/// ```rust
1818
/// #![feature(adt_const_params)]
19+
/// #![feature(unsized_const_params)]
1920
///
2021
/// use typewit::{const_marker::Str, MakeTypeWitness};
2122
///

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,7 @@
454454
#![no_std]
455455
#![cfg_attr(feature = "nightly_mut_refs", feature(const_mut_refs))]
456456
#![cfg_attr(feature = "adt_const_marker", feature(adt_const_params))]
457+
#![cfg_attr(feature = "adt_const_marker", feature(unsized_const_params))]
457458
#![cfg_attr(feature = "adt_const_marker", allow(incomplete_features))]
458459
#![cfg_attr(feature = "docsrs", feature(doc_cfg))]
459460
#![allow(clippy::type_complexity)]

src/type_cmp.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use core::{
1717
///
1818
/// ### Custom array creation
1919
///
20-
/// (this example requires Rust 1.63.0, because of [`std::array::from_fn`]).
20+
/// (this example requires Rust 1.63.0, because of [`core::array::from_fn`]).
2121
///
2222
#[cfg_attr(not(feature = "rust_1_65"), doc = "```ignore")]
2323
#[cfg_attr(feature = "rust_1_65", doc = "```rust")]

src/type_eq.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,9 @@ mod type_eq_ {
297297
// Declared to work around this error in old Rust versions:
298298
// > error[E0658]: function pointers cannot appear in constant functions
299299
struct TypeEqHelper<L: ?Sized, R: ?Sized>(
300+
#[allow(dead_code)]
300301
fn(PhantomData<L>) -> PhantomData<L>,
302+
#[allow(dead_code)]
301303
fn(PhantomData<R>) -> PhantomData<R>,
302304
);
303305

src/type_ne_.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ mod type_ne_ {
8686
// Declared to work around this error in old Rust versions:
8787
// > error[E0658]: function pointers cannot appear in constant functions
8888
struct TypeNeHelper<L: ?Sized, R: ?Sized>(
89+
#[allow(dead_code)]
8990
fn(PhantomData<L>) -> PhantomData<L>,
91+
#[allow(dead_code)]
9092
fn(PhantomData<R>) -> PhantomData<R>,
9193
);
9294

0 commit comments

Comments
 (0)