-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Tracking issue for procedural macros and "hygiene 2.0" #54727
Comments
To give some background, So, it's pretty heterogeneous and is not even entirely about hygiene. |
Copypasting what I wrote in #52121: None of these features is blocked on hygiene, except for
What is really blocked on hygiene is |
|
This looks like the right branch for this question. Sorry about copy-paste, but I really need to know. It seems that since I understand, that this is necessary in order to preserver spans, hygiene and consistency with processed code. Is there or will be any way to work with content of modules in separate files? Its lack may be confusing for end users when trivial refactoring of module organization causes change in macro behavior. |
@CodeSandwich cc @tinco |
From what I remember, this is an open question. The "early expansion behavior" looks preferable to me, and this change in behavior looks like a bug rather than a fix. |
I lack some context, so I can't be certain, what exactly is "process"? If it relies on rustc's pretty printing, then yes this would be a consequence of #52319, and it should be simple to fix by changing the invocation I think. #52319 does two things:
If you need the expanded file, then that should be made explicit in the invocation of the pretty printer. |
Yes, the change is likely due to the pretty-printing change. |
If you can point me at the line of code that invokes the pretty printer, I can suggest a fix. |
By "processing" I mean parsing TokenStream with Syn to an Item, modifying its content and converting it back to TokenStream. The precise spot of parsing is here and content traversal is there. I haven't dug into implementation of Syn yet, so I can't tell for sure if it uses pretty printing. I've set |
I personally feel that what a proc macro receives as input tokens when attached to a module is an open questions, as @petrochenkov said. I do not think that one answer is clearly correct over another ( |
I'm confused why proc macros expanding to |
@eddyb I hoped to at least get rid of the "context transplantation trick" before stabilizing it, but got distracted by the edition stuff. It generally works though, I'm not aware of any specific bugs manifesting in normal cases. |
|
Stabilize `Span::mixed_site` Closes rust-lang#65049. cc rust-lang#54727 (comment) Pre-requisite for rust-lang#68717 ("Stabilize fn-like proc macros in expression, pattern and statement positions"). Stabilization report: rust-lang#68716 (comment).
Stabilize fn-like proc macros in expression, pattern and statement positions I.e. all the positions in which stable `macro_rules` macros are supported. Depends on rust-lang#68716 ("Stabilize `Span::mixed_site`"). cc rust-lang#54727 cc rust-lang#54727 (comment) Stabilization report: rust-lang#68717 (comment).
Stabilize fn-like proc macros in expression, pattern and statement positions I.e. all the positions in which stable `macro_rules` macros are supported. Depends on rust-lang/rust#68716 ("Stabilize `Span::mixed_site`"). cc rust-lang/rust#54727 cc rust-lang/rust#54727 (comment) Stabilization report: rust-lang/rust#68717 (comment).
Stabilize fn-like proc macros in expression, pattern and statement positions I.e. all the positions in which stable `macro_rules` macros are supported. Depends on rust-lang/rust#68716 ("Stabilize `Span::mixed_site`"). cc rust-lang/rust#54727 cc rust-lang/rust#54727 (comment) Stabilization report: rust-lang/rust#68717 (comment).
…ark-Simulacrum bootstrap: propagate test-args to miri and clippy test suites For Miri I verified this works. For clippy, unfortunately it doesn't seem to work as a stage 0 tool: ``` ./x.py --stage 0 test src/tools/clippy --test-args init ``` gives ``` Compiling clippy-mini-macro-test v0.2.0 (/home/r/src/rust/rustc.3/src/tools/clippy/mini-macro) error[E0658]: procedural macros cannot be expanded to expressions --> src/tools/clippy/mini-macro/src/lib.rs:11:5 | 11 | / quote!( 12 | | #[allow(unused)] 13 | | fn needless_take_by_value(s: String) { 14 | | println!("{}", s.len()); ... | 24 | | } 25 | | ) | |_____^ | = note: see issue rust-lang#54727 <rust-lang#54727> for more information = help: add `#![feature(proc_macro_hygiene)]` to the crate attributes to enable Compiling proc-macro2 v1.0.3 Compiling syn v1.0.11 error: aborting due to previous error For more information about this error, try `rustc --explain E0658`. error: could not compile `clippy-mini-macro-test`. ``` But propagating `--test-args` to the test suite seems to make sense regardless. Cc @rust-lang/clippy
A week ago, futures 0.3.18 was released and apparently this does not work with Rust 1.41.0: Compiling xtrace-example v0.0.0 (/home/runner/work/x11rb/x11rb/xtrace-example) Running `rustc --edition=2018 --crate-name xtrace_example xtrace-example/src/main.rs --error-format=json --json=diagnostic-rendered-ansi --emit=dep-info,link -C debuginfo=2 --test -C metadata=516abdc358c39888 -C extra-filename=-516abdc358c39888 --out-dir /home/runner/work/x11rb/x11rb/target/debug/deps -C incremental=/home/runner/work/x11rb/x11rb/target/debug/incremental -L dependency=/home/runner/work/x11rb/x11rb/target/debug/deps --extern futures_io=/home/runner/work/x11rb/x11rb/target/debug/deps/libfutures_io-3756b09c8a44e206.rlib --extern futures_util=/home/runner/work/x11rb/x11rb/target/debug/deps/libfutures_util-411815ec4958698e.rlib --extern smol=/home/runner/work/x11rb/x11rb/target/debug/deps/libsmol-b079add982015d84.rlib --extern x11rb=/home/runner/work/x11rb/x11rb/target/debug/deps/libx11rb-768ac55e45ccd24c.rlib` error[E0658]: procedural macros cannot be expanded to statements --> xtrace-example/src/main.rs:90:5 | 90 | futures_util::try_join!(future1, future2)?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: for more information, see rust-lang/rust#54727 = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) See https://github.com/psychon/x11rb/runs/4375081831 Signed-off-by: Uli Schlachter <[email protected]>
A week ago, futures 0.3.18 was released and apparently this does not work with Rust 1.41.0: Compiling xtrace-example v0.0.0 (/home/runner/work/x11rb/x11rb/xtrace-example) Running `rustc --edition=2018 --crate-name xtrace_example xtrace-example/src/main.rs --error-format=json --json=diagnostic-rendered-ansi --emit=dep-info,link -C debuginfo=2 --test -C metadata=516abdc358c39888 -C extra-filename=-516abdc358c39888 --out-dir /home/runner/work/x11rb/x11rb/target/debug/deps -C incremental=/home/runner/work/x11rb/x11rb/target/debug/incremental -L dependency=/home/runner/work/x11rb/x11rb/target/debug/deps --extern futures_io=/home/runner/work/x11rb/x11rb/target/debug/deps/libfutures_io-3756b09c8a44e206.rlib --extern futures_util=/home/runner/work/x11rb/x11rb/target/debug/deps/libfutures_util-411815ec4958698e.rlib --extern smol=/home/runner/work/x11rb/x11rb/target/debug/deps/libsmol-b079add982015d84.rlib --extern x11rb=/home/runner/work/x11rb/x11rb/target/debug/deps/libx11rb-768ac55e45ccd24c.rlib` error[E0658]: procedural macros cannot be expanded to statements --> xtrace-example/src/main.rs:90:5 | 90 | futures_util::try_join!(future1, future2)?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: for more information, see rust-lang/rust#54727 = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) See https://github.com/psychon/x11rb/runs/4375081831 Signed-off-by: Uli Schlachter <[email protected]>
A week ago, futures 0.3.18 was released and apparently this does not work with Rust 1.41.0: Compiling xtrace-example v0.0.0 (/home/runner/work/x11rb/x11rb/xtrace-example) Running `rustc --edition=2018 --crate-name xtrace_example xtrace-example/src/main.rs --error-format=json --json=diagnostic-rendered-ansi --emit=dep-info,link -C debuginfo=2 --test -C metadata=516abdc358c39888 -C extra-filename=-516abdc358c39888 --out-dir /home/runner/work/x11rb/x11rb/target/debug/deps -C incremental=/home/runner/work/x11rb/x11rb/target/debug/incremental -L dependency=/home/runner/work/x11rb/x11rb/target/debug/deps --extern futures_io=/home/runner/work/x11rb/x11rb/target/debug/deps/libfutures_io-3756b09c8a44e206.rlib --extern futures_util=/home/runner/work/x11rb/x11rb/target/debug/deps/libfutures_util-411815ec4958698e.rlib --extern smol=/home/runner/work/x11rb/x11rb/target/debug/deps/libsmol-b079add982015d84.rlib --extern x11rb=/home/runner/work/x11rb/x11rb/target/debug/deps/libx11rb-768ac55e45ccd24c.rlib` error[E0658]: procedural macros cannot be expanded to statements --> xtrace-example/src/main.rs:90:5 | 90 | futures_util::try_join!(future1, future2)?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: for more information, see rust-lang/rust#54727 = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) See https://github.com/psychon/x11rb/runs/4375081831 Signed-off-by: Uli Schlachter <[email protected]>
There are a number of features tracked in this issue. It sounds like some have been stabilized, while others (like |
I came here from: danakj/dynpath#1 But reading this issue, I have very little clue how "non-inline modules in proc macro input" relates to this issue |
I'm looking forward to this feature. Do you have any updates on the progress or timeline for this feature to become stable? Specifically I would like this subfeature to be released:
|
The users of my use qualifier_attr::qualifiers;
#[cfg_attr(semver_exempt, qualifiers(pub))]
mod private_mod1;
#[cfg_attr(semver_exempt, qualifiers(pub))]
mod private_mod2;
// ... instead of #[cfg(semver_exempt)]
pub mod private_mod1;
#[cfg(not(semver_exempt))]
mod private_mod1;
#[cfg(semver_exempt)]
pub mod private_mod2;
#[cfg(not(semver_exempt))]
mod private_mod2;
// ... where |
We can use `rustversion` for this. For some of the tests its still needed because of this error: ``` error[E0658]: non-inline modules in proc macro input are unstable --> tests/error/mod.rs:53:1 | 53 | mod nightly; | ^^^^^^^^^^^^ | = note: see issue #54727 <rust-lang/rust#54727> for more information ```
This is intended to be a tracking issue for enabling procedural macros to have "more hygiene" than the copy/paste hygiene they have today. This is a very vague tracking issue and there's a very long and storied history to this. The intention here though is to create a fresh tracking issue to collect the current state of play, in hopes that we can close some of the much older and very long issues which contain lots of outdated information.
The text was updated successfully, but these errors were encountered: