Skip to content

Commit a878f35

Browse files
committed
don't ICE when FRU is used on an enum variant
Fixes #26948.
1 parent 9ff2d19 commit a878f35

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

src/librustc_typeck/check/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3426,6 +3426,11 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
34263426
let def = lookup_full_def(tcx, path.span, id);
34273427
let struct_id = match def {
34283428
def::DefVariant(enum_id, variant_id, true) => {
3429+
if let &Some(ref base_expr) = base_expr {
3430+
span_err!(tcx.sess, base_expr.span, E0401,
3431+
"functional record update syntax requires a struct");
3432+
fcx.write_error(base_expr.id);
3433+
}
34293434
check_struct_enum_variant(fcx, id, expr.span, enum_id,
34303435
variant_id, &fields[..]);
34313436
enum_id

src/librustc_typeck/diagnostics.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2209,6 +2209,7 @@ register_diagnostics! {
22092209
E0392, // parameter `{}` is never used
22102210
E0393, // the type parameter `{}` must be explicitly specified in an object
22112211
// type because its default value `{}` references the type `Self`"
2212-
E0399 // trait items need to be implemented because the associated
2212+
E0399, // trait items need to be implemented because the associated
22132213
// type `{}` was overridden
2214+
E0401 // functional record update requires a struct
22142215
}

src/test/compile-fail/issue-26948.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn main() {
12+
enum Foo { A { x: u32 } }
13+
let orig = Foo::A { x: 5 };
14+
Foo::A { x: 6, ..orig };
15+
//~^ ERROR functional record update syntax requires a struct
16+
}

0 commit comments

Comments
 (0)