Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
034cd20f
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,发现更多精彩内容 >>
未验证
提交
034cd20f
编写于
8月 15, 2017
作者:
K
kennytm
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Exclude `impl Trait` functions from everybody_loops.
Fixes #43869.
上级
df806275
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
67 addition
and
6 deletion
+67
-6
src/librustc_driver/pretty.rs
src/librustc_driver/pretty.rs
+35
-6
src/test/rustdoc/issue-43869.rs
src/test/rustdoc/issue-43869.rs
+32
-0
未找到文件。
src/librustc_driver/pretty.rs
浏览文件 @
034cd20f
...
...
@@ -620,6 +620,15 @@ fn to_one_node_id(self, user_option: &str, sess: &Session, map: &hir_map::Map) -
}
// Note: Also used by librustdoc, see PR #43348. Consider moving this struct elsewhere.
//
// FIXME: Currently the `everybody_loops` transformation is not applied to:
// * `const fn`, due to issue #43636 that `loop` is not supported for const evaluation. We are
// waiting for miri to fix that.
// * `impl Trait`, due to issue #43869 that functions returning impl Trait cannot be diverging.
// Solving this may require `!` to implement every trait, which relies on the an even more
// ambitious form of the closed RFC #1637. See also [#34511].
//
// [#34511]: https://github.com/rust-lang/rust/issues/34511#issuecomment-322340401
pub
struct
ReplaceBodyWithLoop
{
within_static_or_const
:
bool
,
}
...
...
@@ -635,14 +644,34 @@ fn run<R, F: FnOnce(&mut Self) -> R>(&mut self, is_const: bool, action: F) -> R
self
.within_static_or_const
=
old_const
;
ret
}
fn
should_ignore_fn
(
ret_ty
:
&
ast
::
FnDecl
)
->
bool
{
if
let
ast
::
FunctionRetTy
::
Ty
(
ref
ty
)
=
ret_ty
.output
{
fn
involves_impl_trait
(
ty
:
&
ast
::
Ty
)
->
bool
{
match
ty
.node
{
ast
::
TyKind
::
ImplTrait
(
_
)
=>
true
,
ast
::
TyKind
::
Slice
(
ref
subty
)
|
ast
::
TyKind
::
Array
(
ref
subty
,
_
)
|
ast
::
TyKind
::
Ptr
(
ast
::
MutTy
{
ty
:
ref
subty
,
..
})
|
ast
::
TyKind
::
Rptr
(
_
,
ast
::
MutTy
{
ty
:
ref
subty
,
..
})
|
ast
::
TyKind
::
Paren
(
ref
subty
)
=>
involves_impl_trait
(
subty
),
ast
::
TyKind
::
Tup
(
ref
tys
)
=>
tys
.iter
()
.any
(|
subty
|
involves_impl_trait
(
subty
)),
_
=>
false
,
}
}
involves_impl_trait
(
ty
)
}
else
{
false
}
}
}
impl
fold
::
Folder
for
ReplaceBodyWithLoop
{
fn
fold_item_kind
(
&
mut
self
,
i
:
ast
::
ItemKind
)
->
ast
::
ItemKind
{
let
is_const
=
match
i
{
ast
::
ItemKind
::
Static
(
..
)
|
ast
::
ItemKind
::
Const
(
..
)
=>
true
,
ast
::
ItemKind
::
Fn
(
_
,
_
,
ref
constness
,
_
,
_
,
_
)
=>
constness
.node
==
ast
::
Constness
::
Const
,
ast
::
ItemKind
::
Fn
(
ref
decl
,
_
,
ref
constness
,
_
,
_
,
_
)
=>
constness
.node
==
ast
::
Constness
::
Const
||
Self
::
should_ignore_fn
(
decl
)
,
_
=>
false
,
};
self
.run
(
is_const
,
|
s
|
fold
::
noop_fold_item_kind
(
i
,
s
))
...
...
@@ -651,8 +680,8 @@ fn fold_item_kind(&mut self, i: ast::ItemKind) -> ast::ItemKind {
fn
fold_trait_item
(
&
mut
self
,
i
:
ast
::
TraitItem
)
->
SmallVector
<
ast
::
TraitItem
>
{
let
is_const
=
match
i
.node
{
ast
::
TraitItemKind
::
Const
(
..
)
=>
true
,
ast
::
TraitItemKind
::
Method
(
ast
::
MethodSig
{
ref
constness
,
..
},
_
)
=>
constness
.node
==
ast
::
Constness
::
Const
,
ast
::
TraitItemKind
::
Method
(
ast
::
MethodSig
{
ref
decl
,
ref
constness
,
..
},
_
)
=>
constness
.node
==
ast
::
Constness
::
Const
||
Self
::
should_ignore_fn
(
decl
)
,
_
=>
false
,
};
self
.run
(
is_const
,
|
s
|
fold
::
noop_fold_trait_item
(
i
,
s
))
...
...
@@ -661,8 +690,8 @@ fn fold_trait_item(&mut self, i: ast::TraitItem) -> SmallVector<ast::TraitItem>
fn
fold_impl_item
(
&
mut
self
,
i
:
ast
::
ImplItem
)
->
SmallVector
<
ast
::
ImplItem
>
{
let
is_const
=
match
i
.node
{
ast
::
ImplItemKind
::
Const
(
..
)
=>
true
,
ast
::
ImplItemKind
::
Method
(
ast
::
MethodSig
{
ref
constness
,
..
},
_
)
=>
constness
.node
==
ast
::
Constness
::
Const
,
ast
::
ImplItemKind
::
Method
(
ast
::
MethodSig
{
ref
decl
,
ref
constness
,
..
},
_
)
=>
constness
.node
==
ast
::
Constness
::
Const
||
Self
::
should_ignore_fn
(
decl
)
,
_
=>
false
,
};
self
.run
(
is_const
,
|
s
|
fold
::
noop_fold_impl_item
(
i
,
s
))
...
...
src/test/rustdoc/issue-43869.rs
0 → 100644
浏览文件 @
034cd20f
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(conservative_impl_trait)]
pub
fn
g
()
->
impl
Iterator
<
Item
=
u8
>
{
Some
(
1u8
)
.into_iter
()
}
pub
fn
h
()
->
(
impl
Iterator
<
Item
=
u8
>
)
{
Some
(
1u8
)
.into_iter
()
}
pub
fn
i
()
->
impl
Iterator
<
Item
=
u8
>
+
'static
{
Some
(
1u8
)
.into_iter
()
}
pub
fn
j
()
->
impl
Iterator
<
Item
=
u8
>
+
Clone
{
Some
(
1u8
)
.into_iter
()
}
// @has issue_43869/fn.g.html
// @has issue_43869/fn.h.html
// @has issue_43869/fn.i.html
// @has issue_43869/fn.j.html
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录