Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
8387896d
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,发现更多精彩内容 >>
提交
8387896d
编写于
1月 09, 2012
作者:
G
Graydon Hoare
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove proto_sugar and 'lambda' as keyword, commit to fn@.
上级
f6ecbe88
变更
30
隐藏空白更改
内联
并排
Showing
30 changed file
with
72 addition
and
79 deletion
+72
-79
doc/keywords.txt
doc/keywords.txt
+1
-1
src/comp/metadata/tydecode.rs
src/comp/metadata/tydecode.rs
+1
-1
src/comp/metadata/tyencode.rs
src/comp/metadata/tyencode.rs
+1
-1
src/comp/middle/capture.rs
src/comp/middle/capture.rs
+5
-5
src/comp/middle/freevars.rs
src/comp/middle/freevars.rs
+2
-2
src/comp/middle/kind.rs
src/comp/middle/kind.rs
+2
-2
src/comp/middle/trans_closure.rs
src/comp/middle/trans_closure.rs
+5
-5
src/comp/middle/tstate/pre_post_conditions.rs
src/comp/middle/tstate/pre_post_conditions.rs
+1
-1
src/comp/middle/ty.rs
src/comp/middle/ty.rs
+3
-4
src/comp/middle/typeck.rs
src/comp/middle/typeck.rs
+11
-11
src/comp/syntax/ast.rs
src/comp/syntax/ast.rs
+1
-6
src/comp/syntax/parse/parser.rs
src/comp/syntax/parse/parser.rs
+6
-6
src/comp/syntax/print/pprust.rs
src/comp/syntax/print/pprust.rs
+1
-2
src/comp/syntax/visit.rs
src/comp/syntax/visit.rs
+1
-1
src/test/compile-fail/block-arg-used-as-lambda-with-illegal-cap.rs
...compile-fail/block-arg-used-as-lambda-with-illegal-cap.rs
+2
-2
src/test/compile-fail/cap-clause-illegal-cap.rs
src/test/compile-fail/cap-clause-illegal-cap.rs
+3
-3
src/test/compile-fail/fn-expr-type-state.rs
src/test/compile-fail/fn-expr-type-state.rs
+1
-1
src/test/compile-fail/lambda-mutate-nested.rs
src/test/compile-fail/lambda-mutate-nested.rs
+3
-3
src/test/compile-fail/lambda-mutate.rs
src/test/compile-fail/lambda-mutate.rs
+2
-2
src/test/compile-fail/sendfn-is-not-a-lambda.rs
src/test/compile-fail/sendfn-is-not-a-lambda.rs
+2
-2
src/test/pretty/cap-clause.rs
src/test/pretty/cap-clause.rs
+3
-3
src/test/run-fail/unwind-lambda.rs
src/test/run-fail/unwind-lambda.rs
+1
-1
src/test/run-pass/block-arg-call-as.rs
src/test/run-pass/block-arg-call-as.rs
+1
-1
src/test/run-pass/block-arg-used-as-lambda.rs
src/test/run-pass/block-arg-used-as-lambda.rs
+2
-2
src/test/run-pass/cap-clause-move.rs
src/test/run-pass/cap-clause-move.rs
+2
-2
src/test/run-pass/fn-type-infer.rs
src/test/run-pass/fn-type-infer.rs
+1
-1
src/test/run-pass/lambda-infer-unresolved.rs
src/test/run-pass/lambda-infer-unresolved.rs
+2
-2
src/test/run-pass/lambda-no-leak.rs
src/test/run-pass/lambda-no-leak.rs
+3
-3
src/test/run-pass/last-use-in-cap-clause.rs
src/test/run-pass/last-use-in-cap-clause.rs
+2
-2
src/test/run-pass/last-use-is-capture.rs
src/test/run-pass/last-use-is-capture.rs
+1
-1
未找到文件。
doc/keywords.txt
浏览文件 @
8387896d
...
...
@@ -7,7 +7,7 @@ do
else export
f32 f64 fail false float fn for
i16 i32 i64 i8 if import in int
l
ambda l
et log
let log
mod mutable
native note
obj
...
...
src/comp/metadata/tydecode.rs
浏览文件 @
8387896d
...
...
@@ -234,7 +234,7 @@ fn parse_ty(st: @pstate, conv: conv_did) -> ty::t {
ret
parse_ty_rust_fn
(
st
,
conv
,
ast
::
proto_send
);
}
'F'
{
ret
parse_ty_rust_fn
(
st
,
conv
,
ast
::
proto_shared
(
ast
::
sugar_normal
)
);
ret
parse_ty_rust_fn
(
st
,
conv
,
ast
::
proto_shared
);
}
'f'
{
ret
parse_ty_rust_fn
(
st
,
conv
,
ast
::
proto_bare
);
...
...
src/comp/metadata/tyencode.rs
浏览文件 @
8387896d
...
...
@@ -203,7 +203,7 @@ fn enc_sty(w: io::writer, cx: @ctxt, st: ty::sty) {
fn
enc_proto
(
w
:
io
::
writer
,
proto
:
proto
)
{
alt
proto
{
proto_send
.
{
w
.write_char
(
's'
);
}
proto_shared
(
_
)
{
w
.write_char
(
'F'
);
}
proto_shared
.
{
w
.write_char
(
'F'
);
}
proto_block
.
{
w
.write_char
(
'B'
);
}
proto_bare
.
{
w
.write_char
(
'f'
);
}
}
...
...
src/comp/middle/capture.rs
浏览文件 @
8387896d
...
...
@@ -34,7 +34,7 @@ fn check_capture_clause(tcx: ty::ctxt,
let
freevars
=
freevars
::
get_freevars
(
tcx
,
fn_expr_id
);
let
seen_defs
=
map
::
new_int_hash
();
let
check_capture_item
=
lambda
(
&&
cap_item
:
@
ast
::
capture_item
)
{
let
check_capture_item
=
fn
@
(
&&
cap_item
:
@
ast
::
capture_item
)
{
let
cap_def
=
tcx
.def_map
.get
(
cap_item
.id
);
if
!
vec
::
any
(
*
freevars
,
{|
fv
|
fv
.def
==
cap_def
})
{
tcx
.sess
.span_warn
(
...
...
@@ -52,7 +52,7 @@ fn check_capture_clause(tcx: ty::ctxt,
}
};
let
check_not_upvar
=
lambda
(
&&
cap_item
:
@
ast
::
capture_item
)
{
let
check_not_upvar
=
fn
@
(
&&
cap_item
:
@
ast
::
capture_item
)
{
alt
tcx
.def_map
.get
(
cap_item
.id
)
{
ast
::
def_upvar
(
_
,
_
,
_
)
{
tcx
.sess
.span_err
(
...
...
@@ -64,7 +64,7 @@ fn check_capture_clause(tcx: ty::ctxt,
}
};
let
check_block_captures
=
lambda
(
v
:
[
@
ast
::
capture_item
])
{
let
check_block_captures
=
fn
@
(
v
:
[
@
ast
::
capture_item
])
{
if
check
vec
::
is_not_empty
(
v
)
{
let
cap_item0
=
vec
::
head
(
v
);
tcx
.sess
.span_err
(
...
...
@@ -78,7 +78,7 @@ fn check_capture_clause(tcx: ty::ctxt,
check_block_captures
(
cap_clause
.copies
);
check_block_captures
(
cap_clause
.moves
);
}
ast
::
proto_bare
.
|
ast
::
proto_shared
(
_
)
|
ast
::
proto_send
.
{
ast
::
proto_bare
.
|
ast
::
proto_shared
.
|
ast
::
proto_send
.
{
vec
::
iter
(
cap_clause
.copies
,
check_capture_item
);
vec
::
iter
(
cap_clause
.moves
,
check_capture_item
);
vec
::
iter
(
cap_clause
.moves
,
check_not_upvar
);
...
...
@@ -113,7 +113,7 @@ fn compute_capture_vars(tcx: ty::ctxt,
let
implicit_mode
=
alt
fn_proto
{
ast
::
proto_block
.
{
cap_ref
}
ast
::
proto_bare
.
|
ast
::
proto_shared
(
_
)
|
ast
::
proto_send
.
{
cap_copy
}
ast
::
proto_bare
.
|
ast
::
proto_shared
.
|
ast
::
proto_send
.
{
cap_copy
}
};
vec
::
iter
(
*
freevars
)
{
|
fvar
|
...
...
src/comp/middle/freevars.rs
浏览文件 @
8387896d
...
...
@@ -37,7 +37,7 @@ fn collect_freevars(def_map: resolve::def_map, blk: ast::blk)
fn
ignore_item
(
_
i
:
@
ast
::
item
,
&&
_
depth
:
int
,
_
v
:
visit
::
vt
<
int
>
)
{
}
let
walk_expr
=
lambda
(
expr
:
@
ast
::
expr
,
&&
depth
:
int
,
v
:
visit
::
vt
<
int
>
)
{
fn
@
(
expr
:
@
ast
::
expr
,
&&
depth
:
int
,
v
:
visit
::
vt
<
int
>
)
{
alt
expr
.node
{
ast
::
expr_fn
(
proto
,
decl
,
_
,
captures
)
{
if
proto
!=
ast
::
proto_bare
{
...
...
@@ -89,7 +89,7 @@ fn annotate_freevars(def_map: resolve::def_map, crate: @ast::crate) ->
freevar_map
{
let
freevars
=
new_int_hash
();
let
walk_fn
=
lambda
(
_
fk
:
visit
::
fn_kind
,
_
decl
:
ast
::
fn_decl
,
let
walk_fn
=
fn
@
(
_
fk
:
visit
::
fn_kind
,
_
decl
:
ast
::
fn_decl
,
blk
:
ast
::
blk
,
_
sp
:
span
,
nid
:
ast
::
node_id
)
{
let
vars
=
collect_freevars
(
def_map
,
blk
);
freevars
.insert
(
nid
,
vars
);
...
...
src/comp/middle/kind.rs
浏览文件 @
8387896d
...
...
@@ -61,7 +61,7 @@ fn with_appropriate_checker(cx: ctx, id: node_id,
let
fty
=
ty
::
node_id_to_monotype
(
cx
.tcx
,
id
);
alt
ty
::
ty_fn_proto
(
cx
.tcx
,
fty
)
{
proto_send
.
{
b
(
check_send
);
}
proto_shared
(
_
)
{
b
(
check_copy
);
}
proto_shared
.
{
b
(
check_copy
);
}
proto_block
.
{
/* no check needed */
}
proto_bare
.
{
b
(
check_none
);
}
}
...
...
@@ -106,7 +106,7 @@ fn check_fn_cap_clause(cx: ctx,
});
//log("freevar_ids", freevar_ids);
with_appropriate_checker
(
cx
,
id
)
{
|
checker
|
let
check_var
=
lambda
(
&&
cap_item
:
@
capture_item
)
{
let
check_var
=
fn
@
(
&&
cap_item
:
@
capture_item
)
{
let
cap_def
=
cx
.tcx.def_map
.get
(
cap_item
.id
);
let
cap_def_id
=
ast_util
::
def_id_of_def
(
cap_def
)
.node
;
if
!
vec
::
member
(
cap_def_id
,
freevar_ids
)
{
...
...
src/comp/middle/trans_closure.rs
浏览文件 @
8387896d
...
...
@@ -208,7 +208,7 @@ fn allocate_cbox(bcx: @block_ctxt,
let
ccx
=
bcx_ccx
(
bcx
);
let
alloc_in_heap
=
lambda
(
bcx
:
@
block_ctxt
,
let
alloc_in_heap
=
fn
@
(
bcx
:
@
block_ctxt
,
xchgheap
:
bool
,
&
temp_cleanups
:
[
ValueRef
])
->
(
@
block_ctxt
,
ValueRef
)
{
...
...
@@ -520,7 +520,7 @@ fn trans_expr_fn(bcx: @block_ctxt,
let
llfn
=
decl_internal_cdecl_fn
(
ccx
.llmod
,
s
,
llfnty
);
register_fn
(
ccx
,
sp
,
sub_cx
.path
,
"anon fn"
,
[],
id
);
let
trans_closure_env
=
lambda
(
ck
:
ty
::
closure_kind
)
->
ValueRef
{
let
trans_closure_env
=
fn
@
(
ck
:
ty
::
closure_kind
)
->
ValueRef
{
let
cap_vars
=
capture
::
compute_capture_vars
(
ccx
.tcx
,
id
,
proto
,
cap_clause
);
let
{
llbox
,
cboxptr_ty
,
bcx
}
=
build_closure
(
bcx
,
cap_vars
,
ck
);
...
...
@@ -532,7 +532,7 @@ fn trans_expr_fn(bcx: @block_ctxt,
let
closure
=
alt
proto
{
ast
::
proto_block
.
{
trans_closure_env
(
ty
::
closure_block
)
}
ast
::
proto_shared
(
_
)
{
trans_closure_env
(
ty
::
closure_shared
)
}
ast
::
proto_shared
.
{
trans_closure_env
(
ty
::
closure_shared
)
}
ast
::
proto_send
.
{
trans_closure_env
(
ty
::
closure_send
)
}
ast
::
proto_bare
.
{
let
closure
=
C_null
(
T_opaque_cbox_ptr
(
ccx
));
...
...
@@ -660,7 +660,7 @@ fn make_fn_glue(
let
bcx
=
cx
;
let
tcx
=
bcx_tcx
(
cx
);
let
fn_env
=
lambda
(
ck
:
ty
::
closure_kind
)
->
@
block_ctxt
{
let
fn_env
=
fn
@
(
ck
:
ty
::
closure_kind
)
->
@
block_ctxt
{
let
box_cell_v
=
GEPi
(
cx
,
v
,
[
0
,
abi
::
fn_field_box
]);
let
box_ptr_v
=
Load
(
cx
,
box_cell_v
);
make_null_test
(
cx
,
box_ptr_v
)
{|
bcx
|
...
...
@@ -675,7 +675,7 @@ fn make_fn_glue(
ty
::
ty_fn
({
proto
:
ast
::
proto_send
.
,
_
})
{
fn_env
(
ty
::
closure_send
)
}
ty
::
ty_fn
({
proto
:
ast
::
proto_shared
(
_
)
,
_
})
{
ty
::
ty_fn
({
proto
:
ast
::
proto_shared
.
,
_
})
{
fn_env
(
ty
::
closure_shared
)
}
_
{
fail
"make_fn_glue invoked on non-function type"
}
...
...
src/comp/middle/tstate/pre_post_conditions.rs
浏览文件 @
8387896d
...
...
@@ -348,7 +348,7 @@ fn find_pre_post_expr(fcx: fn_ctxt, e: @expr) {
expr_fn
(
_
,
_
,
_
,
cap_clause
)
{
find_pre_post_expr_fn_upvars
(
fcx
,
e
);
let
use_cap_item
=
lambda
(
&&
cap_item
:
@
capture_item
)
{
let
use_cap_item
=
fn
@
(
&&
cap_item
:
@
capture_item
)
{
let
d
=
local_node_id_to_local_def_id
(
fcx
,
cap_item
.id
);
option
::
may
(
d
,
{
|
id
|
use_var
(
fcx
,
id
)
});
};
...
...
src/comp/middle/ty.rs
浏览文件 @
8387896d
...
...
@@ -1020,7 +1020,7 @@ fn type_needs_drop(cx: ctxt, ty: t) -> bool {
fn
proto_kind
(
p
:
proto
)
->
kind
{
alt
p
{
ast
::
proto_block
.
{
kind_noncopyable
}
ast
::
proto_shared
(
_
)
{
kind_copyable
}
ast
::
proto_shared
.
{
kind_copyable
}
ast
::
proto_send
.
{
kind_sendable
}
ast
::
proto_bare
.
{
kind_sendable
}
}
...
...
@@ -1563,7 +1563,7 @@ fn ty_fn_proto(cx: ctxt, fty: t) -> ast::proto {
ty
::
ty_fn
(
f
)
{
ret
f
.proto
;
}
ty
::
ty_native_fn
(
_
,
_
)
{
// FIXME: This should probably be proto_bare
ret
ast
::
proto_shared
(
ast
::
sugar_normal
)
;
ret
ast
::
proto_shared
;
}
_
{
cx
.sess
.bug
(
"ty_fn_proto() called on non-fn type"
);
}
}
...
...
@@ -1947,8 +1947,7 @@ fn sub_proto(p_sub: ast::proto, p_sup: ast::proto) -> bool {
(
_
,
ast
::
proto_block
.
)
{
true
}
(
ast
::
proto_bare
.
,
_
)
{
true
}
// Equal prototypes (modulo sugar) are always subprotos:
(
ast
::
proto_shared
(
_
),
ast
::
proto_shared
(
_
))
{
true
}
// Equal prototypes are always subprotos:
(
_
,
_
)
{
p_sub
==
p_sup
}
};
}
...
...
src/comp/middle/typeck.rs
浏览文件 @
8387896d
...
...
@@ -553,7 +553,7 @@ fn ty_of_obj_ctor(tcx: ty::ctxt, mode: mode, id: ast::ident, ob: ast::_obj,
let
t_field
=
ast_ty_to_ty
(
tcx
,
mode
,
f
.ty
);
t_inputs
+=
[{
mode
:
ast
::
by_copy
,
ty
:
t_field
}];
}
let
t_fn
=
ty
::
mk_fn
(
tcx
,
{
proto
:
ast
::
proto_shared
(
ast
::
sugar_normal
)
,
let
t_fn
=
ty
::
mk_fn
(
tcx
,
{
proto
:
ast
::
proto_shared
,
inputs
:
t_inputs
,
output
:
t_obj
.ty
,
ret_style
:
ast
::
return_val
,
constraints
:
[]});
let
tpt
=
{
bounds
:
ty_param_bounds
(
tcx
,
mode
,
ty_params
),
ty
:
t_fn
};
...
...
@@ -697,7 +697,7 @@ fn get_tag_variant_types(cx: @ctxt, tag_ty: ty::t,
}
// FIXME: this will be different for constrained types
ty
::
mk_fn
(
cx
.tcx
,
{
proto
:
ast
::
proto_shared
(
ast
::
sugar_normal
)
,
{
proto
:
ast
::
proto_shared
,
inputs
:
args
,
output
:
tag_ty
,
ret_style
:
ast
::
return_val
,
constraints
:
[]})
};
...
...
@@ -799,13 +799,13 @@ fn convert(cx: @ctxt, it: @ast::item) {
let
t_res
=
ty
::
mk_res
(
cx
.tcx
,
local_def
(
it
.id
),
t_arg
.ty
,
params
);
let
t_ctor
=
ty
::
mk_fn
(
cx
.tcx
,
{
proto
:
ast
::
proto_shared
(
ast
::
sugar_normal
)
,
proto
:
ast
::
proto_shared
,
inputs
:
[{
mode
:
ast
::
by_copy
with
t_arg
}],
output
:
t_res
,
ret_style
:
ast
::
return_val
,
constraints
:
[]
});
let
t_dtor
=
ty
::
mk_fn
(
cx
.tcx
,
{
proto
:
ast
::
proto_shared
(
ast
::
sugar_normal
)
,
proto
:
ast
::
proto_shared
,
inputs
:
[
t_arg
],
output
:
ty
::
mk_nil
(
cx
.tcx
),
ret_style
:
ast
::
return_val
,
constraints
:
[]
});
...
...
@@ -1172,9 +1172,9 @@ fn gather_locals(ccx: @crate_ctxt,
};
let
tcx
=
ccx
.tcx
;
let
next_var_id
=
lambda
()
->
int
{
let
rv
=
*
nvi
;
*
nvi
+=
1
;
ret
rv
;
};
let
next_var_id
=
fn
@
()
->
int
{
let
rv
=
*
nvi
;
*
nvi
+=
1
;
ret
rv
;
};
let
assign
=
lambda
(
nid
:
ast
::
node_id
,
ty_opt
:
option
::
t
<
ty
::
t
>
)
{
fn
@
(
nid
:
ast
::
node_id
,
ty_opt
:
option
::
t
<
ty
::
t
>
)
{
let
var_id
=
next_var_id
();
locals
.insert
(
nid
,
var_id
);
alt
ty_opt
{
...
...
@@ -1206,7 +1206,7 @@ fn gather_locals(ccx: @crate_ctxt,
// Add explicitly-declared locals.
let
visit_local
=
lambda
(
local
:
@
ast
::
local
,
&&
e
:
(),
v
:
visit
::
vt
<
()
>
)
{
fn
@
(
local
:
@
ast
::
local
,
&&
e
:
(),
v
:
visit
::
vt
<
()
>
)
{
let
local_ty
=
ast_ty_to_ty_crate_infer
(
ccx
,
local
.node.ty
);
assign
(
local
.node.id
,
local_ty
);
visit
::
visit_local
(
local
,
e
,
v
);
...
...
@@ -1214,7 +1214,7 @@ fn gather_locals(ccx: @crate_ctxt,
// Add pattern bindings.
let
visit_pat
=
lambda
(
p
:
@
ast
::
pat
,
&&
e
:
(),
v
:
visit
::
vt
<
()
>
)
{
fn
@
(
p
:
@
ast
::
pat
,
&&
e
:
(),
v
:
visit
::
vt
<
()
>
)
{
alt
p
.node
{
ast
::
pat_bind
(
_
,
_
)
{
assign
(
p
.id
,
none
);
}
_
{
/* no-op */
}
...
...
@@ -1726,7 +1726,7 @@ fn check_call_or_bind(fcx: @fn_ctxt, sp: span, f: @ast::expr,
// of arguments when we typecheck the functions. This isn't really the
// right way to do this.
let
check_args
=
lambda
(
check_blocks
:
bool
)
->
bool
{
fn
@
(
check_blocks
:
bool
)
->
bool
{
let
i
=
0u
;
let
bot
=
false
;
for
a_opt
:
option
::
t
<@
ast
::
expr
>
in
args
{
...
...
@@ -2179,7 +2179,7 @@ fn check_binop_type_compat(fcx: @fn_ctxt, span: span, ty: ty::t,
fn
lower_bound_proto
(
proto
:
ast
::
proto
)
->
ast
::
proto
{
// FIXME: This is right for bare fns, possibly not others
alt
proto
{
ast
::
proto_bare
.
{
ast
::
proto_shared
(
ast
::
sugar_normal
)
}
ast
::
proto_bare
.
{
ast
::
proto_shared
}
_
{
proto
}
}
}
...
...
@@ -2632,7 +2632,7 @@ fn check_const(ccx: @crate_ctxt, _sp: span, e: @ast::expr, id: ast::node_id) {
let
fcx
:
@
fn_ctxt
=
@
{
ret_ty
:
rty
,
purity
:
ast
::
pure_fn
,
proto
:
ast
::
proto_shared
(
ast
::
sugar_normal
)
,
proto
:
ast
::
proto_shared
,
var_bindings
:
ty
::
unify
::
mk_var_bindings
(),
locals
:
new_int_hash
::
<
int
>
(),
next_var_id
:
@
mutable
0
,
...
...
src/comp/syntax/ast.rs
浏览文件 @
8387896d
...
...
@@ -110,15 +110,10 @@
tag
mutability
{
mut
;
imm
;
maybe_mut
;
}
tag
proto_sugar
{
sugar_normal
;
sugar_sexy
;
}
tag
proto
{
proto_bare
;
proto_send
;
proto_shared
(
proto_sugar
)
;
proto_shared
;
proto_block
;
}
...
...
src/comp/syntax/parse/parser.rs
浏览文件 @
8387896d
...
...
@@ -168,7 +168,7 @@ fn bad_expr_word_table() -> hashmap<str, ()> {
let
words
=
new_str_hash
();
for
word
in
[
"mod"
,
"if"
,
"else"
,
"while"
,
"do"
,
"alt"
,
"for"
,
"break"
,
"cont"
,
"ret"
,
"be"
,
"fail"
,
"type"
,
"resource"
,
"check"
,
"assert"
,
"claim"
,
"native"
,
"fn"
,
"
lambda
"
,
"pure"
,
"assert"
,
"claim"
,
"native"
,
"fn"
,
"
fn@
"
,
"pure"
,
"unsafe"
,
"block"
,
"import"
,
"export"
,
"let"
,
"const"
,
"log"
,
"tag"
,
"obj"
,
"copy"
,
"sendfn"
,
"impl"
,
"iface"
]
{
words
.insert
(
word
,
());
...
...
@@ -514,8 +514,8 @@ fn parse_ty(p: parser, colons_before_params: bool) -> @ast::ty {
t
=
parse_ty_fn
(
proto
,
p
);
}
else
if
eat_word
(
p
,
"block"
)
{
t
=
parse_ty_fn
(
ast
::
proto_block
,
p
);
}
else
if
eat_word
(
p
,
"
lambda
"
)
{
t
=
parse_ty_fn
(
ast
::
proto_shared
(
ast
::
sugar_sexy
)
,
p
);
}
else
if
eat_word
(
p
,
"
fn@
"
)
{
t
=
parse_ty_fn
(
ast
::
proto_shared
,
p
);
}
else
if
eat_word
(
p
,
"sendfn"
)
{
t
=
parse_ty_fn
(
ast
::
proto_send
,
p
);
}
else
if
eat_word
(
p
,
"obj"
)
{
...
...
@@ -821,8 +821,8 @@ fn parse_bottom_expr(p: parser) -> pexpr {
ret
pexpr
(
parse_fn_expr
(
p
,
proto
));
}
else
if
eat_word
(
p
,
"block"
)
{
ret
pexpr
(
parse_fn_expr
(
p
,
ast
::
proto_block
));
}
else
if
eat_word
(
p
,
"
lambda
"
)
{
ret
pexpr
(
parse_fn_expr
(
p
,
ast
::
proto_shared
(
ast
::
sugar_sexy
)
));
}
else
if
eat_word
(
p
,
"
fn@
"
)
{
ret
pexpr
(
parse_fn_expr
(
p
,
ast
::
proto_shared
));
}
else
if
eat_word
(
p
,
"sendfn"
)
{
ret
pexpr
(
parse_fn_expr
(
p
,
ast
::
proto_send
));
}
else
if
eat_word
(
p
,
"unchecked"
)
{
...
...
@@ -2117,7 +2117,7 @@ fn parse_item_tag(p: parser, attrs: [ast::attribute]) -> @ast::item {
fn
parse_fn_ty_proto
(
p
:
parser
)
->
ast
::
proto
{
if
p
.peek
()
==
token
::
AT
{
p
.bump
();
ast
::
proto_shared
(
ast
::
sugar_normal
)
ast
::
proto_shared
}
else
{
ast
::
proto_bare
}
...
...
src/comp/syntax/print/pprust.rs
浏览文件 @
8387896d
...
...
@@ -1685,8 +1685,7 @@ fn proto_to_str(p: ast::proto) -> str {
ast
::
proto_bare
.
{
"fn"
}
ast
::
proto_block
.
{
"block"
}
ast
::
proto_send
.
{
"sendfn"
}
ast
::
proto_shared
(
ast
::
sugar_normal
.
)
{
"fn@"
}
ast
::
proto_shared
(
ast
::
sugar_sexy
.
)
{
"lambda"
}
ast
::
proto_shared
.
{
"fn@"
}
};
}
...
...
src/comp/syntax/visit.rs
浏览文件 @
8387896d
...
...
@@ -19,7 +19,7 @@
fk_item_fn
(
ident
,
[
ty_param
]);
//< an item declared with fn()
fk_method
(
ident
,
[
ty_param
]);
fk_res
(
ident
,
[
ty_param
]);
fk_anon
(
proto
);
//< an anonymous function like
lambda
(...)
fk_anon
(
proto
);
//< an anonymous function like
fn@
(...)
fk_fn_block
;
//< a block {||...}
}
...
...
src/test/compile-fail/block-arg-used-as-lambda-with-illegal-cap.rs
浏览文件 @
8387896d
// error-pattern: copying a noncopyable value
fn
to_lambda1
(
f
:
lambda
(
uint
)
->
uint
)
->
lambda
(
uint
)
->
uint
{
fn
to_lambda1
(
f
:
fn
@
(
uint
)
->
uint
)
->
fn
@
(
uint
)
->
uint
{
ret
f
;
}
fn
to_lambda2
(
b
:
block
(
uint
)
->
uint
)
->
lambda
(
uint
)
->
uint
{
fn
to_lambda2
(
b
:
block
(
uint
)
->
uint
)
->
fn
@
(
uint
)
->
uint
{
ret
to_lambda1
({|
x
|
b
(
x
)});
}
...
...
src/test/compile-fail/cap-clause-illegal-cap.rs
浏览文件 @
8387896d
// error-pattern: copying a noncopyable value
fn
to_lambda2
(
b
:
block
(
uint
)
->
uint
)
->
lambda
(
uint
)
->
uint
{
fn
to_lambda2
(
b
:
block
(
uint
)
->
uint
)
->
fn
@
(
uint
)
->
uint
{
// test case where copy clause specifies a value that is not used
// in
lambda
body, but value is illegal to copy:
ret
lambda
[
copy
b
](
u
:
uint
)
->
uint
{
22u
};
// in
fn@
body, but value is illegal to copy:
ret
fn
@
[
copy
b
](
u
:
uint
)
->
uint
{
22u
};
}
fn
main
()
{
...
...
src/test/compile-fail/fn-expr-type-state.rs
浏览文件 @
8387896d
// error-pattern:Unsatisfied precondition
fn
main
()
{
// Typestate should work even in a
lambda
. we should reject this program.
// Typestate should work even in a
fn@
. we should reject this program.
let
f
=
fn
()
->
int
{
let
i
:
int
;
ret
i
;
};
log
(
error
,
f
());
}
src/test/compile-fail/lambda-mutate-nested.rs
浏览文件 @
8387896d
// error-pattern:assigning to upvar
// Make sure that nesting a block within a
lambda
doesn't let us
// mutate upvars from a
lambda
.
// Make sure that nesting a block within a
fn@
doesn't let us
// mutate upvars from a
fn@
.
fn
f2
(
x
:
block
())
{
x
();
}
fn
main
()
{
let
i
=
0
;
let
ctr
=
lambda
()
->
int
{
f2
({||
i
=
i
+
1
;
});
ret
i
;
};
let
ctr
=
fn
@
()
->
int
{
f2
({||
i
=
i
+
1
;
});
ret
i
;
};
log
(
error
,
ctr
());
log
(
error
,
ctr
());
log
(
error
,
ctr
());
...
...
src/test/compile-fail/lambda-mutate.rs
浏览文件 @
8387896d
// error-pattern:assigning to upvar
// Make sure we can't write to upvars from
lambda
s
// Make sure we can't write to upvars from
fn@
s
fn
main
()
{
let
i
=
0
;
let
ctr
=
lambda
()
->
int
{
i
=
i
+
1
;
ret
i
;
};
let
ctr
=
fn
@
()
->
int
{
i
=
i
+
1
;
ret
i
;
};
log
(
error
,
ctr
());
log
(
error
,
ctr
());
log
(
error
,
ctr
());
...
...
src/test/compile-fail/sendfn-is-not-a-lambda.rs
浏览文件 @
8387896d
// error-pattern: mismatched types: expected `
lambda
(++uint) -> uint`
// error-pattern: mismatched types: expected `
fn@
(++uint) -> uint`
fn
test
(
f
:
lambda
(
uint
)
->
uint
)
->
uint
{
fn
test
(
f
:
fn
@
(
uint
)
->
uint
)
->
uint
{
ret
f
(
22u
);
}
...
...
src/test/pretty/cap-clause.rs
浏览文件 @
8387896d
...
...
@@ -4,9 +4,9 @@ fn main() {
let
x
=
1
;
let
y
=
2
;
let
z
=
3
;
let
l1
=
lambda
[
copy
x
]()
->
int
{
x
+
y
};
let
l2
=
lambda
[
copy
x
;
move
y
]()
->
int
{
x
+
y
};
let
l3
=
lambda
[
move
z
]()
->
int
{
z
};
let
l1
=
fn
@
[
copy
x
]()
->
int
{
x
+
y
};
let
l2
=
fn
@
[
copy
x
;
move
y
]()
->
int
{
x
+
y
};
let
l3
=
fn
@
[
move
z
]()
->
int
{
z
};
let
x
=
1
;
let
y
=
2
;
...
...
src/test/run-fail/unwind-lambda.rs
浏览文件 @
8387896d
...
...
@@ -8,7 +8,7 @@ fn (tasties: @str, macerate: block(str)) {
macerate
(
*
tasties
);
}
(
carrots
,
{
|
food
|
let
mush
=
food
+
cheese
;
l
ambda
()
{
l
et
_
=
fn
@
()
{
let
chew
=
mush
+
cheese
;
fail
"so yummy"
}
();
...
...
src/test/run-pass/block-arg-call-as.rs
浏览文件 @
8387896d
...
...
@@ -4,7 +4,7 @@ fn asSendfn( f : sendfn()->uint ) -> uint {
ret
f
();
}
fn
asLambda
(
f
:
lambda
()
->
uint
)
->
uint
{
fn
asLambda
(
f
:
fn
@
()
->
uint
)
->
uint
{
ret
f
();
}
...
...
src/test/run-pass/block-arg-used-as-lambda.rs
浏览文件 @
8387896d
fn
to_lambda
(
f
:
lambda
(
uint
)
->
uint
)
->
lambda
(
uint
)
->
uint
{
fn
to_lambda
(
f
:
fn
@
(
uint
)
->
uint
)
->
fn
@
(
uint
)
->
uint
{
ret
f
;
}
fn
main
()
{
let
x
:
lambda
(
uint
)
->
uint
=
to_lambda
({
|
x
|
x
*
2u
});
let
x
:
fn
@
(
uint
)
->
uint
=
to_lambda
({
|
x
|
x
*
2u
});
let
y
=
to_lambda
(
x
);
let
x_r
=
x
(
22u
);
...
...
src/test/run-pass/cap-clause-move.rs
浏览文件 @
8387896d
...
...
@@ -2,8 +2,8 @@ fn main() {
let
x
=
~
1
;
let
y
=
ptr
::
addr_of
(
*
x
)
as
uint
;
let
lam_copy
=
lambda
[
copy
x
]()
->
uint
{
ptr
::
addr_of
(
*
x
)
as
uint
};
let
lam_move
=
lambda
[
move
x
]()
->
uint
{
ptr
::
addr_of
(
*
x
)
as
uint
};
let
lam_copy
=
fn
@
[
copy
x
]()
->
uint
{
ptr
::
addr_of
(
*
x
)
as
uint
};
let
lam_move
=
fn
@
[
move
x
]()
->
uint
{
ptr
::
addr_of
(
*
x
)
as
uint
};
assert
lam_copy
()
!=
y
;
assert
lam_move
()
==
y
;
...
...
src/test/run-pass/fn-type-infer.rs
浏览文件 @
8387896d
fn
main
()
{
// We should be able to type infer inside of
lambda
s.
// We should be able to type infer inside of
fn@
s.
let
f
=
fn
()
{
let
i
=
10
;
};
}
src/test/run-pass/lambda-infer-unresolved.rs
浏览文件 @
8387896d
// This should typecheck even though the type of e is not fully
// resolved when we finish typechecking the
lambda
.
// resolved when we finish typechecking the
fn@
.
fn
main
()
{
let
e
=
@
{
mutable
refs
:
[],
n
:
0
};
let
f
=
lambda
()
{
log
(
error
,
e
.n
);
};
let
f
=
fn
@
()
{
log
(
error
,
e
.n
);
};
e
.refs
+=
[
1
];
}
src/test/run-pass/lambda-no-leak.rs
浏览文件 @
8387896d
// Make sure we don't leak
lambda
s in silly ways.
// Make sure we don't leak
fn@
s in silly ways.
fn
force
(
f
:
fn
@
())
{
f
()
}
fn
main
()
{
let
x
=
7
;
l
ambda
()
{
log
(
error
,
x
);
};
force
(
lambda
()
{
log
(
error
,
x
);
});
l
et
_
=
fn
@
()
{
log
(
error
,
x
);
};
force
(
fn
@
()
{
log
(
error
,
x
);
});
}
src/test/run-pass/last-use-in-cap-clause.rs
浏览文件 @
8387896d
// Make sure #1399 stays fixed
fn
foo
()
->
lambda
()
->
int
{
fn
foo
()
->
fn
@
()
->
int
{
let
k
=
~
22
;
let
_u
=
{
a
:
k
};
ret
lambda
[
move
k
]()
->
int
{
22
};
ret
fn
@
[
move
k
]()
->
int
{
22
};
}
fn
main
()
{
...
...
src/test/run-pass/last-use-is-capture.rs
浏览文件 @
8387896d
// Make sure #1399 stays fixed
fn
main
()
{
fn
invoke
(
f
:
lambda
())
{
f
();
}
fn
invoke
(
f
:
fn
@
())
{
f
();
}
let
k
=
~
22
;
let
_u
=
{
a
:
k
};
invoke
{||
log
(
error
,
k
);}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录