From 6a73f978b0a80a6f2ae8ff9bb6442fe7a2f88c4b Mon Sep 17 00:00:00 2001 From: Yazhong Liu Date: Sat, 19 Jul 2014 00:35:13 +0800 Subject: [PATCH] rustc: fix ICE regarding struct variants in enums --- src/librustc/middle/ty.rs | 6 ++++-- .../compile-fail/struct-variant-no-fields.rs | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 src/test/compile-fail/struct-variant-no-fields.rs diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 95ec43738308e..b1bffc8899d34 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -3665,8 +3665,10 @@ impl VariantInfo { ast::StructVariantKind(ref struct_def) => { let fields: &[StructField] = struct_def.fields.as_slice(); - - assert!(fields.len() > 0); + if fields.len() == 0 { + cx.sess.span_fatal(ast_variant.span, + "struct variant must have at least one field") + } let arg_tys = ty_fn_args(ctor_ty).iter().map(|a| *a).collect(); let arg_names = fields.iter().map(|field| { diff --git a/src/test/compile-fail/struct-variant-no-fields.rs b/src/test/compile-fail/struct-variant-no-fields.rs new file mode 100644 index 0000000000000..15ff2a192db7e --- /dev/null +++ b/src/test/compile-fail/struct-variant-no-fields.rs @@ -0,0 +1,17 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(struct_variant)] + +enum Foo { + Bar { } //~ ERROR struct variant must have at least one field +} + +fn main() {} \ No newline at end of file