Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
f35517ee
R
Rust
项目概览
int
/
Rust
大约 1 年 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rust
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
f35517ee
编写于
12月 26, 2019
作者:
S
Sean McArthur
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
core: add IntoFuture trait and support for await
上级
41501a6b
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
90 addition
and
12 deletion
+90
-12
src/libcore/future/future.rs
src/libcore/future/future.rs
+25
-0
src/libcore/future/mod.rs
src/libcore/future/mod.rs
+3
-0
src/librustc/hir/lowering.rs
src/librustc/hir/lowering.rs
+2
-0
src/librustc/hir/lowering/expr.rs
src/librustc/hir/lowering/expr.rs
+20
-4
src/libstd/future.rs
src/libstd/future.rs
+5
-1
src/libstd/lib.rs
src/libstd/lib.rs
+1
-0
src/libsyntax_pos/symbol.rs
src/libsyntax_pos/symbol.rs
+2
-0
src/test/ui/async-await/async-fn-size-moved-locals.rs
src/test/ui/async-await/async-fn-size-moved-locals.rs
+3
-3
src/test/ui/async-await/await-into-future.rs
src/test/ui/async-await/await-into-future.rs
+28
-0
src/test/ui/async-await/issues/issue-62009-1.stderr
src/test/ui/async-await/issues/issue-62009-1.stderr
+1
-4
未找到文件。
src/libcore/future/future.rs
浏览文件 @
f35517ee
...
...
@@ -99,6 +99,21 @@ pub trait Future {
fn
poll
(
self
:
Pin
<&
mut
Self
>
,
cx
:
&
mut
Context
<
'_
>
)
->
Poll
<
Self
::
Output
>
;
}
/// Conversion into a `Future`.
#[unstable(feature
=
"into_future"
,
issue
=
"67644"
)]
pub
trait
IntoFuture
{
/// The output that the future will produce on completion.
#[unstable(feature
=
"into_future"
,
issue
=
"67644"
)]
type
Output
;
/// Which kind of future are we turning this into?
#[unstable(feature
=
"into_future"
,
issue
=
"67644"
)]
type
Future
:
Future
<
Output
=
Self
::
Output
>
;
/// Creates a future from a value.
#[unstable(feature
=
"into_future"
,
issue
=
"67644"
)]
fn
into_future
(
self
)
->
Self
::
Future
;
}
#[stable(feature
=
"futures_api"
,
since
=
"1.36.0"
)]
impl
<
F
:
?
Sized
+
Future
+
Unpin
>
Future
for
&
mut
F
{
type
Output
=
F
::
Output
;
...
...
@@ -119,3 +134,13 @@ fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
Pin
::
get_mut
(
self
)
.as_mut
()
.poll
(
cx
)
}
}
#[unstable(feature
=
"into_future"
,
issue
=
"67644"
)]
impl
<
F
:
Future
>
IntoFuture
for
F
{
type
Output
=
F
::
Output
;
type
Future
=
F
;
fn
into_future
(
self
)
->
Self
::
Future
{
self
}
}
src/libcore/future/mod.rs
浏览文件 @
f35517ee
...
...
@@ -5,3 +5,6 @@
mod
future
;
#[stable(feature
=
"futures_api"
,
since
=
"1.36.0"
)]
pub
use
self
::
future
::
Future
;
#[unstable(feature
=
"into_future"
,
issue
=
"67644"
)]
pub
use
self
::
future
::
IntoFuture
;
src/librustc/hir/lowering.rs
浏览文件 @
f35517ee
...
...
@@ -168,6 +168,7 @@ pub struct LoweringContext<'a, 'hir: 'a> {
allow_try_trait
:
Option
<
Lrc
<
[
Symbol
]
>>
,
allow_gen_future
:
Option
<
Lrc
<
[
Symbol
]
>>
,
allow_into_future
:
Option
<
Lrc
<
[
Symbol
]
>>
,
}
pub
trait
Resolver
{
...
...
@@ -300,6 +301,7 @@ pub fn lower_crate<'a, 'hir>(
in_scope_lifetimes
:
Vec
::
new
(),
allow_try_trait
:
Some
([
sym
::
try_trait
][
..
]
.into
()),
allow_gen_future
:
Some
([
sym
::
gen_future
][
..
]
.into
()),
allow_into_future
:
Some
([
sym
::
into_future
][
..
]
.into
()),
}
.lower_crate
(
krate
)
}
...
...
src/librustc/hir/lowering/expr.rs
浏览文件 @
f35517ee
...
...
@@ -529,7 +529,7 @@ pub(super) fn make_async_expr(
/// Desugar `<expr>.await` into:
/// ```rust
/// match
<expr>
{
/// match
::std::future::IntoFuture::into_future(<expr>)
{
/// mut pinned => loop {
/// match ::std::future::poll_with_tls_context(unsafe {
/// <::std::pin::Pin>::new_unchecked(&mut pinned)
...
...
@@ -653,11 +653,27 @@ fn lower_expr_await(&mut self, await_span: Span, expr: &Expr) -> hir::ExprKind<'
// mut pinned => loop { ... }
let
pinned_arm
=
self
.arm
(
pinned_pat
,
loop_expr
);
// match <expr> {
// `match ::std::future::IntoFuture::into_future(<expr>) { ... }`
let
into_future_span
=
self
.mark_span_with_reason
(
DesugaringKind
::
Await
,
await_span
,
self
.allow_into_future
.clone
(),
);
let
expr
=
self
.lower_expr_mut
(
expr
);
let
into_future_expr
=
self
.expr_call_std_path
(
into_future_span
,
&
[
sym
::
future
,
sym
::
IntoFuture
,
sym
::
into_future
],
arena_vec!
[
self
;
expr
],
);
// match <into_future_expr> {
// mut pinned => loop { .. }
// }
let
expr
=
self
.lower_expr
(
expr
);
hir
::
ExprKind
::
Match
(
expr
,
arena_vec!
[
self
;
pinned_arm
],
hir
::
MatchSource
::
AwaitDesugar
)
hir
::
ExprKind
::
Match
(
into_future_expr
,
arena_vec!
[
self
;
pinned_arm
],
hir
::
MatchSource
::
AwaitDesugar
,
)
}
fn
lower_expr_closure
(
...
...
src/libstd/future.rs
浏览文件 @
f35517ee
...
...
@@ -10,7 +10,11 @@
#[doc(inline)]
#[stable(feature
=
"futures_api"
,
since
=
"1.36.0"
)]
pub
use
core
::
future
::
*
;
pub
use
core
::
future
::
Future
;
#[doc(inline)]
#[unstable(feature
=
"into_future"
,
issue
=
"67644"
)]
pub
use
core
::
future
::
IntoFuture
;
/// Wrap a generator in a future.
///
...
...
src/libstd/lib.rs
浏览文件 @
f35517ee
...
...
@@ -269,6 +269,7 @@
#![feature(hashmap_internals)]
#![feature(int_error_internals)]
#![feature(int_error_matching)]
#![feature(into_future)]
#![feature(integer_atomics)]
#![feature(lang_items)]
#![feature(libc)]
...
...
src/libsyntax_pos/symbol.rs
浏览文件 @
f35517ee
...
...
@@ -379,6 +379,8 @@
infer_static_outlives_requirements
,
inline
,
intel
,
into_future
,
IntoFuture
,
into_iter
,
IntoIterator
,
into_result
,
...
...
src/test/ui/async-await/async-fn-size-moved-locals.rs
浏览文件 @
f35517ee
...
...
@@ -112,7 +112,7 @@ async fn mixed_sizes() {
fn
main
()
{
assert_eq!
(
1028
,
std
::
mem
::
size_of_val
(
&
single
()));
assert_eq!
(
1032
,
std
::
mem
::
size_of_val
(
&
single_with_noop
()));
assert_eq!
(
308
4
,
std
::
mem
::
size_of_val
(
&
joined
()));
assert_eq!
(
308
4
,
std
::
mem
::
size_of_val
(
&
joined_with_noop
()));
assert_eq!
(
7188
,
std
::
mem
::
size_of_val
(
&
mixed_sizes
()));
assert_eq!
(
308
0
,
std
::
mem
::
size_of_val
(
&
joined
()));
assert_eq!
(
308
0
,
std
::
mem
::
size_of_val
(
&
joined_with_noop
()));
assert_eq!
(
6164
,
std
::
mem
::
size_of_val
(
&
mixed_sizes
()));
}
src/test/ui/async-await/await-into-future.rs
0 → 100644
浏览文件 @
f35517ee
// check-pass
// edition:2018
#![feature(into_future)]
use
std
::{
future
::{
Future
,
IntoFuture
},
pin
::
Pin
};
struct
AwaitMe
;
impl
IntoFuture
for
AwaitMe
{
type
Output
=
i32
;
type
Future
=
Pin
<
Box
<
dyn
Future
<
Output
=
i32
>>>
;
fn
into_future
(
self
)
->
Self
::
Future
{
Box
::
pin
(
me
())
}
}
async
fn
me
()
->
i32
{
41
}
async
fn
run
()
{
assert_eq!
(
AwaitMe
.await
,
41
);
}
fn
main
()
{}
src/test/ui/async-await/issues/issue-62009-1.stderr
浏览文件 @
f35517ee
...
...
@@ -32,11 +32,8 @@ error[E0277]: the trait bound `[closure@$DIR/issue-62009-1.rs:13:5: 13:15]: std:
|
LL | (|_| 2333).await;
| ^^^^^^^^^^^^^^^^ the trait `std::future::Future` is not implemented for `[closure@$DIR/issue-62009-1.rs:13:5: 13:15]`
|
::: $SRC_DIR/libstd/future.rs:LL:COL
|
LL | F: Future,
| ------ required by this bound in `std::future::poll_with_tls_context`
= note: required by `std::future::IntoFuture::into_future`
error: aborting due to 4 previous errors
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录