Skip to content

rust: implement static_assert! in a more idiomatic way - #778

Merged
ojeda merged 2 commits into
rustfrom
alex-patch-1
May 25, 2022
Merged

ojeda merged 2 commits into
rustfrom
alex-patch-1

Conversation

@alex

@alex alex commented May 25, 2022

Copy link
Copy Markdown
Member

Signed-off-by: Alex Gaynor alex.gaynor@gmail.com

@alex

alex commented May 25, 2022

Copy link
Copy Markdown
Member Author

Hmmm, the doctest code relies on overriding assert! with an assertion that's not usable in const contexts.

I don't see an obvious way to work around this, but it also seems unfortunate to be stuck with this kludgy implementation of static_assert! for forever.

@bjorn3 bjorn3 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that assert!() is supported in const contexts that is definitively much clearer!

@bjorn3

bjorn3 commented May 25, 2022

Copy link
Copy Markdown
Member

Hmmm, the doctest code relies on overriding assert! with an assertion that's not usable in const contexts.

You could refer to core::panic!() rather than panic!() I think.

@nbdd0121

Copy link
Copy Markdown
Member

core::assert! will generate fully qualified use of panic!, so core::assert! should be sufficient.

@ojeda

ojeda commented May 25, 2022

Copy link
Copy Markdown
Member

Much better, thanks all!

@ojeda
ojeda merged commit d3ddae3 into rust May 25, 2022
@ojeda
ojeda deleted the alex-patch-1 branch May 25, 2022 17:15
@nbdd0121

Copy link
Copy Markdown
Member

The commits are not signed off.

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants