forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #149 from jacob-hughes/fsa_unions
Emit FSA error for unions with manually drop fields
- Loading branch information
Showing
3 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#![feature(gc)] | ||
#![feature(negative_impls)] | ||
#![feature(rustc_private)] | ||
#![allow(dead_code)] | ||
#![allow(unused_variables)] | ||
|
||
use std::gc::Gc; | ||
use std::mem::ManuallyDrop; | ||
|
||
struct S(u8); | ||
struct T(u8); | ||
|
||
impl Drop for S { | ||
fn drop(&mut self) { | ||
} | ||
} | ||
|
||
|
||
impl Drop for T { | ||
fn drop(&mut self) { | ||
} | ||
} | ||
|
||
union U { | ||
a: ManuallyDrop<S>, | ||
b: ManuallyDrop<T>, | ||
} | ||
|
||
impl Drop for U { | ||
fn drop(&mut self) { | ||
let x = unsafe { &self.a }; | ||
} | ||
} | ||
|
||
impl !Send for U {} | ||
impl !Send for S {} | ||
impl !Send for T {} | ||
|
||
fn main() { | ||
let u = U { a: ManuallyDrop::new(S(1)) }; | ||
Gc::new(u); | ||
//~^ ERROR: The drop method for `U` cannot be safely finalized. | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
error: The drop method for `U` cannot be safely finalized. | ||
--> $DIR/unions.rs:41:13 | ||
| | ||
LL | Gc::new(u); | ||
| --------^- | ||
| | | | ||
| | contains a union whose drop glue cannot be known at compile-time. | ||
| caused by trying to construct a `Gc<U>` here. | ||
|
||
error: aborting due to 1 previous error | ||
|