Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
d0fa4c62
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,发现更多精彩内容 >>
提交
d0fa4c62
编写于
11月 04, 2014
作者:
N
Niko Matsakis
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove the unboxed closure `|:|` notation from types and trait references completely.
上级
221edbae
变更
17
隐藏空白更改
内联
并排
Showing
17 changed file
with
29 addition
and
348 deletion
+29
-348
src/librustc/middle/resolve.rs
src/librustc/middle/resolve.rs
+1
-36
src/librustc/middle/resolve_lifetime.rs
src/librustc/middle/resolve_lifetime.rs
+0
-15
src/librustc/middle/save/mod.rs
src/librustc/middle/save/mod.rs
+1
-1
src/librustc/middle/typeck/astconv.rs
src/librustc/middle/typeck/astconv.rs
+1
-54
src/librustc/middle/typeck/collect.rs
src/librustc/middle/typeck/collect.rs
+2
-55
src/librustc/middle/typeck/infer/error_reporting.rs
src/librustc/middle/typeck/infer/error_reporting.rs
+0
-3
src/librustdoc/clean/inline.rs
src/librustdoc/clean/inline.rs
+0
-1
src/librustdoc/clean/mod.rs
src/librustdoc/clean/mod.rs
+0
-17
src/librustdoc/html/format.rs
src/librustdoc/html/format.rs
+1
-5
src/libsyntax/ast.rs
src/libsyntax/ast.rs
+0
-16
src/libsyntax/ast_map/mod.rs
src/libsyntax/ast_map/mod.rs
+0
-3
src/libsyntax/feature_gate.rs
src/libsyntax/feature_gate.rs
+0
-5
src/libsyntax/fold.rs
src/libsyntax/fold.rs
+0
-23
src/libsyntax/parse/parser.rs
src/libsyntax/parse/parser.rs
+16
-50
src/libsyntax/print/pprust.rs
src/libsyntax/print/pprust.rs
+6
-50
src/libsyntax/visit.rs
src/libsyntax/visit.rs
+0
-13
src/test/run-pass/unboxed-closures-manual-impl.rs
src/test/run-pass/unboxed-closures-manual-impl.rs
+1
-1
未找到文件。
src/librustc/middle/resolve.rs
浏览文件 @
d0fa4c62
...
...
@@ -40,7 +40,7 @@
use
syntax
::
ast
::{
TyF64
,
TyFloat
,
TyI
,
TyI8
,
TyI16
,
TyI32
,
TyI64
,
TyInt
};
use
syntax
::
ast
::{
TyParam
,
TyParamBound
,
TyPath
,
TyPtr
,
TyProc
,
TyQPath
};
use
syntax
::
ast
::{
TyRptr
,
TyStr
,
TyU
,
TyU8
,
TyU16
,
TyU32
,
TyU64
,
TyUint
};
use
syntax
::
ast
::{
TypeImplItem
,
Un
boxedFnTyParamBound
,
Un
namedField
};
use
syntax
::
ast
::{
TypeImplItem
,
UnnamedField
};
use
syntax
::
ast
::{
Variant
,
ViewItem
,
ViewItemExternCrate
};
use
syntax
::
ast
::{
ViewItemUse
,
ViewPathGlob
,
ViewPathList
,
ViewPathSimple
};
use
syntax
::
ast
::{
Visibility
};
...
...
@@ -4523,41 +4523,6 @@ fn resolve_type_parameter_bound(&mut self,
TraitTyParamBound
(
ref
tref
)
=>
{
self
.resolve_trait_reference
(
id
,
tref
,
reference_type
)
}
UnboxedFnTyParamBound
(
ref
unboxed_function
)
=>
{
match
self
.resolve_path
(
unboxed_function
.ref_id
,
&
unboxed_function
.path
,
TypeNS
,
true
)
{
None
=>
{
let
path_str
=
self
.path_names_to_string
(
&
unboxed_function
.path
);
self
.resolve_error
(
unboxed_function
.path.span
,
format!
(
"unresolved trait `{}`"
,
path_str
)
.as_slice
())
}
Some
(
def
)
=>
{
match
def
{
(
DefTrait
(
_
),
_
)
=>
{
self
.record_def
(
unboxed_function
.ref_id
,
def
);
}
_
=>
{
let
msg
=
format!
(
"`{}` is not a trait"
,
self
.path_names_to_string
(
&
unboxed_function
.path
));
self
.resolve_error
(
unboxed_function
.path.span
,
msg
.as_slice
());
}
}
}
}
for
argument
in
unboxed_function
.decl.inputs
.iter
()
{
self
.resolve_type
(
&*
argument
.ty
);
}
self
.resolve_type
(
&*
unboxed_function
.decl.output
);
}
RegionTyParamBound
(
..
)
=>
{}
}
}
...
...
src/librustc/middle/resolve_lifetime.rs
浏览文件 @
d0fa4c62
...
...
@@ -204,9 +204,6 @@ fn visit_ty_param_bounds(&mut self,
ast
::
TraitTyParamBound
(
ref
trait_ref
)
=>
{
self
.visit_trait_ref
(
trait_ref
);
}
ast
::
UnboxedFnTyParamBound
(
ref
fn_decl
)
=>
{
self
.visit_unboxed_fn_ty_param_bound
(
&**
fn_decl
);
}
ast
::
RegionTyParamBound
(
ref
lifetime
)
=>
{
self
.visit_lifetime_ref
(
lifetime
);
}
...
...
@@ -226,18 +223,6 @@ fn visit_trait_ref(&mut self, trait_ref: &ast::TraitRef) {
})
}
fn
visit_unboxed_fn_ty_param_bound
(
&
mut
self
,
bound
:
&
ast
::
UnboxedFnBound
)
{
self
.with
(|
scope
,
f
|
{
f
(
LateScope
(
bound
.ref_id
,
&
bound
.lifetimes
,
scope
))
},
|
v
|
{
for
argument
in
bound
.decl.inputs
.iter
()
{
v
.visit_ty
(
&*
argument
.ty
);
}
v
.visit_ty
(
&*
bound
.decl.output
);
})
}
/// Visits self by adding a scope and handling recursive walk over the contents with `walk`.
fn
visit_fn_decl
(
&
mut
self
,
n
:
ast
::
NodeId
,
...
...
src/librustc/middle/save/mod.rs
浏览文件 @
d0fa4c62
...
...
@@ -705,7 +705,7 @@ fn process_trait(&mut self,
ast
::
TraitTyParamBound
(
ref
trait_ref
)
=>
{
trait_ref
}
ast
::
UnboxedFnTyParamBound
(
..
)
|
ast
::
RegionTyParamBound
(
..
)
=>
{
ast
::
RegionTyParamBound
(
..
)
=>
{
continue
;
}
};
...
...
src/librustc/middle/typeck/astconv.rs
浏览文件 @
d0fa4c62
...
...
@@ -620,15 +620,6 @@ enum PointerTy {
Uniq
}
impl
PointerTy
{
fn
default_region
(
&
self
)
->
ty
::
Region
{
match
*
self
{
Uniq
=>
ty
::
ReStatic
,
RPtr
(
r
)
=>
r
,
}
}
}
pub
fn
trait_ref_for_unboxed_function
<
'tcx
,
AC
:
AstConv
<
'tcx
>
,
RS
:
RegionScope
>
(
this
:
&
AC
,
...
...
@@ -687,31 +678,6 @@ fn mk_pointer<'tcx, AC: AstConv<'tcx>, RS: RegionScope>(
let
ty
=
ast_ty_to_ty
(
this
,
rscope
,
&**
ty
);
return
constr
(
ty
::
mk_vec
(
tcx
,
ty
,
None
));
}
ast
::
TyUnboxedFn
(
ref
unboxed_function
)
=>
{
let
ty
::
TraitRef
{
def_id
,
substs
}
=
trait_ref_for_unboxed_function
(
this
,
rscope
,
unboxed_function
.kind
,
&*
unboxed_function
.decl
,
None
);
let
r
=
ptr_ty
.default_region
();
let
tr
=
ty
::
mk_trait
(
this
.tcx
(),
def_id
,
substs
,
ty
::
region_existential_bound
(
r
));
match
ptr_ty
{
Uniq
=>
{
return
ty
::
mk_uniq
(
this
.tcx
(),
tr
);
}
RPtr
(
r
)
=>
{
return
ty
::
mk_rptr
(
this
.tcx
(),
r
,
ty
::
mt
{
mutbl
:
a_seq_mutbl
,
ty
:
tr
});
}
}
}
ast
::
TyPath
(
ref
path
,
ref
opt_bounds
,
id
)
=>
{
// Note that the "bounds must be empty if path is not a trait"
// restriction is enforced in the below case for ty_path, which
...
...
@@ -941,11 +907,6 @@ pub fn ast_ty_to_ty<'tcx, AC: AstConv<'tcx>, RS: RegionScope>(
ty
::
mk_closure
(
tcx
,
fn_decl
)
}
ast
::
TyUnboxedFn
(
..
)
=>
{
tcx
.sess
.span_err
(
ast_ty
.span
,
"cannot use unboxed functions here"
);
ty
::
mk_err
()
}
ast
::
TyPath
(
ref
path
,
ref
bounds
,
id
)
=>
{
let
a_def
=
match
tcx
.def_map
.borrow
()
.find
(
&
id
)
{
None
=>
{
...
...
@@ -1425,8 +1386,7 @@ pub fn conv_existential_bounds<'tcx, AC: AstConv<'tcx>, RS:RegionScope>(
let
PartitionedBounds
{
builtin_bounds
,
trait_bounds
,
region_bounds
,
unboxed_fn_ty_bounds
}
=
region_bounds
}
=
partition_bounds
(
this
.tcx
(),
span
,
ast_bound_refs
.as_slice
());
if
!
trait_bounds
.is_empty
()
{
...
...
@@ -1437,13 +1397,6 @@ pub fn conv_existential_bounds<'tcx, AC: AstConv<'tcx>, RS:RegionScope>(
as closure or object bounds"
)
.as_slice
());
}
if
!
unboxed_fn_ty_bounds
.is_empty
()
{
this
.tcx
()
.sess
.span_err
(
span
,
format!
(
"only the builtin traits can be used
\
as closure or object bounds"
)
.as_slice
());
}
// The "main trait refs", rather annoyingly, have no type
// specified for the `Self` parameter of the trait. The reason for
// this is that they are, after all, *existential* types, and
...
...
@@ -1572,7 +1525,6 @@ fn compute_region_bound<'tcx, AC: AstConv<'tcx>, RS:RegionScope>(
pub
struct
PartitionedBounds
<
'a
>
{
pub
builtin_bounds
:
ty
::
BuiltinBounds
,
pub
trait_bounds
:
Vec
<&
'a
ast
::
TraitRef
>
,
pub
unboxed_fn_ty_bounds
:
Vec
<&
'a
ast
::
UnboxedFnBound
>
,
pub
region_bounds
:
Vec
<&
'a
ast
::
Lifetime
>
,
}
...
...
@@ -1590,7 +1542,6 @@ pub fn partition_bounds<'a>(tcx: &ty::ctxt,
let
mut
builtin_bounds
=
ty
::
empty_builtin_bounds
();
let
mut
region_bounds
=
Vec
::
new
();
let
mut
trait_bounds
=
Vec
::
new
();
let
mut
unboxed_fn_ty_bounds
=
Vec
::
new
();
let
mut
trait_def_ids
=
HashMap
::
new
();
for
&
ast_bound
in
ast_bounds
.iter
()
{
match
*
ast_bound
{
...
...
@@ -1635,9 +1586,6 @@ pub fn partition_bounds<'a>(tcx: &ty::ctxt,
ast
::
RegionTyParamBound
(
ref
l
)
=>
{
region_bounds
.push
(
l
);
}
ast
::
UnboxedFnTyParamBound
(
ref
unboxed_function
)
=>
{
unboxed_fn_ty_bounds
.push
(
&**
unboxed_function
);
}
}
}
...
...
@@ -1645,7 +1593,6 @@ pub fn partition_bounds<'a>(tcx: &ty::ctxt,
builtin_bounds
:
builtin_bounds
,
trait_bounds
:
trait_bounds
,
region_bounds
:
region_bounds
,
unboxed_fn_ty_bounds
:
unboxed_fn_ty_bounds
}
}
src/librustc/middle/typeck/collect.rs
浏览文件 @
d0fa4c62
...
...
@@ -638,7 +638,7 @@ pub fn ensure_no_ty_param_bounds(ccx: &CrateCtxt,
let
mut
bounds
=
bounds
.chain
(
ty_param
.unbound
.iter
());
for
bound
in
bounds
{
match
*
bound
{
ast
::
TraitTyParamBound
(
..
)
|
ast
::
UnboxedFnTyParamBound
(
..
)
=>
{
ast
::
TraitTyParamBound
(
..
)
=>
{
// According to accepted RFC #XXX, we should
// eventually accept these, but it will not be
// part of this PR. Still, convert to warning to
...
...
@@ -1356,20 +1356,6 @@ pub fn instantiate_trait_ref<'tcx,AC>(this: &AC,
}
}
pub
fn
instantiate_unboxed_fn_ty
<
'tcx
,
AC
>
(
this
:
&
AC
,
unboxed_function
:
&
ast
::
UnboxedFnTy
,
param_ty
:
ty
::
ParamTy
)
->
Rc
<
ty
::
TraitRef
>
where
AC
:
AstConv
<
'tcx
>
{
let
rscope
=
ExplicitRscope
;
let
param_ty
=
param_ty
.to_ty
(
this
.tcx
());
Rc
::
new
(
astconv
::
trait_ref_for_unboxed_function
(
this
,
&
rscope
,
unboxed_function
.kind
,
&*
unboxed_function
.decl
,
Some
(
param_ty
)))
}
fn
get_trait_def
(
ccx
:
&
CrateCtxt
,
trait_id
:
ast
::
DefId
)
->
Rc
<
ty
::
TraitDef
>
{
if
trait_id
.krate
!=
ast
::
LOCAL_CRATE
{
return
ty
::
lookup_trait_def
(
ccx
.tcx
,
trait_id
)
...
...
@@ -1879,7 +1865,6 @@ fn create_type_parameters_for_associated_types<'tcx,AC>(
// In the above example, `ast_trait_ref` is `Iterator`.
let
ast_trait_ref
=
match
*
bound
{
ast
::
TraitTyParamBound
(
ref
r
)
=>
r
,
ast
::
UnboxedFnTyParamBound
(
..
)
=>
{
continue
;
}
ast
::
RegionTyParamBound
(
..
)
=>
{
continue
;
}
};
...
...
@@ -2057,45 +2042,8 @@ fn conv_param_bounds<'tcx,AC>(this: &AC,
merge_param_bounds
(
this
.tcx
(),
param_ty
,
ast_bounds
,
where_clause
);
let
astconv
::
PartitionedBounds
{
builtin_bounds
,
trait_bounds
,
region_bounds
,
unboxed_fn_ty_bounds
}
=
region_bounds
}
=
astconv
::
partition_bounds
(
this
.tcx
(),
span
,
all_bounds
.as_slice
());
let
unboxed_fn_ty_bounds
=
unboxed_fn_ty_bounds
.into_iter
()
.map
(|
b
|
{
let
trait_id
=
(
*
this
.tcx
()
.def_map
.borrow
())[
b
.ref_id
]
.def_id
();
let
mut
kind
=
None
;
for
&
(
lang_item
,
this_kind
)
in
[
(
this
.tcx
()
.lang_items
.fn_trait
(),
ast
::
FnUnboxedClosureKind
),
(
this
.tcx
()
.lang_items
.fn_mut_trait
(),
ast
::
FnMutUnboxedClosureKind
),
(
this
.tcx
()
.lang_items
.fn_once_trait
(),
ast
::
FnOnceUnboxedClosureKind
)
]
.iter
()
{
if
Some
(
trait_id
)
==
lang_item
{
kind
=
Some
(
this_kind
);
break
}
}
let
kind
=
match
kind
{
Some
(
kind
)
=>
kind
,
None
=>
{
this
.tcx
()
.sess
.span_err
(
b
.path.span
,
"unboxed function trait must be one
\
of `Fn`, `FnMut`, or `FnOnce`"
);
ast
::
FnMutUnboxedClosureKind
}
};
let
rscope
=
ExplicitRscope
;
let
param_ty
=
param_ty
.to_ty
(
this
.tcx
());
Rc
::
new
(
astconv
::
trait_ref_for_unboxed_function
(
this
,
&
rscope
,
kind
,
&*
b
.decl
,
Some
(
param_ty
)))
});
let
trait_bounds
:
Vec
<
Rc
<
ty
::
TraitRef
>>
=
trait_bounds
.into_iter
()
.map
(|
b
|
{
...
...
@@ -2104,7 +2052,6 @@ fn conv_param_bounds<'tcx,AC>(this: &AC,
param_ty
.to_ty
(
this
.tcx
()),
Some
(
param_ty
.to_ty
(
this
.tcx
())))
})
.chain
(
unboxed_fn_ty_bounds
)
.collect
();
let
region_bounds
:
Vec
<
ty
::
Region
>
=
region_bounds
.into_iter
()
...
...
src/librustc/middle/typeck/infer/error_reporting.rs
浏览文件 @
d0fa4c62
...
...
@@ -1102,9 +1102,6 @@ fn rebuild_ty_param_bounds(&self,
// be passing down a map.
ast
::
RegionTyParamBound
(
lt
)
}
&
ast
::
UnboxedFnTyParamBound
(
ref
unboxed_function_type
)
=>
{
ast
::
UnboxedFnTyParamBound
((
*
unboxed_function_type
)
.clone
())
}
&
ast
::
TraitTyParamBound
(
ref
tr
)
=>
{
let
last_seg
=
tr
.path.segments
.last
()
.unwrap
();
let
mut
insert
=
Vec
::
new
();
...
...
src/librustdoc/clean/inline.rs
浏览文件 @
d0fa4c62
...
...
@@ -323,7 +323,6 @@ fn build_impl(cx: &DocContext, tcx: &ty::ctxt,
trait_
:
associated_trait
.clean
(
cx
)
.map
(|
bound
|
{
match
bound
{
clean
::
TraitBound
(
ty
)
=>
ty
,
clean
::
UnboxedFnBound
(
..
)
|
clean
::
RegionBound
(
..
)
=>
unreachable!
(),
}
}),
...
...
src/librustdoc/clean/mod.rs
浏览文件 @
d0fa4c62
...
...
@@ -476,7 +476,6 @@ fn clean(&self, cx: &DocContext) -> TyParam {
#[deriving(Clone,
Encodable,
Decodable,
PartialEq)]
pub
enum
TyParamBound
{
RegionBound
(
Lifetime
),
UnboxedFnBound
(
UnboxedFnType
),
TraitBound
(
Type
)
}
...
...
@@ -484,7 +483,6 @@ impl Clean<TyParamBound> for ast::TyParamBound {
fn
clean
(
&
self
,
cx
:
&
DocContext
)
->
TyParamBound
{
match
*
self
{
ast
::
RegionTyParamBound
(
lt
)
=>
RegionBound
(
lt
.clean
(
cx
)),
ast
::
UnboxedFnTyParamBound
(
ref
ty
)
=>
{
UnboxedFnBound
(
ty
.clean
(
cx
))
},
ast
::
TraitTyParamBound
(
ref
t
)
=>
TraitBound
(
t
.clean
(
cx
)),
}
}
...
...
@@ -599,21 +597,6 @@ fn clean(&self, cx: &DocContext) -> Option<Vec<TyParamBound>> {
}
}
#[deriving(Clone,
Encodable,
Decodable,
PartialEq)]
pub
struct
UnboxedFnType
{
pub
path
:
Path
,
pub
decl
:
FnDecl
}
impl
Clean
<
UnboxedFnType
>
for
ast
::
UnboxedFnBound
{
fn
clean
(
&
self
,
cx
:
&
DocContext
)
->
UnboxedFnType
{
UnboxedFnType
{
path
:
self
.path
.clean
(
cx
),
decl
:
self
.decl
.clean
(
cx
)
}
}
}
#[deriving(Clone,
Encodable,
Decodable,
PartialEq)]
pub
struct
Lifetime
(
String
);
...
...
src/librustdoc/html/format.rs
浏览文件 @
d0fa4c62
...
...
@@ -143,9 +143,6 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
clean
::
RegionBound
(
ref
lt
)
=>
{
write!
(
f
,
"{}"
,
*
lt
)
}
clean
::
UnboxedFnBound
(
ref
ty
)
=>
{
write!
(
f
,
"{}{}"
,
ty
.path
,
ty
.decl
)
}
clean
::
TraitBound
(
ref
ty
)
=>
{
write!
(
f
,
"{}"
,
*
ty
)
}
...
...
@@ -404,8 +401,7 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let
mut
ret
=
String
::
new
();
for
bound
in
decl
.bounds
.iter
()
{
match
*
bound
{
clean
::
RegionBound
(
..
)
|
clean
::
UnboxedFnBound
(
..
)
=>
{}
clean
::
RegionBound
(
..
)
=>
{}
clean
::
TraitBound
(
ref
t
)
=>
{
if
ret
.len
()
==
0
{
ret
.push_str
(
": "
);
...
...
src/libsyntax/ast.rs
浏览文件 @
d0fa4c62
...
...
@@ -308,20 +308,11 @@ pub struct DefId {
#[deriving(Clone,
PartialEq,
Eq,
Encodable,
Decodable,
Hash,
Show)]
pub
enum
TyParamBound
{
TraitTyParamBound
(
TraitRef
),
UnboxedFnTyParamBound
(
P
<
UnboxedFnBound
>
),
RegionTyParamBound
(
Lifetime
)
}
pub
type
TyParamBounds
=
OwnedSlice
<
TyParamBound
>
;
#[deriving(Clone,
PartialEq,
Eq,
Encodable,
Decodable,
Hash,
Show)]
pub
struct
UnboxedFnBound
{
pub
path
:
Path
,
pub
decl
:
P
<
FnDecl
>
,
pub
lifetimes
:
Vec
<
LifetimeDef
>
,
pub
ref_id
:
NodeId
,
}
#[deriving(Clone,
PartialEq,
Eq,
Encodable,
Decodable,
Hash,
Show)]
pub
struct
TyParam
{
pub
ident
:
Ident
,
...
...
@@ -1089,12 +1080,6 @@ pub struct BareFnTy {
pub
decl
:
P
<
FnDecl
>
}
#[deriving(Clone,
PartialEq,
Eq,
Encodable,
Decodable,
Hash,
Show)]
pub
struct
UnboxedFnTy
{
pub
kind
:
UnboxedClosureKind
,
pub
decl
:
P
<
FnDecl
>
,
}
#[deriving(Clone,
PartialEq,
Eq,
Encodable,
Decodable,
Hash,
Show)]
pub
enum
Ty_
{
TyNil
,
...
...
@@ -1107,7 +1092,6 @@ pub enum Ty_ {
TyClosure
(
P
<
ClosureTy
>
),
TyProc
(
P
<
ClosureTy
>
),
TyBareFn
(
P
<
BareFnTy
>
),
TyUnboxedFn
(
P
<
UnboxedFnTy
>
),
TyTup
(
Vec
<
P
<
Ty
>>
),
TyPath
(
Path
,
Option
<
TyParamBounds
>
,
NodeId
),
// for #7264; see above
/// A "qualified path", e.g. `<Vec<T> as SomeTrait>::SomeType`
...
...
src/libsyntax/ast_map/mod.rs
浏览文件 @
d0fa4c62
...
...
@@ -848,9 +848,6 @@ fn visit_ty(&mut self, ty: &'ast Ty) {
TyBareFn
(
ref
fd
)
=>
{
self
.visit_fn_decl
(
&*
fd
.decl
);
}
TyUnboxedFn
(
ref
fd
)
=>
{
self
.visit_fn_decl
(
&*
fd
.decl
);
}
_
=>
{}
}
visit
::
walk_ty
(
self
,
ty
);
...
...
src/libsyntax/feature_gate.rs
浏览文件 @
d0fa4c62
...
...
@@ -313,11 +313,6 @@ fn visit_ty(&mut self, t: &ast::Ty) {
experimental and likely to be removed"
);
},
ast
::
TyUnboxedFn
(
..
)
=>
{
self
.gate_feature
(
"unboxed_closure_sugar"
,
t
.span
,
"unboxed closure trait sugar is experimental"
);
}
_
=>
{}
}
...
...
src/libsyntax/fold.rs
浏览文件 @
d0fa4c62
...
...
@@ -424,12 +424,6 @@ pub fn noop_fold_ty<T: Folder>(t: P<Ty>, fld: &mut T) -> P<Ty> {
decl
:
fld
.fold_fn_decl
(
decl
)
}))
}
TyUnboxedFn
(
f
)
=>
{
TyUnboxedFn
(
f
.map
(|
UnboxedFnTy
{
decl
,
kind
}|
UnboxedFnTy
{
decl
:
fld
.fold_fn_decl
(
decl
),
kind
:
kind
,
}))
}
TyTup
(
tys
)
=>
TyTup
(
tys
.move_map
(|
ty
|
fld
.fold_ty
(
ty
))),
TyParen
(
ty
)
=>
TyParen
(
fld
.fold_ty
(
ty
)),
TyPath
(
path
,
bounds
,
id
)
=>
{
...
...
@@ -715,23 +709,6 @@ pub fn noop_fold_ty_param_bound<T>(tpb: TyParamBound, fld: &mut T)
match
tpb
{
TraitTyParamBound
(
ty
)
=>
TraitTyParamBound
(
fld
.fold_trait_ref
(
ty
)),
RegionTyParamBound
(
lifetime
)
=>
RegionTyParamBound
(
fld
.fold_lifetime
(
lifetime
)),
UnboxedFnTyParamBound
(
bound
)
=>
{
match
*
bound
{
UnboxedFnBound
{
ref
path
,
ref
decl
,
ref
lifetimes
,
ref_id
}
=>
{
UnboxedFnTyParamBound
(
P
(
UnboxedFnBound
{
path
:
fld
.fold_path
(
path
.clone
()),
decl
:
fld
.fold_fn_decl
(
decl
.clone
()),
lifetimes
:
fld
.fold_lifetime_defs
(
lifetimes
.clone
()),
ref_id
:
fld
.new_id
(
ref_id
),
}))
}
}
}
}
}
...
...
src/libsyntax/parse/parser.rs
浏览文件 @
d0fa4c62
...
...
@@ -53,9 +53,8 @@
use
ast
::{
TypeField
,
TyFixedLengthVec
,
TyClosure
,
TyProc
,
TyBareFn
};
use
ast
::{
TyTypeof
,
TyInfer
,
TypeMethod
};
use
ast
::{
TyNil
,
TyParam
,
TyParamBound
,
TyParen
,
TyPath
,
TyPtr
,
TyQPath
};
use
ast
::{
TyRptr
,
TyTup
,
TyU32
,
TyUn
boxedFn
,
TyUn
iq
,
TyVec
,
UnUniq
};
use
ast
::{
TyRptr
,
TyTup
,
TyU32
,
TyUniq
,
TyVec
,
UnUniq
};
use
ast
::{
TypeImplItem
,
TypeTraitItem
,
Typedef
,
UnboxedClosureKind
};
use
ast
::{
UnboxedFnBound
,
UnboxedFnTy
,
UnboxedFnTyParamBound
};
use
ast
::{
UnnamedField
,
UnsafeBlock
};
use
ast
::{
UnsafeFn
,
ViewItem
,
ViewItem_
,
ViewItemExternCrate
,
ViewItemUse
};
use
ast
::{
ViewPath
,
ViewPathGlob
,
ViewPathList
,
ViewPathSimple
};
...
...
@@ -1127,19 +1126,16 @@ pub fn parse_ty_closure(&mut self) -> Ty_ {
Vec
::
new
()
};
let
(
optional_unboxed_closure_kind
,
inputs
)
=
if
self
.eat
(
&
token
::
OrOr
)
{
(
None
,
Vec
::
new
()
)
let
inputs
=
if
self
.eat
(
&
token
::
OrOr
)
{
Vec
::
new
(
)
}
else
{
self
.expect_or
();
let
optional_unboxed_closure_kind
=
self
.parse_optional_unboxed_closure_kind
();
let
inputs
=
self
.parse_seq_to_before_or
(
&
token
::
Comma
,
|
p
|
p
.parse_arg_general
(
false
));
self
.expect_or
();
(
optional_unboxed_closure_kind
,
inputs
)
inputs
};
let
bounds
=
self
.parse_colon_then_ty_param_bounds
();
...
...
@@ -1152,23 +1148,13 @@ pub fn parse_ty_closure(&mut self) -> Ty_ {
variadic
:
false
});
match
optional_unboxed_closure_kind
{
Some
(
unboxed_closure_kind
)
=>
{
TyUnboxedFn
(
P
(
UnboxedFnTy
{
kind
:
unboxed_closure_kind
,
decl
:
decl
,
}))
}
None
=>
{
TyClosure
(
P
(
ClosureTy
{
fn_style
:
fn_style
,
onceness
:
onceness
,
bounds
:
bounds
,
decl
:
decl
,
lifetimes
:
lifetime_defs
,
}))
}
}
TyClosure
(
P
(
ClosureTy
{
fn_style
:
fn_style
,
onceness
:
onceness
,
bounds
:
bounds
,
decl
:
decl
,
lifetimes
:
lifetime_defs
,
}))
}
pub
fn
parse_unsafety
(
&
mut
self
)
->
FnStyle
{
...
...
@@ -3935,31 +3921,11 @@ fn parse_ty_param_bounds(&mut self)
token
::
ModSep
|
token
::
Ident
(
..
)
=>
{
let
path
=
self
.parse_path
(
LifetimeAndTypesWithoutColons
)
.path
;
if
self
.token
==
token
::
OpenDelim
(
token
::
Paren
)
{
self
.bump
();
let
inputs
=
self
.parse_seq_to_end
(
&
token
::
CloseDelim
(
token
::
Paren
),
seq_sep_trailing_allowed
(
token
::
Comma
),
|
p
|
p
.parse_arg_general
(
false
));
let
(
return_style
,
output
)
=
self
.parse_ret_ty
();
result
.push
(
UnboxedFnTyParamBound
(
P
(
UnboxedFnBound
{
path
:
path
,
decl
:
P
(
FnDecl
{
inputs
:
inputs
,
output
:
output
,
cf
:
return_style
,
variadic
:
false
,
}),
lifetimes
:
lifetime_defs
,
ref_id
:
ast
::
DUMMY_NODE_ID
,
})));
}
else
{
result
.push
(
TraitTyParamBound
(
ast
::
TraitRef
{
path
:
path
,
ref_id
:
ast
::
DUMMY_NODE_ID
,
lifetimes
:
lifetime_defs
,
}))
}
result
.push
(
TraitTyParamBound
(
ast
::
TraitRef
{
path
:
path
,
ref_id
:
ast
::
DUMMY_NODE_ID
,
lifetimes
:
lifetime_defs
,
}))
}
_
=>
break
,
}
...
...
src/libsyntax/print/pprust.rs
浏览文件 @
d0fa4c62
...
...
@@ -13,7 +13,7 @@
use
ast
::{
FnOnceUnboxedClosureKind
};
use
ast
::{
MethodImplItem
,
RegionTyParamBound
,
TraitTyParamBound
};
use
ast
::{
RequiredMethod
,
ProvidedMethod
,
TypeImplItem
,
TypeTraitItem
};
use
ast
::{
UnboxedClosureKind
,
UnboxedFnTyParamBound
};
use
ast
::{
UnboxedClosureKind
};
use
ast
;
use
ast_util
;
use
owned_slice
::
OwnedSlice
;
...
...
@@ -699,7 +699,6 @@ pub fn print_type(&mut self, ty: &ast::Ty) -> IoResult<()> {
None
,
&
OwnedSlice
::
empty
(),
Some
(
&
generics
),
None
,
None
));
}
ast
::
TyClosure
(
ref
f
)
=>
{
...
...
@@ -719,7 +718,6 @@ pub fn print_type(&mut self, ty: &ast::Ty) -> IoResult<()> {
None
,
&
f
.bounds
,
Some
(
&
generics
),
None
,
None
));
}
ast
::
TyProc
(
ref
f
)
=>
{
...
...
@@ -739,21 +737,8 @@ pub fn print_type(&mut self, ty: &ast::Ty) -> IoResult<()> {
None
,
&
f
.bounds
,
Some
(
&
generics
),
None
,
None
));
}
ast
::
TyUnboxedFn
(
ref
f
)
=>
{
try!
(
self
.print_ty_fn
(
None
,
None
,
ast
::
NormalFn
,
ast
::
Many
,
&*
f
.decl
,
None
,
&
OwnedSlice
::
empty
(),
None
,
None
,
Some
(
f
.kind
)));
}
ast
::
TyPath
(
ref
path
,
ref
bounds
,
_
)
=>
{
try!
(
self
.print_bounded_path
(
path
,
bounds
));
}
...
...
@@ -1212,8 +1197,7 @@ pub fn print_ty_method(&mut self, m: &ast::TypeMethod) -> IoResult<()> {
Some
(
m
.ident
),
&
OwnedSlice
::
empty
(),
Some
(
&
m
.generics
),
Some
(
&
m
.explicit_self.node
),
None
));
Some
(
&
m
.explicit_self.node
)));
word
(
&
mut
self
.s
,
";"
)
}
...
...
@@ -2407,15 +2391,6 @@ pub fn print_bounds(&mut self,
RegionTyParamBound
(
ref
lt
)
=>
{
self
.print_lifetime
(
lt
)
}
UnboxedFnTyParamBound
(
ref
unboxed_function_type
)
=>
{
try!
(
self
.print_path
(
&
unboxed_function_type
.path
,
false
));
try!
(
self
.popen
());
try!
(
self
.print_fn_args
(
&*
unboxed_function_type
.decl
,
None
));
try!
(
self
.pclose
());
self
.print_fn_output
(
&*
unboxed_function_type
.decl
)
}
})
}
Ok
(())
...
...
@@ -2675,9 +2650,7 @@ pub fn print_ty_fn(&mut self,
id
:
Option
<
ast
::
Ident
>
,
bounds
:
&
OwnedSlice
<
ast
::
TyParamBound
>
,
generics
:
Option
<&
ast
::
Generics
>
,
opt_explicit_self
:
Option
<&
ast
::
ExplicitSelf_
>
,
opt_unboxed_closure_kind
:
Option
<
ast
::
UnboxedClosureKind
>
)
opt_explicit_self
:
Option
<&
ast
::
ExplicitSelf_
>
)
->
IoResult
<
()
>
{
try!
(
self
.ibox
(
indent_unit
));
...
...
@@ -2694,9 +2667,7 @@ pub fn print_ty_fn(&mut self,
try!
(
self
.print_fn_style
(
fn_style
));
try!
(
self
.print_opt_abi_and_extern_if_nondefault
(
opt_abi
));
try!
(
self
.print_onceness
(
onceness
));
if
opt_unboxed_closure_kind
.is_none
()
{
try!
(
word
(
&
mut
self
.s
,
"fn"
));
}
try!
(
word
(
&
mut
self
.s
,
"fn"
));
}
match
id
{
...
...
@@ -2710,30 +2681,15 @@ pub fn print_ty_fn(&mut self,
match
generics
{
Some
(
g
)
=>
try!
(
self
.print_generics
(
g
)),
_
=>
()
}
try!
(
zerobreak
(
&
mut
self
.s
));
if
opt_
unboxed_closure_kind
.is_some
()
||
opt_
sigil
==
Some
(
'&'
)
{
if
opt_sigil
==
Some
(
'&'
)
{
try!
(
word
(
&
mut
self
.s
,
"|"
));
}
else
{
try!
(
self
.popen
());
}
match
opt_unboxed_closure_kind
{
Some
(
ast
::
FnUnboxedClosureKind
)
=>
{
try!
(
word
(
&
mut
self
.s
,
"&"
));
try!
(
self
.word_space
(
":"
));
}
Some
(
ast
::
FnMutUnboxedClosureKind
)
=>
{
try!
(
word
(
&
mut
self
.s
,
"&mut"
));
try!
(
self
.word_space
(
":"
));
}
Some
(
ast
::
FnOnceUnboxedClosureKind
)
=>
{
try!
(
self
.word_space
(
":"
));
}
None
=>
{}
}
try!
(
self
.print_fn_args
(
decl
,
opt_explicit_self
));
if
opt_
unboxed_closure_kind
.is_some
()
||
opt_
sigil
==
Some
(
'&'
)
{
if
opt_sigil
==
Some
(
'&'
)
{
try!
(
word
(
&
mut
self
.s
,
"|"
));
}
else
{
if
decl
.variadic
{
...
...
src/libsyntax/visit.rs
浏览文件 @
d0fa4c62
...
...
@@ -365,12 +365,6 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty) {
visitor
.visit_ty
(
&*
function_declaration
.decl.output
);
walk_lifetime_decls
(
visitor
,
&
function_declaration
.lifetimes
);
}
TyUnboxedFn
(
ref
function_declaration
)
=>
{
for
argument
in
function_declaration
.decl.inputs
.iter
()
{
visitor
.visit_ty
(
&*
argument
.ty
)
}
visitor
.visit_ty
(
&*
function_declaration
.decl.output
);
}
TyPath
(
ref
path
,
ref
opt_bounds
,
id
)
=>
{
visitor
.visit_path
(
path
,
id
);
match
*
opt_bounds
{
...
...
@@ -505,13 +499,6 @@ pub fn walk_ty_param_bounds<'v, V: Visitor<'v>>(visitor: &mut V,
TraitTyParamBound
(
ref
typ
)
=>
{
walk_trait_ref_helper
(
visitor
,
typ
)
}
UnboxedFnTyParamBound
(
ref
function_declaration
)
=>
{
for
argument
in
function_declaration
.decl.inputs
.iter
()
{
visitor
.visit_ty
(
&*
argument
.ty
)
}
visitor
.visit_ty
(
&*
function_declaration
.decl.output
);
walk_lifetime_decls
(
visitor
,
&
function_declaration
.lifetimes
);
}
RegionTyParamBound
(
ref
lifetime
)
=>
{
visitor
.visit_lifetime_ref
(
lifetime
);
}
...
...
src/test/run-pass/unboxed-closures-manual-impl.rs
浏览文件 @
d0fa4c62
...
...
@@ -25,7 +25,7 @@ fn call_it<F:FnMut(int)->int>(mut f: F, x: int) -> int {
f
.call_mut
((
x
,))
+
3
}
fn
call_box
(
f
:
&
mut
|
&
mut
:
int
|
->
int
,
x
:
int
)
->
int
{
fn
call_box
(
f
:
&
mut
FnMut
(
int
)
->
int
,
x
:
int
)
->
int
{
f
.call_mut
((
x
,))
+
3
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录