servo: Merge #13425 - Don't crash when #[dom_struct] is applied on an empty struct (from Manishearth:no-crash-empty-dom); r=emilio,Ms2ger
authorManish Goregaokar <manishsmail@gmail.com>
Tue, 27 Sep 2016 06:04:57 -0500
changeset 339759 e52df73087c8c1e924f4ae87768464f516febaa3
parent 339758 8d0273e26608bdcb61b0cdb86d75b22daf9f087a
child 339760 5d11cf9f0e2a96d17da7fc7cc26ac71110ce5b62
push id31307
push usergszorc@mozilla.com
push dateSat, 04 Feb 2017 00:59:06 +0000
treeherdermozilla-central@94079d43835f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersemilio, Ms2ger
servo: Merge #13425 - Don't crash when #[dom_struct] is applied on an empty struct (from Manishearth:no-crash-empty-dom); r=emilio,Ms2ger Source-Repo: https://github.com/servo/servo Source-Revision: 1ed3521dcfdf573dd68afe18148e785a8af2389a
servo/components/plugins/reflector.rs
--- a/servo/components/plugins/reflector.rs
+++ b/servo/components/plugins/reflector.rs
@@ -7,16 +7,21 @@ use syntax::codemap::Span;
 use syntax::ext::base::{Annotatable, ExtCtxt};
 use utils::match_ty_unwrap;
 
 
 pub fn expand_reflector(cx: &mut ExtCtxt, span: Span, _: &MetaItem, annotatable: &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(
                     |f| match_ty_unwrap(&*f.ty, &["dom", "bindings", "reflector", "Reflector"]).is_some()) {
                 // If it has a field that is a Reflector, use that
                 Some(f) => {
                     let field_name = f.ident;
                     let impl_item = quote_item!(cx,