diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index fafdf161b2d..9435f96c08a 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -858,8 +858,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { trait_name)); } ObligationCauseCode::FieldSized => { - err.note("only the last field of a struct or enum variant \ - may have a dynamically sized type"); + err.note("only the last field of a struct may have a dynamically sized type"); } ObligationCauseCode::ConstSized => { err.note("constant expressions must have a statically known size"); diff --git a/src/librustc_typeck/check/wfcheck.rs b/src/librustc_typeck/check/wfcheck.rs index bc5cb68995b..e3634cfe5f5 100644 --- a/src/librustc_typeck/check/wfcheck.rs +++ b/src/librustc_typeck/check/wfcheck.rs @@ -150,7 +150,7 @@ impl<'ccx, 'gcx> CheckTypeWellFormedVisitor<'ccx, 'gcx> { self.check_variances_for_type_defn(item, ast_generics); } hir::ItemEnum(ref enum_def, ref ast_generics) => { - self.check_type_defn(item, false, |fcx| { + self.check_type_defn(item, true, |fcx| { fcx.enum_variants(enum_def) }); diff --git a/src/test/compile-fail/issue-17025.rs b/src/test/compile-fail/issue-17025.rs index 2a1a3397d54..f250103b144 100644 --- a/src/test/compile-fail/issue-17025.rs +++ b/src/test/compile-fail/issue-17025.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// ignore-test the unsized enum no longer compiles + enum A { B(char), C([Box]), diff --git a/src/test/compile-fail/issue-5883.rs b/src/test/compile-fail/issue-5883.rs index 019a7bdc734..e14d9f3a35c 100644 --- a/src/test/compile-fail/issue-5883.rs +++ b/src/test/compile-fail/issue-5883.rs @@ -20,6 +20,4 @@ fn new_struct(r: A+'static) Struct { r: r } } -trait Curve {} -enum E {X(Curve+'static)} fn main() {} diff --git a/src/test/compile-fail/unsized-enum.rs b/src/test/compile-fail/unsized-enum.rs index 61b2b01b355..5d791215f36 100644 --- a/src/test/compile-fail/unsized-enum.rs +++ b/src/test/compile-fail/unsized-enum.rs @@ -19,11 +19,4 @@ fn foo2() { not_sized::>() } // // Not OK: `T` is not sized. -enum Bar { BarSome(U), BarNone } -fn bar1() { not_sized::>() } -fn bar2() { is_sized::>() } -//~^ ERROR `T: std::marker::Sized` is not satisfied -// -// Not OK: `Bar` is not sized, but it should be. - fn main() { } diff --git a/src/test/compile-fail/unsized-enum2.rs b/src/test/compile-fail/unsized-enum2.rs new file mode 100644 index 00000000000..95fc3243fbe --- /dev/null +++ b/src/test/compile-fail/unsized-enum2.rs @@ -0,0 +1,68 @@ +// Copyright 206 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. + +use std::ops::Deref; + +// Due to aggressive error message deduplication, we require 20 *different* +// unsized types (even Path and [u8] are considered the "same"). + +trait Foo {} +trait Bar {} +trait FooBar {} +trait BarFoo {} + +trait PathHelper1 {} +trait PathHelper2 {} +trait PathHelper3 {} +trait PathHelper4 {} + +struct Path1(PathHelper1); +struct Path2(PathHelper2); +struct Path3(PathHelper3); +struct Path4(PathHelper4); + +enum E { + // parameter + VA(W), //~ ERROR `W: std::marker::Sized` is not satisfied + VB{x: X}, //~ ERROR `X: std::marker::Sized` is not satisfied + VC(isize, Y), //~ ERROR `Y: std::marker::Sized` is not satisfied + VD{u: isize, x: Z}, //~ ERROR `Z: std::marker::Sized` is not satisfied + + // slice / str + VE([u8]), //~ ERROR `[u8]: std::marker::Sized` is not satisfied + VF{x: str}, //~ ERROR `str: std::marker::Sized` is not satisfied + VG(isize, [f32]), //~ ERROR `[f32]: std::marker::Sized` is not satisfied + VH{u: isize, x: [u32]}, //~ ERROR `[u32]: std::marker::Sized` is not satisfied + + // unsized struct + VI(Path1), //~ ERROR `PathHelper1 + 'static: std::marker::Sized` is not satisfied + VJ{x: Path2}, //~ ERROR `PathHelper2 + 'static: std::marker::Sized` is not satisfied + VK(isize, Path3), //~ ERROR `PathHelper3 + 'static: std::marker::Sized` is not satisfied + VL{u: isize, x: Path4}, //~ ERROR `PathHelper4 + 'static: std::marker::Sized` is not satisfied + + // plain trait + VM(Foo), //~ ERROR `Foo + 'static: std::marker::Sized` is not satisfied + VN{x: Bar}, //~ ERROR `Bar + 'static: std::marker::Sized` is not satisfied + VO(isize, FooBar), //~ ERROR `FooBar + 'static: std::marker::Sized` is not satisfied + VP{u: isize, x: BarFoo}, //~ ERROR `BarFoo + 'static: std::marker::Sized` is not satisfied + + // projected + VQ(<&'static [i8] as Deref>::Target), //~ ERROR `[i8]: std::marker::Sized` is not satisfied + VR{x: <&'static [char] as Deref>::Target}, + //~^ ERROR `[char]: std::marker::Sized` is not satisfied + VS(isize, <&'static [f64] as Deref>::Target), + //~^ ERROR `[f64]: std::marker::Sized` is not satisfied + VT{u: isize, x: <&'static [i32] as Deref>::Target}, + //~^ ERROR `[i32]: std::marker::Sized` is not satisfied +} + + +fn main() { } + diff --git a/src/test/compile-fail/unsized3.rs b/src/test/compile-fail/unsized3.rs index f88165c02e9..9b6ccf22c8d 100644 --- a/src/test/compile-fail/unsized3.rs +++ b/src/test/compile-fail/unsized3.rs @@ -31,19 +31,8 @@ fn f3(x: &X) { fn f4(x: &X) { } -// Test with unsized enum. -enum E { - V(X), -} - fn f5(x: &Y) {} fn f6(x: &X) {} -fn f7(x1: &E, x2: &E) { - f5(x1); - //~^ ERROR `X: std::marker::Sized` is not satisfied - f6(x2); // ok -} - // Test with unsized struct. struct S { @@ -57,13 +46,13 @@ fn f8(x1: &S, x2: &S) { } // Test some tuples. -fn f9(x1: Box>, x2: Box>) { +fn f9(x1: Box>) { f5(&(*x1, 34)); //~^ ERROR `X: std::marker::Sized` is not satisfied } -fn f10(x1: Box>, x2: Box>) { - f5(&(32, *x2)); +fn f10(x1: Box>) { + f5(&(32, *x1)); //~^ ERROR `X: std::marker::Sized` is not satisfied } diff --git a/src/test/run-pass/unsized2.rs b/src/test/run-pass/unsized2.rs index 5b9fa5230d1..50d8d3d27f2 100644 --- a/src/test/run-pass/unsized2.rs +++ b/src/test/run-pass/unsized2.rs @@ -89,7 +89,7 @@ trait T7 { fn m2(&self, x: &T5); } -// The last field in a struct or variant may be unsized +// The last field in a struct may be unsized struct S2 { f: X, } @@ -97,12 +97,6 @@ struct S3 { f1: isize, f2: X, } -enum E { - V1(X), - V2{x: X}, - V3(isize, X), - V4{u: isize, x: X}, -} pub fn main() { }