#![warn(clippy::literal_string_with_formatting_args)] #![allow(clippy::unnecessary_literal_unwrap)] // Regression test for . // It's not supposed to emit the lint in this case (in `assert!` expansion). fn compiler_macro() { fn parse(_: &str) -> Result<(), i32> { unimplemented!() } assert!( parse( #[allow(clippy::literal_string_with_formatting_args)] "foo {:}" ) .is_err() ); let value = 0; assert!(format!("{value}").is_ascii()); } // Regression test for . fn regression_14007() { let s = "{и}"; let ш = 12; let s = "{ш}"; //~ literal_string_with_formatting_args } fn main() { let x: Option = None; let y = "hello"; x.expect("{y} {}"); //~ literal_string_with_formatting_args x.expect(" {y} bla"); //~ literal_string_with_formatting_args x.expect("{:?}"); //~ literal_string_with_formatting_args x.expect("{y:?}"); //~ literal_string_with_formatting_args x.expect(" {y:?} {y:?} "); //~ literal_string_with_formatting_args x.expect(" {y:..} {y:?} "); //~ literal_string_with_formatting_args x.expect(r"{y:?} {y:?} "); //~ literal_string_with_formatting_args x.expect(r"{y:?} y:?}"); //~ literal_string_with_formatting_args x.expect(r##" {y:?} {y:?} "##); //~ literal_string_with_formatting_args assert!("{y}".is_ascii()); //~ literal_string_with_formatting_args // Ensure that it doesn't try to go in the middle of a unicode character. x.expect("———{:?}"); //~^ literal_string_with_formatting_args // Should not lint! format!("{y:?}"); println!("{y:?}"); x.expect(" {} "); // We ignore `{}` to limit false positives. x.expect(" { } "); // We ignore `{}` to limit false positives. x.expect("{{y} {x"); x.expect("{{y:?}"); x.expect(" {0}"); // If it only contains an integer, we ignore it. x.expect(r##" {x:?} "##); // `x` doesn't exist so we shoud not lint // //~^^ literal_string_with_formatting_args x.expect("{y:...}"); let _ = "fn main {\n\ }"; // Unicode characters escape should not lint either. "\u{0052}".to_string(); // Regression test for . let x: Option = Some(0); x.expect("{…}"); }