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

1.11.0 release #12

Merged
merged 10 commits into from
Dec 4, 2024
21 changes: 13 additions & 8 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ jobs:
strategy:
max-parallel: 3
matrix:
rust: [stable, beta, nightly, 1.65.0, 1.61.0, 1.57.0]
# TODO: add stable/beta once they're versions >= 1.83
rust: [beta, nightly, 1.83.0, 1.65.0, 1.61.0, 1.57.0]

steps:
- uses: actions/checkout@v2
Expand All @@ -29,6 +30,10 @@ jobs:
if: matrix.rust == '1.65.0'
run: echo "rustv=rust_1_65" >> $GITHUB_ENV

- name: enable-rust-1_83
if: matrix.rust == '1.83.0'
run: echo "rustv=rust_1_83" >> $GITHUB_ENV

- name: enable-rust-stable
if: matrix.rust == 'stable' || matrix.rust == 'beta' || matrix.rust == 'nightly'
run: echo "rustv=rust_stable" >> $GITHUB_ENV
Expand Down Expand Up @@ -59,17 +64,17 @@ jobs:
cargo build

cargo test --no-default-features --features \
"rust_stable adt_const_marker nightly_mut_refs"
"rust_stable adt_const_marker"
cargo test --no-default-features --features \
"rust_stable adt_const_marker alloc nightly_mut_refs"
"rust_stable adt_const_marker alloc"

cargo test --no-default-features --features \
"rust_stable adt_const_marker proc_macros alloc nightly_mut_refs"
# "rust_stable adt_const_marker proc_macros __ui_tests alloc nightly_mut_refs"
"rust_stable adt_const_marker proc_macros alloc"
# "rust_stable adt_const_marker proc_macros __ui_tests alloc"

cargo test --no-default-features --features \
"rust_stable adt_const_marker alloc nightly_mut_refs"
# "rust_stable adt_const_marker __ui_tests alloc nightly_mut_refs"
"rust_stable adt_const_marker alloc"
# "rust_stable adt_const_marker __ui_tests alloc"

