Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2024 reserved ## breaks some proc-macros #133887

Open
ehuss opened this issue Dec 5, 2024 · 4 comments · May be fixed by #133924
Open

2024 reserved ## breaks some proc-macros #133887

ehuss opened this issue Dec 5, 2024 · 4 comments · May be fixed by #133924
Labels
A-edition-2024 Area: The 2024 edition A-proc-macros Area: Procedural macros C-bug Category: This is a bug. D-edition Diagnostics: An error or lint that should account for edition differences. F-unprefixed_guarded_strings `#![feature(unprefixed_guarded_strings)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@ehuss
Copy link
Contributor

ehuss commented Dec 5, 2024

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:

@ehuss ehuss added A-edition-2024 Area: The 2024 edition C-bug Category: This is a bug. D-edition Diagnostics: An error or lint that should account for edition differences. F-unprefixed_guarded_strings `#![feature(unprefixed_guarded_strings)]` labels Dec 5, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Dec 5, 2024
@traviscross
Copy link
Contributor

traviscross commented Dec 5, 2024

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

@traviscross traviscross removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Dec 5, 2024
@jieyouxu jieyouxu added T-lang Relevant to the language team, which will review and decide on the PR/issue. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-proc-macros Area: Procedural macros labels Dec 5, 2024
@pitaj
Copy link
Contributor

pitaj commented Dec 5, 2024

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.

@pitaj pitaj linked a pull request Dec 5, 2024 that will close this issue
@pitaj
Copy link
Contributor

pitaj commented Dec 5, 2024

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

@traviscross
Copy link
Contributor

traviscross commented Dec 11, 2024

See the notes on this from today's lang call here:

cc @kevinmehall

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-edition-2024 Area: The 2024 edition A-proc-macros Area: Procedural macros C-bug Category: This is a bug. D-edition Diagnostics: An error or lint that should account for edition differences. F-unprefixed_guarded_strings `#![feature(unprefixed_guarded_strings)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants