Skip to content

rc"" instead of cr"" should get a clear diagnostic #140170

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

Closed
cyrgani opened this issue Apr 22, 2025 · 1 comment · Fixed by #140175
Closed

rc"" instead of cr"" should get a clear diagnostic #140170

cyrgani opened this issue Apr 22, 2025 · 1 comment · Fixed by #140175
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The lexing & parsing of Rust source code to an AST D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@cyrgani
Copy link
Contributor

cyrgani commented Apr 22, 2025

Code

fn main() {
    rc"\n";
}

Current output

error: prefix `rc` is unknown
 --> src/lib.rs:2:5
  |
2 |     rc"\n";
  |     ^^ unknown prefix
  |
  = note: prefixed identifiers and literals are reserved since Rust 2021
help: consider inserting whitespace here
  |
2 |     rc "\n";
  |       +

error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `"\n"`
 --> src/lib.rs:2:7
  |
2 |     rc"\n";
  |       ^^^^ expected one of 8 possible tokens

Desired output

error: prefix `rc` is unknown
help: consider using `cr` instead:

Rationale and extra context

not sure whether the combination of c-string and raw string is common, but this seems like a plausible mistake if it is

Other cases

Rust Version

rustc 1.88.0-nightly (d6c1e454a 2025-04-21)
binary: rustc
commit-hash: d6c1e454aa8af5e7e59fbf5c4e7d3128d2f99582
commit-date: 2025-04-21
host: x86_64-unknown-linux-gnu
release: 1.88.0-nightly
LLVM version: 20.1.2

Anything else?

No response

@cyrgani cyrgani added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 22, 2025
@cyrgani cyrgani changed the title rc"" instead of cr"" shouldget a clear diagnostic rc"" instead of cr"" should get a clear diagnostic Apr 22, 2025
@fmease fmease added A-parser Area: The lexing & parsing of Rust source code to an AST D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. labels Apr 22, 2025
@Kivooeo
Copy link
Contributor

Kivooeo commented Apr 22, 2025

@rustbot claim

@bors bors closed this as completed in ecb9775 Apr 23, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Apr 23, 2025
Rollup merge of rust-lang#140175 - Kivooeo:new-fix-one, r=compiler-errors

`rc""` more clear error message

here is small fix that provides better error message when user is trying to use `rc""` the same way it was made for `rb""`

example of it's work

```rust
  |
2 |     rc"\n";
  |     ^^ unknown prefix
  |
  = note: prefixed identifiers and literals are reserved since Rust 2021
help: use `cr` for a raw C-string
  |
2 -     rc"\n";
2 +     cr"\n";
  |
```

**related issue**
fixes rust-lang#140170

cc `@cyrgani` (issue author)
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-parser Area: The lexing & parsing of Rust source code to an AST D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. 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