Skip to content

Commit 589d994

Browse files
udpdate error message for unsized union field
1 parent 4fc3765 commit 589d994

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

src/librustc/traits/error_reporting.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1112,7 +1112,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
11121112
err.note("structs must have a statically known size to be initialized");
11131113
}
11141114
ObligationCauseCode::FieldSized => {
1115-
err.note("only the last field of a struct may have a dynamically sized type");
1115+
err.note("only the last field of a struct or an union may have a dynamically \
1116+
sized type");
11161117
}
11171118
ObligationCauseCode::ConstSized => {
11181119
err.note("constant expressions must have a statically known size");

src/test/ui/union-sized-field.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2017 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+
#![feature(untagged_unions)]
12+
13+
union Foo<T: ?Sized> {
14+
value: T,
15+
}
16+
17+
fn main() {}

src/test/ui/union-sized-field.stderr

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0277]: the trait bound `T: std::marker::Sized` is not satisfied
2+
--> $DIR/union-sized-field.rs:14:5
3+
|
4+
14 | value: T,
5+
| ^^^^^^^^ `T` does not have a constant size known at compile-time
6+
|
7+
= help: the trait `std::marker::Sized` is not implemented for `T`
8+
= help: consider adding a `where T: std::marker::Sized` bound
9+
= note: only the last field of a struct or an union may have a dynamically sized type
10+
11+
error: aborting due to previous error
12+

0 commit comments

Comments
 (0)