]> git.lizzy.rs Git - rust.git/commitdiff
don't ICE when FRU is used on an enum variant
authorAriel Ben-Yehuda <ariel.byd@gmail.com>
Mon, 13 Jul 2015 18:04:00 +0000 (21:04 +0300)
committerAriel Ben-Yehuda <ariel.byd@gmail.com>
Tue, 14 Jul 2015 15:58:18 +0000 (18:58 +0300)
Fixes #26948.

src/librustc_typeck/check/mod.rs
src/librustc_typeck/diagnostics.rs
src/test/compile-fail/issue-26948.rs [new file with mode: 0644]

index 5a71d1ed0b5bd0fa8d0cb30aaa1b4be563882847..a2fee091689416cf5b239c959cdda9c8645e73d9 100644 (file)
@@ -3426,6 +3426,11 @@ fn check_struct_fields_on_error<'a,'tcx>(fcx: &FnCtxt<'a,'tcx>,
         let def = lookup_full_def(tcx, path.span, id);
         let struct_id = match def {
             def::DefVariant(enum_id, variant_id, true) => {
+                if let &Some(ref base_expr) = base_expr {
+                    span_err!(tcx.sess, base_expr.span, E0401,
+                              "functional record update syntax requires a struct");
+                    fcx.write_error(base_expr.id);
+                }
                 check_struct_enum_variant(fcx, id, expr.span, enum_id,
                                           variant_id, &fields[..]);
                 enum_id
index 5027be5fb62a32523c6d51b306f4219704932683..636a8aeb544e75d595779b261d1007b254bc76fe 100644 (file)
@@ -2209,6 +2209,7 @@ impl Baz for Bar { } // Note: This is OK
     E0392, // parameter `{}` is never used
     E0393, // the type parameter `{}` must be explicitly specified in an object
            // type because its default value `{}` references the type `Self`"
-    E0399  // trait items need to be implemented because the associated
+    E0399, // trait items need to be implemented because the associated
            // type `{}` was overridden
+    E0401  // functional record update requires a struct
 }
diff --git a/src/test/compile-fail/issue-26948.rs b/src/test/compile-fail/issue-26948.rs
new file mode 100644 (file)
index 0000000..c63cb5d
--- /dev/null
@@ -0,0 +1,16 @@
+// Copyright 2015 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+fn main() {
+    enum Foo { A { x: u32 } }
+    let orig = Foo::A { x: 5 };
+    Foo::A { x: 6, ..orig };
+    //~^ ERROR functional record update syntax requires a struct
+}