Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion rinja_derive/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,17 @@ pub(crate) struct TemplateArgs {

impl TemplateArgs {
pub(crate) fn new(ast: &syn::DeriveInput) -> Result<Self, CompileError> {
// FIXME: implement once <https://github.com/rust-lang/rfcs/pull/3715> is stable

Check notice

Code scanning / devskim

A "TODO" or similar was left in source code, possibly indicating incomplete functionality

Suspicious comment
if let syn::Data::Union(data) = &ast.data {
return Err(CompileError::new_with_span(
"rinja templates are not supported for `union` types, only `struct` and `enum`",
None,
Some(data.union_token.span),
));
}

// Check that an attribute called `template()` exists at least once and that it is
// the proper type (list).

let mut templates_attrs = ast
.attrs
.iter()
Expand Down Expand Up @@ -532,6 +540,7 @@ fn no_rinja_code_block(name: &syn::Ident, ast: &syn::DeriveInput) -> CompileErro
let kind = match &ast.data {
syn::Data::Struct(_) => "struct",
syn::Data::Enum(_) => "enum",
// actually unreachable: `union`s are rejected by `TemplateArgs::new()`
syn::Data::Union(_) => "union",
};
CompileError::no_file_info(
Expand Down
8 changes: 4 additions & 4 deletions testing/tests/ui/rinja-block.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ error: when using `in_doc = true`, the enum's documentation needs a `rinja` code
60 | #[template(ext = "txt", in_doc = true)]
| ^^^^^^

error: when using `in_doc = true`, the union's documentation needs a `rinja` code block
--> tests/ui/rinja-block.rs:67:25
error: rinja templates are not supported for `union` types, only `struct` and `enum`
--> tests/ui/rinja-block.rs:68:1
|
67 | #[template(ext = "txt", in_doc = true)]
| ^^^^^^
68 | union NoDocForUnion {
| ^^^^^
10 changes: 10 additions & 0 deletions testing/tests/ui/union.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use rinja::Template;

#[derive(Template)]
#[template(source = "a={{ a }} b={{ b }}", ext = "html")]
union Tmpl {
a: i32,
b: u32,
}

fn main() {}
5 changes: 5 additions & 0 deletions testing/tests/ui/union.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
error: rinja templates are not supported for `union` types, only `struct` and `enum`
--> tests/ui/union.rs:5:1
|
5 | union Tmpl {
| ^^^^^