From 589d994c38dc634545b4e08030bbb86a1558aa40 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 16 Aug 2017 13:32:41 +0200 Subject: [PATCH] udpdate error message for unsized union field --- src/librustc/traits/error_reporting.rs | 3 ++- src/test/ui/union-sized-field.rs | 17 +++++++++++++++++ src/test/ui/union-sized-field.stderr | 12 ++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/union-sized-field.rs create mode 100644 src/test/ui/union-sized-field.stderr diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index c04d448716c..c1a443a5322 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -1112,7 +1112,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { err.note("structs must have a statically known size to be initialized"); } ObligationCauseCode::FieldSized => { - err.note("only the last field of a struct may have a dynamically sized type"); + err.note("only the last field of a struct or an union may have a dynamically \ + sized type"); } ObligationCauseCode::ConstSized => { err.note("constant expressions must have a statically known size"); diff --git a/src/test/ui/union-sized-field.rs b/src/test/ui/union-sized-field.rs new file mode 100644 index 00000000000..9a237f0fd16 --- /dev/null +++ b/src/test/ui/union-sized-field.rs @@ -0,0 +1,17 @@ +// Copyright 2017 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(untagged_unions)] + +union Foo { + value: T, +} + +fn main() {} diff --git a/src/test/ui/union-sized-field.stderr b/src/test/ui/union-sized-field.stderr new file mode 100644 index 00000000000..4dd8befd2cb --- /dev/null +++ b/src/test/ui/union-sized-field.stderr @@ -0,0 +1,12 @@ +error[E0277]: the trait bound `T: std::marker::Sized` is not satisfied + --> $DIR/union-sized-field.rs:14:5 + | +14 | value: T, + | ^^^^^^^^ `T` does not have a constant size known at compile-time + | + = help: the trait `std::marker::Sized` is not implemented for `T` + = help: consider adding a `where T: std::marker::Sized` bound + = note: only the last field of a struct or an union may have a dynamically sized type + +error: aborting due to previous error +