Forbid string literal suffix

This commit is contained in:
Guillaume Gomez 2025-07-20 15:36:39 +02:00 committed by René Kijewski
parent d8bf38978c
commit 6de8ff8042
3 changed files with 20 additions and 1 deletions

View File

@ -687,7 +687,7 @@ fn str_lit<'a>(i: &mut &'a str) -> ParseResult<'a, StrLit<'a>> {
}
fn not_suffix_with_hash<'a>(i: &mut &'a str) -> ParseResult<'a, ()> {
if let Some(suffix) = opt((identifier, '#').take()).parse_next(i)? {
if let Some(suffix) = opt(identifier.take()).parse_next(i)? {
return cut_error!(
"you are missing a space to separate two string literals",
suffix,

View File

@ -0,0 +1,12 @@
// This test ensures that the proc-macro fails if two arguments are not separated.
use askama::Template;
#[derive(Template)]
#[template(
source = r###"{{e!{ r#""#r" \ "}}}"###,
ext = "html"
)]
struct Example;
fn main() {}

View File

@ -0,0 +1,7 @@
error: you are missing a space to separate two string literals
--> <source attribute>:1:11
"r\" \\ \"}}}"
--> tests/ui/macro-args.rs:7:14
|
7 | source = r###"{{e!{ r#""#r" \ "}}}"###,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^