Skip to content

Commit

Permalink
Bumped version to 1.10.0, turned BoolWit into more generic `BoolWit… (
Browse files Browse the repository at this point in the history
#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
  • Loading branch information
rodrimati1992 authored Nov 26, 2024
1 parent 2d79ba0 commit d824f85
Show file tree
Hide file tree
Showing 13 changed files with 145 additions and 14 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,12 @@ jobs:
"rust_stable adt_const_marker alloc nightly_mut_refs"
cargo test --no-default-features --features \
"rust_stable adt_const_marker proc_macros __ui_tests alloc nightly_mut_refs"
"rust_stable adt_const_marker proc_macros alloc nightly_mut_refs"
# "rust_stable adt_const_marker proc_macros __ui_tests alloc nightly_mut_refs"
cargo test --no-default-features --features \
"rust_stable adt_const_marker __ui_tests alloc nightly_mut_refs"
"rust_stable adt_const_marker alloc nightly_mut_refs"
# "rust_stable adt_const_marker __ui_tests alloc nightly_mut_refs"
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 Down
8 changes: 5 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "typewit"
version = "1.9.0"
version = "1.10.0"
authors = ["rodrimati1992 <[email protected]>"]
rust-version = "1.57.0"
edition = "2021"
Expand Down Expand Up @@ -29,8 +29,10 @@ optional = true
version = "0.7"
default-features = false

[dev-dependencies.trybuild]
# no such thing as optional dev-dependencies, aaaaaaah
[dependencies.trybuild]
version = "1.0"
optional = true

[features]
default = ["proc_macros"]
Expand All @@ -44,7 +46,7 @@ alloc = []
mut_refs = ["rust_stable"]
nightly_mut_refs = ["mut_refs"]
docsrs = []
__ui_tests = []
__ui_tests = ["trybuild"]

[package.metadata.docs.rs]
features = ["alloc", "rust_stable", "nightly_mut_refs", "adt_const_marker", "docsrs"]
Expand Down
10 changes: 10 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@ This is the changelog, summarising changes in each version(some minor changes ma

# 1.0

### 1.10.0

Added `typewit::const_marker::BoolWitG` enum

Replaced `typewit::const_marker::BoolWit` enum with type alias to `BoolWitG``

Added `Copy + Clone + Debug` impls to `BoolWit`

Fixed `"adt_const_marker"` crate feature

### 1.9.0

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.
Expand Down
5 changes: 3 additions & 2 deletions src/const_marker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ use crate::{
TypeNe,
};

mod const_witnesses;
mod boolwit;

pub use boolwit::*;

pub use const_witnesses::*;

#[cfg(feature = "adt_const_marker")]
mod slice_const_markers;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use core::fmt::{self, Debug};

