]> git.lizzy.rs Git - rust.git/blob - src/test/compile-fail/issue-18937.rs
Rollup merge of #37622 - ollie27:cstring, r=alexcrichton
[rust.git] / src / test / compile-fail / 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 #![deny(extra_requirement_in_impl)]
14
15 use std::fmt;
16
17 #[derive(Debug)]
18 struct MyString<'a>(&'a String);
19
20 struct B {
21     list: Vec<Box<fmt::Debug>>,
22 }
23
24 trait A<'a> {
25     fn foo<F>(&mut self, f: F)
26         where F: fmt::Debug + 'a,
27               Self: Sized;
28 }
29
30 impl<'a> A<'a> for B {
31     fn foo<F>(&mut self, f: F) //~ ERROR E0276
32         //~^ WARNING future release
33         where F: fmt::Debug + 'static,
34     {
35         self.list.push(Box::new(f));
36     }
37 }
38
39 fn main() {
40     let mut b = B { list: Vec::new() };
41
42     // Create a borrowed pointer, put it in `b`, then drop what's borrowing it
43     let a = "hello".to_string();
44     b.foo(MyString(&a));
45
46     // Drop the data which `b` has a reference to
47     drop(a);
48
49     // Use the data, probably segfaulting
50     for b in b.list.iter() {
51         println!("{:?}", b);
52     }
53 }