Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
7a0c1ea5
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,发现更多精彩内容 >>
提交
7a0c1ea5
编写于
4月 30, 2013
作者:
N
Niko Matsakis
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
correct used_mut annotations for args, inherited case
上级
aa48a170
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
24 addition
and
61 deletion
+24
-61
src/librustc/middle/borrowck/check_loans.rs
src/librustc/middle/borrowck/check_loans.rs
+19
-14
src/librustc/middle/borrowck/gather_loans/lifetime.rs
src/librustc/middle/borrowck/gather_loans/lifetime.rs
+2
-2
src/librustc/middle/borrowck/gather_loans/mod.rs
src/librustc/middle/borrowck/gather_loans/mod.rs
+0
-39
src/librustc/middle/borrowck/gather_loans/restrictions.rs
src/librustc/middle/borrowck/gather_loans/restrictions.rs
+1
-3
src/librustc/middle/borrowck/mod.rs
src/librustc/middle/borrowck/mod.rs
+2
-3
未找到文件。
src/librustc/middle/borrowck/check_loans.rs
浏览文件 @
7a0c1ea5
...
...
@@ -260,11 +260,21 @@ fn check_assignment(&self, expr: @ast::expr) {
// and report an error otherwise.
match
cmt
.mutbl
{
mc
::
McDeclared
=>
{
// OK
// OK, but we have to mark arguments as requiring mut
// if they are assigned (other cases are handled by liveness,
// since we need to distinguish local variables assigned
// once vs those assigned multiple times)
match
cmt
.cat
{
mc
::
cat_self
(
*
)
|
mc
::
cat_arg
(
*
)
=>
{
mark_variable_as_used_mut
(
self
,
cmt
);
}
_
=>
{}
}
}
mc
::
McInherited
=>
{
// OK, but we may have to add an entry to `used_mut_nodes`
mark_
writes_through_upvars
_as_used_mut
(
self
,
cmt
);
mark_
variable
_as_used_mut
(
self
,
cmt
);
}
mc
::
McReadOnly
|
mc
::
McImmutable
=>
{
// Subtle: liveness guarantees that immutable local
...
...
@@ -289,33 +299,28 @@ fn check_assignment(&self, expr: @ast::expr) {
self
,
expr
,
cmt
);
}
fn
mark_
writes_through_upvars
_as_used_mut
(
self
:
&
CheckLoanCtxt
,
cmt
:
mc
::
cmt
)
{
fn
mark_
variable
_as_used_mut
(
self
:
&
CheckLoanCtxt
,
cmt
:
mc
::
cmt
)
{
//! If the mutability of the `cmt` being written is inherited
//! from a local variable
in another closure, liveness may
//! from a local variable
, liveness will
//! not have been able to detect that this variable's mutability
//! is important, so we must add the variable to the
//! `used_mut_nodes` table here. This is because liveness
//! does not consider closures.
//! `used_mut_nodes` table here.
let
mut
passed_upvar
=
false
;
let
mut
cmt
=
cmt
;
loop
{
debug!
(
"mark_writes_through_upvars_as_used_mut(cmt=%s)"
,
cmt
.repr
(
self
.tcx
()));
match
cmt
.cat
{
mc
::
cat_local
(
id
)
|
mc
::
cat_arg
(
id
,
_
)
|
mc
::
cat_arg
(
id
)
|
mc
::
cat_self
(
id
)
=>
{
if
passed_upvar
{
self
.tcx
()
.used_mut_nodes
.insert
(
id
);
}
self
.tcx
()
.used_mut_nodes
.insert
(
id
);
return
;
}
mc
::
cat_stack_upvar
(
b
)
=>
{
cmt
=
b
;
passed_upvar
=
true
;
}
mc
::
cat_rvalue
|
...
...
@@ -552,7 +557,7 @@ fn analyze_move_out_from_cmt(&self, cmt: mc::cmt) -> MoveError {
match
cmt
.cat
{
// Rvalues, locals, and arguments can be moved:
mc
::
cat_rvalue
|
mc
::
cat_local
(
_
)
|
mc
::
cat_arg
(
_
,
ast
::
by_copy
)
|
mc
::
cat_self
(
_
)
=>
{}
mc
::
cat_arg
(
_
)
|
mc
::
cat_self
(
_
)
=>
{}
// It seems strange to allow a move out of a static item,
// but what happens in practice is that you have a
...
...
src/librustc/middle/borrowck/gather_loans/lifetime.rs
浏览文件 @
7a0c1ea5
...
...
@@ -255,7 +255,7 @@ fn is_moved(&self, cmt: mc::cmt) -> bool {
match
cmt
.guarantor
()
.cat
{
mc
::
cat_local
(
id
)
|
mc
::
cat_self
(
id
)
|
mc
::
cat_arg
(
id
,
_
)
=>
{
mc
::
cat_arg
(
id
)
=>
{
self
.bccx.moved_variables_set
.contains
(
&
id
)
}
mc
::
cat_rvalue
|
...
...
@@ -292,7 +292,7 @@ fn scope(&self, cmt: mc::cmt) -> ty::Region {
ty
::
re_static
}
mc
::
cat_local
(
local_id
)
|
mc
::
cat_arg
(
local_id
,
_
)
|
mc
::
cat_arg
(
local_id
)
|
mc
::
cat_self
(
local_id
)
=>
{
self
.bccx.tcx.region_maps
.encl_region
(
local_id
)
}
...
...
src/librustc/middle/borrowck/gather_loans/mod.rs
浏览文件 @
7a0c1ea5
...
...
@@ -27,7 +27,6 @@
use
util
::
ppaux
::{
Repr
};
use
core
::
hashmap
::
HashSet
;
use
core
::
vec
;
use
syntax
::
ast
::{
m_const
,
m_imm
,
m_mutbl
};
use
syntax
::
ast
;
use
syntax
::
ast_util
::
id_range
;
...
...
@@ -169,20 +168,6 @@ fn gather_loans_in_expr(ex: @ast::expr,
visit
::
visit_expr
(
ex
,
self
,
vt
);
}
ast
::
expr_call
(
f
,
ref
args
,
_
)
=>
{
let
arg_tys
=
ty
::
ty_fn_args
(
ty
::
expr_ty
(
self
.tcx
(),
f
));
self
.guarantee_arguments
(
ex
,
*
args
,
arg_tys
);
visit
::
visit_expr
(
ex
,
self
,
vt
);
}
ast
::
expr_method_call
(
_
,
_
,
_
,
ref
args
,
_
)
=>
{
let
arg_tys
=
ty
::
ty_fn_args
(
ty
::
node_id_to_type
(
self
.tcx
(),
ex
.callee_id
));
self
.guarantee_arguments
(
ex
,
*
args
,
arg_tys
);
visit
::
visit_expr
(
ex
,
self
,
vt
);
}
ast
::
expr_match
(
ex_v
,
ref
arms
)
=>
{
let
cmt
=
self
.bccx
.cat_expr
(
ex_v
);
for
arms
.each
|
arm
|
{
...
...
@@ -271,30 +256,6 @@ fn pop_repeating_id(&mut self, id: ast::node_id) {
assert
!
(
id
==
popped
);
}
fn
guarantee_arguments
(
&
mut
self
,
call_expr
:
@
ast
::
expr
,
args
:
&
[
@
ast
::
expr
],
arg_tys
:
&
[
ty
::
arg
])
{
for
vec
::
each2
(
args
,
arg_tys
)
|
arg
,
arg_ty
|
{
match
ty
::
resolved_mode
(
self
.tcx
(),
arg_ty
.mode
)
{
ast
::
by_ref
=>
{
self
.guarantee_by_ref_argument
(
call_expr
,
*
arg
);
}
ast
::
by_copy
=>
{}
}
}
}
fn
guarantee_by_ref_argument
(
&
mut
self
,
call_expr
:
@
ast
::
expr
,
arg_expr
:
@
ast
::
expr
)
{
// FIXME(#5074) nested method calls
let
scope_r
=
ty
::
re_scope
(
call_expr
.id
);
let
arg_cmt
=
self
.bccx
.cat_expr
(
arg_expr
);
self
.guarantee_valid
(
arg_expr
.id
,
arg_expr
.span
,
arg_cmt
,
m_imm
,
scope_r
);
}
fn
guarantee_adjustments
(
&
mut
self
,
expr
:
@
ast
::
expr
,
adjustment
:
&
ty
::
AutoAdjustment
)
{
...
...
src/librustc/middle/borrowck/gather_loans/restrictions.rs
浏览文件 @
7a0c1ea5
...
...
@@ -15,7 +15,6 @@
use
mc
=
middle
::
mem_categorization
;
use
middle
::
ty
;
use
syntax
::
ast
::{
m_const
,
m_imm
,
m_mutbl
};
use
syntax
::
ast
;
use
syntax
::
codemap
::
span
;
pub
enum
RestrictionResult
{
...
...
@@ -74,7 +73,7 @@ fn compute(&self,
}
mc
::
cat_local
(
local_id
)
|
mc
::
cat_arg
(
local_id
,
ast
::
by_copy
)
|
mc
::
cat_arg
(
local_id
)
|
mc
::
cat_self
(
local_id
)
=>
{
let
lp
=
@
LpVar
(
local_id
);
SafeIf
(
lp
,
~
[
Restriction
{
loan_path
:
lp
,
...
...
@@ -114,7 +113,6 @@ fn compute(&self,
mc
::
cat_copied_upvar
(
*
)
|
// FIXME(#2152) allow mutation of upvars
mc
::
cat_static_item
(
*
)
|
mc
::
cat_implicit_self
(
*
)
|
mc
::
cat_arg
(
_
,
ast
::
by_ref
)
|
mc
::
cat_deref
(
_
,
_
,
mc
::
region_ptr
(
m_imm
,
_
))
|
mc
::
cat_deref
(
_
,
_
,
mc
::
gc_ptr
(
m_imm
))
=>
{
Safe
...
...
src/librustc/middle/borrowck/mod.rs
浏览文件 @
7a0c1ea5
...
...
@@ -242,13 +242,12 @@ pub fn opt_loan_path(cmt: mc::cmt) -> Option<@LoanPath> {
mc
::
cat_rvalue
|
mc
::
cat_static_item
|
mc
::
cat_copied_upvar
(
_
)
|
mc
::
cat_implicit_self
|
mc
::
cat_arg
(
_
,
ast
::
by_ref
)
=>
{
mc
::
cat_implicit_self
=>
{
None
}
mc
::
cat_local
(
id
)
|
mc
::
cat_arg
(
id
,
ast
::
by_copy
)
|
mc
::
cat_arg
(
id
)
|
mc
::
cat_self
(
id
)
=>
{
Some
(
@
LpVar
(
id
))
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录