use crate::{
const_marker::Bool,
TypeCmp,
Expand All @@ -6,9 +8,10 @@ use crate::{
};



/// Type Witness that [`Bool<B>`](Bool) is either `Bool<true>` or `Bool<false>`.
///
/// Use this over [`BoolWitG`] if you have a `const B: bool` parameter already.
///
/// # Example
///
/// Making a function that takes a generic `Foo<B>` and calls methods on
Expand Down Expand Up @@ -160,18 +163,45 @@ use crate::{
/// ```
///
///
pub enum BoolWit<const B: bool> {
pub type BoolWit<const B: bool> = BoolWitG<Bool<B>>;


/// Type witness that `B` is either [`Bool`]`<true>` or [`Bool`]`<false>`
///
/// Use this over [`BoolWit`] if you want to write a [`HasTypeWitness`] bound
/// and adding a `const B: bool` parameter would be impossible.
///
///
/// [`HasTypeWitness`]: crate::HasTypeWitness
pub enum BoolWitG<B> {
/// Witnesses that `B == true`
True(TypeEq<Bool<B>, Bool<true>>),
True(TypeEq<B, Bool<true>>),
/// Witnesses that `B == false`
False(TypeEq<Bool<B>, Bool<false>>),
False(TypeEq<B, Bool<false>>),
}

impl<const B: bool> Copy for BoolWitG<Bool<B>> {}

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

impl<const B: bool> Debug for BoolWitG<Bool<B>> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str(match self {
Self::True{..} => "True",
Self::False{..} => "False",
})
}
}

impl<const B: bool> TypeWitnessTypeArg for BoolWit<B> {
impl<const B: bool> TypeWitnessTypeArg for BoolWitG<Bool<B>> {
type Arg = Bool<B>;
}

impl<const B: bool> MakeTypeWitness for BoolWit<B> {
impl<const B: bool> MakeTypeWitness for BoolWitG<Bool<B>> {
const MAKE: Self = {
if let TypeCmp::Eq(te) = Bool.equals(Bool) {
BoolWit::True(te)
Expand Down
1 change: 1 addition & 0 deletions src/const_marker/slice_const_markers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ super::declare_const_param_type! {
///
/// ```rust
/// #![feature(adt_const_params)]
/// #![feature(unsized_const_params)]
///
/// use typewit::{const_marker::Str, MakeTypeWitness};
///
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@
#![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))]
#![cfg_attr(feature = "docsrs", feature(doc_cfg))]
#![allow(clippy::type_complexity)]
Expand Down
2 changes: 1 addition & 1 deletion src/type_cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use core::{
///
/// ### Custom array creation
///
/// (this example requires Rust 1.63.0, because of [`std::array::from_fn`]).
/// (this example requires Rust 1.63.0, because of [`core::array::from_fn`]).
///
#[cfg_attr(not(feature = "rust_1_65"), doc = "```ignore")]
#[cfg_attr(feature = "rust_1_65", doc = "```rust")]
Expand Down
2 changes: 2 additions & 0 deletions src/type_eq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,9 @@ mod type_eq_ {
// Declared to work around this error in old Rust versions:
// > error[E0658]: function pointers cannot appear in constant functions
struct TypeEqHelper<L: ?Sized, R: ?Sized>(
#[allow(dead_code)]
fn(PhantomData<L>) -> PhantomData<L>,
#[allow(dead_code)]
fn(PhantomData<R>) -> PhantomData<R>,
);

Expand Down
2 changes: 2 additions & 0 deletions src/type_ne_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ mod type_ne_ {
// Declared to work around this error in old Rust versions:
// > error[E0658]: function pointers cannot appear in constant functions
struct TypeNeHelper<L: ?Sized, R: ?Sized>(
#[allow(dead_code)]
fn(PhantomData<L>) -> PhantomData<L>,
#[allow(dead_code)]
fn(PhantomData<R>) -> PhantomData<R>,
);

Expand Down
1 change: 1 addition & 0 deletions tests/all_tests.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![deny(unused_mut)]
#![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))]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,24 @@ error[E0119]: conflicting implementations of trait `TypeFn<u8>` for type `Foo`
| ^ conflicting implementation for `Foo`
|
= note: this error originates in the macro `$crate::__impl_with_span` which comes from the expansion of the macro `typewit::inj_type_fn` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0283]: type annotations needed
--> tests/misc_tests/type_fn_ui_tests/./inj_type_fn_conflicting_arguments-err.rs
|
| / typewit::inj_type_fn!{
| | struct Foo;
| |
| | impl u8 => u16;
| | impl<T> T => Vec<T>;
| | }
| |_^ cannot infer type
|
note: multiple `impl`s satisfying `Foo: RevTypeFn<_>` found
--> tests/misc_tests/type_fn_ui_tests/./inj_type_fn_conflicting_arguments-err.rs
|
| impl u8 => u16;
| ^^^
| impl<T> T => Vec<T>;
| ^^^
= note: required for `Foo` to implement `InjTypeFn<u8>`
= note: this error originates in the macro `$crate::__tyfn_injtypefn_impl` which comes from the expansion of the macro `typewit::inj_type_fn` (in Nightly builds, run with -Z macro-backtrace for more info)
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,61 @@ error[E0207]: the type parameter `I` is not constrained by the impl trait, self
|
| impl<I: IntoIterator> I => <I as IntoIterator>::Item;
| ^ unconstrained type parameter

error[E0284]: type annotations needed
--> tests/misc_tests/type_fn_ui_tests/./inj_type_fn_from_too_generic-err.rs
|
| / typewit::inj_type_fn!{
| | struct FromTooGenericA;
| |
| | impl<T, const N: usize> [T; N] => T;
| | }
| |_^ cannot infer the value of const parameter `N`
|
note: required for `FromTooGenericA` to implement `RevTypeFn<T>`
--> tests/misc_tests/type_fn_ui_tests/./inj_type_fn_from_too_generic-err.rs
|
| / typewit::inj_type_fn!{
| | struct FromTooGenericA;
| |
| | impl<T, const N: usize> [T; N] => T;
| | }
| |_^ unsatisfied trait bound introduced here
= note: required for `FromTooGenericA` to implement `InjTypeFn<[T; N]>`
= note: this error originates in the macro `$crate::__tyfn_injtypefn_impl` which comes from the expansion of the macro `typewit::inj_type_fn` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0282]: type annotations needed
--> tests/misc_tests/type_fn_ui_tests/./inj_type_fn_from_too_generic-err.rs
|
| / typewit::inj_type_fn!{
| | struct FromTooGenericB;
| |
| | impl<T, U> (T, U) => T;
| | }
| |_^ cannot infer type
|
= note: this error originates in the macro `$crate::__tyfn_injtypefn_impl` which comes from the expansion of the macro `typewit::inj_type_fn` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0283]: type annotations needed
--> tests/misc_tests/type_fn_ui_tests/./inj_type_fn_from_too_generic-err.rs
|
| / typewit::inj_type_fn!{
| | struct IntoIteratorFn;
| |
| | impl<I: IntoIterator> I => <I as IntoIterator>::Item;
| | }
| |_^ cannot infer type
|
= note: cannot satisfy `_: IntoIterator`
note: required for `IntoIteratorFn` to implement `RevTypeFn<<I as IntoIterator>::Item>`
--> tests/misc_tests/type_fn_ui_tests/./inj_type_fn_from_too_generic-err.rs
|
| / typewit::inj_type_fn!{
| | struct IntoIteratorFn;
| |
| | impl<I: IntoIterator> I => <I as IntoIterator>::Item;
| | ------------ unsatisfied trait bound introduced here
| | }
| |_^
= note: required for `IntoIteratorFn` to implement `InjTypeFn<I>`
= note: this error originates in the macro `$crate::__tyfn_injtypefn_impl` which comes from the expansion of the macro `typewit::inj_type_fn` (in Nightly builds, run with -Z macro-backtrace for more info)

0 comments on commit d824f85

Please sign in to comment.