]> git.proxmox.com Git - rustc.git/blame - src/test/ui/functions-closures/implied-bounds-closure-arg-outlives.rs
Update unsuspicious file list
[rustc.git] / src / test / ui / functions-closures / implied-bounds-closure-arg-outlives.rs
CommitLineData
b7449926 1// run-pass
abe05a73
XL
2// Test that we are able to handle the relationships between free
3// regions bound in a closure callback.
4
5#[derive(Copy, Clone)]
6struct MyCx<'short, 'long: 'short> {
7 short: &'short u32,
8 long: &'long u32,
9}
10
11impl<'short, 'long> MyCx<'short, 'long> {
12 fn short(self) -> &'short u32 { self.short }
13 fn long(self) -> &'long u32 { self.long }
14 fn set_short(&mut self, v: &'short u32) { self.short = v; }
15}
16
17fn with<F, R>(op: F) -> R
18where
19 F: for<'short, 'long> FnOnce(MyCx<'short, 'long>) -> R,
20{
21 op(MyCx {
22 short: &22,
23 long: &22,
24 })
25}
26
27fn main() {
28 with(|mut cx| {
29 // For this to type-check, we need to be able to deduce that
30 // the lifetime of `l` can be `'short`, even though it has
31 // input from `'long`.
32 let l = if true { cx.long() } else { cx.short() };
33 cx.set_short(l);
34 });
35}