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

resolve: Modularize crate-local #[macro_export] macro_rules #52234

Merged
merged 1 commit into from
Jul 31, 2018

Conversation

petrochenkov
Copy link
Contributor

@petrochenkov petrochenkov commented Jul 10, 2018

Based on #50911, cc #50911 (comment)

#[macro_export] macro_rules items are collected from the whole crate and are planted into the root module as items, so the external view of the crate is symmetric with its internal view and something like $crate::my_macro where my_macro is #[macro_export] macro_rules works both locally and from other crates.

Closes #52726

@rust-highfive
Copy link
Collaborator

r? @cramertj

(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 Jul 10, 2018
@petrochenkov
Copy link
Contributor Author

@bors try

@petrochenkov petrochenkov added S-waiting-on-crater Status: Waiting on a crater run to be completed. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 10, 2018
@bors
Copy link
Contributor

bors commented Jul 10, 2018

⌛ Trying commit ee16ce1 with merge bcc0707...

bors added a commit that referenced this pull request Jul 10, 2018
[Experiment] resolve: Modularize crate-local `#[macro_export] macro_rules`

Based on #50911, cc #50911 (comment)

`#[macro_export] macro_rules` items are collected from the whole crate and are planted into the root module as items, so the external view of the crate is symmetric with its internal view and something like `$crate::my_macro` where `my_macro` is `#[macro_export] macro_rules` works both locally and from other crates.
@petrochenkov
Copy link
Contributor Author

ping @pietroalbini
this needs a check-only crater run

@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.
  InsecurePlatformWarning
  Downloading https://files.pythonhosted.org/packages/2d/99/b2c4e9d5a30f6471e410a146232b4118e697fa3ffc06d6a65efde84debd0/futures-3.2.0-py2-none-any.whl
Requirement already satisfied: six>=1.5 in /usr/lib/python2.7/dist-packages (from python-dateutil<3.0.0,>=2.1; python_version >= "2.7"->botocore==1.10.55->awscli)
Building wheels for collected packages: awscli
  Running setup.py bdist_wheel for awscli ... - \ | / - \ done
Successfully built awscli
Installing collected packages: docutils, jmespath, python-dateutil, botocore, colorama, pyasn1, rsa, futures, s3transfer, awscli
Successfully installed awscli-1.15.56 botocore-1.10.55 colorama-0.3.9 docutils-0.14 futures-3.2.0 jmespath-0.9.3 pyasn1-0.4.3 python-dateutil-2.7.3 rsa-3.4.2 s3transfer-0.1.13
/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:122: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#insecureplatformwarning.
---
[00:41:07]     Checking rustc_tsan v0.0.0 (file:///checkout/src/librustc_tsan)
[00:41:07]     Checking rustc_msan v0.0.0 (file:///checkout/src/librustc_msan)
[00:41:07]     Checking rustc_asan v0.0.0 (file:///checkout/src/librustc_asan)
[00:41:07]  Documenting std v0.0.0 (file:///checkout/src/libstd)
[00:41:08] error: macro expansion ignores token `{` and any following
[00:41:08]     |
[00:41:08]     |
[00:41:08] 771 |         ($file:expr) => ({ /* compiler built-in */ });
[00:41:08]     |
[00:41:08]     |
[00:41:08] note: caused by the macro expansion here; the usage of `include!` is likely invalid in item context
[00:41:08]    --> libstd/lib.rs:548:1
[00:41:08]     |
[00:41:08] 548 | include!("primitive_docs.rs");
[00:41:08] 
[00:41:08] 
[00:41:08] error: macro expansion ignores token `{` and any following
[00:41:08]     |
[00:41:08]     |
[00:41:08] 771 |         ($file:expr) => ({ /* compiler built-in */ });
[00:41:08]     |
[00:41:08]     |
[00:41:08] note: caused by the macro expansion here; the usage of `include!` is likely invalid in item context
[00:41:08]    --> libstd/lib.rs:553:1
[00:41:08]     |
[00:41:08] 553 | include!("keyword_docs.rs");
[00:41:08] 
[00:41:08] 
[00:41:08] error: Could not document `std`.
[00:41:08] Caused by:
[00:41:08] Caused by:
[00:41:08]   process didn't exit successfully: `/checkout/obj/build/bootstrap/debug/rustdoc --crate-name std libstd/lib.rs --target x86_64-unknown-linux-gnu -o /checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/doc --cfg feature="alloc_jemalloc" --cfg feature="backtrace" --cfg feature="jemalloc" --cfg feature="panic-unwind" --cfg feature="panic_unwind" -L dependency=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps -L dependency=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/release/deps --extern alloc=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/liballoc-f4ae61a0ac9de403.rmeta --extern alloc_jemalloc=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/liballoc_jemalloc-6e31f4ac527cac4f.rmeta --extern alloc_system=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/liballoc_system-953937df74cec9d8.rmeta --extern compiler_builtins=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/libcompiler_builtins-9cb094b550f36de1.rmeta --extern core=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/libcore-b15f1ff96a8f614d.rmeta --extern libc=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/liblibc-b593463e25ad8bc9.rmeta --extern panic_abort=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/libpanic_abort-d6f76d88eb491ae8.rmeta --extern panic_unwind=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/libpanic_unwind-241c8eb04554268c.rmeta --extern rustc_asan=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/librustc_asan-8fb2bf0fd88472e9.rmeta --extern rustc_lsan=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/librustc_lsan-ec08d8e5e1d73289.rmeta --extern rustc_msan=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/librustc_msan-1341914eb50a09c0.rmeta --extern rustc_tsan=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/librustc_tsan-acea38b6e3885725.rmeta --extern std_unicode=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/libstd_unicode-f63bf17f6ac88315.rmeta --extern unwind=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/libunwind-39eca009eb64ef4f.rmeta` (exit code: 101)
[00:41:08] 
[00:41:08] 
[00:41:08] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "doc" "--target" "x86_64-unknown-linux-gnu" "-j" "4" "--release" "--locked" "--color" "always" "--features" "panic-unwind jemalloc backtrace" "--manifest-path" "/checkout/src/libstd/Cargo.toml" "--no-deps" "-p" "alloc" "-p" "core" "-p" "std" "-p" "std_unicode"
[00:41:08] 
[00:41:08] 
[00:41:08] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap doc
[00:41:08] Build completed unsuccessfully in 0:04:52
[00:41:08] Build completed unsuccessfully in 0:04:52
[00:41:08] make: *** [all] Error 1
[00:41:08] Makefile:28: recipe for target 'all' failed

The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:0755e612
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)
---
travis_time:end:02926932:start=1531269441066222874,finish=1531269441073890522,duration=7667648
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:054d9cfa
$ head -30 ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers || true
head: cannot open ‘./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers’ for reading: No such file or directory
travis_fold:end:after_failure.4
travis_fold:start:after_failure.5
travis_time:start:11e929ba
$ 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)

@bors
Copy link
Contributor

bors commented Jul 11, 2018

💔 Test failed - status-travis

@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-crater Status: Waiting on a crater run to be completed. labels Jul 11, 2018
@rust-highfive
Copy link
Collaborator

The job dist-x86_64-linux 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_fold:end:services

travis_fold:start:git.checkout
travis_time:start:08fbd86e
$ git clone --depth=2 --branch=try https://github.com/rust-lang/rust.git rust-lang/rust
---
[00:59:05]     Checking rustc_lsan v0.0.0 (file:///checkout/src/librustc_lsan)
[00:59:05]     Checking panic_unwind v0.0.0 (file:///checkout/src/libpanic_unwind)
[00:59:05]     Checking rustc_msan v0.0.0 (file:///checkout/src/librustc_msan)
[00:59:05]  Documenting std v0.0.0 (file:///checkout/src/libstd)
[00:59:06] error: macro expansion ignores token `{` and any following
[00:59:06]     |
[00:59:06]     |
[00:59:06] 771 |         ($file:expr) => ({ /* compiler built-in */ });
[00:59:06]     |
[00:59:06]     |
[00:59:06] note: caused by the macro expansion here; the usage of `include!` is likely invalid in item context
[00:59:06]    --> libstd/lib.rs:548:1
[00:59:06]     |
[00:59:06] 548 | include!("primitive_docs.rs");
[00:59:06] 
[00:59:06] 
[00:59:06] error: macro expansion ignores token `{` and any following
[00:59:06]     |
[00:59:06]     |
[00:59:06] 771 |         ($file:expr) => ({ /* compiler built-in */ });
[00:59:06]     |
[00:59:06]     |
[00:59:06] note: caused by the macro expansion here; the usage of `include!` is likely invalid in item context
[00:59:06]    --> libstd/lib.rs:553:1
[00:59:06]     |
[00:59:06] 553 | include!("keyword_docs.rs");
[00:59:06] 
[00:59:06] 
[00:59:06] error: Could not document `std`.
[00:59:06] Caused by:
[00:59:06] Caused by:
[00:59:06]   process didn't exit successfully: `/checkout/obj/build/bootstrap/debug/rustdoc --crate-name std libstd/lib.rs --target x86_64-unknown-linux-gnu -o /checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/doc --cfg feature="alloc_jemalloc" --cfg feature="backtrace" --cfg feature="jemalloc" --cfg feature="panic-unwind" --cfg feature="panic_unwind" --cfg feature="profiler" --cfg feature="profiler_builtins" -L dependency=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps -L dependency=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/release/deps --extern alloc=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/liballoc-11f645d5d50ec01d.rmeta --extern alloc_jemalloc=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/liballoc_jemalloc-b47ce328a4ba70ee.rmeta --extern alloc_system=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/liballoc_system-f97b2ca8b6ea07bd.rmeta --extern compiler_builtins=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/libcompiler_builtins-a79b1686dcdb6599.rmeta --extern core=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/libcore-9dfdb611cdf09a22.rmeta --extern libc=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/liblibc-e113f9b9a0aa6586.rmeta --extern panic_abort=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/libpanic_abort-afa6c0a795054c51.rmeta --extern panic_unwind=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/libpanic_unwind-4f996473c57ff2d7.rmeta --extern profiler_builtins=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/libprofiler_builtins-96fc30c656f77bfd.rmeta --extern rustc_asan=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/librustc_asan-6678a520a240f250.rmeta --extern rustc_lsan=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/librustc_lsan-2b28bf250e8c19b3.rmeta --extern rustc_msan=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/librustc_msan-72f2ee3ef3ce967d.rmeta --extern rustc_tsan=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/librustc_tsan-f130431124e944fe.rmeta --extern std_unicode=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/libstd_unicode-3448644921326dc8.rmeta --extern unwind=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/libunwind-62dce3cd9306a1e4.rmeta` (exit code: 101)
[00:59:06] 
[00:59:06] 
[00:59:06] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "doc" "--target" "x86_64-unknown-linux-gnu" "-j" "4" "--release" "--locked" "--color" "always" "--features" "panic-unwind jemalloc backtrace profiler" "--manifest-path" "/checkout/src/libstd/Cargo.toml" "--no-deps" "-p" "alloc" "-p" "core" "-p" "std" "-p" "std_unicode"
[00:59:06] 
[00:59:06] 
[00:59:06] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap dist --host x86_64-unknown-linux-gnu --target x86_64-unknown-linux-gnu
[00:59:06] Build completed unsuccessfully in 0:53:26

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)

1 similar comment
@rust-highfive
Copy link
Collaborator

The job dist-x86_64-linux 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_fold:end:services

travis_fold:start:git.checkout
travis_time:start:08fbd86e
$ git clone --depth=2 --branch=try https://github.com/rust-lang/rust.git rust-lang/rust
---
[00:59:05]     Checking rustc_lsan v0.0.0 (file:///checkout/src/librustc_lsan)
[00:59:05]     Checking panic_unwind v0.0.0 (file:///checkout/src/libpanic_unwind)
[00:59:05]     Checking rustc_msan v0.0.0 (file:///checkout/src/librustc_msan)
[00:59:05]  Documenting std v0.0.0 (file:///checkout/src/libstd)
[00:59:06] error: macro expansion ignores token `{` and any following
[00:59:06]     |
[00:59:06]     |
[00:59:06] 771 |         ($file:expr) => ({ /* compiler built-in */ });
[00:59:06]     |
[00:59:06]     |
[00:59:06] note: caused by the macro expansion here; the usage of `include!` is likely invalid in item context
[00:59:06]    --> libstd/lib.rs:548:1
[00:59:06]     |
[00:59:06] 548 | include!("primitive_docs.rs");
[00:59:06] 
[00:59:06] 
[00:59:06] error: macro expansion ignores token `{` and any following
[00:59:06]     |
[00:59:06]     |
[00:59:06] 771 |         ($file:expr) => ({ /* compiler built-in */ });
[00:59:06]     |
[00:59:06]     |
[00:59:06] note: caused by the macro expansion here; the usage of `include!` is likely invalid in item context
[00:59:06]    --> libstd/lib.rs:553:1
[00:59:06]     |
[00:59:06] 553 | include!("keyword_docs.rs");
[00:59:06] 
[00:59:06] 
[00:59:06] error: Could not document `std`.
[00:59:06] Caused by:
[00:59:06] Caused by:
[00:59:06]   process didn't exit successfully: `/checkout/obj/build/bootstrap/debug/rustdoc --crate-name std libstd/lib.rs --target x86_64-unknown-linux-gnu -o /checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/doc --cfg feature="alloc_jemalloc" --cfg feature="backtrace" --cfg feature="jemalloc" --cfg feature="panic-unwind" --cfg feature="panic_unwind" --cfg feature="profiler" --cfg feature="profiler_builtins" -L dependency=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps -L dependency=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/release/deps --extern alloc=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/liballoc-11f645d5d50ec01d.rmeta --extern alloc_jemalloc=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/liballoc_jemalloc-b47ce328a4ba70ee.rmeta --extern alloc_system=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/liballoc_system-f97b2ca8b6ea07bd.rmeta --extern compiler_builtins=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/libcompiler_builtins-a79b1686dcdb6599.rmeta --extern core=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/libcore-9dfdb611cdf09a22.rmeta --extern libc=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/liblibc-e113f9b9a0aa6586.rmeta --extern panic_abort=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/libpanic_abort-afa6c0a795054c51.rmeta --extern panic_unwind=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/libpanic_unwind-4f996473c57ff2d7.rmeta --extern profiler_builtins=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/libprofiler_builtins-96fc30c656f77bfd.rmeta --extern rustc_asan=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/librustc_asan-6678a520a240f250.rmeta --extern rustc_lsan=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/librustc_lsan-2b28bf250e8c19b3.rmeta --extern rustc_msan=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/librustc_msan-72f2ee3ef3ce967d.rmeta --extern rustc_tsan=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/librustc_tsan-f130431124e944fe.rmeta --extern std_unicode=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/libstd_unicode-3448644921326dc8.rmeta --extern unwind=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/libunwind-62dce3cd9306a1e4.rmeta` (exit code: 101)
[00:59:06] 
[00:59:06] 
[00:59:06] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "doc" "--target" "x86_64-unknown-linux-gnu" "-j" "4" "--release" "--locked" "--color" "always" "--features" "panic-unwind jemalloc backtrace profiler" "--manifest-path" "/checkout/src/libstd/Cargo.toml" "--no-deps" "-p" "alloc" "-p" "core" "-p" "std" "-p" "std_unicode"
[00:59:06] 
[00:59:06] 
[00:59:06] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap dist --host x86_64-unknown-linux-gnu --target x86_64-unknown-linux-gnu
[00:59:06] Build completed unsuccessfully in 0:53:26

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 Author

petrochenkov commented Jul 11, 2018

Is it necessary to fix the std doc generation mode (cfg(dox)) to run crater?

@pietroalbini
Copy link
Member

I don't think std docs needs to be working to get a crater run, but a successful try build is needed.

@petrochenkov
Copy link
Contributor Author

@bors try

@bors
Copy link
Contributor

bors commented Jul 11, 2018

⌛ Trying commit 1f844a847d62ded4322840a4ddbb499e0228cd48 with merge d39a6f7eddafd45dcc60e99001b8cd08c2bd3255...

@petrochenkov petrochenkov added S-waiting-on-crater Status: Waiting on a crater run to be completed. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 11, 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.
  InsecurePlatformWarning
  Downloading https://files.pythonhosted.org/packages/2d/99/b2c4e9d5a30f6471e410a146232b4118e697fa3ffc06d6a65efde84debd0/futures-3.2.0-py2-none-any.whl
Requirement already satisfied: six>=1.5 in /usr/lib/python2.7/dist-packages (from python-dateutil<3.0.0,>=2.1; python_version >= "2.7"->botocore==1.10.55->awscli)
Building wheels for collected packages: awscli
  Running setup.py bdist_wheel for awscli ... - \ | / - \ done
Successfully built awscli
Installing collected packages: docutils, jmespath, python-dateutil, botocore, colorama, pyasn1, rsa, futures, s3transfer, awscli
Successfully installed awscli-1.15.56 botocore-1.10.55 colorama-0.3.9 docutils-0.14 futures-3.2.0 jmespath-0.9.3 pyasn1-0.4.3 python-dateutil-2.7.3 rsa-3.4.2 s3transfer-0.1.13
/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:122: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#insecureplatformwarning.
---
[01:10:19] travis_fold:end:stage0-linkchecker

[01:10:19] travis_time:end:stage0-linkchecker:start=1531308106477156288,finish=1531308108797621155,duration=2320464867

[01:10:19] std/macro.assert_ne.html:11: broken link - std/macro.assert.html
[01:10:21] std/macro.assert_eq.html:11: broken link - std/macro.assert.html
[01:10:21] std/io/trait.Write.html:121: broken link - std/macro.format_args.html
[01:10:23] std/macro.panic.html:26: broken link - std/macro.compile_error.html
[01:10:25] std/macro.debug_assert.html:8: broken link - std/macro.assert.html
[01:10:25] std/macro.debug_assert.html:11: broken link - std/macro.assert.html
[01:10:25] std/macro.debug_assert.html:20: broken link - std/macro.assert.html
[01:10:26] std/primitive.bool.html:7: broken link - std/macro.assert.html
[01:10:26] std/fmt/fn.format.html:3: broken link - std/macro.format_args.html
[01:10:26] std/fmt/index.html:234: broken link - std/macro.format_args.html
[01:10:26] std/fmt/struct.Arguments.html:5: broken link - std/macro.format_args.html
[01:10:26] std/fmt/struct.Arguments.html:8: broken link - std/macro.format_args.html
[01:10:26] std/fmt/struct.Formatter.html:310: broken link - std/macro.format_args.html
[01:10:28] core/macro.assert_ne.html:10: broken link - core/macro.assert.html
[01:10:29] core/macro.assert_eq.html:10: broken link - core/macro.assert.html
[01:10:29] core/macro.debug_assert.html:8: broken link - core/macro.assert.html
[01:10:29] core/macro.debug_assert.html:11: broken link - core/macro.assert.html
[01:10:29] core/macro.debug_assert.html:20: broken link - core/macro.assert.html
[01:10:30] core/fmt/struct.Arguments.html:5: broken link - std/macro.format_args.html
[01:10:30] core/fmt/struct.Arguments.html:8: broken link - std/macro.format_args.html
[01:10:30] core/fmt/struct.Formatter.html:310: broken link - std/macro.format_args.html
[01:10:34] alloc/fmt/fn.format.html:3: broken link - std/macro.format_args.html
[01:10:34] alloc/fmt/index.html:234: broken link - std/macro.format_args.html
[01:10:34] alloc/fmt/struct.Arguments.html:5: broken link - std/macro.format_args.html
[01:10:34] alloc/fmt/struct.Arguments.html:8: broken link - std/macro.format_args.html
[01:10:34] alloc/fmt/struct.Formatter.html:310: broken link - std/macro.format_args.html
[01:10:34] thread 'main' panicked at 'found some broken links', tools/linkchecker/main.rs:49:9
[01:10:34] 
[01:10:34] 
[01:10:34] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/linkchecker" "/checkout/obj/build/x86_64-unknown-linux-gnu/doc"
[01:10:34] expected success, got: exit code: 101
[01:10:34] expected success, got: exit code: 101
[01:10:34] 
[01:10:34] 
[01:10:34] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test
[01:10:34] Build completed unsuccessfully in 0:28:45
[01:10:34] Makefile:58: recipe for target 'check' failed
[01:10:34] make: *** [check] Error 1

The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:04291a7c
$ 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)

@bors
Copy link
Contributor

bors commented Jul 11, 2018

☀️ Test successful - status-travis
State: approved= try=True

@pietroalbini
Copy link
Member

@craterbot run start=master#ae5b629efd79de78e6ba7ef493c32857bd7f9cf9 end=try#d39a6f7eddafd45dcc60e99001b8cd08c2bd3255 mode=check-only

@craterbot
Copy link
Collaborator

👌 Experiment pr-52234 created and queued.

ℹ️ Crater is a tool to run experiments across the whole Rust ecosystem. Learn more

@craterbot
Copy link
Collaborator

🚧 Experiment pr-52234 is now running on agent crater-1.

ℹ️ Crater is a tool to run experiments across the whole Rust ecosystem. Learn more

@craterbot
Copy link
Collaborator

🎉 Experiment pr-52234 is completed!
📰 Open the full report.

⚠️ If you notice any spurious failure please add them to the blacklist!
ℹ️ Crater is a tool to run experiments across the whole Rust ecosystem. Learn more

@CAD97
Copy link
Contributor

CAD97 commented Apr 25, 2019

macro_expanded_macro_exports_accessed_by_absolute_paths points here but I don't see anything I think is relevant to it. I'm trying to do this basic structure emitted by a derive macro to make the exported macro_rules macro scoped, but it seems to be forbidden now, and I don't see any discussion of that change.

error: macro-expanded `macro_export` macros from the current crate cannot be referred to by absolute paths
  --> pegcel\macros\tests\meta.rs:8:5
   |
8  | /     pegcel_syn! {
...  |
54 | |     }
   | |_____^
   |
   = note: #[deny(macro_expanded_macro_exports_accessed_by_absolute_paths)] on by default
   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
   = note: for more information, see issue #52234 <https://github.com/rust-lang/rust/issues/52234>
note: the macro is defined here
  --> pegcel\macros\tests\meta.rs:8:5
   |
8  | /     pegcel_syn! {
...  |
54 | |     }
   | |_____^

@petrochenkov
Copy link
Contributor Author

petrochenkov commented Apr 25, 2019

@CAD97
The error was introduced in dd0a766 to fix #53144 (and made a deprecation lint later to mitigate some fallout.

The issue is that any #[macro_export] macro m is placed into the root module, so the result of the query "is m defined in the root?" is indeterminate until the crate is completely expanded and no potential #[macro_export]s remain.

Indeterminacies like this cause import resolution to stuck, like it happened in #53144 and similar cases.
With the macro_expanded_macro_exports_accessed_by_absolute_paths error in place we can always give a determinate answer "yes" or "no" and prevent resolution from being stuck.
(More blunt, and therefore non-viable, alternative would be prohibiting macro-expanded #[macro_export]s completely.)

Perhaps the error can be relaxed a bit / made more fine-grained, but I haven't thought how to do that in detail.

@Kixiron
Copy link
Member

Kixiron commented Mar 11, 2020

Hello, I've got a bit of a question, as I've just run into this error during implementation. Since referral by absolute paths is an error, how is the external use of a macro-generated macro supposed to occur?

@petrochenkov
Copy link
Contributor Author

@Kixiron
Only crate-local uses are supposed to be errors, uses from other crates should work.

@ojeda
Copy link
Contributor

ojeda commented Feb 26, 2021

The error mentions "by absolute paths", but if in the (failing) test case 3:

macro_rules! define_exported { () => {
    #[macro_export]
    macro_rules! exported {
        () => ()
    }
}}

define_exported!();

mod m {
    use exported;
}

one changes to a definitely-relative path like use super::exported; or use self::super::exported;, it still fails. The test case mentions "... cannot be accessed with module-relative paths" which fits the behavior, though, but not the error. So why the error mentions absolute paths?

Furthermore, if one encloses the macros inside a module:

mod x {
    macro_rules! define_exported { () => {
        #[macro_export]
        macro_rules! exported {
            () => ()
        }
    }}

    define_exported!();
}

mod m {
    use x::exported;
}

Then the compiler suggests using use ::exported;, which won't work as we know, but will also make import resolution get stuck (but the idea behind this was to avoid that, no?).

@dannymcgee
Copy link

I don't think I'm understanding how I'm meant to work around this. Do I really need to use crate::* in every place where I want to use the generated macros?

@chorman0773
Copy link
Contributor

Indeed, this seems like a huge problem for hygine. I was writing a macro that needed to expand a helper macro and I found it incredibly problematic, as the fcw triggered when adding #[rustfmt::skip] to the macro (which was to solve an issue, though it wasn't useful and the issue was solved a different way).
And, in fact, even worse that there is no way to do it in a way that won't get broken by a crate that defines a macro by the same name (by chance or by malice).

@danielhenrymantilla
Copy link
Contributor

danielhenrymantilla commented Nov 23, 2021

Regarding #[rustfmt::skip], doing #[cfg_attr(rustfmt, rustfmt::skip)] sidesteps that issue (but you may have clippy complaining, then 😅).

Regarding a more general workaround, the trick is to "append a pub use …":

  • #[doc(hidden)] pub use macro_name as some_other_name; right after the #[macro_export] definition, so that $crate::path::to::some_other_name; works everywhere, provided path::to is, in and of itself, pub, with path::to pointing to the module where that pub use is occurring:

    macro_rules! mk_foo {() => (
        #[macro_export]
        macro_rules! foo {() => ()}
    
        #[doc(hidden)] /** Not part of the public API */ pub
        use foo as _foo;
    )}
    
    pub mod example { mk_foo!(); }
    
    crate::example::_foo! {} // OK
    
    #[macro_export]
    macro_rules! bar {() => (
        $crate::example::_foo! {} // OK as well, since `example` is `pub`
    )}
  • In the case where the generated macro name is variable, a variant of this approach would be to emit the #[macro_export] inside an eponymous module.

    macro_rules! export_macro {( $name:ident $(,)? ) => (
        #[doc(hidden)] /** Not part of the public API */ pub
        mod $name {
            #[macro_export]
            macro_rules! $name {() => ()}
            pub use $name;
        }
    )}

    so that $crate::path::to::macro_name::macro_name! { … } works.

  • If you know the "meta-macro" will never be called at the root of a crate, you can simplify both approaches down to emitting #[doc(hidden)] pub use macro_name; right after the macro definition (but this fails if the definition happens at the root of a crate).


Perhaps the error can be relaxed a bit / made more fine-grained, but I haven't thought how to do that in detail.

@petrochenkov IIUC, if the issue with #[macro_export] is that it allows populating the root-of-the-crate from anywhere in the code —even from within sub-modules, const blocks, function bodies, etc.—, could at least the case where the #[macro_export] occurs at the root of the crate, even when macro-expanded, be allowed? (e.g., by making #[macro_export] act as a pub macro (namespacing-wise, I mean) when it detects it's being called at the root module)

nwtnni added a commit to nwtnni/xic-rs that referenced this pull request May 10, 2022
Using the re-exporting trick from rust-lang/rust#52234 (comment)
to reference the macro recursively at a known path. This way any
external callers don't have to import the macro or its dependencies.
nwtnni added a commit to nwtnni/xic-rs that referenced this pull request May 10, 2022
Using the re-exporting trick from rust-lang/rust#52234 (comment)
to reference the macro recursively at a known path. This way any
external callers don't have to import the macro or its dependencies.
nwtnni added a commit to nwtnni/xic-rs that referenced this pull request May 10, 2022
Using the re-exporting trick from rust-lang/rust#52234 (comment)
to reference the macro recursively at a known path. This way any
external callers don't have to import the macro or its dependencies.
@Swoorup
Copy link

Swoorup commented Feb 5, 2023

For anyone stumbling here, I fixed it using like the following,

  #[macro_export]
  macro_rules! impl_str_id {
    ($t:ident) => {
      ::paste::paste! {

        #[derive(Clone, Copy, Hash, Deref)]
        #[display("{0}")]
        pub struct $t(TinyStr16);
        impl_new_type_debug_no_wrap!($t);

        #[macro_export]
        macro_rules! [<_ $t:snake:lower>] {
          ($s:literal) => {{ $t::new(tinystr::tinystr!(16, $s)) }}
        }
        
        // Fixes macro-expanded `macro_export` macros from the current crate cannot be referred to by absolute paths
        #[doc(hidden)] 
        pub use [<_ $t:snake:lower>] as [<$t:snake:lower>];

@dewert99
Copy link

Regarding macro_expanded_macro_exports_accessed_by_absolute_paths, is there a good way of creating a hygienic recursive macro expanded macro? The usual approach for hygienic recursive macros is to use $crate::macro! eg:

#[macro_export]
macro_rules! recur {
  (()) => {$crate::recur!{}};
  () => ()
}

However, this strategy requires accessing the macro by an absolute path so if the recur! macro were generated, using it would lead to macro_expanded_macro_exports_accessed_by_absolute_paths eg:

macro_rules! mk_recur {() => (
    #[macro_export]
    macro_rules! recur {
      (()) => {$crate::recur!{}};
      () => ()
    }

    pub use recur;
)}

pub mod m1 {
    mk_recur!{}
}

mod m2 {
    crate::m1::recur!{()}
}

dannymcgee added a commit to dannymcgee/gramatika that referenced this pull request Apr 22, 2024
# Breaking changes

## Generated token macros are no longer `#[macro_export]`

The `Token` derive macro generates a `macro_rules!` macro for each of the enum
variants. E.g., for Lox's `Token` enum in `examples/lox`:

```rs
// examples/lox/src/tokens.rs

#[derive(DebugLispToken, PartialEq, Token, Lexer)]
pub enum Token {
    #[subset_of(Ident)]
    #[pattern = "and|class|else|false|for|fun|if|nil|or|print|return|super|this|true|var|while"]
    Keyword(Substr, Span),

    #[pattern = "[a-zA-Z_][a-zA-Z0-9_]*"]
    Ident(Substr, Span),

    #[pattern = r"[(){}]"]
    Brace(Substr, Span),

    #[pattern = "[,.;]"]
    Punct(Substr, Span),

    #[pattern = "[=!<>]=?"]
    #[pattern = "[-+*/]"]
    Operator(Substr, Span),

    #[pattern = "[0-9]+"]
    NumLit(Substr, Span),

    #[pattern = r#""[^"]*""#]
    StrLit(Substr, Span),
}
```

We get `macro_rules!` macros named `keyword`, `ident`, `brace`, `punct`,
`operator`, `num_lit` and `str_lit`. These are mostly useful for the `Parse`
implementations, e.g.:

```rs
// examples/lox/src/decl.rs

impl Parse for ClassDecl {
    type Stream = ParseStream;

    fn parse(input: &mut Self::Stream) -> Result<Self> {
        // ...
        let superclass = if input.check(operator![<]) {
            input.consume(operator![<])?;
            Some(input.consume_kind(TokenKind::Ident)?)
        } else {
            None
        };
        // ...
    }
}
```

Previously, those generated macros were declared like this:

```rs
#(
    #[macro_export]
    macro_rules! #snake_case_variant_ident {
        // ...
    }
)*
```

That has always [caused some headaches](rust-lang/rust#52234 (comment))
which I was never really sure how to deal with. In the examples here, and in my
consuming projects, I had resorted to using `*` imports everywhere to work
around the problem (in hindsight though, I think that likely just hides the lint
by obscuring what we're doing instead of actually addressing the issue).

This PR attempts an alternative solution. `#[macro_export]` is intended for
libraries to expose macros to external consumers, but I don't foresee the macros
generated by the `Token` derive being actually useful in that context. So
instead, the generated macros are now declared like this:

```rs
#(
    macro_rules! #snake_case_variant_ident {
        // ...
    }
    pub(crate) use #snake_case_variant_ident;
)*
```

This is a breaking change for two reasons:

1. If you were depending on those `#[macro_export]` attributes to make the
   generated macros available to external consumers of your library, that is no
   longer going to work. Again, I don't imagine this was actually a real-world
   use case for anyone, but I've been wrong before! Let me know if this is a
   problem for you and I'll see what we can do about it.

2. If you had been importing those macros from the root of your crate, but your
   `Token` enum is _not_ declared in the crate root, you'll need to update your
   import paths to instead import them from the module where the enum is
   declared. E.g.:
  
   ```rs
   mod token {
       use gramatika::{DebugLisp, Span, Substr, Token as _};
   
       #[derive(DebugLispToken, PartialEq, Token, Lexer)]
       pub enum Token {
           #[pattern = ".+"]
           Word(Substr, Span),
       }
   }
   
   mod foo {
       // use crate::word;     // 👎
       use crate::token::word; // 👍
   }
   ```
  
   On the bright side, tools like `rust-analyzer` should now find and
   automatically suggest the correct import paths for those macros, so the
   fastest way to migrate will probably be to just delete your existing `use`
   statement and invoke your editor's suggestion feature to re-import any
   unresolved symbols from their correct paths.

# Other changes

* Updated the Rust edition to 2021 and fixed any resulting errors
* Fixed any new `clippy` lints as a result of upgrading my environment to
  v1.77.2
* Performed some low-hanging-fruit dependency upgrades.
  
  `regex-automata` and `syn` are still out of date for now &mdash; I attempted
  to update the former, but couldn't figure out how to migrate after ~10 minutes
  of poking around, and unfortunately I have other priorities that need to take
  precedence. Didn't even attempt `syn` because it's a major version bump, and
  that crate is basically the backbone of this whole project, so it'll have to
  wait for now.
@Kixunil
Copy link
Contributor

Kixunil commented Aug 18, 2024

This seems to also affect the include! macro which doesn't feel right.

@wdanilo
Copy link

wdanilo commented Nov 7, 2024

So, if I have a macro m1 that generates another macro m2, how can I import it from a file in this crate? When I'm trying to do use crate::data::m2 I've got error macro-expanded macro_export macros from the current crate cannot be referred to by absolute paths. I've got the same error when I'm trying to use it with qualified path.

@danielhenrymantilla
Copy link
Contributor

@wdanilo given the usage you describe (m2 being invoked within the very same crate that defined it), you'll probably want to do the following:

  macro_rules! m1 {( ... ) => (
      ...

-     #[macro_export]
      macro_rules! m2 { ... }
+     pub(crate) use m2;
  )}

If you really need it to be macro_exported, follow the steps described over #52234 (comment).

  • If you want to avoid needing paste!, the following ought to work to (although with slightly worse ergonomics):

    + pub(crate) mod name_of_the_macro {
          #[macro_export]
          macro_rules! name_of_the_macro { ... }
    
    +     pub use name_of_the_macro as invoke;
    + }

    So that same-crate callers can then use path::to::macro_name::invoke! to call it


Important

If you have any more usage questions, or if anybody else does, it's probably better to ask over the Rust forum (https://users.rust-lang.org), or over the community Discord (https://discord.gg/rust-lang-community), rather than commenting on this PR 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-macros-1.2 Area: Declarative macros 1.2 disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2018: #[macro_export(local_inner_macros)] breaks recursion in submodules