Skip to content

Conversation

notJoon
Copy link
Contributor

@notJoon notJoon commented Aug 19, 2025

Description

Fixes #144161

When a raw string literal has an invalid suffix (like r#"test"#suffix), the compiler was not reporting the appropriate error message "suffixes on string literals are invalid". This was particularly problematic when the suffix was immediately followed by another token, as in r#" \\ "#r"\\ ".

Changes

Modified parse_expr_lit to handle raw string literals with suffixes by:

  1. Checking if a token is a raw string literal with a suffix before general literal parsing
  2. Using the existing LitKind::from_token_lit to validate and get the appropriate error

To prevent cascading errors, consume the next token if it's another string literal after an error is reported.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 19, 2025
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@notJoon notJoon marked this pull request as ready for review August 20, 2025 05:37
@rustbot
Copy link
Collaborator

rustbot commented Aug 20, 2025

r? @petrochenkov

rustbot has assigned @petrochenkov.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 20, 2025
@petrochenkov
Copy link
Contributor

This is incorrect, the string literal suffix is a semantic error, not a parsing error, and this code

#[cfg(false)]
fn check() {
    let _ = r#"raw"#suffix;
}

should compile successfully.

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 21, 2025
@rustbot
Copy link
Collaborator

rustbot commented Aug 21, 2025

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@bors
Copy link
Collaborator

bors commented Aug 22, 2025

☔ The latest upstream changes (presumably #144689) made this pull request unmergeable. Please resolve the merge conflicts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wrong error for string literal suffix when stuck together
5 participants