From 316b28600d8af30b8af5d552b5f3b466a0ad7c22 Mon Sep 17 00:00:00 2001
From: Dirkjan Ochtman <dirkjan@ochtman.nl>
Date: Sat, 16 Jun 2018 14:06:50 +0200
Subject: Restrict use of macro/import/extend nodes to the top level

---
 askama_derive/src/generator.rs | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

(limited to 'askama_derive')

diff --git a/askama_derive/src/generator.rs b/askama_derive/src/generator.rs
index 0d3dd5f..a6e74bc 100644
--- a/askama_derive/src/generator.rs
+++ b/askama_derive/src/generator.rs
@@ -358,20 +358,20 @@ impl<'a> Generator<'a> {
                     self.write_call(state, ws, scope, name, args);
                 },
                 Node::Macro(_, ref m) => {
-                    if let AstLevel::Nested = level {
+                    if level != AstLevel::Top {
                         panic!("macro blocks only allowed at the top level");
                     }
                     self.flush_ws(&m.ws1);
                     self.prepare_ws(&m.ws2);
                 },
                 Node::Import(ref ws, _, _) => {
-                    if let AstLevel::Nested = level {
+                    if level != AstLevel::Top {
                         panic!("import blocks only allowed at the top level");
                     }
                     self.handle_ws(ws);
                 },
                 Node::Extends(_) => {
-                    if let AstLevel::Nested = level {
+                    if level != AstLevel::Top {
                         panic!("extend blocks only allowed at the top level");
                     }
                     // No whitespace handling: child template top-level is not used,
@@ -974,7 +974,7 @@ fn get_parent_type(ast: &syn::DeriveInput) -> Option<&syn::Type> {
     }.next()
 }
 
-#[derive(Clone)]
+#[derive(Clone, PartialEq)]
 enum AstLevel {
     Top,
     Block,
-- 
cgit