Skip to content

Inert attributes in $expr nonterminals are sometimes duplicated #86055

Closed

Description

@petrochenkov

Reproducer:

macro mac($expr:expr) {
    print_bang!($expr);
}

fn main() {
    mac!(#[allow(warnings)] 0);
}

where print_bang is a proc macro from https://github.com/rust-lang/rust/blob/master/src/test/ui/proc-macro/auxiliary/test-macros.rs

The result looks like this:

PRINT-BANG INPUT (DISPLAY): #[allow(warnings)] 0
PRINT-BANG RE-COLLECTED (DISPLAY): #[allow(warnings)] #[allow(warnings)] 0

The issue can be reproduced after merging #84995, before that PR the example ICEs.

Activity

  1. added
    A-attributesArea: Attributes (`#[…]`, `#![…]`)
    A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)
    on Jun 6, 2021
  2. bvanjoi commented on Jun 5, 2023

    @bvanjoi
    Contributor

    It appears that parse_expr_force_collect has caused duplication of the Expr between the attrs and tokens. Can we remove these duplicated attrs by comparing tokens and attrs?

  3. added a commit that references this issue on Jun 19, 2024
    64c2e9e
  4. added 2 commits that reference this issue on Jun 19, 2024
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-attributesArea: Attributes (`#[…]`, `#![…]`)A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions