Skip to content

Commit

Permalink
allow calling assert_type{,_eq}! at top-level & const ctx
Browse files Browse the repository at this point in the history
This commit allows using `assert_type_eq!` and `assert_type!` macros
at top level.

This is done by using `const _` instead of `let _`. `const`s could not be
uninitialized, so PhantomData is also used.

Note: this requires rustc version 1.37.0 or higher.
  • Loading branch information
WaffleLapkin committed May 22, 2020
1 parent 8362450 commit a0be662
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ rust:
- stable
- beta
- nightly
- 1.22.0
- 1.37.0
cache: cargo
os:
- linux
Expand Down
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

This project follows semantic versioning.

The MSRV (Minimum Supported Rust Version) is 1.22.0, and typenum is tested against this Rust
The MSRV (Minimum Supported Rust Version) is 1.37.0, and typenum is tested against this Rust
version. Much of typenum should work on as low a version as 1.20.0, but that is not guaranteed.

### Unreleased

- [changed] Allowed calling `assert_type_eq` and `assert_type` at top level

### 1.12.0 (2020-04-13)
- [added] Feature `force_unix_path_separator` to support building without Cargo.
- [added] Greatest common divisor operator `Gcd` with alias `Gcf`.
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,14 @@ impl Ord for Equal {
#[macro_export]
macro_rules! assert_type_eq {
($a:ty, $b:ty) => {
let _: <$a as $crate::Same<$b>>::Output;
const _: core::marker::PhantomData<<$a as $crate::Same<$b>>::Output> = core::marker::PhantomData;
};
}

/// Asserts that a type is `True`, aka `B1`.
#[macro_export]
macro_rules! assert_type {
($a:ty) => {
let _: <$a as $crate::Same<True>>::Output;
const _: core::marker::PhantomData<<$a as $crate::Same<True>>::Output> = core::marker::PhantomData;
};
}

0 comments on commit a0be662

Please sign in to comment.