Skip to content

2024 reserved ## breaks some proc-macros #133887

Closed as not planned
Closed as not planned
@ehuss

Description

@ehuss

The prohibition of ## in Rust 2024 breaks some proc-macros. For example, the peg makes use of ## for calling methods:

#![warn(rust_2024_guarded_string_incompatible_syntax)]
use peg::RuleResult;

trait StrExt {
    fn ident_start(&self, pos: usize) -> RuleResult<()>;
}
impl StrExt for str {
    fn ident_start(&self, pos: usize) -> RuleResult<()> {
        let Some(ch) = self[pos..].chars().next() else {
            return RuleResult::Failed;
        };
        RuleResult::Matched(pos + ch.len_utf8(), ())
    }
}

peg::parser!(grammar parser() for str {
    pub(crate) rule simple_literal_start()
        =   [ 'A'..='Z' ] / ##ident_start()
});

Here this will suggest to add a space to supposedly maintain compatibility with Rust 2024:

@@ -15,5 +15,5 @@
 
 peg::parser!(grammar parser() for str {
     pub(crate) rule simple_literal_start()
-        =   [ 'A'..='Z' ] / ##ident_start()
+        =   [ 'A'..='Z' ] / # #ident_start()
 });

However, this breaks peg because the peg macro uses Jointness to detect the ##IDENT() syntax. When the ## tokens are separated, they change to have Alone spacing.

I don't know what we can do here, other than remove the ## reservation in 2024, but that has other implications.

Meta

rustc 1.85.0-nightly (c44b3d50f 2024-12-03)
binary: rustc
commit-hash: c44b3d50fea96a3e0417e8264c16ea21a0a3fca2
commit-date: 2024-12-03
host: aarch64-unknown-linux-gnu
release: 1.85.0-nightly
LLVM version: 19.1.4

Tracking:

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-edition-2024Area: The 2024 editionA-proc-macrosArea: Procedural macrosC-bugCategory: This is a bug.D-editionDiagnostics: An error or lint that should account for edition differences.F-unprefixed_guarded_strings`#![feature(unprefixed_guarded_strings)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language 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