Skip to content

Commit 3e0d052

Browse files
Merge pull request #12 from rodrimati1992/mute
1.11.0 release
2 parents 68c4bb0 + a8a1b2d commit 3e0d052

26 files changed

+410
-99
lines changed

.github/workflows/rust.yml

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ jobs:
1717
strategy:
1818
max-parallel: 3
1919
matrix:
20-
rust: [stable, beta, nightly, 1.65.0, 1.61.0, 1.57.0]
20+
# TODO: add stable/beta once they're versions >= 1.83
21+
rust: [beta, nightly, 1.83.0, 1.65.0, 1.61.0, 1.57.0]
2122

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

33+
- name: enable-rust-1_83
34+
if: matrix.rust == '1.83.0'
35+
run: echo "rustv=rust_1_83" >> $GITHUB_ENV
36+
3237
- name: enable-rust-stable
3338
if: matrix.rust == 'stable' || matrix.rust == 'beta' || matrix.rust == 'nightly'
3439
run: echo "rustv=rust_stable" >> $GITHUB_ENV
@@ -59,17 +64,17 @@ jobs:
5964
cargo build
6065
6166
cargo test --no-default-features --features \
62-
"rust_stable adt_const_marker nightly_mut_refs"
67+
"rust_stable adt_const_marker"
6368
cargo test --no-default-features --features \
64-
"rust_stable adt_const_marker alloc nightly_mut_refs"
69+
"rust_stable adt_const_marker alloc"
6570
6671
cargo test --no-default-features --features \
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"
72+
"rust_stable adt_const_marker proc_macros alloc"
73+
# "rust_stable adt_const_marker proc_macros __ui_tests alloc"
6974
7075
cargo test --no-default-features --features \
71-
"rust_stable adt_const_marker alloc nightly_mut_refs"
72-
# "rust_stable adt_const_marker __ui_tests alloc nightly_mut_refs"
76+
"rust_stable adt_const_marker alloc"
77+
# "rust_stable adt_const_marker __ui_tests alloc"
7378
7479
MIRI_NIGHTLY=nightly-$(curl -s https://rust-lang.github.io/rustup-components-history/x86_64-unknown-linux-gnu/miri)
7580
echo "Installing latest nightly with Miri"
@@ -83,4 +88,4 @@ jobs:
8388
cargo clean
8489
8590
env RUST_BACKTRACE=0 cargo miri test --no-default-features \
86-
--features "${{env.rustv}} adt_const_marker proc_macros alloc nightly_mut_refs"
91+
--features "${{env.rustv}} adt_const_marker proc_macros alloc"

Cargo.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "typewit"
3-
version = "1.10.1"
3+
version = "1.11.0"
44
authors = ["rodrimati1992 <rodrimatt1985@gmail.com>"]
55
rust-version = "1.57.0"
66
edition = "2021"
@@ -38,7 +38,8 @@ optional = true
3838
default = ["proc_macros"]
3939
rust_1_61 = []
4040
rust_1_65 = ["rust_1_61"]
41-
rust_stable = ["rust_1_65"]
41+
rust_1_83 = ["rust_1_65"]
42+
rust_stable = ["rust_1_83"]
4243
proc_macros = ["typewit_proc_macros"]
4344
const_marker = []
4445
adt_const_marker = ["rust_stable"]
@@ -49,5 +50,5 @@ docsrs = []
4950
__ui_tests = ["trybuild"]
5051

5152
[package.metadata.docs.rs]
52-
features = ["alloc", "rust_stable", "nightly_mut_refs", "adt_const_marker", "docsrs"]
53+
features = ["alloc", "rust_stable", "adt_const_marker", "docsrs"]
5354

Changelog.md

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

33
# 1.0
44

5+
### 1.11.0
6+
7+
Added `"rust_1_83"` feature, which turns `typewit` functions that use `&mut` into const fns.
8+
9+
Added these methods to `BoolWitG`:
10+
- `is_true`
11+
- `is_false`
12+
- `to_true`
13+
- `to_false`
14+
- `unwrap_true`
15+
- `unwrap_false`
16+
17+
Relaxed `Copy + Clone + Debug` impls of `BooleanWitG` to work for any `<B> BooleanWitG<B>`, instead of requiring `<const B: bool> BoolWitG<Bool<B>>`.
18+
19+
520
### 1.10.1
621

722
Fixed `TypeWitnessTypeArg` impl for `BoolWitG`, it was overconstrained in a way that made `HasTypeWitness<BoolWitG<T>>` not work as a bound.

src/const_marker/boolwit.rs

Lines changed: 115 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,15 +201,127 @@ pub enum BoolWitG<B> {
201201
False(TypeEq<B, Bool<false>>),
202202
}
203203

204-
impl<const B: bool> Copy for BoolWitG<Bool<B>> {}
204+
impl<B> BoolWitG<B> {
205+
/// Whether `B == Bool<true>`
206+
///
207+
/// # Example
208+
///
209+
/// ```rust
210+
/// use typewit::{const_marker::BoolWitG, TypeEq};
211+
///
212+
/// assert_eq!(BoolWitG::True(TypeEq::NEW).is_true(), true);
213+
/// assert_eq!(BoolWitG::False(TypeEq::NEW).is_true(), false);
214+
/// ```
215+
///
216+
pub const fn is_true(self) -> bool {
217+
matches!(self, Self::True{..})
218+
}
219+
220+
/// Whether `B == Bool<false>`
221+
///
222+
/// # Example
223+
///
224+
/// ```rust
225+
/// use typewit::{const_marker::BoolWitG, TypeEq};
226+
///
227+
/// assert_eq!(BoolWitG::True(TypeEq::NEW).is_false(), false);
228+
/// assert_eq!(BoolWitG::False(TypeEq::NEW).is_false(), true);
229+
/// ```
230+
///
231+
pub const fn is_false(self) -> bool {
232+
matches!(self, Self::False{..})
233+
}
234+
235+
/// Gets a proof of `B == Bool<true>`, returns None if `B == Bool<false>`
236+
///
237+
/// # Example
238+
///
239+
/// ```rust
240+
/// use typewit::{const_marker::{Bool, BoolWitG}, TypeEq};
241+
///
242+
/// assert_eq!(BoolWitG::True(TypeEq::NEW).to_true(), Some(TypeEq::new::<Bool<true>>()));
243+
/// assert_eq!(BoolWitG::False(TypeEq::NEW).to_true(), None);
244+
/// ```
245+
///
246+
pub const fn to_true(self) -> Option<TypeEq<B, Bool<true>>> {
247+
match self {
248+
Self::True(x) => Some(x),
249+
Self::False{..} => None
250+
}
251+
}
252+
253+
/// Gets a proof of `B == Bool<false>`, returns None if `B == Bool<true>`
254+
///
255+
/// # Example
256+
///
257+
/// ```rust
258+
/// use typewit::{const_marker::{Bool, BoolWitG}, TypeEq};
259+
///
260+
/// assert_eq!(BoolWitG::True(TypeEq::NEW).to_false(), None);
261+
/// assert_eq!(BoolWitG::False(TypeEq::NEW).to_false(), Some(TypeEq::new::<Bool<false>>()));
262+
/// ```
263+
///
264+
pub const fn to_false(self) -> Option<TypeEq<B, Bool<false>>> {
265+
match self {
266+
Self::False(x) => Some(x),
267+
Self::True{..} => None
268+
}
269+
}
270+
271+
272+
/// Gets a proof of `B == Bool<true>`.
273+
///
274+
/// # Panic
275+
///
276+
/// Panics if `B == Bool<false>`
277+
///
278+
/// # Example
279+
///
280+
/// ```rust
281+
/// use typewit::{const_marker::{Bool, BoolWitG}, TypeEq};
282+
///
283+
/// assert_eq!(BoolWitG::True(TypeEq::NEW).unwrap_true(), TypeEq::new::<Bool<true>>());
284+
/// ```
285+
///
286+
pub const fn unwrap_true(self) -> TypeEq<B, Bool<true>> {
287+
match self {
288+
Self::True(x) => x,
289+
Self::False{..} => panic!("attempted to unwrap into True on False variant")
290+
}
291+
}
292+
293+
/// Gets a proof of `B == Bool<false>`.
294+
///
295+
/// # Panic
296+
///
297+
/// Panics if `B == Bool<true>`
298+
///
299+
/// # Example
300+
///
301+
/// ```rust
302+
/// use typewit::{const_marker::{Bool, BoolWitG}, TypeEq};
303+
///
304+
/// assert_eq!(BoolWitG::False(TypeEq::NEW).unwrap_false(), TypeEq::new::<Bool<false>>());
305+
/// ```
306+
///
307+
pub const fn unwrap_false(self) -> TypeEq<B, Bool<false>> {
308+
match self {
309+
Self::False(x) => x,
310+
Self::True{..} => panic!("attempted to unwrap into False on True variant")
311+
}
312+
}
313+
314+
}
315+
316+
impl<B> Copy for BoolWitG<B> {}
205317

206-
impl<const B: bool> Clone for BoolWitG<Bool<B>> {
318+
impl<B> Clone for BoolWitG<B> {
207319
fn clone(&self) -> Self {
208320
*self
209321
}
210322
}
211323

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

src/lib.rs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,9 @@
393393
//!
394394
//! - `"rust_stable"`: enables all the `"rust_1_*"` features.
395395
//!
396+
//! - `"rust_1_83"`: turns functions that take mutable references into `const fn`s,
397+
//! and enables the `"rust_1_65"` feature.
398+
//!
396399
//! - `"rust_1_65"`: enables the [`type_constructors`] module,
397400
//! the [`methods`] module,
398401
//! and the `"rust_1_61"` feature.
@@ -414,18 +417,6 @@
414417
//! and marker types in the [`const_marker`] module that have
415418
//! non-primitive `const` parameters.
416419
//!
417-
//! - `"nightly_mut_refs"`:
418-
//! Enables the `"rust_stable"` and `"mut_refs"` crate features,
419-
//! and turns functions that use mutable references into `const fn`s.
420-
//!
421-
//! ### Future-Rust features
422-
//!
423-
//! These features currently require future compiler versions:
424-
//!
425-
//! - `"mut_refs"`: turns functions that take mutable references into `const fn`s.
426-
//! note: as of October 2023,
427-
//! this crate feature requires a stable compiler from the future.
428-
//!
429420
//! # No-std support
430421
//!
431422
//! `typewit` is `#![no_std]`, it can be used anywhere Rust can be used.
@@ -452,7 +443,6 @@
452443
//! [`MetaBaseTypeWit`]: crate::MetaBaseTypeWit
453444
//! [`BaseTypeWitness`]: crate::BaseTypeWitness
454445
#![no_std]
455-
#![cfg_attr(feature = "nightly_mut_refs", feature(const_mut_refs))]
456446
#![cfg_attr(feature = "adt_const_marker", feature(adt_const_params))]
457447
#![cfg_attr(feature = "adt_const_marker", feature(unsized_const_params))]
458448
#![cfg_attr(feature = "adt_const_marker", allow(incomplete_features))]

src/some_type_arg_is_ne.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,11 @@ use crate::{
88

99

1010

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

1614
// The first TypeNe in the 4 `BaseTypeWitness` type parameters
17-
pub(crate) enum SomeTypeArgIsNe<A: BTW, B: BTW, C: BTW = ImpTypeNe, D: BTW = ImpTypeNe> {
15+
pub(crate) enum SomeTypeArgIsNe<A: BTW, B: BTW, C: BTW = PadTyEq, D: BTW = PadTyEq> {
1816
A(TypeEq<A, TypeNe<A::L, A::R>>),
1917
B(TypeEq<B, TypeNe<B::L, B::R>>),
2018
C(TypeEq<C, TypeNe<C::L, C::R>>),
@@ -41,21 +39,21 @@ impl<A: BTW, B: BTW, C: BTW, D: BTW> SomeTypeArgIsNe<A, B, C, D> {
4139
}
4240
}
4341

44-
impl<A: BTW, B: BTW> SomeTypeArgIsNe<A, B, ImpTypeNe, ImpTypeNe>
42+
impl<A: BTW, B: BTW> SomeTypeArgIsNe<A, B, PadTyEq, PadTyEq>
4543
where
4644
A::L: Sized,
4745
A::R: Sized,
4846
{
4947
#[inline(always)]
5048
pub(crate) const fn zip2(self, _: A, _: B) -> TypeNe<(A::L, B::L), (A::R, B::R)> {
51-
// SAFETY: either `A` or `B` is a TypeNe (ImpTypeNe can't be constructed),
49+
// SAFETY: either `A` or `B` is a TypeNe (PadTyEq isn't a TypeNe),
5250
// therefore: `(A::L, B::L) != (A::R, B::R)`.
5351
// (the function parameters are needed for soundness,
5452
// since `TypeNe` guarantees type inequality at the value level)
5553
unsafe { TypeNe::new_unchecked() }
5654
}
5755
}
58-
impl<A: BTW, B: BTW, C: BTW> SomeTypeArgIsNe<A, B, C, ImpTypeNe>
56+
impl<A: BTW, B: BTW, C: BTW> SomeTypeArgIsNe<A, B, C, PadTyEq>
5957
where
6058
A::L: Sized,
6159
A::R: Sized,
@@ -69,7 +67,7 @@ where
6967
_: B,
7068
_: C,
7169
) -> TypeNe<(A::L, B::L, C::L), (A::R, B::R, C::R)> {
72-
// SAFETY: either `A`, `B`, or `C is a TypeNe (ImpTypeNe can't be constructed),
70+
// SAFETY: either `A`, `B`, or `C is a TypeNe (PadTyEq isn't a TypeNe),
7371
// therefore: `(A::L, B::L, C::L) != (A::R, B::R, C::R)`.
7472
// (the function parameters are needed for soundness,
7573
// since `TypeNe` guarantees type inequality at the value level)

src/type_cmp/extra_type_cmp_methods.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,14 +203,13 @@ impl<L: ?Sized, R: ?Sized> TypeCmp<L, R> {
203203
}
204204

205205
crate::utils::conditionally_const!{
206-
feature = "mut_refs";
206+
feature = "rust_1_83";
207207

208208
/// Converts a `TypeCmp<L, R>` to `TypeCmp<&mut L, &mut R>`
209209
///
210210
/// # Constness
211211
///
212-
/// This requires either of the `"mut_refs"` or `"const_mut_refs"`
213-
/// crate features to be enabled to be a `const fn`.
212+
/// This requires the `"rust_1_83"` crate feature to be a `const fn`.
214213
///
215214
/// # Example
216215
///

src/type_eq.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -992,22 +992,20 @@ impl<L: ?Sized, R: ?Sized> TypeEq<L, R> {
992992
}
993993

994994
crate::utils::conditionally_const!{
995-
feature = "mut_refs";
995+
feature = "rust_1_83";
996996

997997
/// Converts a `TypeEq<L, R>` to `TypeEq<&mut L, &mut R>`
998998
///
999999
/// # Constness
10001000
///
1001-
/// This requires either of the `"mut_refs"` or `"const_mut_refs"`
1002-
/// crate features to be enabled to be a `const fn`.
1001+
/// This requires the `"rust_1_83"` feature to be a `const fn`.
10031002
///
10041003
/// # Example
10051004
///
10061005
/// Because this example calls `in_mut` inside a `const fn`,
1007-
/// it requires either of the `"mut_refs"` or `"nightly_mut_refs"` crate features.
1008-
#[cfg_attr(not(feature = "mut_refs"), doc = "```ignore")]
1009-
#[cfg_attr(feature = "mut_refs", doc = "```rust")]
1010-
#[cfg_attr(feature = "nightly_mut_refs", doc = "# #![feature(const_mut_refs)]")]
1006+
/// it requires the `"rust_1_83"` crate feature.
1007+
#[cfg_attr(not(feature = "rust_1_83"), doc = "```ignore")]
1008+
#[cfg_attr(feature = "rust_1_83", doc = "```rust")]
10111009
///
10121010
/// use typewit::{TypeEq, type_eq};
10131011
///

src/type_ne/extra_type_ne_methods.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,14 +180,13 @@ impl<L: ?Sized, R: ?Sized> TypeNe<L, R> {
180180
}
181181

182182
crate::utils::conditionally_const!{
183-
feature = "mut_refs";
183+
feature = "rust_1_83";
184184

185185
/// Converts a `TypeNe<L, R>` to `TypeNe<&mut L, &mut R>`
186186
///
187187
/// # Constness
188188
///
189-
/// This requires either of the `"mut_refs"` or `"const_mut_refs"`
190-
/// crate features to be enabled to be a `const fn`.
189+
/// This requires the `"rust_1_83"` feature to be a `const fn`.
191190
///
192191
/// # Example
193192
///

tests/all_tests.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#![cfg_attr(feature = "adt_const_marker", feature(adt_const_params))]
33
#![cfg_attr(feature = "adt_const_marker", feature(unsized_const_params))]
44
#![cfg_attr(feature = "adt_const_marker", allow(incomplete_features))]
5-
#![cfg_attr(feature = "nightly_mut_refs", feature(const_mut_refs))]
65

76
mod misc_tests {
87
mod test_utils;

0 commit comments

Comments
 (0)