Skip to content

Commit ee51a3c

Browse files
committed
Review nits and updates
Move future_from_generator out of raw Update await to use $crate Renumber errors
1 parent 85e4866 commit ee51a3c

File tree

7 files changed

+51
-53
lines changed

7 files changed

+51
-53
lines changed

src/librustc/diagnostics.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2134,7 +2134,7 @@ register_diagnostics! {
21342134

21352135
E0906, // closures cannot be static
21362136

2137-
E0703, // multiple different lifetimes used in arguments of `async fn`
2138-
E0704, // multiple elided lifetimes used in arguments of `async fn`
2139-
E0705, // `async` non-`move` closures with arguments are not currently supported
2137+
E0725, // multiple different lifetimes used in arguments of `async fn`
2138+
E0726, // multiple elided lifetimes used in arguments of `async fn`
2139+
E0727, // `async` non-`move` closures with arguments are not currently supported
21402140
}

src/librustc/hir/lowering.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -877,7 +877,7 @@ impl<'a> LoweringContext<'a> {
877877

878878
let unstable_span = self.allow_internal_unstable(CompilerDesugaringKind::Async, span);
879879
let gen_future = self.expr_std_path(
880-
unstable_span, &["raw", "future_from_generator"], None, ThinVec::new());
880+
unstable_span, &["future", "future_from_generator"], None, ThinVec::new());
881881
hir::ExprCall(P(gen_future), hir_vec![generator])
882882
}
883883

