Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
22a14dd7
R
Rust
项目概览
int
/
Rust
12 个月 前同步成功
通知
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,发现更多精彩内容 >>
提交
22a14dd7
编写于
8月 09, 2012
作者:
N
Niko Matsakis
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Enforce a stricter notion of purity when borrowing. Fixes #3162.
上级
be2e4ef6
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
48 addition
and
2 deletion
+48
-2
src/rustc/middle/borrowck/check_loans.rs
src/rustc/middle/borrowck/check_loans.rs
+24
-2
src/test/compile-fail/borrowck-imm-ref-to-mut-rec-field-issue-3162-b.rs
...le-fail/borrowck-imm-ref-to-mut-rec-field-issue-3162-b.rs
+12
-0
src/test/compile-fail/borrowck-imm-ref-to-mut-rec-field-issue-3162.rs
...pile-fail/borrowck-imm-ref-to-mut-rec-field-issue-3162.rs
+12
-0
未找到文件。
src/rustc/middle/borrowck/check_loans.rs
浏览文件 @
22a14dd7
...
...
@@ -322,10 +322,32 @@ fn check_assignment(at: assignment_type, ex: @ast::expr) {
// is not visible from the outside
match
self
.purity
(
ex
.id
)
{
none
=>
(),
some
(
pc
)
=>
{
if
cmt
.lp
.is_none
()
{
some
(
pc
@
pc_cmt
(
_
))
=>
{
// Subtle: Issue #3162. If we are enforcing purity
// because there is a reference to aliasable, mutable data
// that we require to be immutable, we can't allow writes
// even to data owned by the current stack frame. This is
// because that aliasable data might have been located on
// the current stack frame, we don't know.
match
cmt
.lp
{
some
(
@
lp_local
(
*
))
|
some
(
@
lp_arg
(
*
))
=>
{
// it's ok to mutate a local variable, as it is either
// lent our or not. The problem arises when you have
// some subcomponent that might have been lent out
// through an alias on the condition that you ensure
// purity.
}
none
|
some
(
@
lp_comp
(
*
))
|
some
(
@
lp_deref
(
*
))
=>
{
self
.report_purity_error
(
pc
,
ex
.span
,
at
.ing_form
(
self
.bccx
.cmt_to_str
(
cmt
)));
}
}
}
some
(
pc_pure_fn
)
=>
{
if
cmt
.lp
.is_none
()
{
self
.report_purity_error
(
pc_pure_fn
,
ex
.span
,
at
.ing_form
(
self
.bccx
.cmt_to_str
(
cmt
)));
}
}
}
...
...
src/test/compile-fail/borrowck-imm-ref-to-mut-rec-field-issue-3162-b.rs
0 → 100644
浏览文件 @
22a14dd7
fn
each
<
T
>
(
x
:
&
[
T
],
op
:
fn
(
elem
:
&
T
)
->
bool
)
{
uint
::
range
(
0
,
x
.len
(),
|
i
|
op
(
&
x
[
i
]));
}
fn
main
()
{
let
x
=
[{
mut
a
:
0
}];
for
each
(
x
)
|
y
|
{
let
z
=
&
y
.a
;
//~ ERROR illegal borrow unless pure
x
[
0
]
.a
=
10
;
//~ NOTE impure due to assigning to mutable field
log
(
error
,
z
);
}
}
src/test/compile-fail/borrowck-imm-ref-to-mut-rec-field-issue-3162.rs
0 → 100644
浏览文件 @
22a14dd7
fn
each
<
T
>
(
x
:
&
[
T
],
op
:
fn
(
elem
:
&
T
)
->
bool
)
{
uint
::
range
(
0
,
x
.len
(),
|
i
|
op
(
&
x
[
i
]));
}
fn
main
()
{
let
x
=
~
[{
mut
a
:
0
}];
for
each
(
x
)
|
y
|
{
let
z
=
&
y
.a
;
//~ ERROR illegal borrow unless pure
x
[
0
]
.a
=
10
;
//~ NOTE impure due to assigning to mutable field
log
(
error
,
z
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录