Skip to content

Commit 206dc78

Browse files
committed
Implement suggested fix and update test
1 parent c9e0f09 commit 206dc78

File tree

3 files changed

+33
-16
lines changed

3 files changed

+33
-16
lines changed

compiler/rustc_parse/src/lexer/unescape_error_reporting.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,18 @@ pub(crate) fn emit_unescape_error(
159159
version control settings",
160160
);
161161
} else if looks_like_quote(c) {
162+
diag.span_suggestion(
163+
err_span,
164+
"if you meant to use a unicode quote; \
165+
consider using its escaped form for clarity",
166+
// lit.replace(c, &ec[1..]),
167+
&ec,
168+
Applicability::MaybeIncorrect,
169+
);
170+
162171
diag.help(format!(
163-
"{ec} is not an ascii quote, \
164-
but may look like one in some fonts.\n\
165-
consider writing it in its \
166-
escaped form for clarity."
172+
"{ec} is not an ascii quote, but may look like one in some fonts; \
173+
consider writing it in its escaped form for clarity."
167174
));
168175
} else {
169176
if mode == Mode::Str || mode == Mode::Char {

tests/ui/unicode-quote.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
fn main() {
2-
dbg!("since when is \“THIS\” not allowed in a string literal");
2+
dbg!("Is this \“ a small sized quote or a big sized quote. \“ ");
3+
//~^ 2:20: 2:21: unknown character escape: `\u{201c}`
4+
//~^^ 2:65: 2:66: unknown character escape: `\u{201c}`
35
}

tests/ui/unicode-quote.stderr

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
11
error: unknown character escape: `\u{201c}`
2-
--> $DIR/unicode-quote.rs:2:26
2+
--> $DIR/unicode-quote.rs:2:20
33
|
4-
LL | dbg!("since when is \“THIS\” not allowed in a string literal");
5-
| ^ unknown character escape
4+
LL | dbg!("Is this \“ a small sized quote or a big sized quote. \“ ");
5+
| ^ unknown character escape
6+
|
7+
= help: \u{201c} is not an ascii quote, but may look like one in some fonts; consider writing it in its escaped form for clarity.
8+
help: if you meant to use a unicode quote; consider using its escaped form for clarity
9+
|
10+
LL - dbg!("Is this \“ a small sized quote or a big sized quote. \“ ");
11+
LL + dbg!("Is this \u{201c} a small sized quote or a big sized quote. \“ ");
612
|
7-
= help: \u{201c} is not an ascii quote, but may look like one in some fonts.
8-
consider writing it in its escaped form for clarity.
913

10-
error: unknown character escape: `\u{201d}`
11-
--> $DIR/unicode-quote.rs:2:32
14+
error: unknown character escape: `\u{201c}`
15+
--> $DIR/unicode-quote.rs:2:65
16+
|
17+
LL | dbg!("Is this \“ a small sized quote or a big sized quote. \“ ");
18+
| ^ unknown character escape
19+
|
20+
= help: \u{201c} is not an ascii quote, but may look like one in some fonts; consider writing it in its escaped form for clarity.
21+
help: if you meant to use a unicode quote; consider using its escaped form for clarity
1222
|
13-
LL | dbg!("since when is \“THIS\” not allowed in a string literal");
14-
| ^ unknown character escape
23+
LL - dbg!("Is this \“ a small sized quote or a big sized quote. \“ ");
24+
LL + dbg!("Is this \“ a small sized quote or a big sized quote. \u{201c} ");
1525
|
16-
= help: \u{201d} is not an ascii quote, but may look like one in some fonts.
17-
consider writing it in its escaped form for clarity.
1826

1927
error: aborting due to 2 previous errors
2028

0 commit comments

Comments
 (0)