@@ -2049,7 +2049,7 @@ impl<'a> LoweringContext<'a> {
20492049
struct_span_err!(
20502050
self.context.sess,
20512051
current_lt_span.between(lifetime.span),
2052-
E0703,
2052+
E0725,
20532053
"multiple different lifetimes used in arguments of `async fn`",
20542054
)
20552055
.span_label(current_lt_span, "first lifetime here")
@@ -2061,7 +2061,7 @@ impl<'a> LoweringContext<'a> {
20612061
struct_span_err!(
20622062
self.context.sess,
20632063
current_lt_span.between(lifetime.span),
2064-
E0704,
2064+
E0726,
20652065
"multiple elided lifetimes used in arguments of `async fn`",
20662066
)
20672067
.span_label(current_lt_span, "first lifetime here")
@@ -2582,9 +2582,10 @@ impl<'a> LoweringContext<'a> {
25822582
let fn_def_id = self.resolver.definitions().local_def_id(id);
25832583

25842584
self.with_new_scopes(|this| {
2585-
// Note: we can use non-async decl here because lower_body
2586-
// only cares about the input argument patterns,
2587-
// not the return types.
2585+
// Note: we don't need to change the return type from `T` to
2586+
// `impl Future<Output = T>` here because lower_body
2587+
// only cares about the input argument patterns in the function
2588+
// declaration (decl), not the return types.
25882589
let body_id = this.lower_body(Some(decl), |this| {
25892590
if let IsAsync::Async(async_node_id) = header.asyncness {
25902591
let async_expr = this.make_async_expr(
@@ -3560,7 +3561,7 @@ impl<'a> LoweringContext<'a> {
35603561
struct_span_err!(
35613562
this.sess,
35623563
fn_decl_span,
3563-
E0705,
3564+
E0727,
35643565
"`async` non-`move` closures with arguments \
35653566
are not currently supported",
35663567
)

src/libstd/raw.rs renamed to src/libstd/future.rs

+12-16
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -8,27 +8,18 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#![allow(missing_docs)]
12-
#![unstable(feature = "raw", issue = "27751")]
13-
14-
//! Contains struct definitions for the layout of compiler built-in types.
15-
//!
16-
//! They can be used as targets of transmutes in unsafe code for manipulating
17-
//! the raw representations directly.
18-
//!
19-
//! Their definition should always match the ABI defined in `rustc::back::abi`.
11+
//! Asynchronous values.
2012
2113
use core::cell::Cell;
22-
use core::future::Future;
2314
use core::marker::Unpin;
2415
use core::mem::PinMut;
2516
use core::option::Option;
2617
use core::ptr::NonNull;
2718
use core::task::{self, Poll};
2819
use core::ops::{Drop, Generator, GeneratorState};
2920

30-
#[stable(feature = "rust1", since = "1.0.0")]
31-
pub use core::raw::*;
21+
#[doc(inline)]
22+
pub use core::future::*;
3223

3324
/// Wrap a future in a generator.
3425
///
@@ -52,7 +43,7 @@ impl<T: Generator<Yield = ()>> !Unpin for GenFuture<T> {}
5243
impl<T: Generator<Yield = ()>> Future for GenFuture<T> {
5344
type Output = T::Return;
5445
fn poll(self: PinMut<Self>, cx: &mut task::Context) -> Poll<Self::Output> {
55-
with_set_cx(cx, || match unsafe { PinMut::get_mut(self).0.resume() } {
46+
set_task_cx(cx, || match unsafe { PinMut::get_mut(self).0.resume() } {
5647
GeneratorState::Yielded(()) => Poll::Pending,
5748
GeneratorState::Complete(x) => Poll::Ready(x),
5849
})
@@ -74,7 +65,8 @@ impl Drop for SetOnDrop {
7465
}
7566

7667
#[unstable(feature = "gen_future", issue = "50547")]
77-
pub fn with_set_cx<F, R>(cx: &mut task::Context, f: F) -> R
68+
/// Sets the thread-local task context used by async/await futures.
69+
pub fn set_task_cx<F, R>(cx: &mut task::Context, f: F) -> R
7870
where
7971
F: FnOnce() -> R
8072
{
@@ -90,7 +82,11 @@ where
9082
}
9183

9284
#[unstable(feature = "gen_future", issue = "50547")]
93-
pub fn with_get_cx<F, R>(f: F) -> R
85+
/// Retrieves the thread-local task context used by async/await futures.
86+
///
87+
/// Panics if no task has been set or if the task context has already been
88+
/// retrived by a surrounding call to get_task_cx.
89+
pub fn get_task_cx<F, R>(f: F) -> R
9490
where
9591
F: FnOnce(&mut task::Context) -> R
9692
{

src/libstd/lib.rs

+18-17
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,8 @@ pub use core::ops;
411411
#[stable(feature = "rust1", since = "1.0.0")]
412412
pub use core::ptr;
413413
#[stable(feature = "rust1", since = "1.0.0")]
414+
pub use core::raw;
415+
#[stable(feature = "rust1", since = "1.0.0")]
414416
pub use core::result;
415417
#[stable(feature = "rust1", since = "1.0.0")]
416418
pub use core::option;
@@ -461,22 +463,6 @@ pub use core::u128;
461463
#[stable(feature = "core_hint", since = "1.27.0")]
462464
pub use core::hint;
463465

464-
#[unstable(feature = "futures_api",
465-
reason = "futures in libcore are unstable",
466-
issue = "50547")]
467-
pub mod task {
468-
//! Types and Traits for working with asynchronous tasks.
469-
#[doc(inline)]
470-
pub use core::task::*;
471-
#[doc(inline)]
472-
pub use alloc_crate::task::*;
473-
}
474-
475-
#[unstable(feature = "futures_api",
476-
reason = "futures in libcore are unstable",
477-
issue = "50547")]
478-
pub use core::future;
479-
480466
pub mod f32;
481467
pub mod f64;
482468

@@ -495,10 +481,25 @@ pub mod os;
495481
pub mod panic;
496482
pub mod path;
497483
pub mod process;
498-
pub mod raw;
499484
pub mod sync;
500485
pub mod time;
501486

487+
#[unstable(feature = "futures_api",
488+
reason = "futures in libcore are unstable",
489+
issue = "50547")]
490+
pub mod task {
491+
//! Types and Traits for working with asynchronous tasks.
492+
#[doc(inline)]
493+
pub use core::task::*;
494+
#[doc(inline)]
495+
pub use alloc_crate::task::*;
496+
}
497+
498+
#[unstable(feature = "futures_api",
499+
reason = "futures in libcore are unstable",
500+
issue = "50547")]
501+
pub mod future;
502+
502503
// Platform-abstraction modules
503504
#[macro_use]
504505
mod sys_common;

src/libstd/macros.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -220,15 +220,15 @@ macro_rules! eprintln {
220220
macro_rules! await {
221221
($e:expr) => { {
222222
let mut pinned = $e;
223-
let mut pinned = unsafe { ::core::mem::PinMut::new_unchecked(&mut pinned) };
223+
let mut pinned = unsafe { $crate::mem::PinMut::new_unchecked(&mut pinned) };
224224
loop {
225-
match ::std::raw::with_get_cx(|cx|
226-
::core::future::Future::poll(pinned.reborrow(), cx))
225+
match $crate::future::get_task_cx(|cx|
226+
$crate::future::Future::poll(pinned.reborrow(), cx))
227227
{
228228
// FIXME(cramertj) prior to stabilizing await, we have to ensure that this
229229
// can't be used to create a generator on stable via `|| await!()`.
230-
::core::task::Poll::Pending => yield,
231-
::core::task::Poll::Ready(x) => break x,
230+
$crate::task::Poll::Pending => yield,
231+
$crate::task::Poll::Ready(x) => break x,
232232
}
233233
}
234234
} }

src/test/ui/async-fn-multiple-lifetimes.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0703]: multiple different lifetimes used in arguments of `async fn`
1+
error[E0725]: multiple different lifetimes used in arguments of `async fn`
22
--> $DIR/async-fn-multiple-lifetimes.rs:17:49
33
|
44
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) {}
88
|
99
= help: `async fn` can only accept borrowed values with identical lifetimes
1010

11-
error[E0704]: multiple elided lifetimes used in arguments of `async fn`
11+
error[E0726]: multiple elided lifetimes used in arguments of `async fn`
1212
--> $DIR/async-fn-multiple-lifetimes.rs:26:39
1313
|
1414
LL | async fn multiple_elided_lifetimes(_: &u8, _: &u8) {}
@@ -28,5 +28,5 @@ LL | async fn multiple_elided_lifetimes(_: &u8, _: &u8) {}
2828

2929
error: aborting due to 3 previous errors
3030

31-
Some errors occurred: E0106, E0703, E0704.
31+
Some errors occurred: E0106, E0725, E0726.
3232
For more information about an error, try `rustc --explain E0106`.
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0705]: `async` non-`move` closures with arguments are not currently supported
1+
error[E0727]: `async` non-`move` closures with arguments are not currently supported
22
--> $DIR/no-args-non-move-async-closure.rs:16:13
33
|
44
LL | let _ = async |x: u8| {};
@@ -8,4 +8,4 @@ LL | let _ = async |x: u8| {};
88

99
error: aborting due to previous error
1010

11-
For more information about this error, try `rustc --explain E0705`.
11+
For more information about this error, try `rustc --explain E0727`.

0 commit comments

Comments
 (0)