]>
git.proxmox.com Git - rustc.git/blob - src/test/ui/span/issue28498-reject-passed-to-fn.rs
1 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 // Demonstrate that a type param in negative position causes dropck to reject code
12 // that might indirectly access previously dropped value.
14 // Compare with run-pass/issue28498-ugeh-with-passed-to-fn.rs
17 struct ScribbleOnDrop(String
);
19 impl Drop
for ScribbleOnDrop
{
21 self.0 = format
!("DROPPED");
25 struct Foo
<T
>(u32, T
, Box
<for <'r
> fn(&'r T
) -> String
>);
27 impl<T
> Drop
for Foo
<T
> {
29 // Use of `unsafe_destructor_blind_to_params` is unsound,
30 // because we pass `T` to the callback in `self.2`
31 // below, and thus potentially read from borrowed data.
32 println
!("Dropping Foo({}, {})", self.0, (self.2)(&self.1));
36 fn callback(s
: & &ScribbleOnDrop
) -> String { format!("{:?}
", s) }
39 let (last_dropped, foo0);
40 let (foo1, first_dropped);
42 last_dropped = ScribbleOnDrop(format!("last
"));
43 first_dropped = ScribbleOnDrop(format!("first
"));
44 foo0 = Foo(0, &last_dropped, Box::new(callback));
45 //~^ ERROR `last_dropped` does not live long enough
46 foo1 = Foo(1, &first_dropped, Box::new(callback));
47 //~^ ERROR `first_dropped` does not live long enough
49 println!("foo0
.1
: {:?} foo1
.1
: {:?}
", foo0.1, foo1.1);