1
1
use crate :: { EarlyContext , EarlyLintPass , LintContext } ;
2
+ use ast:: util:: unicode:: { contains_text_flow_control_chars, TEXT_FLOW_CONTROL_CHARS } ;
2
3
use rustc_ast as ast;
3
4
use rustc_errors:: { Applicability , SuggestionStyle } ;
4
5
use rustc_span:: { BytePos , Span , Symbol } ;
@@ -37,11 +38,6 @@ declare_lint! {
37
38
38
39
declare_lint_pass ! ( HiddenUnicodeCodepoints => [ TEXT_DIRECTION_CODEPOINT_IN_LITERAL ] ) ;
39
40
40
- crate const UNICODE_TEXT_FLOW_CHARS : & [ char ] = & [
41
- '\u{202A}' , '\u{202B}' , '\u{202D}' , '\u{202E}' , '\u{2066}' , '\u{2067}' , '\u{2068}' , '\u{202C}' ,
42
- '\u{2069}' ,
43
- ] ;
44
-
45
41
impl HiddenUnicodeCodepoints {
46
42
fn lint_text_direction_codepoint (
47
43
& self ,
@@ -57,7 +53,7 @@ impl HiddenUnicodeCodepoints {
57
53
. as_str ( )
58
54
. char_indices ( )
59
55
. filter_map ( |( i, c) | {
60
- UNICODE_TEXT_FLOW_CHARS . contains ( & c) . then ( || {
56
+ TEXT_FLOW_CONTROL_CHARS . contains ( & c) . then ( || {
61
57
let lo = span. lo ( ) + BytePos ( i as u32 + padding) ;
62
58
( c, span. with_lo ( lo) . with_hi ( lo + BytePos ( c. len_utf8 ( ) as u32 ) ) )
63
59
} )
@@ -131,7 +127,7 @@ impl HiddenUnicodeCodepoints {
131
127
impl EarlyLintPass for HiddenUnicodeCodepoints {
132
128
fn check_attribute ( & mut self , cx : & EarlyContext < ' _ > , attr : & ast:: Attribute ) {
133
129
if let ast:: AttrKind :: DocComment ( _, comment) = attr. kind {
134
- if comment. as_str ( ) . contains ( UNICODE_TEXT_FLOW_CHARS ) {
130
+ if contains_text_flow_control_chars ( & comment. as_str ( ) ) {
135
131
self . lint_text_direction_codepoint ( cx, comment, attr. span , 0 , false , "doc comment" ) ;
136
132
}
137
133
}
@@ -142,7 +138,7 @@ impl EarlyLintPass for HiddenUnicodeCodepoints {
142
138
let ( text, span, padding) = match & expr. kind {
143
139
ast:: ExprKind :: Lit ( ast:: Lit { token, kind, span } ) => {
144
140
let text = token. symbol ;
145
- if !text. as_str ( ) . contains ( UNICODE_TEXT_FLOW_CHARS ) {
141
+ if !contains_text_flow_control_chars ( & text. as_str ( ) ) {
146
142
return ;
147
143
}
148
144
let padding = match kind {
0 commit comments