Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure that the argument to static_assert is a bool #55945

Merged
merged 1 commit into from
Nov 23, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/librustc_data_structures/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
/// A simple static assertion macro. The first argument should be a unique
/// ALL_CAPS identifier that describes the condition.
#[macro_export]
#[allow_internal_unstable]
macro_rules! static_assert {
($name:ident: $test:expr) => {
// Use the bool to access an array such that if the bool is false, the access
// is out-of-bounds.
#[allow(dead_code)]
static $name: () = [()][!$test as usize];
static $name: () = [()][!($test: bool) as usize];
Copy link
Member

Choose a reason for hiding this comment

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

You could use #[allow_internal_unstable] instead, maybe?
Also, has the const _ = ...; proposal been implemented?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, has the const _ = ...; proposal been implemented?

It has been implemented, but it does not cope well with allow_internal_unstable, because the crate using static_assert won't have the feature for _ items enabled, thus causing an error about item with name _ being declared multiple times

Copy link
Member

Choose a reason for hiding this comment

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

I'm very confused, how could that even happen?!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know, I presume it's because we now do have multiple items with the name _, but the multiple items with same name check doesn't know about allow_internal_unstable and thus assumes the relevant feature gate (for _ names) isn't active.

Copy link
Member

Choose a reason for hiding this comment

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

But the implementation should be using gensym so that should be impossible?

Copy link
Member

Choose a reason for hiding this comment

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

@oli-obk No, because that won't preserve the association. Anyway, gensyms are just an implementation hack, you don't actually need a name for these items.

Copy link
Contributor Author

@oli-obk oli-obk Nov 16, 2018

Choose a reason for hiding this comment

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

I can refactor AST and HIR to have Option<Symbol> for their items' names

Copy link
Member

Choose a reason for hiding this comment

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

That seems overkill for now, and also, we can move this into an issue and land a simpler version of this patch.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

by simpler you mean keeping the actual names for the assert items?

Copy link
Member

Choose a reason for hiding this comment

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

yeah

}
}