From 85b65fc0d3c5e6ceca3f79b24f6e8f3c83a3f136 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Mon, 26 Sep 2016 10:59:41 +0200 Subject: [PATCH] Don't crash when #[dom_struct] is applied on an empty struct --- components/plugins/reflector.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/components/plugins/reflector.rs b/components/plugins/reflector.rs index 04e22fa826c..27f8054fd54 100644 --- a/components/plugins/reflector.rs +++ b/components/plugins/reflector.rs @@ -12,6 +12,11 @@ pub fn expand_reflector(cx: &mut ExtCtxt, span: Span, _: &MetaItem, annotatable: push: &mut FnMut(Annotatable)) { if let &Annotatable::Item(ref item) = annotatable { if let ItemKind::Struct(ref def, _) = item.node { + if def.fields().is_empty() { + cx.span_err(span, "#[dom_struct] should have a reflector or \ + parent dom struct as its first field"); + return; + } let struct_name = item.ident; // This path has to be hardcoded, unfortunately, since we can't resolve paths at expansion time match def.fields().iter().find(