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

rustc: Disallow modules and macros in expansions #50820

Merged
merged 1 commit into from
May 20, 2018

Conversation

alexcrichton
Copy link
Member

This commit feature gates generating modules and macro definitions in procedural
macro expansions. Custom derive is exempt from this check as it would be a large
retroactive breaking change (#50587). It's hoped that we can hopefully stem the
bleeding to figure out a better solution here before opening up the floodgates.

The restriction here is specifically targeted at surprising hygiene results 1
that result in non-"copy/paste" behavior. Hygiene and procedural macros is
intended to be avoided as much as possible for Macros 1.2 by saying everything
is "as if you copy/pasted the code", but modules and macros are sort of weird
exceptions to this rule that aren't fully fleshed out.

cc #50504

@rust-highfive
Copy link
Collaborator

r? @eddyb

(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 May 17, 2018
@alexcrichton
Copy link
Member Author

r? @petrochenkov

@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-3.9 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:start:tidy
tidy check
[00:04:39] * 542 error codes
[00:04:39] * highest error code: E0911
[00:04:40] tidy error: Found 1 features without a gate test.
[00:04:40] Expected a gate test for the feature 'proc_macro_gen'.
[00:04:40] Hint: create a failing test file named 'feature-gate-proc_macro_gen.rs'
[00:04:40]       in the 'ui' test suite, with its failures due to
[00:04:40]       missing usage of #![feature(proc_macro_gen)].
[00:04:40] Hint: If you already have such a test and don't want to rename it,
[00:04:40]       you can also add a // gate-test-proc_macro_gen line to the test file.
[00:04:40] some tidy checks failed
[00:04:40] 
[00:04:40] 
[00:04:40] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/tidy" "/checkout/src" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "--no-vendor" "--quiet"
[00:04:40] 
[00:04:40] 
[00:04:40] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test src/tools/tidy
[00:04:40] Build completed unsuccessfully in 0:01:47
[00:04:40] Build completed unsuccessfully in 0:01:47
[00:04:40] Makefile:79: recipe for target 'tidy' failed
[00:04:40] make: *** [tidy] Error 1

The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:04c5039e
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)

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
Copy link
Contributor

Couple of tests?
One for a module, one for a macro and one for nested module/macro inside some non-module/macro item like fn f() { mod m { ... } }.
r=me after that

@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 17, 2018
@alexcrichton
Copy link
Member Author

@bors: r=petrochenkov

@bors
Copy link
Contributor

bors commented May 17, 2018

📌 Commit 81fc850 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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 17, 2018
@kennytm
Copy link
Member

kennytm commented May 17, 2018

@bors r-

run-pass-fulldeps/macro-quote-test.rs is missing a #![feature(proc_macro_gen)]. (Log: https://travis-ci.org/rust-lang/rust/jobs/380273579)

[01:13:54] ---- [run-pass] run-pass-fulldeps/macro-quote-test.rs stdout ----
[01:13:54] 	
[01:13:54] error: compilation failed!
[01:13:54] status: exit code: 101
[01:13:54] command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/run-pass-fulldeps/macro-quote-test.rs" "--target=x86_64-unknown-linux-gnu" "-C" "prefer-dynamic" "-o" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/run-pass-fulldeps/macro-quote-test/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/run-pass-fulldeps/macro-quote-test/auxiliary"
[01:13:54] stdout:
[01:13:54] ------------------------------------------
[01:13:54] 
[01:13:54] ------------------------------------------
[01:13:54] stderr:
[01:13:54] ------------------------------------------
[01:13:54] error[E0658]: procedural macros cannot expand to macro definitions
[01:13:54]   --> /checkout/src/test/run-pass-fulldeps/macro-quote-test.rs:21:5
[01:13:54]    |
[01:13:54] 21 |     hello_macro::hello!();
[01:13:54]    |     ^^^^^^^^^^^^^^^^^^^^^^
[01:13:54]    |
[01:13:54]    = help: add #![feature(proc_macro_gen)] to the crate attributes to enable
[01:13:54] 
[01:13:54] error: aborting due to previous error
[01:13:54] 
[01:13:54] For more information about this error, try `rustc --explain E0658`.
[01:13:54] 
[01:13:54] ------------------------------------------
[01:13:54] 
[01:13:54] thread '[run-pass] run-pass-fulldeps/macro-quote-test.rs' panicked at 'explicit panic', tools/compiletest/src/runtest.rs:3014:9
[01:13:54] note: Run with `RUST_BACKTRACE=1` for a backtrace.
[01:13:54] 
[01:13:54] 
[01:13:54] failures:
[01:13:54]     [run-pass] run-pass-fulldeps/macro-quote-test.rs
[01:13:54] 
[01:13:54] test result: FAILED. 89 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels May 17, 2018
This commit feature gates generating modules and macro definitions in procedural
macro expansions. Custom derive is exempt from this check as it would be a large
retroactive breaking change (rust-lang#50587). It's hoped that we can hopefully stem the
bleeding to figure out a better solution here before opening up the floodgates.

The restriction here is specifically targeted at surprising hygiene results [1]
that result in non-"copy/paste" behavior. Hygiene and procedural macros is
intended to be avoided as much as possible for Macros 1.2 by saying everything
is "as if you copy/pasted the code", but modules and macros are sort of weird
exceptions to this rule that aren't fully fleshed out.

[1]: rust-lang#50504 (comment)

cc rust-lang#50504
@alexcrichton
Copy link
Member Author

@bors: r=petrochenkov

@bors
Copy link
Contributor

bors commented May 18, 2018

📌 Commit 5e4bac3 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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 18, 2018
@bors
Copy link
Contributor

bors commented May 20, 2018

⌛ Testing commit 5e4bac3 with merge ccb5e97...

bors added a commit that referenced this pull request May 20, 2018
rustc: Disallow modules and macros in expansions

This commit feature gates generating modules and macro definitions in procedural
macro expansions. Custom derive is exempt from this check as it would be a large
retroactive breaking change (#50587). It's hoped that we can hopefully stem the
bleeding to figure out a better solution here before opening up the floodgates.

The restriction here is specifically targeted at surprising hygiene results [1]
that result in non-"copy/paste" behavior. Hygiene and procedural macros is
intended to be avoided as much as possible for Macros 1.2 by saying everything
is "as if you copy/pasted the code", but modules and macros are sort of weird
exceptions to this rule that aren't fully fleshed out.

[1]: #50504 (comment)

cc #50504
@bors
Copy link
Contributor

bors commented May 20, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: petrochenkov
Pushing ccb5e97 to master...

@bors bors merged commit 5e4bac3 into rust-lang:master May 20, 2018
@sgrif
Copy link
Contributor

sgrif commented Sep 3, 2018

Since #51952 landed, do we still need this feature gate? It looks like the underlying problem has now been fixed.

@petrochenkov
Copy link
Contributor

@sgrif
#53459 partially stabilized proc_macro_gen recently (the module part).

@sgrif
Copy link
Contributor

sgrif commented Sep 6, 2018

Thanks

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.

7 participants