]> git.lizzy.rs Git - rust.git/blob - src/test/ui/drop/dropck-eyepatch-extern-crate.rs
Apply suggestions from code review
[rust.git] / src / test / ui / drop / dropck-eyepatch-extern-crate.rs
1 // run-pass
2 // aux-build:dropck_eyepatch_extern_crate.rs
3
4 extern crate dropck_eyepatch_extern_crate as other;
5
6 use other::{Dt,Dr,Pt,Pr,St,Sr};
7
8 fn main() {
9     use std::cell::RefCell;
10
11     struct CheckOnDrop(RefCell<String>, &'static str);
12     impl Drop for CheckOnDrop {
13         fn drop(&mut self) { assert_eq!(*self.0.borrow(), self.1); }
14     }
15
16     let c_long;
17     let (c, dt, dr, pt, pr, st, sr)
18         : (CheckOnDrop, Dt<_>, Dr<_>, Pt<_, _>, Pr<_>, St<_>, Sr<_>);
19     c_long = CheckOnDrop(RefCell::new("c_long".to_string()),
20                          "c_long|pr|pt|dr|dt");
21     c = CheckOnDrop(RefCell::new("c".to_string()),
22                     "c");
23
24     // No error: sufficiently long-lived state can be referenced in dtors
25     dt = Dt("dt", &c_long.0);
26     dr = Dr("dr", &c_long.0);
27
28     // No error: Drop impl asserts .1 (A and &'a _) are not accessed
29     pt = Pt("pt", &c.0, &c_long.0);
30     pr = Pr("pr", &c.0, &c_long.0);
31
32     // No error: St and Sr have no destructor.
33     st = St("st", &c.0);
34     sr = Sr("sr", &c.0);
35
36     println!("{:?}", (dt.0, dr.0, pt.0, pr.0, st.0, sr.0));
37     assert_eq!(*c_long.0.borrow(), "c_long");
38     assert_eq!(*c.0.borrow(), "c");
39 }