Skip to content

Hint on unknown escape of Unicode quotation marks in string literal - #156768

Draft
gilescope wants to merge 3 commits into
rust-lang:mainfrom
gilescope:giles-finish-137067
Draft

Hint on unknown escape of Unicode quotation marks in string literal#156768
gilescope wants to merge 3 commits into
rust-lang:mainfrom
gilescope:giles-finish-137067

Conversation

@gilescope

@gilescope gilescope commented May 20, 2026

Copy link
Copy Markdown
Contributor

Fixes #128858

This finishes off @LFS6502's PR #137067, which had been pre-approved by reviewers pending small follow-ups. Two reviewers (@Noratrieb and @estebank) left a short list of concrete requests; the original author indicated they were "working on this now" on 2025-08-28 but never returned. Picking it up so it can land.

The substantive change (the diagnostic itself) is @LFS6502's work, preserved as a single commit in their authorship. The second commit applies the reviewer asks:

  • Remove the leftover // lit.replace(c, &ec[1..]) development comment in unescape_error_reporting.rs (Noratrieb, then re-raised by estebank).
  • Merge the duplicated help+suggestion. The explanation stays in help; the action moves into span_suggestion_verbose so the same text isn't said twice (estebank).
  • Drop redundant line/column numbers from //~^ERROR annotations in the UI test (Noratrieb).
  • Re-bless tests/ui/unicode-quote.stderr — picks up the previously-applied asciiASCII capitalization fix and the zero-width-diacritic caret-column positions that the rust-log-analyzer flagged on the last CI run.

