Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
f0baec69
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,发现更多精彩内容 >>
提交
f0baec69
编写于
8月 01, 2016
作者:
E
Eduard Burtescu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
syntax: add anonymized type syntax, i.e. impl TraitA+TraitB.
上级
c976e073
变更
13
隐藏空白更改
内联
并排
Showing
13 changed file
with
68 addition
and
4 deletion
+68
-4
src/librustc/hir/fold.rs
src/librustc/hir/fold.rs
+3
-0
src/librustc/hir/intravisit.rs
src/librustc/hir/intravisit.rs
+3
-0
src/librustc/hir/lowering.rs
src/librustc/hir/lowering.rs
+4
-2
src/librustc/hir/mod.rs
src/librustc/hir/mod.rs
+2
-0
src/librustc/hir/print.rs
src/librustc/hir/print.rs
+3
-0
src/librustdoc/clean/mod.rs
src/librustdoc/clean/mod.rs
+4
-0
src/librustdoc/html/format.rs
src/librustdoc/html/format.rs
+10
-0
src/libsyntax/ast.rs
src/libsyntax/ast.rs
+2
-0
src/libsyntax/feature_gate.rs
src/libsyntax/feature_gate.rs
+8
-1
src/libsyntax/fold.rs
src/libsyntax/fold.rs
+3
-0
src/libsyntax/parse/parser.rs
src/libsyntax/parse/parser.rs
+20
-1
src/libsyntax/print/pprust.rs
src/libsyntax/print/pprust.rs
+3
-0
src/libsyntax/visit.rs
src/libsyntax/visit.rs
+3
-0
未找到文件。
src/librustc/hir/fold.rs
浏览文件 @
f0baec69
...
...
@@ -375,6 +375,9 @@ pub fn noop_fold_ty<T: Folder>(t: P<Ty>, fld: &mut T) -> P<Ty> {
TyPolyTraitRef
(
bounds
)
=>
{
TyPolyTraitRef
(
bounds
.move_map
(|
b
|
fld
.fold_ty_param_bound
(
b
)))
}
TyImplTrait
(
bounds
)
=>
{
TyImplTrait
(
bounds
.move_map
(|
b
|
fld
.fold_ty_param_bound
(
b
)))
}
},
span
:
fld
.new_span
(
span
),
}
...
...
src/librustc/hir/intravisit.rs
浏览文件 @
f0baec69
...
...
@@ -427,6 +427,9 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty) {
TyPolyTraitRef
(
ref
bounds
)
=>
{
walk_list!
(
visitor
,
visit_ty_param_bound
,
bounds
);
}
TyImplTrait
(
ref
bounds
)
=>
{
walk_list!
(
visitor
,
visit_ty_param_bound
,
bounds
);
}
TyTypeof
(
ref
expression
)
=>
{
visitor
.visit_expr
(
expression
)
}
...
...
src/librustc/hir/lowering.rs
浏览文件 @
f0baec69
...
...
@@ -293,8 +293,10 @@ fn lower_ty(&mut self, t: &Ty) -> P<hir::Ty> {
hir
::
TyTypeof
(
self
.lower_expr
(
expr
))
}
PolyTraitRef
(
ref
bounds
)
=>
{
let
bounds
=
bounds
.iter
()
.map
(|
b
|
self
.lower_ty_param_bound
(
b
))
.collect
();
hir
::
TyPolyTraitRef
(
bounds
)
hir
::
TyPolyTraitRef
(
self
.lower_bounds
(
bounds
))
}
ImplTrait
(
ref
bounds
)
=>
{
hir
::
TyImplTrait
(
self
.lower_bounds
(
bounds
))
}
Mac
(
_
)
=>
panic!
(
"TyMac should have been expanded by now."
),
},
...
...
src/librustc/hir/mod.rs
浏览文件 @
f0baec69
...
...
@@ -1132,6 +1132,8 @@ pub enum Ty_ {
TyObjectSum
(
P
<
Ty
>
,
TyParamBounds
),
/// A type like `for<'a> Foo<&'a Bar>`
TyPolyTraitRef
(
TyParamBounds
),
/// An `impl TraitA+TraitB` type.
TyImplTrait
(
TyParamBounds
),
/// Unused for now
TyTypeof
(
P
<
Expr
>
),
/// TyInfer means the type should be inferred instead of it having been
...
...
src/librustc/hir/print.rs
浏览文件 @
f0baec69
...
...
@@ -536,6 +536,9 @@ pub fn print_type(&mut self, ty: &hir::Ty) -> io::Result<()> {
hir
::
TyPolyTraitRef
(
ref
bounds
)
=>
{
self
.print_bounds
(
""
,
&
bounds
[
..
])
?
;
}
hir
::
TyImplTrait
(
ref
bounds
)
=>
{
self
.print_bounds
(
"impl "
,
&
bounds
[
..
])
?
;
}
hir
::
TyFixedLengthVec
(
ref
ty
,
ref
v
)
=>
{
word
(
&
mut
self
.s
,
"["
)
?
;
self
.print_type
(
&
ty
)
?
;
...
...
src/librustdoc/clean/mod.rs
浏览文件 @
f0baec69
...
...
@@ -1492,6 +1492,9 @@ pub enum Type {
// for<'a> Foo(&'a)
PolyTraitRef
(
Vec
<
TyParamBound
>
),
// impl TraitA+TraitB
ImplTrait
(
Vec
<
TyParamBound
>
),
}
#[derive(Clone,
RustcEncodable,
RustcDecodable,
PartialEq,
Eq,
Hash,
Copy,
Debug)]
...
...
@@ -1777,6 +1780,7 @@ fn clean(&self, cx: &DocContext) -> Type {
}
TyBareFn
(
ref
barefn
)
=>
BareFunction
(
box
barefn
.clean
(
cx
)),
TyPolyTraitRef
(
ref
bounds
)
=>
PolyTraitRef
(
bounds
.clean
(
cx
)),
TyImplTrait
(
ref
bounds
)
=>
ImplTrait
(
bounds
.clean
(
cx
)),
TyInfer
=>
Infer
,
TyTypeof
(
..
)
=>
panic!
(
"Unimplemented type {:?}"
,
self
.node
),
}
...
...
src/librustdoc/html/format.rs
浏览文件 @
f0baec69
...
...
@@ -539,6 +539,16 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
}
Ok
(())
}
clean
::
ImplTrait
(
ref
bounds
)
=>
{
write!
(
f
,
"impl "
)
?
;
for
(
i
,
bound
)
in
bounds
.iter
()
.enumerate
()
{
if
i
!=
0
{
write!
(
f
,
" + "
)
?
;
}
write!
(
f
,
"{}"
,
*
bound
)
?
;
}
Ok
(())
}
// It's pretty unsightly to look at `<A as B>::C` in output, and
// we've got hyperlinking on our side, so try to avoid longer
// notation as much as possible by making `C` a hyperlink to trait
...
...
src/libsyntax/ast.rs
浏览文件 @
f0baec69
...
...
@@ -1368,6 +1368,8 @@ pub enum TyKind {
ObjectSum
(
P
<
Ty
>
,
TyParamBounds
),
/// A type like `for<'a> Foo<&'a Bar>`
PolyTraitRef
(
TyParamBounds
),
/// An `impl TraitA+TraitB` type.
ImplTrait
(
TyParamBounds
),
/// No-op; kept solely so that we can pretty-print faithfully
Paren
(
P
<
Ty
>
),
/// Unused for now
...
...
src/libsyntax/feature_gate.rs
浏览文件 @
f0baec69
...
...
@@ -277,7 +277,10 @@ pub fn new() -> Features {
(
active
,
cfg_target_has_atomic
,
"1.9.0"
,
Some
(
32976
)),
// Allows `..` in tuple (struct) patterns
(
active
,
dotdot_in_tuple_patterns
,
"1.10.0"
,
Some
(
33627
))
(
active
,
dotdot_in_tuple_patterns
,
"1.10.0"
,
Some
(
33627
)),
// Allows `impl Trait` in function return types.
(
active
,
conservative_impl_trait
,
"1.12.0"
,
Some
(
34511
))
);
declare_features!
(
...
...
@@ -952,6 +955,10 @@ fn visit_ty(&mut self, ty: &ast::Ty) {
ast
::
TyKind
::
BareFn
(
ref
bare_fn_ty
)
=>
{
self
.check_abi
(
bare_fn_ty
.abi
,
ty
.span
);
}
ast
::
TyKind
::
ImplTrait
(
..
)
=>
{
gate_feature_post!
(
&
self
,
conservative_impl_trait
,
ty
.span
,
"`impl Trait` is experimental"
);
}
_
=>
{}
}
visit
::
walk_ty
(
self
,
ty
)
...
...
src/libsyntax/fold.rs
浏览文件 @
f0baec69
...
...
@@ -397,6 +397,9 @@ pub fn noop_fold_ty<T: Folder>(t: P<Ty>, fld: &mut T) -> P<Ty> {
TyKind
::
PolyTraitRef
(
bounds
)
=>
{
TyKind
::
PolyTraitRef
(
bounds
.move_map
(|
b
|
fld
.fold_ty_param_bound
(
b
)))
}
TyKind
::
ImplTrait
(
bounds
)
=>
{
TyKind
::
ImplTrait
(
bounds
.move_map
(|
b
|
fld
.fold_ty_param_bound
(
b
)))
}
TyKind
::
Mac
(
mac
)
=>
{
TyKind
::
Mac
(
fld
.fold_mac
(
mac
))
}
...
...
src/libsyntax/parse/parser.rs
浏览文件 @
f0baec69
...
...
@@ -1051,7 +1051,7 @@ pub fn get_lifetime(&mut self) -> ast::Ident {
pub
fn
parse_for_in_type
(
&
mut
self
)
->
PResult
<
'a
,
TyKind
>
{
/*
Parses whatever can come after a `for` keyword in a type.
The `for` has
already
been consumed.
The `for` has
n't
been consumed.
Deprecated:
...
...
@@ -1091,6 +1091,23 @@ pub fn parse_for_in_type(&mut self) -> PResult<'a, TyKind> {
}
}
pub
fn
parse_impl_trait_type
(
&
mut
self
)
->
PResult
<
'a
,
TyKind
>
{
/*
Parses whatever can come after a `impl` keyword in a type.
The `impl` has already been consumed.
*/
let
bounds
=
self
.parse_ty_param_bounds
(
BoundParsingMode
::
Modified
)
?
;
if
!
bounds
.iter
()
.any
(|
b
|
if
let
TraitTyParamBound
(
..
)
=
*
b
{
true
}
else
{
false
})
{
let
last_span
=
self
.last_span
;
self
.span_err
(
last_span
,
"at least one trait must be specified"
);
}
Ok
(
ast
::
TyKind
::
ImplTrait
(
bounds
))
}
pub
fn
parse_ty_path
(
&
mut
self
)
->
PResult
<
'a
,
TyKind
>
{
Ok
(
TyKind
::
Path
(
None
,
self
.parse_path
(
PathStyle
::
Type
)
?
))
}
...
...
@@ -1406,6 +1423,8 @@ pub fn parse_ty(&mut self) -> PResult<'a, P<Ty>> {
self
.parse_borrowed_pointee
()
?
}
else
if
self
.check_keyword
(
keywords
::
For
)
{
self
.parse_for_in_type
()
?
}
else
if
self
.eat_keyword
(
keywords
::
Impl
)
{
self
.parse_impl_trait_type
()
?
}
else
if
self
.token_is_bare_fn_keyword
()
{
// BARE FUNCTION
self
.parse_ty_bare_fn
(
Vec
::
new
())
?
...
...
src/libsyntax/print/pprust.rs
浏览文件 @
f0baec69
...
...
@@ -1018,6 +1018,9 @@ pub fn print_type(&mut self, ty: &ast::Ty) -> io::Result<()> {
ast
::
TyKind
::
PolyTraitRef
(
ref
bounds
)
=>
{
try!
(
self
.print_bounds
(
""
,
&
bounds
[
..
]));
}
ast
::
TyKind
::
ImplTrait
(
ref
bounds
)
=>
{
try!
(
self
.print_bounds
(
"impl "
,
&
bounds
[
..
]));
}
ast
::
TyKind
::
FixedLengthVec
(
ref
ty
,
ref
v
)
=>
{
try!
(
word
(
&
mut
self
.s
,
"["
));
try!
(
self
.print_type
(
&
ty
));
...
...
src/libsyntax/visit.rs
浏览文件 @
f0baec69
...
...
@@ -343,6 +343,9 @@ pub fn walk_ty<V: Visitor>(visitor: &mut V, typ: &Ty) {
TyKind
::
PolyTraitRef
(
ref
bounds
)
=>
{
walk_list!
(
visitor
,
visit_ty_param_bound
,
bounds
);
}
TyKind
::
ImplTrait
(
ref
bounds
)
=>
{
walk_list!
(
visitor
,
visit_ty_param_bound
,
bounds
);
}
TyKind
::
Typeof
(
ref
expression
)
=>
{
visitor
.visit_expr
(
expression
)
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录