Skip to content

Macro hygiene change breaks Firefox builds. #76480

Closed

Description

@emilio

The following program with paste = "0.1.12" compiles on stable (rustc 1.46.0 (04488afe3 2020-08-24)), but doesn't on Nightly (rustc 1.48.0-nightly (0e2c1281e 2020-09-07)).

This is minimized from Firefox source code, which doesn't build anymore with Rust Nightly.

To be fair, I'm surprised it built in the first place...

#[macro_use] extern crate paste;

#[derive(Clone, Copy)]
struct Bar {
    member: i32,
}

impl Bar {
    fn get_member(&self, _: i32, _: i32) -> i32 {
        self.member
    }
}

macro_rules! foo {
    ($fn_name:ident $(, $arg:ident)*) => {
        paste::expr! {
            Bar::[<get_ $fn_name>](&self.bar $(, $arg)* ,callback)
        }
    };
}

struct Foo {
    bar: Bar,
}

impl Foo {
    fn member(&self, n: i32, callback: i32) -> i32 {
        foo!(member, n)
    }
}

fn main() {}

Activity

  1. added
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Sep 8, 2020
  2. sugar700 commented on Sep 8, 2020

    @sugar700
    Contributor

    This also happens on 1.47.0-beta.2 (84b047b 2020-08-28) making it regression-from-stable-to-beta.

  3. added this to the 1.47.0 milestone on Sep 8, 2020
  4. added
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Sep 8, 2020
  5. Mark-Simulacrum commented on Sep 8, 2020

    @Mark-Simulacrum
    Member
  6. emilio commented on Sep 8, 2020

    @emilio
    ContributorAuthor

    I'm fixing this in Firefox in https://bugzilla.mozilla.org/show_bug.cgi?id=1663677. There's another macro-related regression that I'm trying to reduce and that seems much harder to work around, but I'll file that separately.

  7. Aaron1011 commented on Sep 8, 2020

    @Aaron1011
    Contributor

    This is intentional - before PR #73084, we were using re-parsed tokens for the call to paste::expr! due to the use of a metavariable. We now use the original tokens, which preserves the hygiene information on self and callback.

  8. emilio commented on Sep 8, 2020

    @emilio
    ContributorAuthor

    I'm ok with wontfix, as I noted in my report I was surprised that this compiled at all. But it seems odd to see breaking changes like that...

  9. emilio commented on Sep 8, 2020

    @emilio
    ContributorAuthor

    Chances are that #76482 is the same too (just with a bit of indirection because of syn), not sure.

  10. Aaron1011 commented on Sep 8, 2020

    @Aaron1011
    Contributor

    @emilio: The breaking changes are unfortunate, but are an unavoidable part of making progress towards fixing #43081. As you noted, the broken code should have never compiled in the first place due to the hygiene rules of macro_rules! macros.

    Several Crater runs were performed before landing #73084. Unfortunately, Crater cannot test all Rust code - in this case, it looks like firefox-accounts-bridge could have been tested, but Crater did not know about it (it's on neither crates.io nor GitHub).

  11. emilio commented on Sep 9, 2020

    @emilio
    ContributorAuthor

    In the past, breaking changes at least caused warnings for a release or two, which allowed us to notice the brekage and fix in advance without breaking developer builds. Anyhow I'm ok with this being wontfix, it's just odd to have such breakage being introduced without notice.

  12. 20 remaining items

  13. added
    regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.
    and removed on Nov 6, 2020
  14. added
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Nov 6, 2020
  15. Mark-Simulacrum commented on Nov 6, 2020

    @Mark-Simulacrum
    Member

    This was shipped in 1.47, and included in release notes (IIRC). I don't think there's anything further here so let's go ahead and close.

  16. removed
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Nov 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions