Skip to content

Commit

Permalink
Auto merge of #131869 - matthiaskrgr:rollup-xrkz174, r=matthiaskrgr
Browse files Browse the repository at this point in the history
Rollup of 5 pull requests

Successful merges:

 - #131654 (Various fixes for Xous)
 - #131743 (rustc_metadata: minor tidying)
 - #131823 (Bump libc to 0.2.161)
 - #131850 (Missing parenthesis)
 - #131857 (Allow dropping dyn principal)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Oct 18, 2024
2 parents cfe7f2a + 4630fe8 commit 5fa5f87
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
51 changes: 51 additions & 0 deletions tests/pass/dyn-upcast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ fn main() {
struct_();
replace_vptr();
vtable_nop_cast();
drop_principal();
}

fn vtable_nop_cast() {
Expand Down Expand Up @@ -430,3 +431,53 @@ fn replace_vptr() {
let s = S(42);
invoke_outer(&s);
}

fn drop_principal() {
use std::{alloc::Layout, 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");
}

let x = Box::new(CallMe::new(goodbye)) as Box<dyn Any + Send>;
let x_layout = Layout::for_value(&*x);
let y = yeet_principal(x);
let y_layout = Layout::for_value(&*y);
assert_eq!(x_layout, y_layout);
println!("before");
drop(y);

let x = Box::new(CallMe::new(goodbye)) as Box<dyn Bar>;
let x_layout = Layout::for_value(&*x);
let y = yeet_principal_2(x);
let y_layout = Layout::for_value(&*y);
assert_eq!(x_layout, y_layout);
println!("before");
drop(y);
}
4 changes: 4 additions & 0 deletions tests/pass/dyn-upcast.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
before
goodbye
before
goodbye

0 comments on commit 5fa5f87

Please sign in to comment.