2 #![allow(non_upper_case_globals)]
4 // ignore-pretty issue #37201
6 // This test is ensuring that parameters are indeed dropped after
7 // temporaries in a fn body.
9 use std::cell::RefCell;
14 let log = RefCell::new(vec![]);
15 d::println("created empty log");
18 assert_eq!(&log.borrow()[..],
21 // +-- Make D(da_0, 0)
22 // | +-- Make D(de_1, 1)
25 // | | +-- Make D(de_2, 2)
26 // | | | +-- Make D(da_1, 3)
27 // | | | | +-- Make D(de_3, 4)
28 // | | | | | +-- Make D(de_4, 5)
29 3, // | | | +-- Drop D(da_1, 3)
31 4, // | | | +-- Drop D(de_3, 4)
33 // | | | | eval tail of foo
34 // | | | +-- Make D(de_5, 6)
35 // | | | | +-- Make D(de_6, 7)
36 5, // | | | | | +-- Drop D(de_4, 5)
38 2, // | | +-- Drop D(de_2, 2)
40 6, // | | +-- Drop D(de_5, 6)
42 1, // | +-- Drop D(de_1, 1)
44 0, // +-- Drop D(da_0, 0)
46 // | result D(de_6, 7)
47 7 // +-- Drop D(de_6, 7)
52 fn test<'a>(log: d::Log<'a>) {
53 let da = D::new("da", 0, log);
54 let de = D::new("de", 1, log);
55 d::println("calling foo");
56 let result = foo(da, de);
57 d::println(&format!("result {}", result));
60 fn foo<'a>(da0: D<'a>, de1: D<'a>) -> D<'a> {
61 d::println("entered foo");
62 let de2 = de1.incr(); // creates D(de_2, 2)
64 let _da1 = da0.incr(); // creates D(da_1, 3)
65 de2.incr().incr() // creates D(de_3, 4) and D(de_4, 5)
67 d::println("eval tail of foo");
68 de4.incr().incr() // creates D(de_5, 6) and D(de_6, 7)
71 // This module provides simultaneous printouts of the dynamic extents
72 // of all of the D values, in addition to logging the order that each
75 const PREF_INDENT: u32 = 16;
78 #![allow(unused_parens)]
81 use std::cell::RefCell;
83 static mut counter: u32 = 0;
84 static mut trails: u64 = 0;
86 pub type Log<'a> = &'a RefCell<Vec<u32>>;
88 pub fn current_width() -> u32 {
89 unsafe { max_width() - trails.leading_zeros() }
92 pub fn max_width() -> u32 {
94 (mem::size_of_val(&trails)*8) as u32
98 pub fn indent_println(my_trails: u32, s: &str) {
99 let mut indent: String = String::new();
100 for i in 0..my_trails {
102 if trails & (1 << i) != 0 {
103 indent = indent + "| ";
105 indent = indent + " ";
109 println!("{}{}", indent, s);
112 pub fn println(s: &str) {
113 indent_println(super::PREF_INDENT, s);
116 fn first_avail() -> u32 {
119 if trails & (1 << i) == 0 {
124 panic!("exhausted trails");
128 name: &'static str, i: u32, uid: u32, trail: u32, log: Log<'a>
131 impl<'a> fmt::Display for D<'a> {
132 fn fmt(&self, w: &mut fmt::Formatter) -> fmt::Result {
133 write!(w, "D({}_{}, {})", self.name, self.i, self.uid)
138 pub fn new(name: &'static str, i: u32, log: Log<'a>) -> D<'a> {
140 let trail = first_avail();
143 trails |= (1 << trail);
145 name: name, i: i, log: log, uid: ctr, trail: trail
147 indent_println(trail, &format!("+-- Make {}", ret));
151 pub fn incr(&self) -> D<'a> {
152 D::new(self.name, self.i + 1, self.log)
156 impl<'a> Drop for D<'a> {
158 unsafe { trails &= !(1 << self.trail); };
159 self.log.borrow_mut().push(self.uid);
160 indent_println(self.trail, &format!("+-- Drop {}", self));
161 indent_println(::PREF_INDENT, "");