Skip to content

Commit 5a6169d

Browse files
committed
Auto merge of rust-lang#8034 - togami2864:non-ascii-in-sigle-literal, r=llogiq
Non ascii in sigle literal fix: rust-lang#8013 changelog: `non_ascii_literal` warn against non-ASCII within `char`, not just `strings`
2 parents 35b0f24 + cd8b724 commit 5a6169d

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

clippy_lints/src/unicode.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ declare_clippy_lint! {
2828

2929
declare_clippy_lint! {
3030
/// ### What it does
31-
/// Checks for non-ASCII characters in string literals.
31+
/// Checks for non-ASCII characters in string and char literals.
3232
///
3333
/// ### Why is this bad?
3434
/// Yeah, we know, the 90's called and wanted their charset
@@ -75,7 +75,7 @@ declare_lint_pass!(Unicode => [INVISIBLE_CHARACTERS, NON_ASCII_LITERAL, UNICODE_
7575
impl LateLintPass<'_> for Unicode {
7676
fn check_expr(&mut self, cx: &LateContext<'_>, expr: &'_ Expr<'_>) {
7777
if let ExprKind::Lit(ref lit) = expr.kind {
78-
if let LitKind::Str(_, _) = lit.node {
78+
if let LitKind::Str(_, _) | LitKind::Char(_) = lit.node {
7979
check_str(cx, lit.span, expr.hir_id);
8080
}
8181
}

tests/ui/unicode.rs

+8
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,16 @@ fn uni() {
2020
print!("\u{DC}ben!"); // this is ok
2121
}
2222

23+
// issue 8013
24+
#[warn(clippy::non_ascii_literal)]
25+
fn single_quote() {
26+
const _EMPTY_BLOCK: char = '▱';
27+
const _FULL_BLOCK: char = '▰';
28+
}
29+
2330
fn main() {
2431
zero();
2532
uni();
2633
canon();
34+
single_quote();
2735
}

tests/ui/unicode.stderr

+13-1
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,17 @@ LL | print!("Üben!");
3434
|
3535
= note: `-D clippy::non-ascii-literal` implied by `-D warnings`
3636

37-
error: aborting due to 5 previous errors
37+
error: literal non-ASCII character detected
38+
--> $DIR/unicode.rs:26:32
39+
|
40+
LL | const _EMPTY_BLOCK: char = '▱';
41+
| ^^^ help: consider replacing the string with: `'/u{25b1}'`
42+
43+
error: literal non-ASCII character detected
44+
--> $DIR/unicode.rs:27:31
45+
|
46+
LL | const _FULL_BLOCK: char = '▰';
47+
| ^^^ help: consider replacing the string with: `'/u{25b0}'`
48+
49+
error: aborting due to 7 previous errors
3850

0 commit comments

Comments
 (0)