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 #134 from jacob-hughes/fsa_early_exit
Less granular FSA errors for standard library types
- Loading branch information
Showing
2 changed files
with
101 additions
and
35 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,40 @@ | ||
#![feature(gc)] | ||
#![feature(negative_impls)] | ||
|
||
use std::gc::Gc; | ||
use std::rc::Rc; | ||
|
||
// S is FSA-safe but the inner RC is not. | ||
#[derive(Clone)] | ||
struct S(Rc<u8>); | ||
|
||
struct Unsafe(u8); | ||
impl !FinalizerSafe for Unsafe {} | ||
|
||
// Make sure that FSA still reports an error for the `Unsafe` field. | ||
struct T(S, Unsafe); | ||
|
||
// This should only give a single `Rc` FSA error. | ||
struct U(Rc<Rc<Rc<u8>>>); | ||
|
||
impl Drop for T { | ||
fn drop(&mut self) { | ||
println!("Boom {}", self.1.0); // deref `Unsafe` | ||
} | ||
} | ||
|
||
fn main() { | ||
let s = S(Rc::new(1)); | ||
let t = T(s.clone(), Unsafe(1)); | ||
let u = U(Rc::new(Rc::new(Rc::new(1)))); | ||
|
||
Gc::new(s); | ||
//~^ ERROR: `s` has a drop method which cannot be safely finalized. | ||
|
||
Gc::new(t); | ||
//~^ ERROR: `t` has a drop method which cannot be safely finalized. | ||
//~^^ ERROR: `t` has a drop method which cannot be safely finalized. | ||
|
||
Gc::new(u); | ||
//~^ ERROR: `u` has a drop method which cannot be safely finalized. | ||
} |