Skip to content

Commit 8e7786a

Browse files
committed
Add run-pass test for reinitialized unions.
This commit adds a run-pass test for the subset of `src/test/ui/borrowck/borrowck-union-move-assign.rs` that is intended to pass as the union is reinitialized.
1 parent a4e0945 commit 8e7786a

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

Diff for: src/test/ui/nll/issue-55651.rs

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright 2016 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+
// compile-pass
12+
13+
#![feature(untagged_unions)]
14+
15+
struct A;
16+
struct B;
17+
18+
union U {
19+
a: A,
20+
b: B,
21+
}
22+
23+
fn main() {
24+
unsafe {
25+
{
26+
let mut u = U { a: A };
27+
let a = u.a;
28+
u.a = A;
29+
let a = u.a; // OK
30+
}
31+
{
32+
let mut u = U { a: A };
33+
let a = u.a;
34+
u.b = B;
35+
let a = u.a; // OK
36+
}
37+
}
38+
}

0 commit comments

Comments
 (0)