File tree Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change 1+ #![ feature( untagged_unions) ]
2+
3+ union Test {
4+ a : A , //~ ERROR unions may not contain fields that need dropping
5+ b : B
6+ }
7+
8+ #[ derive( Debug ) ]
9+ struct A ( i32 ) ;
10+ impl Drop for A {
11+ fn drop ( & mut self ) { println ! ( "A" ) ; }
12+ }
13+
14+ #[ derive( Debug ) ]
15+ struct B ( f32 ) ;
16+ impl Drop for B {
17+ fn drop ( & mut self ) { println ! ( "B" ) ; }
18+ }
19+
20+ fn main ( ) {
21+ let mut test = Test { a : A ( 3 ) } ;
22+ println ! ( "{:?}" , unsafe { test. b } ) ;
23+ unsafe { test. b = B ( 0.5 ) ; }
24+ }
Original file line number Diff line number Diff line change 1+ error[E0740]: unions may not contain fields that need dropping
2+ --> $DIR/issue-41073.rs:4:5
3+ |
4+ LL | a: A,
5+ | ^^^^
6+ |
7+ note: `std::mem::ManuallyDrop` can be used to wrap the type
8+ --> $DIR/issue-41073.rs:4:5
9+ |
10+ LL | a: A,
11+ | ^^^^
12+
13+ error: aborting due to previous error
14+
15+ For more information about this error, try `rustc --explain E0740`.
You can’t perform that action at this time.
0 commit comments