-
-
Notifications
You must be signed in to change notification settings - Fork 14.3k
compiler: Make Externally Implementable Items (eii) in std build #150592
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
Conversation
|
|
This comment was marked as outdated.
This comment was marked as outdated.
|
Ok let's roll then: r? compiler |
|
@rustbot ready |
|
I'll do it anyway, reached cap because of the holidays |
|
So I think what's going on here is that in std, all items must have a stability attribute. And since we generate a bunch of extra items, their stability attributes match. I remember leaving a FIXME somewhere even that we have to forward more attributes. However, I'd like to be somewhat systematic about that. Making sure we forward all the right attributes to the right items, not just stability. I'm not sure I understand the transparency attributes entirely correctly, but I think stability is tracked through spans and as such, the spans generated by the macro expansion affect the stability of the items. I think the real solution is to forward stability attributes themselves? |
|
I could be wrong there, maybe you've tried that |
|
(oh, sent you a message on zulip btw) |
|
@rustbot author |
|
☔ The latest upstream changes (presumably #150900) made this pull request unmergeable. Please resolve the merge conflicts. |
compiler: Forward attributes to eii-expanded macros Since rust-lang#150592 is quite complicated to reason about I figured it would be good to split it up in smaller pieces that are easier to digest. Here is the attribute fix in isolation. ## The Problem With this eii in **library/std/src/io/mod.rs**: ```rs /// Foo #[eii(on_broken_pipe)] #[unstable(feature = "on_broken_pipe", issue = "150588")] pub fn on_broken_pipe() -> OnBrokenPipe { OnBrokenPipe::BackwardsCompatible } ``` you currently get this compilation error: ``` error: attribute macro has missing stability attribute --> library/std/src/io/mod.rs:2269:1 | 2269 | #[eii(on_broken_pipe)] | ^^^^^^^^^^^^^^^^^^^^-- | | | in this attribute macro expansion | ::: library/core/src/macros/mod.rs:1899:5 | 1899 | pub macro eii($item:item) { | ------------- in this expansion of `#[eii]` ``` because with ` MAGIC_EXTRA_RUSTFLAGS=-Zunpretty=expanded ./x build library/std` we can see that a pub item in the expanded code is indeed missing that attribute: ```rs const _: () = { #[on_broken_pipe] fn on_broken_pipe() -> OnBrokenPipe { OnBrokenPipe::BackwardsCompatible } }; unsafe extern "Rust" { /// Foo #[unstable(feature = "on_broken_pipe", issue = "150588")] #[rustc_eii_extern_item] pub safe fn on_broken_pipe() -> OnBrokenPipe; } #[rustc_builtin_macro(eii_shared_macro)] #[eii_extern_target(on_broken_pipe)] pub macro on_broken_pipe { () => {} } ``` ## The Solution With the fix, that error goes away because we get this expanded code instead: ```rs const _: () = { #[on_broken_pipe] fn on_broken_pipe() -> OnBrokenPipe { OnBrokenPipe::BackwardsCompatible } }; unsafe extern "Rust" { /// Foo #[unstable(feature = "on_broken_pipe", issue = "150588")] #[rustc_eii_extern_item] pub safe fn on_broken_pipe() -> OnBrokenPipe; } /// Foo #[unstable(feature = "on_broken_pipe", issue = "150588")] #[rustc_builtin_macro(eii_shared_macro)] #[eii_extern_target(on_broken_pipe)] pub macro on_broken_pipe { () => {} } ``` Note that we also need to forward the docs, otherwise get get (fatal) warnings like these: ``` warning: missing documentation for an attribute macro --> library/std/src/io/mod.rs:2269:1 ``` r? @jdonszelmann Tracking issues: - rust-lang#125418 - rust-lang#150588 ### What about a test? rust-lang#150591 will prevent regressions once it lands since it does not build without this fix. I think it is overkill to add a temporary eii to std before that.
compiler: Forward attributes to eii-expanded macros Since rust-lang#150592 is quite complicated to reason about I figured it would be good to split it up in smaller pieces that are easier to digest. Here is the attribute fix in isolation. ## The Problem With this eii in **library/std/src/io/mod.rs**: ```rs /// Foo #[eii(on_broken_pipe)] #[unstable(feature = "on_broken_pipe", issue = "150588")] pub fn on_broken_pipe() -> OnBrokenPipe { OnBrokenPipe::BackwardsCompatible } ``` you currently get this compilation error: ``` error: attribute macro has missing stability attribute --> library/std/src/io/mod.rs:2269:1 | 2269 | #[eii(on_broken_pipe)] | ^^^^^^^^^^^^^^^^^^^^-- | | | in this attribute macro expansion | ::: library/core/src/macros/mod.rs:1899:5 | 1899 | pub macro eii($item:item) { | ------------- in this expansion of `#[eii]` ``` because with ` MAGIC_EXTRA_RUSTFLAGS=-Zunpretty=expanded ./x build library/std` we can see that a pub item in the expanded code is indeed missing that attribute: ```rs const _: () = { #[on_broken_pipe] fn on_broken_pipe() -> OnBrokenPipe { OnBrokenPipe::BackwardsCompatible } }; unsafe extern "Rust" { /// Foo #[unstable(feature = "on_broken_pipe", issue = "150588")] #[rustc_eii_extern_item] pub safe fn on_broken_pipe() -> OnBrokenPipe; } #[rustc_builtin_macro(eii_shared_macro)] #[eii_extern_target(on_broken_pipe)] pub macro on_broken_pipe { () => {} } ``` ## The Solution With the fix, that error goes away because we get this expanded code instead: ```rs const _: () = { #[on_broken_pipe] fn on_broken_pipe() -> OnBrokenPipe { OnBrokenPipe::BackwardsCompatible } }; unsafe extern "Rust" { /// Foo #[unstable(feature = "on_broken_pipe", issue = "150588")] #[rustc_eii_extern_item] pub safe fn on_broken_pipe() -> OnBrokenPipe; } /// Foo #[unstable(feature = "on_broken_pipe", issue = "150588")] #[rustc_builtin_macro(eii_shared_macro)] #[eii_extern_target(on_broken_pipe)] pub macro on_broken_pipe { () => {} } ``` Note that we also need to forward the docs, otherwise get get (fatal) warnings like these: ``` warning: missing documentation for an attribute macro --> library/std/src/io/mod.rs:2269:1 ``` r? @jdonszelmann Tracking issues: - rust-lang#125418 - rust-lang#150588 ### What about a test? rust-lang#150591 will prevent regressions once it lands since it does not build without this fix. I think it is overkill to add a temporary eii to std before that.
Rollup merge of #150913 - eii-macro-attrs, r=jdonszelmann compiler: Forward attributes to eii-expanded macros Since #150592 is quite complicated to reason about I figured it would be good to split it up in smaller pieces that are easier to digest. Here is the attribute fix in isolation. ## The Problem With this eii in **library/std/src/io/mod.rs**: ```rs /// Foo #[eii(on_broken_pipe)] #[unstable(feature = "on_broken_pipe", issue = "150588")] pub fn on_broken_pipe() -> OnBrokenPipe { OnBrokenPipe::BackwardsCompatible } ``` you currently get this compilation error: ``` error: attribute macro has missing stability attribute --> library/std/src/io/mod.rs:2269:1 | 2269 | #[eii(on_broken_pipe)] | ^^^^^^^^^^^^^^^^^^^^-- | | | in this attribute macro expansion | ::: library/core/src/macros/mod.rs:1899:5 | 1899 | pub macro eii($item:item) { | ------------- in this expansion of `#[eii]` ``` because with ` MAGIC_EXTRA_RUSTFLAGS=-Zunpretty=expanded ./x build library/std` we can see that a pub item in the expanded code is indeed missing that attribute: ```rs const _: () = { #[on_broken_pipe] fn on_broken_pipe() -> OnBrokenPipe { OnBrokenPipe::BackwardsCompatible } }; unsafe extern "Rust" { /// Foo #[unstable(feature = "on_broken_pipe", issue = "150588")] #[rustc_eii_extern_item] pub safe fn on_broken_pipe() -> OnBrokenPipe; } #[rustc_builtin_macro(eii_shared_macro)] #[eii_extern_target(on_broken_pipe)] pub macro on_broken_pipe { () => {} } ``` ## The Solution With the fix, that error goes away because we get this expanded code instead: ```rs const _: () = { #[on_broken_pipe] fn on_broken_pipe() -> OnBrokenPipe { OnBrokenPipe::BackwardsCompatible } }; unsafe extern "Rust" { /// Foo #[unstable(feature = "on_broken_pipe", issue = "150588")] #[rustc_eii_extern_item] pub safe fn on_broken_pipe() -> OnBrokenPipe; } /// Foo #[unstable(feature = "on_broken_pipe", issue = "150588")] #[rustc_builtin_macro(eii_shared_macro)] #[eii_extern_target(on_broken_pipe)] pub macro on_broken_pipe { () => {} } ``` Note that we also need to forward the docs, otherwise get get (fatal) warnings like these: ``` warning: missing documentation for an attribute macro --> library/std/src/io/mod.rs:2269:1 ``` r? @jdonszelmann Tracking issues: - #125418 - #150588 ### What about a test? #150591 will prevent regressions once it lands since it does not build without this fix. I think it is overkill to add a temporary eii to std before that.
|
Closing since this PR has been split up into two smaller ones: |
Closes #150514
Merging this PR unblocks #150591 and that PR will also act as a regression test since the code in that PR does not build without this fix. We could add a temporary dummy eii item to std before that PR lands, but it does not seem worth the effort.
To be honest I don't fully understand why
#[rustc_macro_transparency = "transparent"]works, all I know is that it works. Without it, we get > 800 errors that looks like this.r? @jdonszelmann is maybe interested in reviewing? Of course feel free to re-roll if you don't have time right now though.
Tracking issues
#[std::io::on_broken_pipe]#150588