]> git.proxmox.com Git - rustc.git/blob - tests/ui/typeck/issue-18937.rs
New upstream version 1.68.2+dfsg1
[rustc.git] / tests / ui / typeck / issue-18937.rs
1 // Regression test for #18937.
2
3 use std::fmt;
4
5 #[derive(Debug)]
6 struct MyString<'a>(&'a String);
7
8 struct B {
9 list: Vec<Box<dyn fmt::Debug>>,
10 }
11
12 trait A<'a> {
13 fn foo<F>(&mut self, f: F)
14 where F: fmt::Debug + 'a,
15 Self: Sized;
16 }
17
18 impl<'a> A<'a> for B {
19 fn foo<F>(&mut self, f: F)
20 where F: fmt::Debug + 'static, //~ ERROR impl has stricter
21 {
22 self.list.push(Box::new(f));
23 }
24 }
25
26 fn main() {
27 let mut b = B { list: Vec::new() };
28
29 // Create a borrowed pointer, put it in `b`, then drop what's borrowing it
30 let a = "hello".to_string();
31 b.foo(MyString(&a));
32
33 // Drop the data which `b` has a reference to
34 drop(a);
35
36 // Use the data, probably segfaulting
37 for b in b.list.iter() {
38 println!("{:?}", b);
39 }
40 }