From d824f85fbe8dc1c7624d610a09500006e7031cd7 Mon Sep 17 00:00:00 2001 From: rodrimati1992 Date: Tue, 26 Nov 2024 01:49:59 -0300 Subject: [PATCH] =?UTF-8?q?Bumped=20version=20to=201.10.0,=20turned=20`Boo?= =?UTF-8?q?lWit`=20into=20more=20generic=20`BoolWit=E2=80=A6=20(#13)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 --- .github/workflows/rust.yml | 6 +- Cargo.toml | 8 ++- Changelog.md | 10 ++++ src/const_marker.rs | 5 +- .../{const_witnesses.rs => boolwit.rs} | 42 ++++++++++++-- src/const_marker/slice_const_markers.rs | 1 + src/lib.rs | 1 + src/type_cmp.rs | 2 +- src/type_eq.rs | 2 + src/type_ne_.rs | 2 + tests/all_tests.rs | 1 + ...ype_fn_conflicting_arguments-pm_err.stderr | 21 +++++++ ...inj_type_fn_from_too_generic-pm_err.stderr | 58 +++++++++++++++++++ 13 files changed, 145 insertions(+), 14 deletions(-) rename src/const_marker/{const_witnesses.rs => boolwit.rs} (84%) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 81a28c4..385b4b3 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -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" diff --git a/Cargo.toml b/Cargo.toml index ad2e330..53bcbec 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "typewit" -version = "1.9.0" +version = "1.10.0" authors = ["rodrimati1992 "] rust-version = "1.57.0" edition = "2021" @@ -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"] @@ -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"] diff --git a/Changelog.md b/Changelog.md index 731bbb2..bc8f3af 100644 --- a/Changelog.md +++ b/Changelog.md @@ -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::() != TypeId::of::()` implying `L != R`, which is not true in the general case. diff --git a/src/const_marker.rs b/src/const_marker.rs index 18306d9..0bbe89e 100644 --- a/src/const_marker.rs +++ b/src/const_marker.rs @@ -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; diff --git a/src/const_marker/const_witnesses.rs b/src/const_marker/boolwit.rs similarity index 84% rename from src/const_marker/const_witnesses.rs rename to src/const_marker/boolwit.rs index cdc5dc5..cf89277 100644 --- a/src/const_marker/const_witnesses.rs +++ b/src/const_marker/boolwit.rs @@ -1,3 +1,5 @@ +use core::fmt::{self, Debug}; + use crate::{ const_marker::Bool, TypeCmp, @@ -6,9 +8,10 @@ use crate::{ }; - /// Type Witness that [`Bool`](Bool) is either `Bool` or `Bool`. /// +/// Use this over [`BoolWitG`] if you have a `const B: bool` parameter already. +/// /// # Example /// /// Making a function that takes a generic `Foo` and calls methods on @@ -160,18 +163,45 @@ use crate::{ /// ``` /// /// -pub enum BoolWit { +pub type BoolWit = BoolWitG>; + + +/// Type witness that `B` is either [`Bool`]`` or [`Bool`]`` +/// +/// 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 { /// Witnesses that `B == true` - True(TypeEq, Bool>), + True(TypeEq>), /// Witnesses that `B == false` - False(TypeEq, Bool>), + False(TypeEq>), +} + +impl Copy for BoolWitG> {} + +impl Clone for BoolWitG> { + fn clone(&self) -> Self { + *self + } +} + +impl Debug for BoolWitG> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.write_str(match self { + Self::True{..} => "True", + Self::False{..} => "False", + }) + } } -impl TypeWitnessTypeArg for BoolWit { +impl TypeWitnessTypeArg for BoolWitG> { type Arg = Bool; } -impl MakeTypeWitness for BoolWit { +impl MakeTypeWitness for BoolWitG> { const MAKE: Self = { if let TypeCmp::Eq(te) = Bool.equals(Bool) { BoolWit::True(te) diff --git a/src/const_marker/slice_const_markers.rs b/src/const_marker/slice_const_markers.rs index 4aae343..c8a6d64 100644 --- a/src/const_marker/slice_const_markers.rs +++ b/src/const_marker/slice_const_markers.rs @@ -16,6 +16,7 @@ super::declare_const_param_type! { /// /// ```rust /// #![feature(adt_const_params)] + /// #![feature(unsized_const_params)] /// /// use typewit::{const_marker::Str, MakeTypeWitness}; /// diff --git a/src/lib.rs b/src/lib.rs index ccfcdfb..6f1ac3a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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)] diff --git a/src/type_cmp.rs b/src/type_cmp.rs index a2b4876..0fe9cd9 100644 --- a/src/type_cmp.rs +++ b/src/type_cmp.rs @@ -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")] diff --git a/src/type_eq.rs b/src/type_eq.rs index ba7d9e4..86b9840 100644 --- a/src/type_eq.rs +++ b/src/type_eq.rs @@ -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( + #[allow(dead_code)] fn(PhantomData) -> PhantomData, + #[allow(dead_code)] fn(PhantomData) -> PhantomData, ); diff --git a/src/type_ne_.rs b/src/type_ne_.rs index b16906f..a84b771 100644 --- a/src/type_ne_.rs +++ b/src/type_ne_.rs @@ -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( + #[allow(dead_code)] fn(PhantomData) -> PhantomData, + #[allow(dead_code)] fn(PhantomData) -> PhantomData, ); diff --git a/tests/all_tests.rs b/tests/all_tests.rs index 5e00eb1..619eabd 100644 --- a/tests/all_tests.rs +++ b/tests/all_tests.rs @@ -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))] diff --git a/tests/misc_tests/type_fn_ui_tests/inj_type_fn_conflicting_arguments-pm_err.stderr b/tests/misc_tests/type_fn_ui_tests/inj_type_fn_conflicting_arguments-pm_err.stderr index 9a713c6..f25a164 100644 --- a/tests/misc_tests/type_fn_ui_tests/inj_type_fn_conflicting_arguments-pm_err.stderr +++ b/tests/misc_tests/type_fn_ui_tests/inj_type_fn_conflicting_arguments-pm_err.stderr @@ -7,3 +7,24 @@ error[E0119]: conflicting implementations of trait `TypeFn` 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 => Vec; + | | } + | |_^ 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 => Vec; + | ^^^ + = note: required for `Foo` to implement `InjTypeFn` + = 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) diff --git a/tests/misc_tests/type_fn_ui_tests/inj_type_fn_from_too_generic-pm_err.stderr b/tests/misc_tests/type_fn_ui_tests/inj_type_fn_from_too_generic-pm_err.stderr index b1542f7..da0549e 100644 --- a/tests/misc_tests/type_fn_ui_tests/inj_type_fn_from_too_generic-pm_err.stderr +++ b/tests/misc_tests/type_fn_ui_tests/inj_type_fn_from_too_generic-pm_err.stderr @@ -23,3 +23,61 @@ error[E0207]: the type parameter `I` is not constrained by the impl trait, self | | impl I => ::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; N] => T; + | | } + | |_^ cannot infer the value of const parameter `N` + | +note: required for `FromTooGenericA` to implement `RevTypeFn` + --> tests/misc_tests/type_fn_ui_tests/./inj_type_fn_from_too_generic-err.rs + | + | / typewit::inj_type_fn!{ + | | struct FromTooGenericA; + | | + | | impl [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; + | | } + | |_^ 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 => ::Item; + | | } + | |_^ cannot infer type + | + = note: cannot satisfy `_: IntoIterator` +note: required for `IntoIteratorFn` to implement `RevTypeFn<::Item>` + --> tests/misc_tests/type_fn_ui_tests/./inj_type_fn_from_too_generic-err.rs + | + | / typewit::inj_type_fn!{ + | | struct IntoIteratorFn; + | | + | | impl I => ::Item; + | | ------------ unsatisfied trait bound introduced here + | | } + | |_^ + = note: required for `IntoIteratorFn` to implement `InjTypeFn` + = 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)