-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8fcd4dd
commit e2bb040
Showing
7 changed files
with
61 additions
and
4 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
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,46 @@ | ||
//@ run-pass | ||
//@ check-run-results | ||
|
||
use std::any::Any; | ||
|
||
fn yeet_principal(x: Box<dyn Any + Send>) -> Box<dyn Send> { | ||
x | ||
} | ||
|
||
trait Bar: Send {} | ||
|
||
impl<T: Send> Bar for T {} | ||
|
||
fn yeet_principal_2(x: Box<dyn Bar>) -> Box<dyn Send> { | ||
x | ||
} | ||
|
||
struct CallMe<F: FnOnce()>(Option<F>); | ||
|
||
impl<F: FnOnce()> CallMe<F> { | ||
fn new(f: F) -> Self { | ||
CallMe(Some(f)) | ||
} | ||
} | ||
|
||
impl<F: FnOnce()> Drop for CallMe<F> { | ||
fn drop(&mut self) { | ||
(self.0.take().unwrap())(); | ||
} | ||
} | ||
|
||
fn goodbye() { | ||
println!("goodbye"); | ||
} | ||
|
||
fn main() { | ||
let x = Box::new(CallMe::new(goodbye)) as Box<dyn Any + Send>; | ||
let y = yeet_principal(x); | ||
println!("before"); | ||
drop(y); | ||
|
||
let x = Box::new(CallMe::new(goodbye)) as Box<dyn Bar>; | ||
let y = yeet_principal_2(x); | ||
println!("before"); | ||
drop(y); | ||
} |
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,4 @@ | ||
before | ||
goodbye | ||
before | ||
goodbye |