Skip to content

Commit 1987b15

Browse files
authored
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.
2 parents c2448d7 + a0df7b2 commit 1987b15

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

  • compiler/rustc_builtin_macros/src

compiler/rustc_builtin_macros/src/eii.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ fn eii_(
133133
macro_name,
134134
foreign_item_name,
135135
impl_unsafe,
136+
&attrs_from_decl,
136137
)));
137138

138139
return_items.into_iter().map(wrap_item).collect()
@@ -416,9 +417,14 @@ fn generate_attribute_macro_to_implement(
416417
macro_name: Ident,
417418
foreign_item_name: Ident,
418419
impl_unsafe: bool,
420+
attrs_from_decl: &[Attribute],
419421
) -> ast::Item {
420422
let mut macro_attrs = ThinVec::new();
421423

424+
// To avoid e.g. `error: attribute macro has missing stability attribute`
425+
// errors for eii's in std.
426+
macro_attrs.extend_from_slice(attrs_from_decl);
427+
422428
// #[builtin_macro(eii_shared_macro)]
423429
macro_attrs.push(ecx.attr_nested_word(sym::rustc_builtin_macro, sym::eii_shared_macro, span));
424430

0 commit comments

Comments
 (0)