diff --git a/rinja_derive/src/config.rs b/rinja_derive/src/config.rs index 1854d350..9cad7232 100644 --- a/rinja_derive/src/config.rs +++ b/rinja_derive/src/config.rs @@ -360,6 +360,26 @@ impl<'a> RawSyntax<'a> { } } + for end in [syntax.block_end, syntax.expr_end, syntax.comment_end] { + for prefix in ["<<", ">>", "&&", "..", "||"] { + if end.starts_with(prefix) { + let msg = if end == prefix { + format!("a closing delimiter must not start with an operator: {end:?}") + } else { + format!( + "a closing delimiter must not start an with operator: \ + {end:?} vs {prefix:?}", + ) + }; + return Err(CompileError::new_with_span( + msg, + file_info.copied(), + config_span, + )); + } + } + } + Ok(syntax) } } diff --git a/testing/issue-128-2.toml b/testing/issue-128-2.toml new file mode 100644 index 00000000..650731aa --- /dev/null +++ b/testing/issue-128-2.toml @@ -0,0 +1,4 @@ +[[syntax]] +name = "mwe" +expr_start = "<<<" +expr_end = ">>>" diff --git a/testing/issue-128.toml b/testing/issue-128.toml new file mode 100644 index 00000000..4bb9d6a0 --- /dev/null +++ b/testing/issue-128.toml @@ -0,0 +1,4 @@ +[[syntax]] +name = "mwe" +expr_start = "<<" +expr_end = ">>" diff --git a/testing/tests/ui/terminator-operator.rs b/testing/tests/ui/terminator-operator.rs new file mode 100644 index 00000000..20a45a09 --- /dev/null +++ b/testing/tests/ui/terminator-operator.rs @@ -0,0 +1,17 @@ +use rinja::Template; + +#[derive(Template)] +#[template(source = "<> and <>", config = "issue-128.toml", syntax = "mwe", ext="")] +struct HelloTemplate { + a: u32, + b: u32, +} + +#[derive(Template)] +#[template(source = "<> and <>", config = "issue-128-2.toml", syntax = "mwe", ext="")] +struct HelloTemplate2 { + a: u32, + b: u32, +} + +fn main() {} diff --git a/testing/tests/ui/terminator-operator.stderr b/testing/tests/ui/terminator-operator.stderr new file mode 100644 index 00000000..73afa8c7 --- /dev/null +++ b/testing/tests/ui/terminator-operator.stderr @@ -0,0 +1,13 @@ +error: a closing delimiter must not start with an operator: ">>" + --> testing/issue-128.toml + --> tests/ui/terminator-operator.rs:4:49 + | +4 | #[template(source = "<> and <>", config = "issue-128.toml", syntax = "mwe", ext="")] + | ^^^^^^^^^^^^^^^^ + +error: a closing delimiter must not start an with operator: ">>>" vs ">>" + --> testing/issue-128-2.toml + --> tests/ui/terminator-operator.rs:11:49 + | +11 | #[template(source = "<> and <>", config = "issue-128-2.toml", syntax = "mwe", ext="")] + | ^^^^^^^^^^^^^^^^^^