Review nits and updates
Move future_from_generator out of raw Update await to use $crate Renumber errors
This commit is contained in:
parent
85e4866320
commit
ee51a3c10a
|
@ -2134,7 +2134,7 @@ register_diagnostics! {
|
||||||
|
|
||||||
E0906, // closures cannot be static
|
E0906, // closures cannot be static
|
||||||
|
|
||||||
E0703, // multiple different lifetimes used in arguments of `async fn`
|
E0725, // multiple different lifetimes used in arguments of `async fn`
|
||||||
E0704, // multiple elided lifetimes used in arguments of `async fn`
|
E0726, // multiple elided lifetimes used in arguments of `async fn`
|
||||||
E0705, // `async` non-`move` closures with arguments are not currently supported
|
E0727, // `async` non-`move` closures with arguments are not currently supported
|
||||||
}
|
}
|
||||||
|
|
|
@ -877,7 +877,7 @@ impl<'a> LoweringContext<'a> {
|
||||||
|
|
||||||
let unstable_span = self.allow_internal_unstable(CompilerDesugaringKind::Async, span);
|
let unstable_span = self.allow_internal_unstable(CompilerDesugaringKind::Async, span);
|
||||||
let gen_future = self.expr_std_path(
|
let gen_future = self.expr_std_path(
|
||||||
unstable_span, &["raw", "future_from_generator"], None, ThinVec::new());
|
unstable_span, &["future", "future_from_generator"], None, ThinVec::new());
|
||||||
hir::ExprCall(P(gen_future), hir_vec![generator])
|
hir::ExprCall(P(gen_future), hir_vec![generator])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2049,7 +2049,7 @@ impl<'a> LoweringContext<'a> {
|
||||||
struct_span_err!(
|
struct_span_err!(
|
||||||
self.context.sess,
|
self.context.sess,
|
||||||
current_lt_span.between(lifetime.span),
|
current_lt_span.between(lifetime.span),
|
||||||
E0703,
|
E0725,
|
||||||
"multiple different lifetimes used in arguments of `async fn`",
|
"multiple different lifetimes used in arguments of `async fn`",
|
||||||
)
|
)
|
||||||
.span_label(current_lt_span, "first lifetime here")
|
.span_label(current_lt_span, "first lifetime here")
|
||||||
|
@ -2061,7 +2061,7 @@ impl<'a> LoweringContext<'a> {
|
||||||
struct_span_err!(
|
struct_span_err!(
|
||||||
self.context.sess,
|
self.context.sess,
|
||||||
current_lt_span.between(lifetime.span),
|
current_lt_span.between(lifetime.span),
|
||||||
E0704,
|
E0726,
|
||||||
"multiple elided lifetimes used in arguments of `async fn`",
|
"multiple elided lifetimes used in arguments of `async fn`",
|
||||||
)
|
)
|
||||||
.span_label(current_lt_span, "first lifetime here")
|
.span_label(current_lt_span, "first lifetime here")
|
||||||
|
@ -2582,9 +2582,10 @@ impl<'a> LoweringContext<'a> {
|
||||||
let fn_def_id = self.resolver.definitions().local_def_id(id);
|
let fn_def_id = self.resolver.definitions().local_def_id(id);
|
||||||
|
|
||||||
self.with_new_scopes(|this| {
|
self.with_new_scopes(|this| {
|
||||||
// Note: we can use non-async decl here because lower_body
|
// Note: we don't need to change the return type from `T` to
|
||||||
// only cares about the input argument patterns,
|
// `impl Future<Output = T>` here because lower_body
|
||||||
// not the return types.
|
// only cares about the input argument patterns in the function
|
||||||
|
// declaration (decl), not the return types.
|
||||||
let body_id = this.lower_body(Some(decl), |this| {
|
let body_id = this.lower_body(Some(decl), |this| {
|
||||||
if let IsAsync::Async(async_node_id) = header.asyncness {
|
if let IsAsync::Async(async_node_id) = header.asyncness {
|
||||||
let async_expr = this.make_async_expr(
|
let async_expr = this.make_async_expr(
|
||||||
|
@ -3560,7 +3561,7 @@ impl<'a> LoweringContext<'a> {
|
||||||
struct_span_err!(
|
struct_span_err!(
|
||||||
this.sess,
|
this.sess,
|
||||||
fn_decl_span,
|
fn_decl_span,
|
||||||
E0705,
|
E0727,
|
||||||
"`async` non-`move` closures with arguments \
|
"`async` non-`move` closures with arguments \
|
||||||
are not currently supported",
|
are not currently supported",
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
|
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
|
||||||
// file at the top-level directory of this distribution and at
|
// file at the top-level directory of this distribution and at
|
||||||
// http://rust-lang.org/COPYRIGHT.
|
// http://rust-lang.org/COPYRIGHT.
|
||||||
//
|
//
|
||||||
|
@ -8,18 +8,9 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
#![allow(missing_docs)]
|
//! Asynchronous values.
|
||||||
#![unstable(feature = "raw", issue = "27751")]
|
|
||||||
|
|
||||||
//! Contains struct definitions for the layout of compiler built-in types.
|
|
||||||
//!
|
|
||||||
//! They can be used as targets of transmutes in unsafe code for manipulating
|
|
||||||
//! the raw representations directly.
|
|
||||||
//!
|
|
||||||
//! Their definition should always match the ABI defined in `rustc::back::abi`.
|
|
||||||
|
|
||||||
use core::cell::Cell;
|
use core::cell::Cell;
|
||||||
use core::future::Future;
|
|
||||||
use core::marker::Unpin;
|
use core::marker::Unpin;
|
||||||
use core::mem::PinMut;
|
use core::mem::PinMut;
|
||||||
use core::option::Option;
|
use core::option::Option;
|
||||||
|
@ -27,8 +18,8 @@ use core::ptr::NonNull;
|
||||||
use core::task::{self, Poll};
|
use core::task::{self, Poll};
|
||||||
use core::ops::{Drop, Generator, GeneratorState};
|
use core::ops::{Drop, Generator, GeneratorState};
|
||||||
|
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[doc(inline)]
|
||||||
pub use core::raw::*;
|
pub use core::future::*;
|
||||||
|
|
||||||
/// Wrap a future in a generator.
|
/// Wrap a future in a generator.
|
||||||
///
|
///
|
||||||
|
@ -52,7 +43,7 @@ impl<T: Generator<Yield = ()>> !Unpin for GenFuture<T> {}
|
||||||
impl<T: Generator<Yield = ()>> Future for GenFuture<T> {
|
impl<T: Generator<Yield = ()>> Future for GenFuture<T> {
|
||||||
type Output = T::Return;
|
type Output = T::Return;
|
||||||
fn poll(self: PinMut<Self>, cx: &mut task::Context) -> Poll<Self::Output> {
|
fn poll(self: PinMut<Self>, cx: &mut task::Context) -> Poll<Self::Output> {
|
||||||
with_set_cx(cx, || match unsafe { PinMut::get_mut(self).0.resume() } {
|
set_task_cx(cx, || match unsafe { PinMut::get_mut(self).0.resume() } {
|
||||||
GeneratorState::Yielded(()) => Poll::Pending,
|
GeneratorState::Yielded(()) => Poll::Pending,
|
||||||
GeneratorState::Complete(x) => Poll::Ready(x),
|
GeneratorState::Complete(x) => Poll::Ready(x),
|
||||||
})
|
})
|
||||||
|
@ -74,7 +65,8 @@ impl Drop for SetOnDrop {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unstable(feature = "gen_future", issue = "50547")]
|
#[unstable(feature = "gen_future", issue = "50547")]
|
||||||
pub fn with_set_cx<F, R>(cx: &mut task::Context, f: F) -> R
|
/// Sets the thread-local task context used by async/await futures.
|
||||||
|
pub fn set_task_cx<F, R>(cx: &mut task::Context, f: F) -> R
|
||||||
where
|
where
|
||||||
F: FnOnce() -> R
|
F: FnOnce() -> R
|
||||||
{
|
{
|
||||||
|
@ -90,7 +82,11 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unstable(feature = "gen_future", issue = "50547")]
|
#[unstable(feature = "gen_future", issue = "50547")]
|
||||||
pub fn with_get_cx<F, R>(f: F) -> R
|
/// Retrieves the thread-local task context used by async/await futures.
|
||||||
|
///
|
||||||
|
/// Panics if no task has been set or if the task context has already been
|
||||||
|
/// retrived by a surrounding call to get_task_cx.
|
||||||
|
pub fn get_task_cx<F, R>(f: F) -> R
|
||||||
where
|
where
|
||||||
F: FnOnce(&mut task::Context) -> R
|
F: FnOnce(&mut task::Context) -> R
|
||||||
{
|
{
|
|
@ -411,6 +411,8 @@ pub use core::ops;
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
pub use core::ptr;
|
pub use core::ptr;
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
pub use core::raw;
|
||||||
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
pub use core::result;
|
pub use core::result;
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
pub use core::option;
|
pub use core::option;
|
||||||
|
@ -461,22 +463,6 @@ pub use core::u128;
|
||||||
#[stable(feature = "core_hint", since = "1.27.0")]
|
#[stable(feature = "core_hint", since = "1.27.0")]
|
||||||
pub use core::hint;
|
pub use core::hint;
|
||||||
|
|
||||||
#[unstable(feature = "futures_api",
|
|
||||||
reason = "futures in libcore are unstable",
|
|
||||||
issue = "50547")]
|
|
||||||
pub mod task {
|
|
||||||
//! Types and Traits for working with asynchronous tasks.
|
|
||||||
#[doc(inline)]
|
|
||||||
pub use core::task::*;
|
|
||||||
#[doc(inline)]
|
|
||||||
pub use alloc_crate::task::*;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[unstable(feature = "futures_api",
|
|
||||||
reason = "futures in libcore are unstable",
|
|
||||||
issue = "50547")]
|
|
||||||
pub use core::future;
|
|
||||||
|
|
||||||
pub mod f32;
|
pub mod f32;
|
||||||
pub mod f64;
|
pub mod f64;
|
||||||
|
|
||||||
|
@ -495,10 +481,25 @@ pub mod os;
|
||||||
pub mod panic;
|
pub mod panic;
|
||||||
pub mod path;
|
pub mod path;
|
||||||
pub mod process;
|
pub mod process;
|
||||||
pub mod raw;
|
|
||||||
pub mod sync;
|
pub mod sync;
|
||||||
pub mod time;
|
pub mod time;
|
||||||
|
|
||||||
|
#[unstable(feature = "futures_api",
|
||||||
|
reason = "futures in libcore are unstable",
|
||||||
|
issue = "50547")]
|
||||||
|
pub mod task {
|
||||||
|
//! Types and Traits for working with asynchronous tasks.
|
||||||
|
#[doc(inline)]
|
||||||
|
pub use core::task::*;
|
||||||
|
#[doc(inline)]
|
||||||
|
pub use alloc_crate::task::*;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[unstable(feature = "futures_api",
|
||||||
|
reason = "futures in libcore are unstable",
|
||||||
|
issue = "50547")]
|
||||||
|
pub mod future;
|
||||||
|
|
||||||
// Platform-abstraction modules
|
// Platform-abstraction modules
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
mod sys_common;
|
mod sys_common;
|
||||||
|
|
|
@ -220,15 +220,15 @@ macro_rules! eprintln {
|
||||||
macro_rules! await {
|
macro_rules! await {
|
||||||
($e:expr) => { {
|
($e:expr) => { {
|
||||||
let mut pinned = $e;
|
let mut pinned = $e;
|
||||||
let mut pinned = unsafe { ::core::mem::PinMut::new_unchecked(&mut pinned) };
|
let mut pinned = unsafe { $crate::mem::PinMut::new_unchecked(&mut pinned) };
|
||||||
loop {
|
loop {
|
||||||
match ::std::raw::with_get_cx(|cx|
|
match $crate::future::get_task_cx(|cx|
|
||||||
::core::future::Future::poll(pinned.reborrow(), cx))
|
$crate::future::Future::poll(pinned.reborrow(), cx))
|
||||||
{
|
{
|
||||||
// FIXME(cramertj) prior to stabilizing await, we have to ensure that this
|
// FIXME(cramertj) prior to stabilizing await, we have to ensure that this
|
||||||
// can't be used to create a generator on stable via `|| await!()`.
|
// can't be used to create a generator on stable via `|| await!()`.
|
||||||
::core::task::Poll::Pending => yield,
|
$crate::task::Poll::Pending => yield,
|
||||||
::core::task::Poll::Ready(x) => break x,
|
$crate::task::Poll::Ready(x) => break x,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} }
|
} }
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
error[E0703]: multiple different lifetimes used in arguments of `async fn`
|
error[E0725]: multiple different lifetimes used in arguments of `async fn`
|
||||||
--> $DIR/async-fn-multiple-lifetimes.rs:17:49
|
--> $DIR/async-fn-multiple-lifetimes.rs:17:49
|
||||||
|
|
|
|
||||||
LL | async fn multiple_named_lifetimes<'a, 'b>(_: &'a u8, _: &'b u8) {}
|
LL | async fn multiple_named_lifetimes<'a, 'b>(_: &'a u8, _: &'b u8) {}
|
||||||
|
@ -8,7 +8,7 @@ LL | async fn multiple_named_lifetimes<'a, 'b>(_: &'a u8, _: &'b u8) {}
|
||||||
|
|
|
|
||||||
= help: `async fn` can only accept borrowed values with identical lifetimes
|
= help: `async fn` can only accept borrowed values with identical lifetimes
|
||||||
|
|
||||||
error[E0704]: multiple elided lifetimes used in arguments of `async fn`
|
error[E0726]: multiple elided lifetimes used in arguments of `async fn`
|
||||||
--> $DIR/async-fn-multiple-lifetimes.rs:26:39
|
--> $DIR/async-fn-multiple-lifetimes.rs:26:39
|
||||||
|
|
|
|
||||||
LL | async fn multiple_elided_lifetimes(_: &u8, _: &u8) {}
|
LL | async fn multiple_elided_lifetimes(_: &u8, _: &u8) {}
|
||||||
|
@ -28,5 +28,5 @@ LL | async fn multiple_elided_lifetimes(_: &u8, _: &u8) {}
|
||||||
|
|
||||||
error: aborting due to 3 previous errors
|
error: aborting due to 3 previous errors
|
||||||
|
|
||||||
Some errors occurred: E0106, E0703, E0704.
|
Some errors occurred: E0106, E0725, E0726.
|
||||||
For more information about an error, try `rustc --explain E0106`.
|
For more information about an error, try `rustc --explain E0106`.
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
error[E0705]: `async` non-`move` closures with arguments are not currently supported
|
error[E0727]: `async` non-`move` closures with arguments are not currently supported
|
||||||
--> $DIR/no-args-non-move-async-closure.rs:16:13
|
--> $DIR/no-args-non-move-async-closure.rs:16:13
|
||||||
|
|
|
|
||||||
LL | let _ = async |x: u8| {};
|
LL | let _ = async |x: u8| {};
|
||||||
|
@ -8,4 +8,4 @@ LL | let _ = async |x: u8| {};
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0705`.
|
For more information about this error, try `rustc --explain E0727`.
|
||||||
|
|
Loading…
Reference in New Issue