Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
introduce fn-ctxt so we can invoke regionck code
- Loading branch information
1 parent
ac968c4
commit f3cc374
Showing
3 changed files
with
91 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use std::fmt; | ||
|
||
#[derive(Debug)] | ||
struct MyString<'a>(&'a String); | ||
|
||
struct B { | ||
list: Vec<Box<fmt::Debug>>, | ||
} | ||
|
||
trait A<'a> { | ||
fn foo<F>(&mut self, f: F) | ||
where F: fmt::Debug + 'a, | ||
Self: Sized; | ||
} | ||
|
||
impl<'a> A<'a> for B { | ||
fn foo<F>(&mut self, f: F) //~ ERROR parameter type `F` may not live long enough | ||
where F: fmt::Debug + 'static, | ||
{ | ||
self.list.push(Box::new(f)); | ||
} | ||
} | ||
|
||
fn main() { | ||
let mut b = B { list: Vec::new() }; | ||
|
||
// Create a borrowed pointer, put it in `b`, then drop what's borrowing it | ||
let a = "hello".to_string(); | ||
b.foo(MyString(&a)); | ||
|
||
// Drop the data which `b` has a reference to | ||
drop(a); | ||
|
||
// Use the data, probably segfaulting | ||
for b in b.list.iter() { | ||
println!("{:?}", b); | ||
} | ||
} |