-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
3a85d3f
commit e3800a1
Showing
10 changed files
with
83 additions
and
35 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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,24 +1,12 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/unsized_coercion5.rs:16:32 | ||
| | ||
LL | let y: Box<dyn Send> = x as Box<dyn Trait + Send>; | ||
| ------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^ expected trait `Send`, found trait `Trait + Send` | ||
| | | ||
| expected due to this | ||
| | ||
= note: expected struct `Box<dyn Send>` | ||
found struct `Box<dyn Trait + Send>` | ||
|
||
error[E0277]: the size for values of type `impl Trait + ?Sized` cannot be known at compilation time | ||
--> $DIR/unsized_coercion5.rs:16:32 | ||
--> $DIR/unsized_coercion5.rs:17:32 | ||
| | ||
LL | let y: Box<dyn Send> = x as Box<dyn Trait + Send>; | ||
| ^ doesn't have a size known at compile-time | ||
| | ||
= help: the trait `Sized` is not implemented for `impl Trait + ?Sized` | ||
= note: required for the cast from `Box<impl Trait + ?Sized>` to `Box<dyn Trait + Send>` | ||
|
||
error: aborting due to 2 previous errors | ||
error: aborting due to 1 previous error | ||
|
||
Some errors have detailed explanations: E0277, E0308. | ||
For more information about an error, try `rustc --explain E0277`. | ||
For more information about this error, try `rustc --explain E0277`. |
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,62 @@ | ||
//@ run-pass | ||
//@ check-run-results | ||
|
||
use std::any::Any; | ||
|
||
const fn yeet_principal(x: Box<dyn Any + Send>) -> Box<dyn Send> { | ||
x | ||
} | ||
|
||
trait Bar: Send + Sync {} | ||
|
||
impl<T: Send + Sync> Bar for T {} | ||
|
||
const 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); | ||
} | ||
|
||
// Test that upcast works in `const` | ||
|
||
const fn yeet_principal_3(x: &(dyn Any + Send + Sync)) -> &(dyn Send + Sync) { | ||
x | ||
} | ||
|
||
#[used] | ||
pub static FOO: &(dyn Send + Sync) = yeet_principal_3(&false); | ||
|
||
const fn yeet_principal_4(x: &dyn Bar) -> &(dyn Send + Sync) { | ||
x | ||
} | ||
|
||
#[used] | ||
pub static BAR: &(dyn Send + Sync) = yeet_principal_4(&false); |
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 |