Skip to content

macros sometimes allow expr followed by ident #44975

Open

Description

@durka

You can use a repetition to get around the future proofer.

macro_rules! bad {
    ($e:expr $i:ident) => {} //~ERROR
}

macro_rules! sneaky {
    ($($i:ident $e:expr)*) => {} // no error
}

fn main() {
    sneaky!(a b c d);
}

I feel that both of these should be accepted, or neither. BTW, I am using the equivalent of sneaky! in brainmunch (found this while preparing my RustFest talk).

Fixing this by disallowing both macros would require cratering.

cc @jseyfried @LeoTestard

Activity

  1. added
    A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)
    T-langRelevant to the language team
    on Oct 3, 2017
  2. aturon commented on Oct 19, 2017

    @aturon
    Contributor
  3. nikomatsakis commented on Oct 19, 2017

    @nikomatsakis
    Contributor

    The danger here is that contextual keywords become impossible. In particular, consider if we added await f as an expression, which would work with bad! today but fail tomorrow.

  4. joshtriplett commented on Oct 19, 2017

    @joshtriplett
    Member

    One possibility would be to leave this alone and fix it in macros 2.0. The other would be a crater run and evaluation for a fix.

  5. nikomatsakis commented on Oct 19, 2017

    @nikomatsakis
    Contributor

    Some possible routes:

    • I don't think we should accept bad!, for the reasons given above.
    • We could leave this as is -- we have said in the past that when you break the forwards compatibility rules "in spirit" you may get broken.
    • Or, better really, we would do a fix and try to do a crater run.
  6. nikomatsakis commented on Oct 19, 2017

    @nikomatsakis
    Contributor

    triage: P-medium

  7. nikomatsakis commented on Oct 19, 2017

    @nikomatsakis
    Contributor

    I feel like we should at least try the fix -- though it may be hard to ascertain the impact entirely.

  8. durka commented on Oct 25, 2017

    @durka
    ContributorAuthor

    @nikomatsakis do you have any idea how to fix it?

  9. added
    C-enhancementCategory: An issue proposing an enhancement or a PR with one.
    on Jan 22, 2018
  10. estebank commented on Oct 26, 2018

    @estebank
    Contributor

    I'm afraid fixing this is going to be problematic, because even we are using this "feature" in rustc. I'll post a PR with the fix (including changing our mis-uses), but will expect there to be breakage. If that is the case after a crater run, should we still include the fix as a warning?

  11. durka commented on Oct 26, 2018

    @durka
    ContributorAuthor
  12. estebank commented on Oct 26, 2018

    @estebank
    Contributor

    (callers too?)

    @durka It'd be nice to do, but I'm tempted at leaving devs to deal with the fallout after changing the signature by following the errors they'll get then instead of trying to preempt them, as extending the diagnostic to the callers would be a bigger PR, I fear.

  13. added 2 commits that reference this issue on Oct 26, 2018
    5bb2e5e
    730d21c
  14. added a commit that references this issue on Nov 22, 2018
    72bd4c0
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

    A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-enhancementCategory: An issue proposing an enhancement or a PR with one.P-mediumMedium priorityT-langRelevant to the language team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions