Skip to content

Non ascii in sigle literal #8034

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions clippy_lints/src/unicode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 and char literals.
///
/// ### Why is this bad?
/// Yeah, we know, the 90's called and wanted their charset
Expand Down Expand Up @@ -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);
}
}
Expand Down
8 changes: 8 additions & 0 deletions tests/ui/unicode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
14 changes: 13 additions & 1 deletion tests/ui/unicode.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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