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

Conversation

oli-obk
Copy link
Contributor

@oli-obk oli-obk commented Nov 14, 2018

cc @eddyb

@rust-highfive
Copy link
Collaborator

r? @michaelwoerister

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 14, 2018
@@ -16,6 +16,6 @@ macro_rules! static_assert {
// 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

@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-5.0 of your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
travis_time:end:012f6537:start=1542293740011405310,finish=1542293794140951248,duration=54129545938
$ git checkout -qf FETCH_HEAD
travis_fold:end:git.checkout

Encrypted environment variables have been removed for security reasons.
See https://docs.travis-ci.com/user/pull-requests/#Pull-Requests-and-Security-Restrictions
$ export SCCACHE_BUCKET=rust-lang-ci-sccache2
$ export SCCACHE_REGION=us-west-1
Setting environment variables from .travis.yml
$ export IMAGE=x86_64-gnu-llvm-5.0
---
[00:06:59]    Compiling proc_macro v0.0.0 (/checkout/src/libproc_macro)
[00:07:09]    Compiling syntax_ext v0.0.0 (/checkout/src/libsyntax_ext)
[00:12:44]    Compiling rustc_mir v0.0.0 (/checkout/src/librustc_mir)
[00:12:44]    Compiling rustc_allocator v0.0.0 (/checkout/src/librustc_allocator)
[00:12:45] error[E0428]: the name `_` is defined multiple times
[00:12:45]   |
[00:12:45]   = note: `_` must be defined only once in the value namespace of this module
[00:12:45] 
[00:12:45] error[E0428]: the name `_` is defined multiple times
[00:12:45]   |
[00:12:45]   = note: `_` must be defined only once in the value namespace of this module
[00:12:45] 
[00:12:45] error[E0428]: the name `_` is defined multiple times
[00:12:45]   |
[00:12:45]   = note: `_` must be defined only once in the value namespace of this module
[00:12:45] error: aborting due to previous error
[00:12:45] 
[00:12:45] For more information about this error, try `rustc --explain E0428`.
[00:12:45] error: Could not compile `rustc_incremental`.
---
[00:12:58] 
[00:12:58] To learn more, run the command again with --verbose.
[00:12:58] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "build" "--target" "x86_64-unknown-linux-gnu" "-j" "4" "--release" "--locked" "--color" "always" "--features" "" "--manifest-path" "/checkout/src/rustc/Cargo.toml" "--message-format" "json"
[00:12:58] expected success, got: exit code: 101
[00:12:58] thread 'main' panicked at 'cargo must succeed', bootstrap/compile.rs:1101:9
[00:12:58] travis_fold:end:stage0-rustc

[00:12:58] travis_time:end:stage0-rustc:start=1542294094969952935,finish=1542294582869087564,duration=487899134629


[00:12:58] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap build
[00:12:58] Build completed unsuccessfully in 0:09:13
[00:12:58] Makefile:28: recipe for target 'all' failed
[00:12:58] make: *** [all] Error 1

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@petrochenkov petrochenkov removed their assignment Nov 16, 2018
@michaelwoerister
Copy link
Member

@oli-obk Looks pretty cool, if you can get it to work :)

@michaelwoerister
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Nov 22, 2018

📌 Commit 65e6fdb has been approved by michaelwoerister

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 22, 2018
kennytm added a commit to kennytm/rust that referenced this pull request Nov 23, 2018
…ichaelwoerister

Ensure that the argument to `static_assert` is a `bool`

cc @eddyb
bors added a commit that referenced this pull request Nov 23, 2018
Rollup of 14 pull requests

Successful merges:

 - #55767 (Disable some pretty-printers when gdb is rust-enabled)
 - #55838 (Fix #[cfg] for step impl on ranges)
 - #55869 (Add std::iter::unfold)
 - #55945 (Ensure that the argument to `static_assert` is a `bool`)
 - #56022 (When popping in CTFE, perform validation before jumping to next statement to have a better span for the error)
 - #56048 (Add rustc_codegen_ssa to sysroot)
 - #56091 (Fix json output in the self-profiler)
 - #56097 (Fix invalid bitcast taking bool out of a union represented as a scalar)
 - #56116 (ci: Download clang/lldb from tarballs)
 - #56120 (Add unstable Literal::subspan().)
 - #56154 (Pass additional linker flags when targeting Fuchsia)
 - #56162 (std::str Adapt documentation to reality)
 - #56163 ([master] Backport 1.30.1 release notes)
 - #56168 (Fix the tracking issue for hash_raw_entry)

Failed merges:

r? @ghost
@bors bors merged commit 65e6fdb into rust-lang:master Nov 23, 2018
@oli-obk oli-obk deleted the static_assert_arg_type branch June 15, 2020 15:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants