Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test calling Box<dyn FnOnce> #680

Merged
merged 5 commits into from
Apr 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rust-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
f717b58dd70829f105960a071c7992b440720482
3de0106789468b211bcc3a25c09c0cf07119186d
4 changes: 1 addition & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,7 @@ pub fn eval_main<'a, 'tcx: 'a>(
trace!("Frame {}", i);
trace!(" return: {:#?}", frame.return_place);
for (i, local) in frame.locals.iter().enumerate() {
if let Ok(local) = local.access() {
trace!(" local {}: {:?}", i, local);
}
trace!(" local {}: {:?}", i, local.value);
}
}
}
Expand Down
16 changes: 8 additions & 8 deletions tests/run-pass/async-fn.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
// ignore-test FIXME ignored to let https://github.com/rust-lang/rust/pull/59119 land
#![feature(
async_await,
await_macro,
futures_api,
)]

use std::{future::Future, pin::Pin, task::Poll, ptr};
use std::task::{Waker, RawWaker, RawWakerVTable};
use std::task::{Waker, RawWaker, RawWakerVTable, Context};

// See if we can run a basic `async fn`
pub async fn foo(x: &u32, y: u32) -> u32 {
Expand All @@ -27,15 +26,16 @@ fn raw_waker_wake(_this: *const ()) {
}
fn raw_waker_drop(_this: *const ()) {}

static RAW_WAKER: RawWakerVTable = RawWakerVTable {
clone: raw_waker_clone,
wake: raw_waker_wake,
drop: raw_waker_drop,
};
static RAW_WAKER: RawWakerVTable = RawWakerVTable::new(
raw_waker_clone,
raw_waker_wake,
raw_waker_drop,
);

fn main() {
let x = 5;
let mut fut = foo(&x, 7);
let waker = unsafe { Waker::new_unchecked(RawWaker::new(ptr::null(), &RAW_WAKER)) };
assert_eq!(unsafe { Pin::new_unchecked(&mut fut) }.poll(&waker), Poll::Ready(31));
let mut context = Context::from_waker(&waker);
assert_eq!(unsafe { Pin::new_unchecked(&mut fut) }.poll(&mut context), Poll::Ready(31));
}
5 changes: 5 additions & 0 deletions tests/run-pass/closures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,14 @@ fn fn_once_closure_with_multiple_args() -> i64 {
}
}

fn boxed(f: Box<dyn FnOnce() -> i32>) -> i32 {
f()
}

fn main() {
assert_eq!(simple(), 12);
assert_eq!(crazy_closure(), (84, 10, 10));
assert_eq!(closure_arg_adjustment_problem(), 3);
assert_eq!(fn_once_closure_with_multiple_args(), 6);
assert_eq!(boxed(Box::new({let x = 13; move || x})), 13);
}