The first commit attributes the original work to @LFS6502 (and the PR description in their original draft credits #128906 as the prior continuation).

r? compiler

Continuation of #137067 (closes #128858).

@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 May 20, 2026
@LFS6502 LFS6502 added A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` labels May 20, 2026
@rust-log-analyzer

This comment has been minimized.

LFS6502 and others added 3 commits May 21, 2026 15:52
Fixes rust-lang#128858

Original work by @LFS6502 in PR rust-lang#137067, squashed.
Continuation of PR rust-lang#128906.

Signed-off-by: Giles Cope <gilescope@gmail.com>
Apply remaining review requests from estebank and Noratrieb on PR rust-lang#137067:

- Remove leftover `// lit.replace(...)` development comment
- Merge duplicated help+suggestion text by keeping the explanation in
  `help` and moving the actionable part into `span_suggestion_verbose`
- Drop redundant line/column numbers from `//~^ERROR` annotations
- Bless stderr (now matches the previously-applied `ASCII` capitalization
  fix and the zero-width-diacritic caret positions reported by CI)

Signed-off-by: Giles Cope <gilescope@gmail.com>
- Suggestion message now reads e.g. "consider writing it as \`\u{2033}\` for clarity"
  so the diagnostic itself names the form the user should type, rather than
  abstractly referring to "its escaped form".
- Move tests/ui/unicode-quote.{rs,stderr} into tests/ui/parser/ to satisfy
  the ui_tests tidy rule (compiler-team#902): ui tests must live under a
  meaningful subdirectory.

Signed-off-by: Giles Cope <gilescope@gmail.com>
@gilescope
gilescope force-pushed the giles-finish-137067 branch from 9c96bca to adc634c Compare May 21, 2026 15:25
@rust-log-analyzer

Copy link
Copy Markdown
Collaborator

The job aarch64-gnu-llvm-21-1 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
diff of stderr:

41   --> $DIR/unicode-quote.rs:10:12
42    |
43 LL |     dbg!("\̋"); //U+030B
-    |            ^unknown character escape
+    |            ^ unknown character escape
45    |
46    = help: \u{30b} is not an ASCII quote, but may look like one in some fonts
47 help: consider writing it as `\u{30b}` for clarity

54   --> $DIR/unicode-quote.rs:12:12
55    |
56 LL |     dbg!("\̎"); //U+030E
-    |            ^unknown character escape
+    |            ^ unknown character escape
58    |
59    = help: \u{30e} is not an ASCII quote, but may look like one in some fonts
60 help: consider writing it as `\u{30e}` for clarity

103    |
104 
105 error: aborting due to 8 previous errors
+ 
---
To only update this specific test, also pass `--test-args parser/unicode-quote.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/parser/unicode-quote.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2" "--target=aarch64-unknown-linux-gnu" "--check-cfg" "cfg(test,FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/parser/unicode-quote" "-A" "unused" "-W" "unused_attributes" "-A" "internal_features" "-A" "incomplete_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers"
stdout: none
--- stderr -------------------------------
error: unknown character escape: `\u{2033}`
##[error]  --> /checkout/tests/ui/parser/unicode-quote.rs:4:12
   |
LL |     dbg!("\″"); //U+2033
   |            ^ unknown character escape
   |
   = help: \u{2033} is not an ASCII quote, but may look like one in some fonts
help: consider writing it as `\u{2033}` for clarity
   |
LL -     dbg!("\″"); //U+2033
LL +     dbg!("\u{2033}"); //U+2033
   |

error: unknown character escape: `\u{2ba}`
##[error]  --> /checkout/tests/ui/parser/unicode-quote.rs:6:12
   |
LL |     dbg!("\ʺ"); //U+02BA
   |            ^ unknown character escape
   |
   = help: \u{2ba} is not an ASCII quote, but may look like one in some fonts
help: consider writing it as `\u{2ba}` for clarity
   |
LL -     dbg!("\ʺ"); //U+02BA
LL +     dbg!("\u{2ba}"); //U+02BA
   |

error: unknown character escape: `\u{2dd}`
##[error]  --> /checkout/tests/ui/parser/unicode-quote.rs:8:12
   |
LL |     dbg!("\˝"); //U+02DD
   |            ^ unknown character escape
   |
   = help: \u{2dd} is not an ASCII quote, but may look like one in some fonts
help: consider writing it as `\u{2dd}` for clarity
   |
LL -     dbg!("\˝"); //U+02DD
LL +     dbg!("\u{2dd}"); //U+02DD
   |

error: unknown character escape: `\u{30b}`
##[error]  --> /checkout/tests/ui/parser/unicode-quote.rs:10:12
   |
LL |     dbg!("\̋"); //U+030B
   |            ^ unknown character escape
   |
   = help: \u{30b} is not an ASCII quote, but may look like one in some fonts
help: consider writing it as `\u{30b}` for clarity
   |
LL -     dbg!("\̋"); //U+030B
LL +     dbg!("\u{30b}"); //U+030B
   |

error: unknown character escape: `\u{30e}`
##[error]  --> /checkout/tests/ui/parser/unicode-quote.rs:12:12
   |
LL |     dbg!("\̎"); //U+030E
   |            ^ unknown character escape
   |
   = help: \u{30e} is not an ASCII quote, but may look like one in some fonts
help: consider writing it as `\u{30e}` for clarity
   |
LL -     dbg!("\̎"); //U+030E
LL +     dbg!("\u{30e}"); //U+030E
   |

error: unknown character escape: `\u{5f4}`
##[error]  --> /checkout/tests/ui/parser/unicode-quote.rs:14:12
   |
LL |     dbg!("\״"); //U+05F4
   |            ^ unknown character escape
   |
   = help: \u{5f4} is not an ASCII quote, but may look like one in some fonts
help: consider writing it as `\u{5f4}` for clarity
   |
LL -     dbg!("\״"); //U+05F4
LL +     dbg!("\u{5f4}"); //U+05F4
   |

error: unknown character escape: `\u{201c}`
##[error]  --> /checkout/tests/ui/parser/unicode-quote.rs:16:12
   |
LL |     dbg!("\“"); //U+201C
   |            ^ unknown character escape
   |
   = help: \u{201c} is not an ASCII quote, but may look like one in some fonts
help: consider writing it as `\u{201c}` for clarity
   |
LL -     dbg!("\“"); //U+201C
LL +     dbg!("\u{201c}"); //U+201C
   |

error: unknown character escape: `\u{201d}`
##[error]  --> /checkout/tests/ui/parser/unicode-quote.rs:18:12
   |
LL |     dbg!("\”"); //U+201D
   |            ^ unknown character escape
   |
   = help: \u{201d} is not an ASCII quote, but may look like one in some fonts
help: consider writing it as `\u{201d}` for clarity
   |
LL -     dbg!("\”"); //U+201D
LL +     dbg!("\u{201d}"); //U+201D
   |

error: aborting due to 8 previous errors
------------------------------------------

));
diag.span_suggestion_verbose(
err_span,
format!("consider writing it as `{ec}` for clarity"),

@estebank estebank May 28, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe something more along the lines of the following?

Suggested change
format!("consider writing it as `{ec}` for clarity"),
format!("consider writing the character as escaped Unicode codepoint `{ec}` for clarity"),

View changes since the review

@jieyouxu jieyouxu assigned estebank and unassigned jieyouxu May 29, 2026
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-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` 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.

Hint on unknown escape of Unicode quotation marks in string literal

6 participants