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

Implement RFC 2539: cfg_attr with multiple attributes #54862

Merged
merged 4 commits into from
Oct 11, 2018

Conversation

Havvy
Copy link
Contributor

@Havvy Havvy commented Oct 6, 2018

This PR implements RFC 2539, except for the lint.

The lint is non-trivial and will be done in its own PR.

The tracking issue 555666 used in this PR does not actually exist, since there's no tracking issue for this RFC at the time of this. Once there's a tracking issue, I'll update the URL.

I moved src/ui/cfg-attr-trailing-comma.rs into src/ui/conditional-compilation/parse.rs instead of having it be its own test file.

r? @petrochenkov


There is one problem with getting the error message to say expected identifier or `)` for cfg_attr(pred, attr,,)). Instead, it just says expected identifier. It also says that when the feature gate is not enabled, which is definitely wrong and confusing. The expected identifier message comes from Parser::expected_ident_found which doesn't look at the `Parser::expected_tokens vec. I'm wondering if I should fix that in this PR as well.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 6, 2018
@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.
[00:49:42] .................................................................................................... 1000/4560
[00:49:44] .................................................................................................... 1100/4560
[00:49:46] .................................................................................................... 1200/4560
[00:49:49] .................................................................................................... 1300/4560
[00:49:51] ..............FF.................................................................................... 1400/4560
[00:49:57] .................i.................................................................................. 1600/4560
[00:50:00] .................................................................................................... 1700/4560
[00:50:04] .................................................................................................... 1800/4560
[00:50:07] ..............................................i..................................................... 1900/4560
---
[00:51:39] ---- [ui] ui/feature-gates/feature-gate-cfg-attr-multi-2.rs stdout ----
[00:51:39] 
[00:51:39] error: ui test compiled successfully!
[00:51:39] status: exit code: 0
[00:51:39] command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/feature-gates/feature-gate-cfg-attr-multi-2.rs" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "-Zui-testing" "-C" "prefer-dynamic" "-o" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/feature-gates/feature-gate-cfg-attr-multi-2/a" "-Crpath" "-O" "-Zunstable-options" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/feature-gates/feature-gate-cfg-attr-multi-2/auxiliary" "-A" "unused"
[00:51:39] ------------------------------------------
[00:51:39] 
[00:51:39] ------------------------------------------
[00:51:39] stderr:
[00:51:39] stderr:
[00:51:39] ------------------------------------------
[00:51:39] 
[00:51:39] ------------------------------------------
[00:51:39] 
[00:51:39] thread '[ui] ui/feature-gates/feature-gate-cfg-attr-multi-2.rs' panicked at 'explicit panic', tools/compiletest/src/runtest.rs:3267:9
[00:kout!\(.*\)|\1|;y|!|/|'); if [ -f "$EXE" ]; then printf travis_fold":start:crashlog\n\033[31;1m%s\033[0m\n" "$CORE"; gdb --batch -q -c "$CORE" "$EXE" -iex 'set auto-load off' -iex 'dir src/' -iex 'set sysroot .' -ex bt -ex q; echo travis_fold":"end:crashlog; fi; done || true
travis_fold:end:after_failure.4
travis_fold:start:after_failure.5
travis_time:start:1ff3b324
travis_time:start:1ff3b324
$ cat ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers || true
cat: ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers: No such file or directory
travis_fold:end:after_failure.5
travis_fold:start:after_failure.6
travis_time:start:0103086c
$ dmesg | grep -i kill

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)

parser.eat(&token::Comma); // Optional trailing comma

// Presumably, the majority of the time there will only be one attr.
let mut expanded_attrs = Vec::with_capacity(1);
Copy link
Member

Choose a reason for hiding this comment

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

Maybe premature, but have you considered using SmallVec to save an allocation?

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 how to measure whether or not that would be a win. And yes, it's a bit premature, since I want to get the code right first.

@petrochenkov
Copy link
Contributor

Sorry for the delay, will review tomorrow.

// compile-pass

#![cfg_attr(all(),)]
#![cfg_attr(all(), feature(cfg_attr_multi), crate_type="bin")]
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a fun example.
I didn't know that crate attributes are configured twice to get the correct feature list early.

@petrochenkov
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Oct 9, 2018

📌 Commit bbe832d has been approved by petrochenkov

@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 Oct 9, 2018
Manishearth added a commit to Manishearth/rust that referenced this pull request Oct 10, 2018
bors added a commit that referenced this pull request Oct 11, 2018
Rollup of 9 pull requests

Successful merges:

 - #54747 (codegen_llvm: verify that inline assembly operands are scalars)
 - #54848 (Better Diagnostic for Trait Object Capture)
 - #54850 (Fix #54707 - parse_trait_item_ now handles interpolated blocks as function body decls)
 - #54858 (second round of refactorings for universes)
 - #54862 (Implement RFC 2539: cfg_attr with multiple attributes)
 - #54869 (Fix mobile docs)
 - #54870 (Stabilize tool lints)
 - #54893 (Fix internal compiler error on malformed match arm pattern.)
 - #54904 (Stabilize the `Option::replace` method)

Failed merges:

 - #54909 ( Add chalk rules related to associated type defs)

r? @ghost
bors added a commit that referenced this pull request Oct 11, 2018
Rollup of 9 pull requests

Successful merges:

 - #54747 (codegen_llvm: verify that inline assembly operands are scalars)
 - #54848 (Better Diagnostic for Trait Object Capture)
 - #54850 (Fix #54707 - parse_trait_item_ now handles interpolated blocks as function body decls)
 - #54858 (second round of refactorings for universes)
 - #54862 (Implement RFC 2539: cfg_attr with multiple attributes)
 - #54869 (Fix mobile docs)
 - #54870 (Stabilize tool lints)
 - #54893 (Fix internal compiler error on malformed match arm pattern.)
 - #54904 (Stabilize the `Option::replace` method)

Failed merges:

 - #54909 ( Add chalk rules related to associated type defs)

r? @ghost
@bors bors merged commit bbe832d into rust-lang:master Oct 11, 2018
@Havvy Havvy deleted the cfg_attr_multi branch October 12, 2018 05:49
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.

5 participants