@@ -463,12 +463,18 @@ fn check_literal(cx: &LateContext<'_>, format_args: &FormatArgs, name: &str) {
463463 && let Some ( value_string) = snippet_opt ( cx, arg. expr . span )
464464 {
465465 let ( replacement, replace_raw) = match lit. kind {
466- LitKind :: Str | LitKind :: StrRaw ( _) => extract_str_literal ( & value_string) ,
466+ LitKind :: Str | LitKind :: StrRaw ( _) => match extract_str_literal ( & value_string) {
467+ Some ( extracted) => extracted,
468+ None => return ,
469+ } ,
467470 LitKind :: Char => (
468471 match lit. symbol . as_str ( ) {
469472 "\" " => "\\ \" " ,
470473 "\\ '" => "'" ,
471- _ => & value_string[ 1 ..value_string. len ( ) - 1 ] ,
474+ _ => match value_string. strip_prefix ( '\'' ) . and_then ( |s| s. strip_suffix ( '\'' ) ) {
475+ Some ( stripped) => stripped,
476+ None => return ,
477+ } ,
472478 }
473479 . to_string ( ) ,
474480 false ,
@@ -533,13 +539,13 @@ fn check_literal(cx: &LateContext<'_>, format_args: &FormatArgs, name: &str) {
533539/// `r#"a"#` -> (`a`, true)
534540///
535541/// `"b"` -> (`b`, false)
536- fn extract_str_literal ( literal : & str ) -> ( String , bool ) {
542+ fn extract_str_literal ( literal : & str ) -> Option < ( String , bool ) > {
537543 let ( literal, raw) = match literal. strip_prefix ( 'r' ) {
538544 Some ( stripped) => ( stripped. trim_matches ( '#' ) , true ) ,
539545 None => ( literal, false ) ,
540546 } ;
541547
542- ( literal[ 1 ..literal . len ( ) - 1 ] . to_string ( ) , raw)
548+ Some ( ( literal. strip_prefix ( '"' ) ? . strip_suffix ( '"' ) ? . to_string ( ) , raw) )
543549}
544550
545551enum UnescapeErr {
0 commit comments