Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
e319f409
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,发现更多精彩内容 >>
提交
e319f409
编写于
9月 22, 2017
作者:
F
Felix S. Klock II
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove now dead code.
上级
d9d10c16
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
1 addition
and
299 deletion
+1
-299
src/librustc_mir/borrow_check.rs
src/librustc_mir/borrow_check.rs
+1
-299
未找到文件。
src/librustc_mir/borrow_check.rs
浏览文件 @
e319f409
...
...
@@ -544,19 +544,6 @@ fn consume_lvalue(&mut self,
}
}
}
#[cfg(not_anymore)]
fn
borrow
(
&
mut
self
,
context
:
Context
,
location
:
Location
,
bk
:
BorrowKind
,
lvalue_span
:
(
&
Lvalue
<
'gcx
>
,
Span
),
flow_state
:
&
InProgress
<
'b
,
'gcx
>
)
{
debug!
(
"borrow location: {:?} lvalue: {:?} span: {:?}"
,
location
,
lvalue_span
.0
,
lvalue_span
.1
);
self
.check_if_path_is_moved
(
context
,
lvalue_span
,
flow_state
);
self
.check_for_conflicting_loans
(
context
,
location
,
bk
,
lvalue_span
,
flow_state
);
}
}
impl
<
'c
,
'b
,
'a
:
'b
+
'c
,
'gcx
,
'tcx
:
'a
>
MirBorrowckCtxt
<
'c
,
'b
,
'a
,
'gcx
,
'tcx
>
{
...
...
@@ -697,64 +684,7 @@ fn check_if_assigned_path_is_moved(&mut self,
}
}
}
#[cfg(not_anymore)]
fn
check_for_conflicting_loans
(
&
mut
self
,
context
:
Context
,
_
location
:
Location
,
_
bk
:
BorrowKind
,
lvalue_span
:
(
&
Lvalue
<
'gcx
>
,
Span
),
flow_state
:
&
InProgress
<
'b
,
'gcx
>
)
{
// NOTE FIXME: The analogous code in old borrowck
// check_loans.rs is careful to iterate over every *issued*
// loan, as opposed to just the in scope ones.
//
// (Or if you prefer, all the *other* iterations over loans
// only consider loans that are in scope of some given
// region::Scope)
//
// The (currently skeletal) code here does not encode such a
// distinction, which means it is almost certainly over
// looking something.
//
// (It is probably going to reject code that should be
// accepted, I suspect, by treated issued-but-out-of-scope
// loans as issued-and-in-scope, and thus causing them to
// interfere with other loans.)
//
// However, I just want to get something running, especially
// since I am trying to move into new territory with NLL, so
// lets get this going first, and then address the issued vs
// in-scope distinction later.
let
state
=
&
flow_state
.borrows
;
let
data
=
&
state
.base_results
.operator
()
.borrows
();
debug!
(
"check_for_conflicting_loans location: {:?}"
,
_
location
);
// does any loan generated here conflict with a previously issued loan?
let
mut
loans_generated
=
0
;
for
(
g
,
gen
)
in
state
.elems_generated
()
.map
(|
g
|
(
g
,
&
data
[
g
]))
{
loans_generated
+=
1
;
for
(
i
,
issued
)
in
state
.elems_incoming
()
.map
(|
i
|
(
i
,
&
data
[
i
]))
{
debug!
(
"check_for_conflicting_loans gen: {:?} issued: {:?} conflicts: {}"
,
(
g
,
gen
,
self
.base_path
(
&
gen
.lvalue
),
self
.restrictions
(
&
gen
.lvalue
)
.collect
::
<
Vec
<
_
>>
()),
(
i
,
issued
,
self
.base_path
(
&
issued
.lvalue
),
self
.restrictions
(
&
issued
.lvalue
)
.collect
::
<
Vec
<
_
>>
()),
self
.conflicts_with
(
gen
,
issued
));
if
self
.conflicts_with
(
gen
,
issued
)
{
self
.report_conflicting_borrow
(
context
,
lvalue_span
,
gen
,
issued
);
}
}
}
// MIR statically ensures each statement gens *at most one*
// loan; mutual conflict (within a statement) can't arise.
//
// As safe-guard, assert that above property actually holds.
assert
!
(
loans_generated
<=
1
);
}
}
}
impl
<
'c
,
'b
,
'a
:
'b
+
'c
,
'gcx
,
'tcx
:
'a
>
MirBorrowckCtxt
<
'c
,
'b
,
'a
,
'gcx
,
'tcx
>
{
fn
each_borrow_involving_path
<
F
>
(
&
mut
self
,
...
...
@@ -954,194 +884,6 @@ fn next(&mut self) -> Option<Self::Item> {
}
}
}
}
#[cfg(not_anymore)]
mod
restrictions
{
use
super
::
MirBorrowckCtxt
;
use
rustc
::
hir
;
use
rustc
::
ty
::{
self
,
TyCtxt
};
use
rustc
::
mir
::{
Lvalue
,
Mir
,
ProjectionElem
};
pub
(
super
)
struct
Restrictions
<
'c
,
'tcx
:
'c
>
{
mir
:
&
'c
Mir
<
'tcx
>
,
tcx
:
TyCtxt
<
'c
,
'tcx
,
'tcx
>
,
lvalue_stack
:
Vec
<&
'c
Lvalue
<
'tcx
>>
,
}
impl
<
'c
,
'b
,
'a
:
'b
+
'c
,
'gcx
,
'tcx
:
'a
>
MirBorrowckCtxt
<
'c
,
'b
,
'a
,
'gcx
,
'tcx
>
{
pub
(
super
)
fn
restrictions
<
'd
>
(
&
self
,
lvalue
:
&
'd
Lvalue
<
'gcx
>
)
->
Restrictions
<
'd
,
'gcx
>
where
'b
:
'd
{
let
lvalue_stack
=
if
self
.has_restrictions
(
lvalue
)
{
vec!
[
lvalue
]
}
else
{
vec!
[]
};
Restrictions
{
lvalue_stack
,
mir
:
self
.mir
,
tcx
:
self
.tcx
}
}
fn
has_restrictions
(
&
self
,
lvalue
:
&
Lvalue
<
'gcx
>
)
->
bool
{
let
mut
cursor
=
lvalue
;
loop
{
let
proj
=
match
*
cursor
{
Lvalue
::
Local
(
_
)
=>
return
true
,
Lvalue
::
Static
(
_
)
=>
return
false
,
Lvalue
::
Projection
(
ref
proj
)
=>
proj
,
};
match
proj
.elem
{
ProjectionElem
::
Index
(
..
)
|
ProjectionElem
::
ConstantIndex
{
..
}
|
ProjectionElem
::
Downcast
(
..
)
|
ProjectionElem
::
Subslice
{
..
}
|
ProjectionElem
::
Field
(
_
/*field*/
,
_
/*ty*/
)
=>
{
cursor
=
&
proj
.base
;
continue
;
}
ProjectionElem
::
Deref
=>
{
let
ty
=
proj
.base
.ty
(
self
.mir
,
self
.tcx
)
.to_ty
(
self
.tcx
);
match
ty
.sty
{
ty
::
TyRawPtr
(
_
)
=>
{
return
false
;
}
ty
::
TyRef
(
_
,
ty
::
TypeAndMut
{
ty
:
_
,
mutbl
:
hir
::
MutImmutable
})
=>
{
// FIXME: do I need to check validity of
// region here though? (I think the original
// check_loans code did, like readme says)
return
false
;
}
ty
::
TyRef
(
_
,
ty
::
TypeAndMut
{
ty
:
_
,
mutbl
:
hir
::
MutMutable
})
=>
{
cursor
=
&
proj
.base
;
continue
;
}
ty
::
TyAdt
(
..
)
if
ty
.is_box
()
=>
{
cursor
=
&
proj
.base
;
continue
;
}
_
=>
{
panic!
(
"unknown type fed to Projection Deref."
);
}
}
}
}
}
}
}
impl
<
'c
,
'tcx
>
Iterator
for
Restrictions
<
'c
,
'tcx
>
{
type
Item
=
&
'c
Lvalue
<
'tcx
>
;
fn
next
(
&
mut
self
)
->
Option
<
Self
::
Item
>
{
'pop
:
loop
{
let
lvalue
=
match
self
.lvalue_stack
.pop
()
{
None
=>
return
None
,
Some
(
lvalue
)
=>
lvalue
,
};
// `lvalue` may not be a restriction itself, but may
// hold one further down (e.g. we never return
// downcasts here, but may return a base of a
// downcast).
//
// Also, we need to enqueue any additional
// subrestrictions that it implies, since we can only
// return from from this call alone.
let
mut
cursor
=
lvalue
;
'cursor
:
loop
{
let
proj
=
match
*
cursor
{
Lvalue
::
Local
(
_
)
=>
return
Some
(
cursor
),
// search yielded this leaf
Lvalue
::
Static
(
_
)
=>
continue
'pop
,
// fruitless leaf; try next on stack
Lvalue
::
Projection
(
ref
proj
)
=>
proj
,
};
match
proj
.elem
{
ProjectionElem
::
Field
(
_
/*field*/
,
_
/*ty*/
)
=>
{
// FIXME: add union handling
self
.lvalue_stack
.push
(
&
proj
.base
);
return
Some
(
cursor
);
}
ProjectionElem
::
Downcast
(
..
)
|
ProjectionElem
::
Subslice
{
..
}
|
ProjectionElem
::
ConstantIndex
{
..
}
|
ProjectionElem
::
Index
(
_
)
=>
{
cursor
=
&
proj
.base
;
continue
'cursor
;
}
ProjectionElem
::
Deref
=>
{
// (handled below)
}
}
assert_eq!
(
proj
.elem
,
ProjectionElem
::
Deref
);
let
ty
=
proj
.base
.ty
(
self
.mir
,
self
.tcx
)
.to_ty
(
self
.tcx
);
match
ty
.sty
{
ty
::
TyRawPtr
(
_
)
=>
{
// borrowck ignores raw ptrs; treat analogous to imm borrow
continue
'pop
;
}
// R-Deref-Imm-Borrowed
ty
::
TyRef
(
_
/*rgn*/
,
ty
::
TypeAndMut
{
ty
:
_
,
mutbl
:
hir
::
MutImmutable
})
=>
{
// immutably-borrowed referents do not
// have recursively-implied restrictions
// (because preventing actions on `*LV`
// does nothing about aliases like `*LV1`)
// FIXME: do I need to check validity of
// `_r` here though? (I think the original
// check_loans code did, like the readme
// says)
// (And do I *really* not have to
// recursively process the `base` as a
// further search here? Leaving this `if
// false` here as a hint to look at this
// again later.
//
// Ah, it might be because the
// restrictions are distinct from the path
// substructure. Note that there is a
// separate loop over the path
// substructure in fn
// each_borrow_involving_path, for better
// or for worse.
if
false
{
cursor
=
&
proj
.base
;
continue
'cursor
;
}
else
{
continue
'pop
;
}
}
// R-Deref-Mut-Borrowed
ty
::
TyRef
(
_
/*rgn*/
,
ty
::
TypeAndMut
{
ty
:
_
,
mutbl
:
hir
::
MutMutable
})
=>
{
// mutably-borrowed referents are
// themselves restricted.
// FIXME: do I need to check validity of
// `_r` here though? (I think the original
// check_loans code did, like the readme
// says)
// schedule base for future iteration.
self
.lvalue_stack
.push
(
&
proj
.base
);
return
Some
(
cursor
);
// search yielded interior node
}
// R-Deref-Send-Pointer
ty
::
TyAdt
(
..
)
if
ty
.is_box
()
=>
{
// borrowing interior of a box implies that
// its base can no longer be mutated (o/w box
// storage would be freed)
self
.lvalue_stack
.push
(
&
proj
.base
);
return
Some
(
cursor
);
// search yielded interior node
}
_
=>
panic!
(
"unknown type fed to Projection Deref."
),
}
}
}
}
}
}
impl
<
'c
,
'b
,
'a
:
'b
+
'c
,
'gcx
,
'tcx
:
'a
>
MirBorrowckCtxt
<
'c
,
'b
,
'a
,
'gcx
,
'tcx
>
{
...
...
@@ -1319,26 +1061,6 @@ fn retrieve_borrow_span(&self, borrow: &BorrowData) -> Span {
}
impl
<
'c
,
'b
,
'a
:
'b
+
'c
,
'gcx
,
'tcx
:
'a
>
MirBorrowckCtxt
<
'c
,
'b
,
'a
,
'gcx
,
'tcx
>
{
// FIXME: needs to be able to express errors analogous to check_loans.rs
#[cfg(not_anymore)]
fn
conflicts_with
(
&
self
,
loan1
:
&
BorrowData
<
'gcx
>
,
loan2
:
&
BorrowData
<
'gcx
>
)
->
bool
{
if
loan1
.compatible_with
(
loan2
.kind
)
{
return
false
;
}
let
loan2_base_path
=
self
.base_path
(
&
loan2
.lvalue
);
for
restricted
in
self
.restrictions
(
&
loan1
.lvalue
)
{
if
restricted
!=
loan2_base_path
{
continue
;
}
return
true
;
}
let
loan1_base_path
=
self
.base_path
(
&
loan1
.lvalue
);
for
restricted
in
self
.restrictions
(
&
loan2
.lvalue
)
{
if
restricted
!=
loan1_base_path
{
continue
;
}
return
true
;
}
return
false
;
}
// FIXME (#16118): function intended to allow the borrow checker
// to be less precise in its handling of Box while still allowing
// moves out of a Box. They should be removed when/if we stop
...
...
@@ -1518,28 +1240,8 @@ fn apply_local_effect(&mut self) {
self
.curr_state
.subtract
(
&
self
.stmt_kill
);
}
#[allow(dead_code)]
fn
elems_generated
(
&
self
)
->
indexed_set
::
Elems
<
BD
::
Idx
>
{
let
univ
=
self
.base_results
.sets
()
.bits_per_block
();
self
.stmt_gen
.elems
(
univ
)
}
fn
elems_incoming
(
&
self
)
->
indexed_set
::
Elems
<
BD
::
Idx
>
{
let
univ
=
self
.base_results
.sets
()
.bits_per_block
();
self
.curr_state
.elems
(
univ
)
}
}
impl
<
'tcx
>
BorrowData
<
'tcx
>
{
#[allow(dead_code)]
fn
compatible_with
(
&
self
,
bk
:
BorrowKind
)
->
bool
{
match
(
self
.kind
,
bk
)
{
(
BorrowKind
::
Shared
,
BorrowKind
::
Shared
)
=>
true
,
(
BorrowKind
::
Mut
,
_
)
|
(
BorrowKind
::
Unique
,
_
)
|
(
_
,
BorrowKind
::
Mut
)
|
(
_
,
BorrowKind
::
Unique
)
=>
false
,
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录