11use clippy_utils:: diagnostics:: span_lint_and_then;
2+ use clippy_utils:: source:: snippet_opt;
23use clippy_utils:: source:: { indent_of, reindent_multiline} ;
3- use clippy_utils:: sugg:: Sugg ;
44use clippy_utils:: ty:: is_type_lang_item;
55use if_chain:: if_chain;
66use rustc_ast:: ast:: LitKind ;
@@ -19,8 +19,10 @@ pub(super) fn check<'tcx>(
1919 arg : & ' tcx Expr < ' _ > ,
2020) {
2121 if let ExprKind :: MethodCall ( path_segment, ..) = recv. kind {
22- let method_name = path_segment. ident . name . as_str ( ) ;
23- if method_name == "to_lowercase" || method_name == "to_uppercase" {
22+ if matches ! (
23+ path_segment. ident. name. as_str( ) ,
24+ "to_lowercase" | "to_uppercase" | "to_ascii_lowercase" | "to_ascii_uppercase"
25+ ) {
2426 return ;
2527 }
2628 }
@@ -45,28 +47,29 @@ pub(super) fn check<'tcx>(
4547 "case-sensitive file extension comparison" ,
4648 |diag| {
4749 diag. help( "consider using a case-insensitive comparison instead" ) ;
48- let mut recv_source = Sugg :: hir ( cx, recv, "" ) . to_string ( ) ;
50+ if let Some ( mut recv_source) = snippet_opt ( cx, recv. span ) {
4951
50- if is_type_lang_item ( cx , recv_ty , LangItem :: String ) {
51- recv_source = format!( "&{recv_source}" ) ;
52- }
52+ if !cx . typeck_results ( ) . expr_ty ( recv ) . is_ref ( ) {
53+ recv_source = format!( "&{recv_source}" ) ;
54+ }
5355
54- let suggestion_source = reindent_multiline(
55- format!(
56- "std::path::Path::new({})
57- .extension()
58- .map_or(false, |ext| ext.eq_ignore_ascii_case(\" {}\" ))" ,
59- recv_source, ext_str. strip_prefix( '.' ) . unwrap( ) ) . into( ) ,
60- true ,
61- Some ( indent_of( cx, call_span) . unwrap_or( 0 ) + 4 )
62- ) ;
56+ let suggestion_source = reindent_multiline(
57+ format!(
58+ "std::path::Path::new({})
59+ .extension()
60+ .map_or(false, |ext| ext.eq_ignore_ascii_case(\" {}\" ))" ,
61+ recv_source, ext_str. strip_prefix( '.' ) . unwrap( ) ) . into( ) ,
62+ true ,
63+ Some ( indent_of( cx, call_span) . unwrap_or( 0 ) + 4 )
64+ ) ;
6365
64- diag. span_suggestion(
65- recv. span. to( call_span) ,
66- "use std::path::Path" ,
67- suggestion_source,
68- Applicability :: MaybeIncorrect ,
69- ) ;
66+ diag. span_suggestion(
67+ recv. span. to( call_span) ,
68+ "use std::path::Path" ,
69+ suggestion_source,
70+ Applicability :: MaybeIncorrect ,
71+ ) ;
72+ }
7073 }
7174 ) ;
7275 }
0 commit comments