MIRI_NIGHTLY=nightly-$(curl -s https://rust-lang.github.io/rustup-components-history/x86_64-unknown-linux-gnu/miri)
echo "Installing latest nightly with Miri"
Expand All @@ -83,4 +88,4 @@ jobs:
cargo clean

env RUST_BACKTRACE=0 cargo miri test --no-default-features \
--features "${{env.rustv}} adt_const_marker proc_macros alloc nightly_mut_refs"
--features "${{env.rustv}} adt_const_marker proc_macros alloc"
7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "typewit"
version = "1.10.1"
version = "1.11.0"
authors = ["rodrimati1992 <[email protected]>"]
rust-version = "1.57.0"
edition = "2021"
Expand Down Expand Up @@ -38,7 +38,8 @@ optional = true
default = ["proc_macros"]
rust_1_61 = []
rust_1_65 = ["rust_1_61"]
rust_stable = ["rust_1_65"]
rust_1_83 = ["rust_1_65"]
rust_stable = ["rust_1_83"]
proc_macros = ["typewit_proc_macros"]
const_marker = []
adt_const_marker = ["rust_stable"]
Expand All @@ -49,5 +50,5 @@ docsrs = []
__ui_tests = ["trybuild"]

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

15 changes: 15 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@ This is the changelog, summarising changes in each version(some minor changes ma

# 1.0

### 1.11.0

Added `"rust_1_83"` feature, which turns `typewit` functions that use `&mut` into const fns.

Added these methods to `BoolWitG`:
- `is_true`
- `is_false`
- `to_true`
- `to_false`
- `unwrap_true`
- `unwrap_false`

Relaxed `Copy + Clone + Debug` impls of `BooleanWitG` to work for any `<B> BooleanWitG<B>`, instead of requiring `<const B: bool> BoolWitG<Bool<B>>`.


### 1.10.1

Fixed `TypeWitnessTypeArg` impl for `BoolWitG`, it was overconstrained in a way that made `HasTypeWitness<BoolWitG<T>>` not work as a bound.
Expand Down
118 changes: 115 additions & 3 deletions src/const_marker/boolwit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,15 +201,127 @@ pub enum BoolWitG<B> {
False(TypeEq<B, Bool<false>>),
}

impl<const B: bool> Copy for BoolWitG<Bool<B>> {}
impl<B> BoolWitG<B> {
/// Whether `B == Bool<true>`
///
/// # Example
///
/// ```rust
/// use typewit::{const_marker::BoolWitG, TypeEq};
///
/// assert_eq!(BoolWitG::True(TypeEq::NEW).is_true(), true);
/// assert_eq!(BoolWitG::False(TypeEq::NEW).is_true(), false);
/// ```
///
pub const fn is_true(self) -> bool {
matches!(self, Self::True{..})
}

/// Whether `B == Bool<false>`
///
/// # Example
///
/// ```rust
/// use typewit::{const_marker::BoolWitG, TypeEq};
///
/// assert_eq!(BoolWitG::True(TypeEq::NEW).is_false(), false);
/// assert_eq!(BoolWitG::False(TypeEq::NEW).is_false(), true);
/// ```
///
pub const fn is_false(self) -> bool {
matches!(self, Self::False{..})
}

/// Gets a proof of `B == Bool<true>`, returns None if `B == Bool<false>`
///
/// # Example
///
/// ```rust
/// use typewit::{const_marker::{Bool, BoolWitG}, TypeEq};
///
/// assert_eq!(BoolWitG::True(TypeEq::NEW).to_true(), Some(TypeEq::new::<Bool<true>>()));
/// assert_eq!(BoolWitG::False(TypeEq::NEW).to_true(), None);
/// ```
///
pub const fn to_true(self) -> Option<TypeEq<B, Bool<true>>> {
match self {
Self::True(x) => Some(x),
Self::False{..} => None
}
}

/// Gets a proof of `B == Bool<false>`, returns None if `B == Bool<true>`
///
/// # Example
///
/// ```rust
/// use typewit::{const_marker::{Bool, BoolWitG}, TypeEq};
///
/// assert_eq!(BoolWitG::True(TypeEq::NEW).to_false(), None);
/// assert_eq!(BoolWitG::False(TypeEq::NEW).to_false(), Some(TypeEq::new::<Bool<false>>()));
/// ```
///
pub const fn to_false(self) -> Option<TypeEq<B, Bool<false>>> {
match self {
Self::False(x) => Some(x),
Self::True{..} => None
}
}


/// Gets a proof of `B == Bool<true>`.
///
/// # Panic
///
/// Panics if `B == Bool<false>`
///
/// # Example
///
/// ```rust
/// use typewit::{const_marker::{Bool, BoolWitG}, TypeEq};
///
/// assert_eq!(BoolWitG::True(TypeEq::NEW).unwrap_true(), TypeEq::new::<Bool<true>>());
/// ```
///
pub const fn unwrap_true(self) -> TypeEq<B, Bool<true>> {
match self {
Self::True(x) => x,
Self::False{..} => panic!("attempted to unwrap into True on False variant")
}
}

/// Gets a proof of `B == Bool<false>`.
///
/// # Panic
///
/// Panics if `B == Bool<true>`
///
/// # Example
///
/// ```rust
/// use typewit::{const_marker::{Bool, BoolWitG}, TypeEq};
///
/// assert_eq!(BoolWitG::False(TypeEq::NEW).unwrap_false(), TypeEq::new::<Bool<false>>());
/// ```
///
pub const fn unwrap_false(self) -> TypeEq<B, Bool<false>> {
match self {
Self::False(x) => x,
Self::True{..} => panic!("attempted to unwrap into False on True variant")
}
}

}

impl<B> Copy for BoolWitG<B> {}

impl<const B: bool> Clone for BoolWitG<Bool<B>> {
impl<B> Clone for BoolWitG<B> {
fn clone(&self) -> Self {
*self
}
}

impl<const B: bool> Debug for BoolWitG<Bool<B>> {
impl<B> Debug for BoolWitG<B> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str(match self {
Self::True{..} => "True",
Expand Down
16 changes: 3 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,9 @@
//!
//! - `"rust_stable"`: enables all the `"rust_1_*"` features.
//!
//! - `"rust_1_83"`: turns functions that take mutable references into `const fn`s,
//! and enables the `"rust_1_65"` feature.
//!
//! - `"rust_1_65"`: enables the [`type_constructors`] module,
//! the [`methods`] module,
//! and the `"rust_1_61"` feature.
Expand All @@ -414,18 +417,6 @@
//! and marker types in the [`const_marker`] module that have
//! non-primitive `const` parameters.
//!
//! - `"nightly_mut_refs"`:
//! Enables the `"rust_stable"` and `"mut_refs"` crate features,
//! and turns functions that use mutable references into `const fn`s.
//!
//! ### Future-Rust features
//!
//! These features currently require future compiler versions:
//!
//! - `"mut_refs"`: turns functions that take mutable references into `const fn`s.
//! note: as of October 2023,
//! this crate feature requires a stable compiler from the future.
//!
//! # No-std support
//!
//! `typewit` is `#![no_std]`, it can be used anywhere Rust can be used.
Expand All @@ -452,7 +443,6 @@
//! [`MetaBaseTypeWit`]: crate::MetaBaseTypeWit
//! [`BaseTypeWitness`]: crate::BaseTypeWitness
#![no_std]
#![cfg_attr(feature = "nightly_mut_refs", feature(const_mut_refs))]
#![cfg_attr(feature = "adt_const_marker", feature(adt_const_params))]
#![cfg_attr(feature = "adt_const_marker", feature(unsized_const_params))]
#![cfg_attr(feature = "adt_const_marker", allow(incomplete_features))]
Expand Down
16 changes: 7 additions & 9 deletions src/some_type_arg_is_ne.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@ use crate::{



// A `TypeNe` that's impossible to soundly make,
// because `()` is the same type as `()`,
// while `TypeNe` requires its type arguments not to be the same type.
type ImpTypeNe = TypeNe<(), ()>;
// A `TypeEq` that's used as padding for the trailing type arguments of SomeTypeArgIsNe.
type PadTyEq = TypeEq<(), ()>;

// The first TypeNe in the 4 `BaseTypeWitness` type parameters
pub(crate) enum SomeTypeArgIsNe<A: BTW, B: BTW, C: BTW = ImpTypeNe, D: BTW = ImpTypeNe> {
pub(crate) enum SomeTypeArgIsNe<A: BTW, B: BTW, C: BTW = PadTyEq, D: BTW = PadTyEq> {
A(TypeEq<A, TypeNe<A::L, A::R>>),
B(TypeEq<B, TypeNe<B::L, B::R>>),
C(TypeEq<C, TypeNe<C::L, C::R>>),
Expand All @@ -41,21 +39,21 @@ impl<A: BTW, B: BTW, C: BTW, D: BTW> SomeTypeArgIsNe<A, B, C, D> {
}
}

impl<A: BTW, B: BTW> SomeTypeArgIsNe<A, B, ImpTypeNe, ImpTypeNe>
impl<A: BTW, B: BTW> SomeTypeArgIsNe<A, B, PadTyEq, PadTyEq>
where
A::L: Sized,
A::R: Sized,
{
#[inline(always)]
pub(crate) const fn zip2(self, _: A, _: B) -> TypeNe<(A::L, B::L), (A::R, B::R)> {
// SAFETY: either `A` or `B` is a TypeNe (ImpTypeNe can't be constructed),
// SAFETY: either `A` or `B` is a TypeNe (PadTyEq isn't a TypeNe),
// therefore: `(A::L, B::L) != (A::R, B::R)`.
// (the function parameters are needed for soundness,
// since `TypeNe` guarantees type inequality at the value level)
unsafe { TypeNe::new_unchecked() }
}
}
impl<A: BTW, B: BTW, C: BTW> SomeTypeArgIsNe<A, B, C, ImpTypeNe>
impl<A: BTW, B: BTW, C: BTW> SomeTypeArgIsNe<A, B, C, PadTyEq>
where
A::L: Sized,
A::R: Sized,
Expand All @@ -69,7 +67,7 @@ where
_: B,
_: C,
) -> TypeNe<(A::L, B::L, C::L), (A::R, B::R, C::R)> {
// SAFETY: either `A`, `B`, or `C is a TypeNe (ImpTypeNe can't be constructed),
// SAFETY: either `A`, `B`, or `C is a TypeNe (PadTyEq isn't a TypeNe),
// therefore: `(A::L, B::L, C::L) != (A::R, B::R, C::R)`.
// (the function parameters are needed for soundness,
// since `TypeNe` guarantees type inequality at the value level)
Expand Down
5 changes: 2 additions & 3 deletions src/type_cmp/extra_type_cmp_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,14 +203,13 @@ impl<L: ?Sized, R: ?Sized> TypeCmp<L, R> {
}

crate::utils::conditionally_const!{
feature = "mut_refs";
feature = "rust_1_83";

/// Converts a `TypeCmp<L, R>` to `TypeCmp<&mut L, &mut R>`
///
/// # Constness
///
/// This requires either of the `"mut_refs"` or `"const_mut_refs"`
/// crate features to be enabled to be a `const fn`.
/// This requires the `"rust_1_83"` crate feature to be a `const fn`.
///
/// # Example
///
Expand Down
12 changes: 5 additions & 7 deletions src/type_eq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -992,22 +992,20 @@ impl<L: ?Sized, R: ?Sized> TypeEq<L, R> {
}

crate::utils::conditionally_const!{
feature = "mut_refs";
feature = "rust_1_83";

/// Converts a `TypeEq<L, R>` to `TypeEq<&mut L, &mut R>`
///
/// # Constness
///
/// This requires either of the `"mut_refs"` or `"const_mut_refs"`
/// crate features to be enabled to be a `const fn`.
/// This requires the `"rust_1_83"` feature to be a `const fn`.
///
/// # Example
///
/// Because this example calls `in_mut` inside a `const fn`,
/// it requires either of the `"mut_refs"` or `"nightly_mut_refs"` crate features.
#[cfg_attr(not(feature = "mut_refs"), doc = "```ignore")]
#[cfg_attr(feature = "mut_refs", doc = "```rust")]
#[cfg_attr(feature = "nightly_mut_refs", doc = "# #![feature(const_mut_refs)]")]
/// it requires the `"rust_1_83"` crate feature.
#[cfg_attr(not(feature = "rust_1_83"), doc = "```ignore")]
#[cfg_attr(feature = "rust_1_83", doc = "```rust")]
///
/// use typewit::{TypeEq, type_eq};
///
Expand Down
5 changes: 2 additions & 3 deletions src/type_ne/extra_type_ne_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,14 +180,13 @@ impl<L: ?Sized, R: ?Sized> TypeNe<L, R> {
}

crate::utils::conditionally_const!{
feature = "mut_refs";
feature = "rust_1_83";

/// Converts a `TypeNe<L, R>` to `TypeNe<&mut L, &mut R>`
///
/// # Constness
///
/// This requires either of the `"mut_refs"` or `"const_mut_refs"`
/// crate features to be enabled to be a `const fn`.
/// This requires the `"rust_1_83"` feature to be a `const fn`.
///
/// # Example
///
Expand Down
1 change: 0 additions & 1 deletion tests/all_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#![cfg_attr(feature = "adt_const_marker", feature(adt_const_params))]
#![cfg_attr(feature = "adt_const_marker", feature(unsized_const_params))]
#![cfg_attr(feature = "adt_const_marker", allow(incomplete_features))]
#![cfg_attr(feature = "nightly_mut_refs", feature(const_mut_refs))]

mod misc_tests {
mod test_utils;
Expand Down
2 changes: 2 additions & 0 deletions tests/misc_tests/const_marker_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ use typewit::{
#[cfg(feature = "adt_const_marker")]
mod slice_const_marker_tests;

mod boolwit_tests;


#[test]
fn test_integer_const_marker() {
Expand Down
Loading
Loading