Skip to content

2024 reserved ## breaks some proc-macros #133887

Closed as not planned
Closed as not planned

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:

Activity

  1. added
    C-bugCategory: This is a bug.
    D-editionDiagnostics: An error or lint that should account for edition differences.
    on Dec 5, 2024
  2. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Dec 5, 2024
  3. traviscross commented on Dec 5, 2024

    @traviscross
    Contributor

    Looks like they added that in kevinmehall/rust-peg@1f3418c, though interestingly, I'm struggling to find that feature anywhere in the documentation.

    Any idea how many crates are affected?

    Worst case, we could just reserve ###+ instead.

    cc @pitaj

  4. removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Dec 5, 2024
  5. added
    T-langRelevant to the language team
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Dec 5, 2024
  6. pitaj commented on Dec 5, 2024

    @pitaj
    Contributor

    I guess we should have run crater before merging the ## version of that feature.

    Anyways, it will be pretty easy to change it to reserve #", ##", ### instead.

  7. pitaj commented on Dec 5, 2024

    @pitaj
    Contributor

    #133924 removes the reservation of ##, and instead reserves #", ##", and ###.

  8. traviscross commented on Dec 11, 2024

    @traviscross
    Contributor
  9. traviscross commented on Dec 18, 2024

    @traviscross
    Contributor

    We discussed this in the lang call today and confirmed, in light of the very much appreciated feedback from @kevinmehall, that we're comfortable proceeding as planned with the ## reservation.

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-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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions