allow calling assert_type{,_eq}! at top-level#152
Merged
paholg merged 1 commit intopaholg:mainfrom Mar 12, 2021
Merged
Conversation
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.
Owner
|
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. |
This was referenced Mar 15, 2021
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR allows using
assert_type_eq!andassert_type!macrosat top-level.
This is done by using
const _instead oflet _.consts could not beuninitialized, so PhantomData is also used.
Note:
This requires
rustcversion1.37.0or higher (the version in whichunderscore_const_nameswas stabilized).If such a bump of MSRV is not acceptable either of 2 things can be done:
Personally, I would prefer the second one, but both are fine.
*anyway on
1.37+ you can doconst _: () = { assert_type_eq!(A, B) };**: