This commit is contained in:
Dániel Buga 2020-10-03 00:07:56 +02:00
parent 998bd3b6b4
commit 572e4c4837
3 changed files with 16 additions and 5 deletions

View file

@ -91,14 +91,17 @@ fn escape<T: Iterator<Item = char>>(s: T) -> String {
fn check_str(cx: &LateContext<'_>, span: Span, id: HirId) {
let string = snippet(cx, span, "");
if string.chars().any(|c| ['\u{200B}', '\u{ad}'].contains(&c)) {
if string.chars().any(|c| ['\u{200B}', '\u{ad}', '\u{2060}'].contains(&c)) {
span_lint_and_sugg(
cx,
INVISIBLE_CHARACTERS,
span,
"invisible character detected",
"consider replacing the string with",
string.replace("\u{200B}", "\\u{200B}").replace("\u{ad}", "\\u{AD}"),
string
.replace("\u{200B}", "\\u{200B}")
.replace("\u{ad}", "\\u{AD}")
.replace("\u{2060}", "\\u{2060}"),
Applicability::MachineApplicable,
);
}

View file

@ -4,6 +4,8 @@ fn zero() {
print!("This\u{200B}is\u{200B}fine");
print!("Here >­< is a SHY, and ­another");
print!("This\u{ad}is\u{ad}fine");
print!("Here >< is a WJ, and another");
print!("This\u{2060}is\u{2060}fine");
}
#[warn(clippy::unicode_not_nfc)]

View file

@ -12,8 +12,14 @@ error: invisible character detected
LL | print!("Here >­< is a SHY, and ­another");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider replacing the string with: `"Here >/u{AD}< is a SHY, and /u{AD}another"`
error: invisible character detected
--> $DIR/unicode.rs:7:12
|
LL | print!("Here >< is a WJ, and another");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider replacing the string with: `"Here >/u{2060}< is a WJ, and /u{2060}another"`
error: non-NFC Unicode sequence detected
--> $DIR/unicode.rs:11:12
--> $DIR/unicode.rs:13:12
|
LL | print!("̀àh?");
| ^^^^^ help: consider replacing the string with: `"̀àh?"`
@ -21,12 +27,12 @@ LL | print!("̀àh?");
= note: `-D clippy::unicode-not-nfc` implied by `-D warnings`
error: literal non-ASCII character detected
--> $DIR/unicode.rs:17:12
--> $DIR/unicode.rs:19:12
|
LL | print!("Üben!");
| ^^^^^^^ help: consider replacing the string with: `"/u{dc}ben!"`
|
= note: `-D clippy::non-ascii-literal` implied by `-D warnings`
error: aborting due to 4 previous errors
error: aborting due to 5 previous errors