Skip to content

Conversation

@WaffleLapkin
Copy link
Contributor

This PR allows using assert_type_eq! and assert_type! macros
at top-level.

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

Note:
This requires rustc version 1.37.0 or higher (the version in which underscore_const_names was stabilized).
If such a bump of MSRV is not acceptable either of 2 things can be done:

  • simply close this pr*
  • update this pr, so in the macros, there will be 2 branches - one with const, and one without**

Personally, I would prefer the second one, but both are fine.

*anyway on 1.37+ you can do const _: () = { assert_type_eq!(A, B) };
**:

($a:ty, $b:ty) => {
    let _: <$a as $crate::Same<$b>>::Output;
};
(const $a:ty, $b:ty) => {
    const _: core::marker::PhantomData<<$a as $crate::Same<$b>>::Output> = 
core::marker::PhantomData;
};

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.
Base automatically changed from master to main March 12, 2021 03:55
@paholg
Copy link
Owner

paholg commented Mar 12, 2021

Sorry for my delay; this looks good to me.

The last time I (accidentally) bumped the MSRV, it broke a dependent's MSRV build, and I reverted it. But it looks like they're on 1.41 now, and 1.37 seems plenty old enough.

There's a merge conflict because I changed build systems, but I can handle that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants