diff --git a/compiler/rustc_parse_format/src/lib.rs b/compiler/rustc_parse_format/src/lib.rs index f150f7a41ae..92d974690b5 100644 --- a/compiler/rustc_parse_format/src/lib.rs +++ b/compiler/rustc_parse_format/src/lib.rs @@ -730,7 +730,7 @@ fn find_skips_from_snippet( str_style: Option, ) -> (Vec, bool) { let snippet = match snippet { - Some(ref s) if s.starts_with('"') || s.starts_with("r#") => s, + Some(ref s) if s.starts_with('"') || s.starts_with("r\"") || s.starts_with("r#") => s, _ => return (vec![], false), }; diff --git a/src/test/ui/fmt/format-args-capture.rs b/src/test/ui/fmt/format-args-capture.rs index d5886a13558..6c97a807b05 100644 --- a/src/test/ui/fmt/format-args-capture.rs +++ b/src/test/ui/fmt/format-args-capture.rs @@ -5,6 +5,7 @@ fn main() { named_argument_takes_precedence_to_captured(); formatting_parameters_can_be_captured(); + capture_raw_strings_and_idents(); #[cfg(panic = "unwind")] { @@ -25,6 +26,16 @@ fn named_argument_takes_precedence_to_captured() { assert_eq!(&s, "positional-named-captured"); } +fn capture_raw_strings_and_idents() { + let r#type = "apple"; + let s = format!(r#"The fruit is an {type}"#); + assert_eq!(&s, "The fruit is an apple"); + + let r#type = "orange"; + let s = format!(r"The fruit is an {type}"); + assert_eq!(&s, "The fruit is an orange"); +} + #[cfg(panic = "unwind")] fn panic_with_single_argument_does_not_get_formatted() { // panic! with a single argument does not perform string formatting. diff --git a/src/test/ui/issues/issue-75307.stderr b/src/test/ui/issues/issue-75307.stderr index 4a5d997e00d..10c952006c2 100644 --- a/src/test/ui/issues/issue-75307.stderr +++ b/src/test/ui/issues/issue-75307.stderr @@ -1,8 +1,8 @@ error: invalid reference to positional arguments 1 and 2 (there is 1 argument) - --> $DIR/issue-75307.rs:2:13 + --> $DIR/issue-75307.rs:2:17 | LL | format!(r"{}{}{}", named_arg=1); - | ^^^^^^^^^ + | ^^^^ | = note: positional arguments are zero-based