Skip to content

Visibility tokens on types in extern { ... } blocks are no longer given to procedural macros #69315

Closed

Description

@alexcrichton

I had wasm-bindgen/wasm-bindgen#2009 opened up on a project recently but this looks to be a regression I think. This regressed between nightly-2020-02-19 and nightly-2020-02-20, and bisecting further by commit reveals #69271 as the culprit. I'm not sure which of the PRs in that rollup though are the culprit here.

This can be reproduced by running cargo check from the crates/js-sys folder in the wasm-bindgen repository. Unfortunately this one probably isn't super easy to reproduce, so I'm hoping that someone more knowledgeable can hopefully take a look at this and have a better idea about what's going on.

There's definitely macros going on in #[wasm_bindgen] (the Memory type is synthesized by a macro), which leads me to think that #69211 may be the culprit? (cc @petrochenkov)

Activity

  1. added
    A-visibilityArea: Visibility / privacy
    C-bugCategory: This is a bug.
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Feb 20, 2020
  2. added
    A-parserArea: The lexing & parsing of Rust source code to an AST
    E-needs-mcveCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example
    and removed
    C-bugCategory: This is a bug.
    on Feb 20, 2020
  3. petrochenkov commented on Feb 20, 2020

    @petrochenkov
    Contributor

    The large parser PR from @Centril (#69194) could also cause something like this.

  4. self-assigned this
    on Feb 20, 2020
  5. petrochenkov commented on Feb 20, 2020

    @petrochenkov
    Contributor

    I'll be able to look at this during the weekend, but it would be great if someone could come up with a minimal reproduction before that.

  6. alexcrichton commented on Feb 20, 2020

    @alexcrichton
    MemberAuthor

    Ok, wanted to get a gut-check to see if it was known what was happening. Did some reduction and it looks like the macro no longer gets the pub token for the input type.

    Given this input:

    pub mod wasm {
        #[the_macro::the_macro]
        extern "C" {
            pub type Memory;
        }
    }
    
    fn main() {
        let _: wasm::Memory;
    }

    then with this macro:

    extern crate proc_macro;
    
    use proc_macro::*;
    
    #[proc_macro_attribute]
    pub fn the_macro(_attr: TokenStream, body: TokenStream) -> TokenStream {
        let g = match body.clone().into_iter().nth(2) {
            Some(TokenTree::Group(g)) => g,
            _ => panic!("unexpected input"),
        };
        let tokens = g.stream().into_iter().collect::<Vec<_>>();
        assert_eq!(tokens[0].to_string(), "pub");
        return body;
    }

    it fails with:

    $ cargo +nightly build
       Compiling wut v0.1.0 (/home/alex/code/wut)
    error: custom attribute panicked
     --> src/main.rs:2:5
      |
    2 |     #[the_macro::the_macro]
      |     ^^^^^^^^^^^^^^^^^^^^^^^
      |
      = help: message: assertion failed: `(left == right)`
                left: `"type"`,
               right: `"pub"`
    
    error: aborting due to previous error
    
    error: could not compile `wut`.
    
    To learn more, run the command again with --verbose.
    

    On stable it yields the expected error[E0658]: extern types are experimental error which indicates that the pub token was fed to the macro.

    If the #[wasm_bindgen] macro doesn't see the pub token it doesn't make the final result public, which is why the privacy error happened in the first place.

  7. changed the title [-]Macro-expanded public struct no longer considered public[/-] [+]Visibility tokens on types in `extern { ... }` blocks are no longer given to procedural macros[/+] on Feb 20, 2020
  8. alexcrichton commented on Feb 20, 2020

    @alexcrichton
    MemberAuthor

    (updated the issue title to reflect what appears to be the actual bug)

  9. self-assigned this
    on Feb 20, 2020
  10. removed
    E-needs-mcveCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example
    on Feb 20, 2020
  11. Centril commented on Feb 21, 2020

    @Centril
    Contributor

    Fixed by #69334.

  12. added 2 commits that reference this issue on Feb 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

A-parserArea: The lexing & parsing of Rust source code to an ASTA-visibilityArea: Visibility / privacyT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions