]> git.lizzy.rs Git - rust.git/blob - src/test/ui/issues/issue-18937.rs
Auto merge of #54624 - arielb1:evaluate-outlives, r=nikomatsakis
[rust.git] / src / test / ui / issues / issue-18937.rs
1 // Copyright 2016 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.
4 //
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.
10
11 // Regression test for #18937.
12
13 use std::fmt;
14
15 #[derive(Debug)]
16 struct MyString<'a>(&'a String);
17
18 struct B {
19     list: Vec<Box<fmt::Debug>>,
20 }
21
22 trait A<'a> {
23     fn foo<F>(&mut self, f: F)
24         where F: fmt::Debug + 'a,
25               Self: Sized;
26 }
27
28 impl<'a> A<'a> for B {
29     fn foo<F>(&mut self, f: F) //~ ERROR impl has stricter
30         where F: fmt::Debug + 'static,
31     {
32         self.list.push(Box::new(f));
33     }
34 }
35
36 fn main() {
37     let mut b = B { list: Vec::new() };
38
39     // Create a borrowed pointer, put it in `b`, then drop what's borrowing it
40     let a = "hello".to_string();
41     b.foo(MyString(&a));
42
43     // Drop the data which `b` has a reference to
44     drop(a);
45
46     // Use the data, probably segfaulting
47     for b in b.list.iter() {
48         println!("{:?}", b);
49     }
50 }