Skip to content

Commit a4748ae

Browse files
committed
perf: skip snippet lookup for pure-ASCII literals in unicode lints
1 parent 824aa1f commit a4748ae

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

clippy_lints/src/unicode.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,16 @@ declare_lint_pass!(Unicode => [
8080

8181
impl LateLintPass<'_> for Unicode {
8282
fn check_expr(&mut self, cx: &LateContext<'_>, expr: &'_ Expr<'_>) {
83-
if let ExprKind::Lit(lit) = expr.kind
84-
&& let LitKind::Str(_, _) | LitKind::Char(_) = lit.node
85-
{
86-
check_str(cx, lit.span, expr.hir_id);
83+
if let ExprKind::Lit(lit) = expr.kind {
84+
// If the literal's value is all ASCII, so is its source: skip the snippet lookup.
85+
let has_non_ascii = match lit.node {
86+
LitKind::Str(sym, _) => !sym.as_str().is_ascii(),
87+
LitKind::Char(c) => !c.is_ascii(),
88+
_ => false,
89+
};
90+
if has_non_ascii {
91+
check_str(cx, lit.span, expr.hir_id);
92+
}
8793
}
8894
}
8995
}

0 commit comments

Comments
 (0)