From 140ba610e490c356bfbe982e62bf686232e5f394 Mon Sep 17 00:00:00 2001 From: togami2864 Date: Fri, 26 Nov 2021 18:34:07 +0900 Subject: [PATCH 1/5] add test suit --- tests/ui/unicode.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/ui/unicode.rs b/tests/ui/unicode.rs index 1f596c312fe..e0a4eadce33 100644 --- a/tests/ui/unicode.rs +++ b/tests/ui/unicode.rs @@ -20,8 +20,16 @@ fn uni() { print!("\u{DC}ben!"); // this is ok } +// issue 8013 +#[warn(clippy::non_ascii_literal)] +fn single_quote() { + const _EMPTY_BLOCK: char = '▱'; + const _FULL_BLOCK: char = '▰'; +} + fn main() { zero(); uni(); canon(); + single_quote(); } From a745cc55f3e5658e90c971d6532529c2526bf87b Mon Sep 17 00:00:00 2001 From: togami2864 Date: Fri, 26 Nov 2021 18:42:41 +0900 Subject: [PATCH 2/5] make non_ascii_literal to catch char --- clippy_lints/src/unicode.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/unicode.rs b/clippy_lints/src/unicode.rs index a514e8c44e2..b5e4bc75bd1 100644 --- a/clippy_lints/src/unicode.rs +++ b/clippy_lints/src/unicode.rs @@ -75,7 +75,7 @@ declare_lint_pass!(Unicode => [INVISIBLE_CHARACTERS, NON_ASCII_LITERAL, UNICODE_ impl LateLintPass<'_> for Unicode { fn check_expr(&mut self, cx: &LateContext<'_>, expr: &'_ Expr<'_>) { if let ExprKind::Lit(ref lit) = expr.kind { - if let LitKind::Str(_, _) = lit.node { + if let LitKind::Str(_, _) | LitKind::Char(_)= lit.node { check_str(cx, lit.span, expr.hir_id); } } From e8ef6ca5e31f6cd648aca9c0cfe7a9743ec880d7 Mon Sep 17 00:00:00 2001 From: togami2864 Date: Fri, 26 Nov 2021 18:49:14 +0900 Subject: [PATCH 3/5] fix stderr --- clippy_lints/src/unicode.rs | 2 +- tests/ui/unicode.stderr | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/unicode.rs b/clippy_lints/src/unicode.rs index b5e4bc75bd1..82d7a1cbb8e 100644 --- a/clippy_lints/src/unicode.rs +++ b/clippy_lints/src/unicode.rs @@ -75,7 +75,7 @@ declare_lint_pass!(Unicode => [INVISIBLE_CHARACTERS, NON_ASCII_LITERAL, UNICODE_ impl LateLintPass<'_> for Unicode { fn check_expr(&mut self, cx: &LateContext<'_>, expr: &'_ Expr<'_>) { if let ExprKind::Lit(ref lit) = expr.kind { - if let LitKind::Str(_, _) | LitKind::Char(_)= lit.node { + if let LitKind::Str(_, _) | LitKind::Char(_) = lit.node { check_str(cx, lit.span, expr.hir_id); } } diff --git a/tests/ui/unicode.stderr b/tests/ui/unicode.stderr index 3fca463c620..3f54e3880e7 100644 --- a/tests/ui/unicode.stderr +++ b/tests/ui/unicode.stderr @@ -34,5 +34,17 @@ LL | print!("Üben!"); | = note: `-D clippy::non-ascii-literal` implied by `-D warnings` -error: aborting due to 5 previous errors +error: literal non-ASCII character detected + --> $DIR/unicode.rs:26:32 + | +LL | const _EMPTY_BLOCK: char = '▱'; + | ^^^ help: consider replacing the string with: `'/u{25b1}'` + +error: literal non-ASCII character detected + --> $DIR/unicode.rs:27:31 + | +LL | const _FULL_BLOCK: char = '▰'; + | ^^^ help: consider replacing the string with: `'/u{25b0}'` + +error: aborting due to 7 previous errors From e6a6ed44b20a50bb99cb3da56ff3b5fc31a84cac Mon Sep 17 00:00:00 2001 From: togami2864 Date: Fri, 26 Nov 2021 18:52:27 +0900 Subject: [PATCH 4/5] fix doc --- clippy_lints/src/unicode.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/unicode.rs b/clippy_lints/src/unicode.rs index 82d7a1cbb8e..11d9705b8c6 100644 --- a/clippy_lints/src/unicode.rs +++ b/clippy_lints/src/unicode.rs @@ -28,7 +28,7 @@ declare_clippy_lint! { declare_clippy_lint! { /// ### What it does - /// Checks for non-ASCII characters in string literals. + /// Checks for non-ASCII characters in string literals or char. /// /// ### Why is this bad? /// Yeah, we know, the 90's called and wanted their charset From cd8b72443dd4af41d12ae22848a456d4833b1313 Mon Sep 17 00:00:00 2001 From: togami2864 Date: Fri, 26 Nov 2021 19:27:14 +0900 Subject: [PATCH 5/5] fix small nit --- clippy_lints/src/unicode.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/unicode.rs b/clippy_lints/src/unicode.rs index 11d9705b8c6..fbc4732e0ce 100644 --- a/clippy_lints/src/unicode.rs +++ b/clippy_lints/src/unicode.rs @@ -28,7 +28,7 @@ declare_clippy_lint! { declare_clippy_lint! { /// ### What it does - /// Checks for non-ASCII characters in string literals or char. + /// Checks for non-ASCII characters in string and char literals. /// /// ### Why is this bad? /// Yeah, we know, the 90's called and wanted their charset