Skip to content

Commit 859b329

Browse files
author
BO41
committed
Make non_ascii_literal auto-fixable
1 parent 874de88 commit 859b329

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

clippy_lints/src/unicode.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
use crate::utils::{is_allowed, snippet, span_help_and_lint};
1+
use crate::utils::{is_allowed, snippet, span_help_and_lint, 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};
5+
use rustc_errors::Applicability;
56
use syntax::ast::LitKind;
67
use syntax::source_map::Span;
78
use unicode_normalization::UnicodeNormalization;
@@ -103,7 +104,7 @@ fn check_str(cx: &LateContext<'_, '_>, span: Span, id: HirId) {
103104
);
104105
}
105106
if string.chars().any(|c| c as u32 > 0x7F) {
106-
span_help_and_lint(
107+
span_lint_and_sugg(
107108
cx,
108109
NON_ASCII_LITERAL,
109110
span,
@@ -116,6 +117,15 @@ fn check_str(cx: &LateContext<'_, '_>, span: Span, id: HirId) {
116117
escape(string.nfc())
117118
}
118119
),
120+
format!(
121+
"{}",
122+
if is_allowed(cx, UNICODE_NOT_NFC, id) {
123+
escape(string.chars())
124+
} else {
125+
escape(string.nfc())
126+
}
127+
),
128+
Applicability::MachineApplicable,
119129
);
120130
}
121131
if is_allowed(cx, NON_ASCII_LITERAL, id) && string.chars().zip(string.nfc()).any(|(a, b)| a != b) {

0 commit comments

Comments
 (0)