Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
c026d19b
R
Rust
项目概览
int
/
Rust
11 个月 前同步成功
通知
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,发现更多精彩内容 >>
提交
c026d19b
编写于
12月 20, 2017
作者:
T
Taylor Cramer
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add a feature gate for nested uses of `impl Trait`
上级
eff3de09
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
112 addition
and
5 deletion
+112
-5
src/libsyntax/feature_gate.rs
src/libsyntax/feature_gate.rs
+70
-2
src/test/compile-fail/E0657.rs
src/test/compile-fail/E0657.rs
+1
-1
src/test/compile-fail/feature-gate-nested_impl_trait.rs
src/test/compile-fail/feature-gate-nested_impl_trait.rs
+39
-0
src/test/compile-fail/impl-trait/where-allowed.rs
src/test/compile-fail/impl-trait/where-allowed.rs
+1
-1
src/test/run-pass/impl-trait/lifetimes.rs
src/test/run-pass/impl-trait/lifetimes.rs
+1
-1
未找到文件。
src/libsyntax/feature_gate.rs
浏览文件 @
c026d19b
...
...
@@ -441,6 +441,9 @@ pub fn new() -> Features {
// `foo.rs` as an alternative to `foo/mod.rs`
(
active
,
non_modrs_mods
,
"1.24.0"
,
Some
(
44660
)),
// Nested `impl Trait`
(
active
,
nested_impl_trait
,
"1.24.0"
,
Some
(
34511
)),
);
declare_features!
(
...
...
@@ -1314,8 +1317,73 @@ fn contains_novel_literal(item: &ast::MetaItem) -> bool {
}
}
// Bans nested `impl Trait`, e.g. `impl Into<impl Debug>`.
// Nested `impl Trait` _is_ allowed in associated type position,
// e.g `impl Iterator<Item=impl Debug>`
struct
NestedImplTraitVisitor
<
'a
>
{
context
:
&
'a
Context
<
'a
>
,
is_in_impl_trait
:
bool
,
}
impl
<
'a
>
NestedImplTraitVisitor
<
'a
>
{
fn
with_impl_trait
<
F
>
(
&
mut
self
,
is_in_impl_trait
:
bool
,
f
:
F
)
where
F
:
FnOnce
(
&
mut
NestedImplTraitVisitor
<
'a
>
)
{
let
old_is_in_impl_trait
=
self
.is_in_impl_trait
;
self
.is_in_impl_trait
=
is_in_impl_trait
;
f
(
self
);
self
.is_in_impl_trait
=
old_is_in_impl_trait
;
}
}
impl
<
'a
>
Visitor
<
'a
>
for
NestedImplTraitVisitor
<
'a
>
{
fn
visit_ty
(
&
mut
self
,
t
:
&
'a
ast
::
Ty
)
{
if
let
ast
::
TyKind
::
ImplTrait
(
_
)
=
t
.node
{
if
self
.is_in_impl_trait
{
gate_feature_post!
(
&
self
,
nested_impl_trait
,
t
.span
,
"nested `impl Trait` is experimental"
);
}
self
.with_impl_trait
(
true
,
|
this
|
visit
::
walk_ty
(
this
,
t
));
}
else
{
visit
::
walk_ty
(
self
,
t
);
}
}
fn
visit_path_parameters
(
&
mut
self
,
_
:
Span
,
path_parameters
:
&
'a
ast
::
PathParameters
)
{
match
*
path_parameters
{
ast
::
PathParameters
::
AngleBracketed
(
ref
params
)
=>
{
for
type_
in
&
params
.types
{
self
.visit_ty
(
type_
);
}
for
type_binding
in
&
params
.bindings
{
// Type bindings such as `Item=impl Debug` in `Iterator<Item=Debug>`
// are allowed to contain nested `impl Trait`.
self
.with_impl_trait
(
false
,
|
this
|
visit
::
walk_ty
(
this
,
&
type_binding
.ty
));
}
}
ast
::
PathParameters
::
Parenthesized
(
ref
params
)
=>
{
for
type_
in
&
params
.inputs
{
self
.visit_ty
(
type_
);
}
if
let
Some
(
ref
type_
)
=
params
.output
{
// `-> Foo` syntax is essentially an associated type binding,
// so it is also allowed to contain nested `impl Trait`.
self
.with_impl_trait
(
false
,
|
this
|
visit
::
walk_ty
(
this
,
type_
));
}
}
}
}
}
impl
<
'a
>
PostExpansionVisitor
<
'a
>
{
fn
whole_crate_feature_gates
(
&
mut
self
)
{
fn
whole_crate_feature_gates
(
&
mut
self
,
krate
:
&
ast
::
Crate
)
{
visit
::
walk_crate
(
&
mut
NestedImplTraitVisitor
{
context
:
self
.context
,
is_in_impl_trait
:
false
,
},
krate
);
for
&
(
ident
,
span
)
in
&*
self
.context.parse_sess.non_modrs_mods
.borrow
()
{
if
!
span
.allows_unstable
()
{
let
cx
=
&
self
.context
;
...
...
@@ -1892,7 +1960,7 @@ pub fn check_crate(krate: &ast::Crate,
plugin_attributes
,
};
let
visitor
=
&
mut
PostExpansionVisitor
{
context
:
&
ctx
};
visitor
.whole_crate_feature_gates
();
visitor
.whole_crate_feature_gates
(
krate
);
visit
::
walk_crate
(
visitor
,
krate
);
}
...
...
src/test/compile-fail/E0657.rs
浏览文件 @
c026d19b
...
...
@@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![allow(warnings)]
#![feature(conservative_impl_trait)]
#![feature(conservative_impl_trait
,
nested_impl_trait
)]
trait
Id
<
T
>
{}
trait
Lt
<
'a
>
{}
...
...
src/test/compile-fail/feature-gate-nested_impl_trait.rs
0 → 100644
浏览文件 @
c026d19b
// 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,
universal_impl_trait)]
use
std
::
fmt
::
Debug
;
fn
fine
(
x
:
impl
Into
<
u32
>
)
->
impl
Into
<
u32
>
{
x
}
fn
bad_in_ret_position
(
x
:
impl
Into
<
u32
>
)
->
impl
Into
<
impl
Debug
>
{
x
}
//~^ ERROR nested `impl Trait` is experimental
fn
bad_in_fn_syntax
(
x
:
fn
()
->
impl
Into
<
impl
Debug
>
)
{}
//~^ ERROR nested `impl Trait` is experimental
fn
bad_in_arg_position
(
_
:
impl
Into
<
impl
Debug
>
)
{
}
//~^ ERROR nested `impl Trait` is experimental
struct
X
;
impl
X
{
fn
bad
(
x
:
impl
Into
<
u32
>
)
->
impl
Into
<
impl
Debug
>
{
x
}
//~^ ERROR nested `impl Trait` is experimental
}
fn
allowed_in_assoc_type
()
->
impl
Iterator
<
Item
=
impl
Fn
()
>
{
vec!
[||
println!
(
"woot"
)]
.into_iter
()
}
fn
allowed_in_ret_type
()
->
impl
Fn
()
->
impl
Into
<
u32
>
{
||
5
}
fn
main
()
{}
src/test/compile-fail/impl-trait/where-allowed.rs
浏览文件 @
c026d19b
...
...
@@ -10,7 +10,7 @@
//! A simple test for testing many permutations of allowedness of
//! impl Trait
#![feature(conservative_impl_trait,
universal_impl_trait,
dyn_trait)]
#![feature(conservative_impl_trait,
nested_impl_trait,
universal_impl_trait,
dyn_trait)]
use
std
::
fmt
::
Debug
;
// Allowed
...
...
src/test/run-pass/impl-trait/lifetimes.rs
浏览文件 @
c026d19b
...
...
@@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(conservative_impl_trait,
underscore_lifetimes,
universal_impl_trait)]
#![feature(conservative_impl_trait,
underscore_lifetimes,
universal_impl_trait
,
nested_impl_trait
)]
#![allow(warnings)]
use
std
::
fmt
::
Debug
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录