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 ## diagnostic is confusing #131615

Closed
ehuss opened this issue Oct 12, 2024 · 1 comment · Fixed by #133487
Closed

2024: Reserved ## diagnostic is confusing #131615

ehuss opened this issue Oct 12, 2024 · 1 comment · Fixed by #133487
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-edition-2024 Area: The 2024 edition D-confusing Diagnostics: Confusing error or lint that should be reworked. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@ehuss
Copy link
Contributor

ehuss commented Oct 12, 2024

Code

// Edition 2024
macro_rules! m {
    ($a:tt $b:tt) => {};
}

m!{##}

Current output

error: invalid string literal
 --> src/lib.rs:5:4
  |
5 | m!{##}
  |    ^^
  |
  = note: unprefixed guarded string literals are reserved for future use since Rust 2024
help: consider inserting whitespace here
  |
5 | m!{# #}
  |     +

error: unexpected end of macro invocation
 --> src/lib.rs:5:6
  |
1 | macro_rules! m {
  | -------------- when calling this macro
...
5 | m!{##}
  |      ^ missing tokens in macro arguments
  |
note: while trying to match meta-variable `$b:tt`
 --> src/lib.rs:2:12
  |
2 |     ($a:tt $b:tt) => {};
  |            ^^^^^

Desired output

error: reserved multi-hash token is not allowed
 --> src/lib.rs:5:4
  |
5 | m!{##}
  |    ^^
  |
  = note: a sequence of two or more # is reserved for future use since Rust 2024
help: consider inserting whitespace here
  |
5 | m!{# #}
  |     +

error: unexpected end of macro invocation
 --> src/lib.rs:5:6
  |
1 | macro_rules! m {
  | -------------- when calling this macro
...
5 | m!{##}
  |      ^ missing tokens in macro arguments
  |
note: while trying to match meta-variable `$b:tt`
 --> src/lib.rs:2:12
  |
2 |     ($a:tt $b:tt) => {};
  |            ^^^^^

Rationale and extra context

The existing message referring to a "string literal" is confusing to me since there are no strings anywhere in the source. I don't think it will be obvious to users to make the connection between ## and "that might come before some reserved string thing that doesn't yet exist". I would suggest avoiding the terminology of "string literal" if there is no string literal following the last #.

Other cases

No response

Rust Version

rustc 1.83.0-nightly (1bc403d 2024-10-11)
binary: rustc
commit-hash: 1bc403d
commit-date: 2024-10-11
host: aarch64-apple-darwin
release: 1.83.0-nightly
LLVM version: 19.1.1

Anything else?

No response

@ehuss ehuss added A-diagnostics Area: Messages for errors, warnings, and lints A-edition-2024 Area: The 2024 edition D-confusing Diagnostics: Confusing error or lint that should be reworked. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 12, 2024
@traviscross traviscross changed the title 2024: Reserved ## diagnostic is confusing 2024: Reserved ## diagnostic is confusing Oct 22, 2024
@traviscross
Copy link
Contributor

cc @pitaj

@pitaj pitaj self-assigned this Nov 26, 2024
@bors bors closed this as completed in ca71c8f Nov 28, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Nov 28, 2024
Rollup merge of rust-lang#133487 - pitaj:reserve-guarded-strings, r=fee1-dead

fix confusing diagnostic for reserved `##`

Closes rust-lang#131615
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-edition-2024 Area: The 2024 edition D-confusing Diagnostics: Confusing error or lint that should be reworked. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants