Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
58b8e883
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,发现更多精彩内容 >>
提交
58b8e883
编写于
10月 06, 2011
作者:
N
Niko Matsakis
提交者:
Brian Anderson
10月 12, 2011
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
expand purity to include unsafe
上级
9476692b
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
29 addition
and
18 deletion
+29
-18
src/comp/middle/alias.rs
src/comp/middle/alias.rs
+22
-18
src/comp/middle/typeck.rs
src/comp/middle/typeck.rs
+1
-0
src/comp/syntax/ast.rs
src/comp/syntax/ast.rs
+1
-0
src/comp/syntax/parse/parser.rs
src/comp/syntax/parse/parser.rs
+5
-0
未找到文件。
src/comp/middle/alias.rs
浏览文件 @
58b8e883
...
...
@@ -29,10 +29,10 @@
type
scope
=
{
bs
:
[
binding
],
ret_info
:
ret_info
};
fn
mk_binding
(
cx
:
ctx
,
id
:
node_id
,
span
:
span
,
root_var
:
option
::
t
<
node_id
>
,
unsafe
:
[
unsafe_ty
])
->
binding
{
unsafe
_tys
:
[
unsafe_ty
])
->
binding
{
ret
@
{
node_id
:
id
,
span
:
span
,
root_var
:
root_var
,
local_id
:
local_id_of_node
(
cx
,
id
),
unsafe_tys
:
unsafe
,
mutable
ok
:
valid
,
unsafe_tys
:
unsafe
_tys
,
mutable
ok
:
valid
,
mutable
copied
:
not_copied
};
}
...
...
@@ -284,12 +284,12 @@ fn check_call(cx: ctx, f: @ast::expr, args: [@ast::expr]) -> [binding] {
}
let
j
=
0u
;
for
b
in
bindings
{
for
unsafe
in
b
.unsafe_tys
{
for
unsafe
_ty
in
b
.unsafe_tys
{
let
i
=
0u
;
for
arg_t
:
ty
::
arg
in
arg_ts
{
let
mut_alias
=
arg_t
.mode
==
ast
::
by_mut_ref
;
if
i
!=
j
&&
ty_can_unsafely_include
(
cx
,
unsafe
,
arg_t
.ty
,
ty_can_unsafely_include
(
cx
,
unsafe
_ty
,
arg_t
.ty
,
mut_alias
)
&&
cant_copy
(
cx
,
b
)
{
cx
.tcx.sess
.span_err
...
...
@@ -397,24 +397,28 @@ fn check_alt(cx: ctx, input: @ast::expr, arms: [ast::arm], sc: scope,
let
new_bs
=
sc
.bs
;
let
root_var
=
path_def_id
(
cx
,
root
.ex
);
let
pat_id_map
=
ast_util
::
pat_id_map
(
a
.pats
[
0
]);
type
info
=
{
id
:
node_id
,
mutable
unsafe
:
[
unsafe_ty
],
span
:
span
};
type
info
=
{
id
:
node_id
,
mutable
unsafe_tys
:
[
unsafe_ty
],
span
:
span
};
let
binding_info
:
[
info
]
=
[];
for
pat
in
a
.pats
{
for
proot
in
pattern_roots
(
cx
.tcx
,
root
.mut
,
pat
)
{
let
canon_id
=
pat_id_map
.get
(
proot
.name
);
alt
vec
::
find
({|
x
|
x
.id
==
canon_id
},
binding_info
)
{
some
(
s
)
{
s
.unsafe
+=
unsafe_set
(
proot
.mut
);
}
some
(
s
)
{
s
.unsafe
_tys
+=
unsafe_set
(
proot
.mut
);
}
none
.
{
binding_info
+=
[{
id
:
canon_id
,
mutable
unsafe
:
unsafe_set
(
proot
.mut
),
span
:
proot
.span
}];
binding_info
+=
[
{
id
:
canon_id
,
mutable
unsafe_tys
:
unsafe_set
(
proot
.mut
),
span
:
proot
.span
}];
}
}
}
}
for
info
in
binding_info
{
new_bs
+=
[
mk_binding
(
cx
,
info
.id
,
info
.span
,
root_var
,
copy
info
.unsafe
)];
copy
info
.unsafe
_tys
)];
}
visit
::
visit_arm
(
a
,
{
bs
:
new_bs
with
sc
},
v
);
}
...
...
@@ -470,8 +474,8 @@ fn check_var(cx: ctx, ex: @ast::expr, p: ast::path, id: ast::node_id,
for
b
in
sc
.bs
{
// excludes variables introduced since the alias was made
if
my_local_id
<
b
.local_id
{
for
unsafe
in
b
.unsafe_tys
{
if
ty_can_unsafely_include
(
cx
,
unsafe
,
var_t
,
assign
)
{
for
unsafe
_ty
in
b
.unsafe_tys
{
if
ty_can_unsafely_include
(
cx
,
unsafe
_ty
,
var_t
,
assign
)
{
b
.ok
=
val_taken
(
ex
.span
,
p
);
}
}
...
...
@@ -689,9 +693,9 @@ fn walk(tcx: ty::ctxt, mut: option::t<unsafe_ty>, pat: @ast::pat,
fn
expr_root
(
cx
:
ctx
,
ex
:
@
ast
::
expr
,
autoderef
:
bool
)
->
{
ex
:
@
ast
::
expr
,
mut
:
option
::
t
<
unsafe_ty
>
}
{
let
base_root
=
mut
::
expr_root
(
cx
.tcx
,
ex
,
autoderef
);
let
unsafe
=
none
;
let
unsafe
_ty
=
none
;
for
d
in
*
base_root
.ds
{
if
d
.mut
{
unsafe
=
some
(
contains
(
d
.outer_t
));
break
;
}
if
d
.mut
{
unsafe
_ty
=
some
(
contains
(
d
.outer_t
));
break
;
}
}
if
is_none
(
path_def_id
(
cx
,
base_root
.ex
))
{
alt
base_root
.ex.node
{
...
...
@@ -703,10 +707,10 @@ fn expr_root(cx: ctx, ex: @ast::expr, autoderef: bool)
let
arg_root
=
expr_root
(
cx
,
arg
,
false
);
if
mut
{
let
ret_ty
=
ty
::
expr_ty
(
cx
.tcx
,
base_root
.ex
);
unsafe
=
some
(
mut_contains
(
ret_ty
));
unsafe
_ty
=
some
(
mut_contains
(
ret_ty
));
}
if
!
is_none
(
arg_root
.mut
)
{
unsafe
=
arg_root
.mut
;
}
ret
{
ex
:
arg_root
.ex
,
mut
:
unsafe
};
if
!
is_none
(
arg_root
.mut
)
{
unsafe
_ty
=
arg_root
.mut
;
}
ret
{
ex
:
arg_root
.ex
,
mut
:
unsafe
_ty
};
}
_
{}
}
...
...
@@ -714,7 +718,7 @@ fn expr_root(cx: ctx, ex: @ast::expr, autoderef: bool)
_
{}
}
}
ret
{
ex
:
base_root
.ex
,
mut
:
unsafe
};
ret
{
ex
:
base_root
.ex
,
mut
:
unsafe
_ty
};
}
fn
unsafe_set
(
from
:
option
::
t
<
unsafe_ty
>
)
->
[
unsafe_ty
]
{
...
...
src/comp/middle/typeck.rs
浏览文件 @
58b8e883
...
...
@@ -1525,6 +1525,7 @@ fn matches(name: str, f: ty::field) -> bool {
fn
require_impure
(
sess
:
session
::
session
,
f_purity
:
ast
::
purity
,
sp
:
span
)
{
alt
f_purity
{
ast
::
unsafe_fn
.
{
ret
;
}
ast
::
impure_fn
.
{
ret
;
}
ast
::
pure_fn
.
{
sess
.span_fatal
(
sp
,
"Found impure expression in pure function decl"
);
...
...
src/comp/syntax/ast.rs
浏览文件 @
58b8e883
...
...
@@ -390,6 +390,7 @@
tag
purity
{
pure_fn
;
// declared with "pure fn"
unsafe_fn
;
// declared with "unsafe fn"
impure_fn
;
// declared with "fn"
}
...
...
src/comp/syntax/parse/parser.rs
浏览文件 @
58b8e883
...
...
@@ -165,6 +165,7 @@ fn bad_expr_word_table() -> hashmap<str, ()> {
words
.insert
(
"fn"
,
());
words
.insert
(
"lambda"
,
());
words
.insert
(
"pure"
,
());
words
.insert
(
"unsafe"
,
());
words
.insert
(
"iter"
,
());
words
.insert
(
"block"
,
());
words
.insert
(
"import"
,
());
...
...
@@ -2153,6 +2154,10 @@ fn parse_item(p: parser, attrs: [ast::attribute]) -> option::t<@ast::item> {
let
proto
=
parse_fn_proto
(
p
);
ret
some
(
parse_item_fn_or_iter
(
p
,
ast
::
pure_fn
,
proto
,
attrs
,
ast
::
il_normal
));
}
else
if
eat_word
(
p
,
"unsafe"
)
{
expect_word
(
p
,
"fn"
);
ret
some
(
parse_item_fn_or_iter
(
p
,
ast
::
unsafe_fn
,
ast
::
proto_fn
,
attrs
,
ast
::
il_normal
));
}
else
if
eat_word
(
p
,
"iter"
)
{
ret
some
(
parse_item_fn_or_iter
(
p
,
ast
::
impure_fn
,
ast
::
proto_iter
,
attrs
,
ast
::
il_normal
));
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录