]> git.lizzy.rs Git - rust.git/commitdiff
udpdate error message for unsized union field
authorGuillaume Gomez <guillaume1.gomez@gmail.com>
Wed, 16 Aug 2017 11:32:41 +0000 (13:32 +0200)
committerGuillaume Gomez <guillaume1.gomez@gmail.com>
Wed, 16 Aug 2017 11:32:41 +0000 (13:32 +0200)
src/librustc/traits/error_reporting.rs
src/test/ui/union-sized-field.rs [new file with mode: 0644]
src/test/ui/union-sized-field.stderr [new file with mode: 0644]

index c04d448716c5bf205419843eaa71f05ab9e175b7..c1a443a532200801f2886266ed8cdbcf06401b3f 100644 (file)
@@ -1112,7 +1112,8 @@ fn note_obligation_cause_code<T>(&self,
                 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 (file)
index 0000000..9a237f0
--- /dev/null
@@ -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 <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.
+
+#![feature(untagged_unions)]
+
+union Foo<T: ?Sized> {
+    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 (file)
index 0000000..4dd8bef
--- /dev/null
@@ -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
+