@@ -9,7 +9,7 @@ use rustc_ast::ast::RangeLimits;
99use rustc_errors:: Applicability ;
1010use rustc_hir:: { Expr , ExprKind , Node , Param , PatKind , RangeEnd } ;
1111use rustc_lint:: { LateContext , LateLintPass } ;
12- use rustc_middle:: ty;
12+ use rustc_middle:: ty:: { self , Ty } ;
1313use rustc_session:: impl_lint_pass;
1414use rustc_span:: { Span , sym} ;
1515
@@ -114,7 +114,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualIsAsciiCheck {
114114 && !matches ! ( cx. typeck_results( ) . expr_ty( arg) . peel_refs( ) . kind( ) , ty:: Param ( _) )
115115 {
116116 let arg = peel_ref_operators ( cx, arg) ;
117- let ty_sugg = get_ty_sugg ( cx, arg, start ) ;
117+ let ty_sugg = get_ty_sugg ( cx, arg) ;
118118 let range = check_range ( start, end) ;
119119 check_is_ascii ( cx, expr. span , arg, & range, ty_sugg) ;
120120 }
@@ -123,19 +123,14 @@ impl<'tcx> LateLintPass<'tcx> for ManualIsAsciiCheck {
123123 extract_msrv_attr ! ( LateContext ) ;
124124}
125125
126- fn get_ty_sugg ( cx : & LateContext < ' _ > , arg : & Expr < ' _ > , bound_expr : & Expr < ' _ > ) -> Option < ( Span , & ' static str ) > {
127- if let ExprKind :: Lit ( lit) = bound_expr. kind
128- && let local_hid = path_to_local ( arg) ?
129- && let Node :: Param ( Param { ty_span, span, .. } ) = cx. tcx . parent_hir_node ( local_hid)
126+ fn get_ty_sugg < ' tcx > ( cx : & LateContext < ' tcx > , arg : & Expr < ' _ > ) -> Option < ( Span , Ty < ' tcx > ) > {
127+ let local_hid = path_to_local ( arg) ?;
128+ if let Node :: Param ( Param { ty_span, span, .. } ) = cx. tcx . parent_hir_node ( local_hid)
130129 // `ty_span` and `span` are the same for inferred type, thus a type suggestion must be given
131130 && ty_span == span
132131 {
133- let ty_str = match lit. node {
134- Char ( _) => "char" ,
135- Byte ( _) => "u8" ,
136- _ => return None ,
137- } ;
138- return Some ( ( * ty_span, ty_str) ) ;
132+ let arg_type = cx. typeck_results ( ) . expr_ty ( arg) ;
133+ return Some ( ( * ty_span, arg_type) ) ;
139134 }
140135 None
141136}
@@ -145,7 +140,7 @@ fn check_is_ascii(
145140 span : Span ,
146141 recv : & Expr < ' _ > ,
147142 range : & CharRange ,
148- ty_sugg : Option < ( Span , & ' _ str ) > ,
143+ ty_sugg : Option < ( Span , Ty < ' _ > ) > ,
149144) {
150145 let sugg = match range {
151146 CharRange :: UpperChar => "is_ascii_uppercase" ,
@@ -159,8 +154,8 @@ fn check_is_ascii(
159154 let mut app = Applicability :: MachineApplicable ;
160155 let recv = Sugg :: hir_with_context ( cx, recv, span. ctxt ( ) , default_snip, & mut app) . maybe_par ( ) ;
161156 let mut suggestion = vec ! [ ( span, format!( "{recv}.{sugg}()" ) ) ] ;
162- if let Some ( ( ty_span, ty_str ) ) = ty_sugg {
163- suggestion. push ( ( ty_span, format ! ( "{recv}: {ty_str }" ) ) ) ;
157+ if let Some ( ( ty_span, ty ) ) = ty_sugg {
158+ suggestion. push ( ( ty_span, format ! ( "{recv}: {ty }" ) ) ) ;
164159 }
165160
166161 span_lint_and_then (
0 commit comments