Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

rust_2024_incompatible_pat bad suggestion with proc-macro when brace comes from input #132963

Open
Labels
A-edition-2024Area: The 2024 edition A-proc-macrosArea: Procedural macros C-bugCategory: This is a bug. D-editionDiagnostics: An error or lint that should account for edition differences. D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code. I-edition-triagedIssue: This issue has been reviewed and triaged by the Edition team. L-rust_2024_incompatible_patLint: rust_2024_incompatible_pat T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
@ehuss

Description

When a proc-macro generates code, and the opening brace of a pattern from that code comes from the input, then the compiler thinks that the pattern is a 2024 pattern, and thus enforces the new pattern rules using the local edition, not the edition from the proc-macro.

There are two consequences:

  1. This is incompatible with supporting macros that are on different editions.
  2. It generates an invalid suggestion.

Example of the bad suggestion might be:

#[derive(my_macro)]
struct S {
 f1: i32
}

will give a suggestion to modify the struct to add an & which is invalid syntax like this:

struct &S {
 f1: i32
}

This was seen with swc_macros_common here where it uses the brace token from the input.

One option is to change this in the macro to generate a new token with the correct span information.

I'm also wondering if there are options for changing the ways tokens are processed from proc-macros to avoid this altogether.

Meta

rustc --version --verbose:

rustc 1.84.0-nightly (81eef2d36 2024年11月11日)
binary: rustc
commit-hash: 81eef2d362a6f03db6f8928f82d94298d31eb81b
commit-date: 2024年11月11日
host: aarch64-unknown-linux-gnu
release: 1.84.0-nightly
LLVM version: 19.1.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-edition-2024Area: The 2024 edition A-proc-macrosArea: Procedural macros C-bugCategory: This is a bug. D-editionDiagnostics: An error or lint that should account for edition differences. D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code. I-edition-triagedIssue: This issue has been reviewed and triaged by the Edition team. L-rust_2024_incompatible_patLint: rust_2024_incompatible_pat T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        AltStyle によって変換されたページ (->オリジナル) /