3 use syntax::codemap::{BytePos, Span};
6 declare_lint!{ pub ZERO_WIDTH_SPACE, Deny, "Zero-width space is confusing" }
11 impl LintPass for Unicode {
12 fn get_lints(&self) -> LintArray {
13 lint_array!(ZERO_WIDTH_SPACE)
16 fn check_expr(&mut self, cx: &Context, expr: &Expr) {
17 if let ExprLit(ref lit) = expr.node {
18 if let LitStr(ref string, _) = lit.node {
19 check_str(cx, string, lit.span)
25 fn check_str(cx: &Context, string: &str, span: Span) {
26 let mut start: Option<usize> = None;
27 for (i, c) in string.char_indices() {
29 if start.is_none() { start = Some(i); }
31 lint_zero_width(cx, span, start);
35 lint_zero_width(cx, span, start);
38 fn lint_zero_width(cx: &Context, span: Span, start: Option<usize>) {
40 span_lint(cx, ZERO_WIDTH_SPACE, Span {
41 lo: span.lo + BytePos(index as u32),
42 hi: span.lo + BytePos(index as u32),
43 expn_id: span.expn_id,
44 }, "Zero-width space detected. Consider using \\u{200B}")