Skip to content

Commit 572e4c4

Browse files
committed
Add WJ
1 parent 998bd3b commit 572e4c4

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

clippy_lints/src/unicode.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,17 @@ fn escape<T: Iterator<Item = char>>(s: T) -> String {
9191

9292
fn check_str(cx: &LateContext<'_>, span: Span, id: HirId) {
9393
let string = snippet(cx, span, "");
94-
if string.chars().any(|c| ['\u{200B}', '\u{ad}'].contains(&c)) {
94+
if string.chars().any(|c| ['\u{200B}', '\u{ad}', '\u{2060}'].contains(&c)) {
9595
span_lint_and_sugg(
9696
cx,
9797
INVISIBLE_CHARACTERS,
9898
span,
9999
"invisible character detected",
100100
"consider replacing the string with",
101-
string.replace("\u{200B}", "\\u{200B}").replace("\u{ad}", "\\u{AD}"),
101+
string
102+
.replace("\u{200B}", "\\u{200B}")
103+
.replace("\u{ad}", "\\u{AD}")
104+
.replace("\u{2060}", "\\u{2060}"),
102105
Applicability::MachineApplicable,
103106
);
104107
}

tests/ui/unicode.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ fn zero() {
44
print!("This\u{200B}is\u{200B}fine");
55
print!("Here >­< is a SHY, and ­another");
66
print!("This\u{ad}is\u{ad}fine");
7+
print!("Here >⁠< is a WJ, and ⁠another");
8+
print!("This\u{2060}is\u{2060}fine");
79
}
810

911
#[warn(clippy::unicode_not_nfc)]

tests/ui/unicode.stderr

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,27 @@ error: invisible character detected
1212
LL | print!("Here >­< is a SHY, and ­another");
1313
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider replacing the string with: `"Here >/u{AD}< is a SHY, and /u{AD}another"`
1414

15+
error: invisible character detected
16+
--> $DIR/unicode.rs:7:12
17+
|
18+
LL | print!("Here >⁠< is a WJ, and ⁠another");
19+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider replacing the string with: `"Here >/u{2060}< is a WJ, and /u{2060}another"`
20+
1521
error: non-NFC Unicode sequence detected
16-
--> $DIR/unicode.rs:11:12
22+
--> $DIR/unicode.rs:13:12
1723
|
1824
LL | print!("̀àh?");
1925
| ^^^^^ help: consider replacing the string with: `"̀àh?"`
2026
|
2127
= note: `-D clippy::unicode-not-nfc` implied by `-D warnings`
2228

2329
error: literal non-ASCII character detected
24-
--> $DIR/unicode.rs:17:12
30+
--> $DIR/unicode.rs:19:12
2531
|
2632
LL | print!("Üben!");
2733
| ^^^^^^^ help: consider replacing the string with: `"/u{dc}ben!"`
2834
|
2935
= note: `-D clippy::non-ascii-literal` implied by `-D warnings`
3036

31-
error: aborting due to 4 previous errors
37+
error: aborting due to 5 previous errors
3238

0 commit comments

Comments
 (0)