Skip to content

Commit 36c8aab

Browse files
author
BO41
committed
Fix tests and make other ascii lints auto-fixable
1 parent 859b329 commit 36c8aab

File tree

2 files changed

+15
-33
lines changed

2 files changed

+15
-33
lines changed

clippy_lints/src/unicode.rs

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::utils::{is_allowed, snippet, span_help_and_lint, span_lint_and_sugg};
1+
use crate::utils::{is_allowed, snippet, span_lint_and_sugg};
22
use rustc::hir::*;
33
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
44
use rustc::{declare_lint_pass, declare_tool_lint};
@@ -92,15 +92,14 @@ fn escape<T: Iterator<Item = char>>(s: T) -> String {
9292
fn check_str(cx: &LateContext<'_, '_>, span: Span, id: HirId) {
9393
let string = snippet(cx, span, "");
9494
if string.contains('\u{200B}') {
95-
span_help_and_lint(
95+
span_lint_and_sugg(
9696
cx,
9797
ZERO_WIDTH_SPACE,
9898
span,
9999
"zero-width space detected",
100-
&format!(
101-
"Consider replacing the string with:\n\"{}\"",
102-
string.replace("\u{200B}", "\\u{200B}")
103-
),
100+
"consider replacing the string with",
101+
string.replace("\u{200B}", "\\u{200B}"),
102+
Applicability::MachineApplicable,
104103
);
105104
}
106105
if string.chars().any(|c| c as u32 > 0x7F) {
@@ -109,35 +108,24 @@ fn check_str(cx: &LateContext<'_, '_>, span: Span, id: HirId) {
109108
NON_ASCII_LITERAL,
110109
span,
111110
"literal non-ASCII character detected",
112-
&format!(
113-
"Consider replacing the string with:\n\"{}\"",
114-
if is_allowed(cx, UNICODE_NOT_NFC, id) {
115-
escape(string.chars())
116-
} else {
117-
escape(string.nfc())
118-
}
119-
),
120-
format!(
121-
"{}",
122-
if is_allowed(cx, UNICODE_NOT_NFC, id) {
123-
escape(string.chars())
124-
} else {
125-
escape(string.nfc())
126-
}
127-
),
111+
"consider replacing the string with",
112+
if is_allowed(cx, UNICODE_NOT_NFC, id) {
113+
escape(string.chars())
114+
} else {
115+
escape(string.nfc())
116+
},
128117
Applicability::MachineApplicable,
129118
);
130119
}
131120
if is_allowed(cx, NON_ASCII_LITERAL, id) && string.chars().zip(string.nfc()).any(|(a, b)| a != b) {
132-
span_help_and_lint(
121+
span_lint_and_sugg(
133122
cx,
134123
UNICODE_NOT_NFC,
135124
span,
136125
"non-nfc unicode sequence detected",
137-
&format!(
138-
"Consider replacing the string with:\n\"{}\"",
139-
string.nfc().collect::<String>()
140-
),
126+
"consider replacing the string with",
127+
string.nfc().collect::<String>(),
128+
Applicability::MachineApplicable,
141129
);
142130
}
143131
}

tests/ui/unicode.stderr

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ LL | print!("Here >​< is a ZWS, and ​another");
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
= note: `-D clippy::zero-width-space` implied by `-D warnings`
8-
= help: Consider replacing the string with:
9-
""Here >/u{200B}< is a ZWS, and /u{200B}another""
108

119
error: non-nfc unicode sequence detected
1210
--> $DIR/unicode.rs:9:12
@@ -15,8 +13,6 @@ LL | print!("̀àh?");
1513
| ^^^^^
1614
|
1715
= note: `-D clippy::unicode-not-nfc` implied by `-D warnings`
18-
= help: Consider replacing the string with:
19-
""̀àh?""
2016

2117
error: literal non-ASCII character detected
2218
--> $DIR/unicode.rs:15:12
@@ -25,8 +21,6 @@ LL | print!("Üben!");
2521
| ^^^^^^^
2622
|
2723
= note: `-D clippy::non-ascii-literal` implied by `-D warnings`
28-
= help: Consider replacing the string with:
29-
""/u{dc}ben!""
3024

3125
error: aborting due to 3 previous errors
3226

0 commit comments

Comments
 (0)