Skip to content

suggest hex escapes for C-style escapes#156376

Open
euclio wants to merge 1 commit into
rust-lang:mainfrom
euclio:foreign-escapes
Open

suggest hex escapes for C-style escapes#156376
euclio wants to merge 1 commit into
rust-lang:mainfrom
euclio:foreign-escapes

Conversation

@euclio
Copy link
Copy Markdown
Contributor

@euclio euclio commented May 9, 2026

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 9, 2026

The parser was modified, potentially altering the grammar of (stable) Rust
which would be a breaking change.

cc @fmease

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 9, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 9, 2026

r? @mu001999

rustbot has assigned @mu001999.
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

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 73 candidates
  • Random selection from 18 candidates

@rust-log-analyzer

This comment has been minimized.

@asquared31415
Copy link
Copy Markdown
Contributor

I don't think that the "(perhaps transcribing from another language)" part is useful to the diagnostic. It should be clear from context that Rust simply does this differently.

Copy link
Copy Markdown
Member

@mu001999 mu001999 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Just some nits

View changes since this review

Comment thread compiler/rustc_parse/src/lexer/unescape_error_reporting.rs Outdated
Comment thread compiler/rustc_parse/src/lexer/unescape_error_reporting.rs Outdated
Comment thread compiler/rustc_parse/src/lexer/unescape_error_reporting.rs Outdated
Comment thread compiler/rustc_parse/src/lexer/unescape_error_reporting.rs Outdated
@mu001999
Copy link
Copy Markdown
Member

@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 May 10, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 10, 2026

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

@euclio euclio force-pushed the foreign-escapes branch from 774186b to 1ee8da5 Compare May 10, 2026 04:15
@rust-log-analyzer

This comment has been minimized.

@euclio euclio force-pushed the foreign-escapes branch from 1ee8da5 to 08c3cfc Compare May 10, 2026 15:54
@euclio
Copy link
Copy Markdown
Contributor Author

euclio commented May 10, 2026

@rustbot ready

@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 May 10, 2026
Copy link
Copy Markdown
Member

@mu001999 mu001999 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented May 11, 2026

📌 Commit 08c3cfc has been approved by mu001999

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 11, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request May 11, 2026
@mu001999
Copy link
Copy Markdown
Member

@bors r-

@rust-bors rust-bors Bot 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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels May 11, 2026
@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented May 11, 2026

This pull request was unapproved.

This PR was contained in a rollup (#156432), which was unapproved.

View changes since this unapproval

Copy link
Copy Markdown
Member

@mu001999 mu001999 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread compiler/rustc_parse/src/lexer/unescape_error_reporting.rs
Comment thread compiler/rustc_parse/src/lexer/unescape_error_reporting.rs
Comment thread compiler/rustc_parse/src/lexer/unescape_error_reporting.rs Outdated
@euclio euclio force-pushed the foreign-escapes branch from 08c3cfc to 2c3bd8e Compare May 14, 2026 23:31
@euclio
Copy link
Copy Markdown
Contributor Author

euclio commented May 15, 2026

@rustbot ready

@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 May 15, 2026
Comment on lines +323 to +334
let (name, hex) = match escaped_char {
"a" => ("an audible bell", String::from("07")),
"b" => ("a backspace", String::from("08")),
"f" => ("a form feed", String::from("0C")),
"v" => ("a vertical tab", String::from("0B")),
"e" => ("an ANSI escape sequence", String::from("1B")),
ec if u8::from_str_radix(ec, 8).is_ok() => {
diag.help(r"if you meant to write an ASCII control code, use a `\xNN` hex escape");
return;
}
_ => return,
};
Copy link
Copy Markdown
Member

@mu001999 mu001999 May 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let (name, hex) = match escaped_char {
"a" => ("an audible bell", String::from("07")),
"b" => ("a backspace", String::from("08")),
"f" => ("a form feed", String::from("0C")),
"v" => ("a vertical tab", String::from("0B")),
"e" => ("an ANSI escape sequence", String::from("1B")),
ec if u8::from_str_radix(ec, 8).is_ok() => {
diag.help(r"if you meant to write an ASCII control code, use a `\xNN` hex escape");
return;
}
_ => return,
};
if u8::from_str_radix(escaped_char, 8).is_ok() {
diag.help(r"if you meant to write an ASCII control code, use a `\xNN` hex escape");
return;
}
let (name, hex) = match escaped_char {
"a" => ("an audible bell", "07"),
"b" => ("a backspace", "08"),
"f" => ("a form feed", "0C"),
"v" => ("a vertical tab", "0B"),
"e" => ("an ANSI escape sequence", "1B"),
_ => return,
};

View changes since the review

Copy link
Copy Markdown
Member

@mu001999 mu001999 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rustbot review

r=me after nits

View changes since this review

@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 May 15, 2026
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.

Diagnostics should recognize string/char escape sequences from C and suggest appropriate Rust equivalents

5 participants