Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
99ebb7a5
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,发现更多精彩内容 >>
提交
99ebb7a5
编写于
5月 02, 2019
作者:
Y
Yuki Okushi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove Context and ContextKind
上级
6cc24f26
变更
5
展开全部
隐藏空白更改
内联
并排
Showing
5 changed file
with
171 addition
and
211 deletion
+171
-211
src/librustc_mir/borrow_check/error_reporting.rs
src/librustc_mir/borrow_check/error_reporting.rs
+38
-38
src/librustc_mir/borrow_check/mod.rs
src/librustc_mir/borrow_check/mod.rs
+83
-120
src/librustc_mir/borrow_check/nll/explain_borrow/mod.rs
src/librustc_mir/borrow_check/nll/explain_borrow/mod.rs
+9
-9
src/librustc_mir/borrow_check/nll/invalidation.rs
src/librustc_mir/borrow_check/nll/invalidation.rs
+40
-42
src/librustc_mir/borrow_check/path_utils.rs
src/librustc_mir/borrow_check/path_utils.rs
+1
-2
未找到文件。
src/librustc_mir/borrow_check/error_reporting.rs
浏览文件 @
99ebb7a5
...
...
@@ -22,7 +22,7 @@
use
syntax
::
source_map
::
CompilerDesugaringKind
;
use
super
::
borrow_set
::
BorrowData
;
use
super
::{
Context
,
MirBorrowckCtxt
};
use
super
::{
MirBorrowckCtxt
};
use
super
::{
InitializationRequiringAction
,
PrefixSet
};
use
crate
::
dataflow
::
drop_flag_effects
;
use
crate
::
dataflow
::
indexes
::{
MovePathIndex
,
MoveOutIndex
};
...
...
@@ -42,22 +42,22 @@ struct MoveSite {
impl
<
'cx
,
'gcx
,
'tcx
>
MirBorrowckCtxt
<
'cx
,
'gcx
,
'tcx
>
{
pub
(
super
)
fn
report_use_of_moved_or_uninitialized
(
&
mut
self
,
context
:
Context
,
location
:
Location
,
desired_action
:
InitializationRequiringAction
,
(
moved_place
,
used_place
,
span
):
(
&
Place
<
'tcx
>
,
&
Place
<
'tcx
>
,
Span
),
mpi
:
MovePathIndex
,
)
{
debug!
(
"report_use_of_moved_or_uninitialized:
context
={:?} desired_action={:?}
\
"report_use_of_moved_or_uninitialized:
location
={:?} desired_action={:?}
\
moved_place={:?} used_place={:?} span={:?} mpi={:?}"
,
context
,
desired_action
,
moved_place
,
used_place
,
span
,
mpi
location
,
desired_action
,
moved_place
,
used_place
,
span
,
mpi
);
let
use_spans
=
self
.move_spans
(
moved_place
,
context
.loc
)
.or_else
(||
self
.borrow_spans
(
span
,
context
.loc
));
let
use_spans
=
self
.move_spans
(
moved_place
,
location
)
.or_else
(||
self
.borrow_spans
(
span
,
location
));
let
span
=
use_spans
.args_or_use
();
let
move_site_vec
=
self
.get_moved_indexes
(
context
,
mpi
);
let
move_site_vec
=
self
.get_moved_indexes
(
location
,
mpi
);
debug!
(
"report_use_of_moved_or_uninitialized: move_site_vec={:?}"
,
move_site_vec
...
...
@@ -125,7 +125,7 @@ pub(super) fn report_use_of_moved_or_uninitialized(
);
self
.add_moved_or_invoked_closure_note
(
context
.loc
,
location
,
used_place
,
&
mut
err
,
);
...
...
@@ -261,13 +261,13 @@ pub(super) fn report_use_of_moved_or_uninitialized(
pub
(
super
)
fn
report_move_out_while_borrowed
(
&
mut
self
,
context
:
Context
,
location
:
Location
,
(
place
,
span
):
(
&
Place
<
'tcx
>
,
Span
),
borrow
:
&
BorrowData
<
'tcx
>
,
)
{
debug!
(
"report_move_out_while_borrowed:
context
={:?} place={:?} span={:?} borrow={:?}"
,
context
,
place
,
span
,
borrow
"report_move_out_while_borrowed:
location
={:?} place={:?} span={:?} borrow={:?}"
,
location
,
place
,
span
,
borrow
);
let
tcx
=
self
.infcx.tcx
;
let
value_msg
=
match
self
.describe_place
(
place
)
{
...
...
@@ -282,7 +282,7 @@ pub(super) fn report_move_out_while_borrowed(
let
borrow_spans
=
self
.retrieve_borrow_spans
(
borrow
);
let
borrow_span
=
borrow_spans
.args_or_use
();
let
move_spans
=
self
.move_spans
(
place
,
context
.loc
);
let
move_spans
=
self
.move_spans
(
place
,
location
);
let
span
=
move_spans
.args_or_use
();
let
mut
err
=
tcx
.cannot_move_when_borrowed
(
...
...
@@ -304,7 +304,7 @@ pub(super) fn report_move_out_while_borrowed(
);
self
.explain_why_borrow_contains_point
(
context
,
location
,
borrow
,
None
,
)
.add_explanation_to_diagnostic
(
self
.infcx.tcx
,
self
.mir
,
&
mut
err
,
""
,
Some
(
borrow_span
));
...
...
@@ -313,7 +313,7 @@ pub(super) fn report_move_out_while_borrowed(
pub
(
super
)
fn
report_use_while_mutably_borrowed
(
&
mut
self
,
context
:
Context
,
location
:
Location
,
(
place
,
_
span
):
(
&
Place
<
'tcx
>
,
Span
),
borrow
:
&
BorrowData
<
'tcx
>
,
)
->
DiagnosticBuilder
<
'cx
>
{
...
...
@@ -324,7 +324,7 @@ pub(super) fn report_use_while_mutably_borrowed(
// Conflicting borrows are reported separately, so only check for move
// captures.
let
use_spans
=
self
.move_spans
(
place
,
context
.loc
);
let
use_spans
=
self
.move_spans
(
place
,
location
);
let
span
=
use_spans
.var_or_use
();
let
mut
err
=
tcx
.cannot_use_when_mutably_borrowed
(
...
...
@@ -343,14 +343,14 @@ pub(super) fn report_use_while_mutably_borrowed(
format!
(
"borrow occurs due to use of `{}`{}"
,
desc_place
,
borrow_spans
.describe
())
});
self
.explain_why_borrow_contains_point
(
context
,
borrow
,
None
)
self
.explain_why_borrow_contains_point
(
location
,
borrow
,
None
)
.add_explanation_to_diagnostic
(
self
.infcx.tcx
,
self
.mir
,
&
mut
err
,
""
,
None
);
err
}
pub
(
super
)
fn
report_conflicting_borrow
(
&
mut
self
,
context
:
Context
,
location
:
Location
,
(
place
,
span
):
(
&
Place
<
'tcx
>
,
Span
),
gen_borrow_kind
:
BorrowKind
,
issued_borrow
:
&
BorrowData
<
'tcx
>
,
...
...
@@ -358,7 +358,7 @@ pub(super) fn report_conflicting_borrow(
let
issued_spans
=
self
.retrieve_borrow_spans
(
issued_borrow
);
let
issued_span
=
issued_spans
.args_or_use
();
let
borrow_spans
=
self
.borrow_spans
(
span
,
context
.loc
);
let
borrow_spans
=
self
.borrow_spans
(
span
,
location
);
let
span
=
borrow_spans
.args_or_use
();
let
container_name
=
if
issued_spans
.for_generator
()
||
borrow_spans
.for_generator
()
{
...
...
@@ -370,7 +370,7 @@ pub(super) fn report_conflicting_borrow(
let
(
desc_place
,
msg_place
,
msg_borrow
,
union_type_name
)
=
self
.describe_place_for_conflicting_borrow
(
place
,
&
issued_borrow
.borrowed_place
);
let
explanation
=
self
.explain_why_borrow_contains_point
(
context
,
issued_borrow
,
None
);
let
explanation
=
self
.explain_why_borrow_contains_point
(
location
,
issued_borrow
,
None
);
let
second_borrow_desc
=
if
explanation
.is_explained
()
{
"second "
}
else
{
...
...
@@ -671,7 +671,7 @@ pub(super) fn describe_place_for_conflicting_borrow(
/// `Drop::drop` with an aliasing borrow.)
pub
(
super
)
fn
report_borrowed_value_does_not_live_long_enough
(
&
mut
self
,
context
:
Context
,
location
:
Location
,
borrow
:
&
BorrowData
<
'tcx
>
,
place_span
:
(
&
Place
<
'tcx
>
,
Span
),
kind
:
Option
<
WriteKind
>
,
...
...
@@ -680,7 +680,7 @@ pub(super) fn report_borrowed_value_does_not_live_long_enough(
"report_borrowed_value_does_not_live_long_enough(
\
{:?}, {:?}, {:?}, {:?}
\
)"
,
context
,
borrow
,
place_span
,
kind
location
,
borrow
,
place_span
,
kind
);
let
drop_span
=
place_span
.1
;
...
...
@@ -719,7 +719,7 @@ pub(super) fn report_borrowed_value_does_not_live_long_enough(
// destructor conflict.
if
!
borrow
.borrowed_place
.is_prefix_of
(
place_span
.0
)
{
self
.report_borrow_conflicts_with_destructor
(
context
,
borrow
,
place_span
,
kind
,
dropped_ty
,
location
,
borrow
,
place_span
,
kind
,
dropped_ty
,
);
return
;
}
...
...
@@ -728,7 +728,7 @@ pub(super) fn report_borrowed_value_does_not_live_long_enough(
let
place_desc
=
self
.describe_place
(
&
borrow
.borrowed_place
);
let
kind_place
=
kind
.filter
(|
_
|
place_desc
.is_some
())
.map
(|
k
|
(
k
,
place_span
.0
));
let
explanation
=
self
.explain_why_borrow_contains_point
(
context
,
&
borrow
,
kind_place
);
let
explanation
=
self
.explain_why_borrow_contains_point
(
location
,
&
borrow
,
kind_place
);
let
err
=
match
(
place_desc
,
explanation
)
{
(
Some
(
_
),
_
)
if
self
.is_place_thread_local
(
root_place
)
=>
{
...
...
@@ -784,7 +784,7 @@ pub(super) fn report_borrowed_value_does_not_live_long_enough(
},
)
=>
self
.report_escaping_data
(
borrow_span
,
name
,
upvar_span
,
upvar_name
,
span
),
(
Some
(
name
),
explanation
)
=>
self
.report_local_value_does_not_live_long_enough
(
context
,
location
,
&
name
,
&
scope_tree
,
&
borrow
,
...
...
@@ -793,7 +793,7 @@ pub(super) fn report_borrowed_value_does_not_live_long_enough(
explanation
,
),
(
None
,
explanation
)
=>
self
.report_temporary_value_does_not_live_long_enough
(
context
,
location
,
&
scope_tree
,
&
borrow
,
drop_span
,
...
...
@@ -808,7 +808,7 @@ pub(super) fn report_borrowed_value_does_not_live_long_enough(
fn
report_local_value_does_not_live_long_enough
(
&
mut
self
,
context
:
Context
,
location
:
Location
,
name
:
&
str
,
scope_tree
:
&
'tcx
ScopeTree
,
borrow
:
&
BorrowData
<
'tcx
>
,
...
...
@@ -820,7 +820,7 @@ fn report_local_value_does_not_live_long_enough(
"report_local_value_does_not_live_long_enough(
\
{:?}, {:?}, {:?}, {:?}, {:?}, {:?}
\
)"
,
context
,
name
,
scope_tree
,
borrow
,
drop_span
,
borrow_spans
location
,
name
,
scope_tree
,
borrow
,
drop_span
,
borrow_spans
);
let
borrow_span
=
borrow_spans
.var_or_use
();
...
...
@@ -914,7 +914,7 @@ fn report_local_value_does_not_live_long_enough(
fn
report_borrow_conflicts_with_destructor
(
&
mut
self
,
context
:
Context
,
location
:
Location
,
borrow
:
&
BorrowData
<
'tcx
>
,
(
place
,
drop_span
):
(
&
Place
<
'tcx
>
,
Span
),
kind
:
Option
<
WriteKind
>
,
...
...
@@ -924,7 +924,7 @@ fn report_borrow_conflicts_with_destructor(
"report_borrow_conflicts_with_destructor(
\
{:?}, {:?}, ({:?}, {:?}), {:?}
\
)"
,
context
,
borrow
,
place
,
drop_span
,
kind
,
location
,
borrow
,
place
,
drop_span
,
kind
,
);
let
borrow_spans
=
self
.retrieve_borrow_spans
(
borrow
);
...
...
@@ -957,7 +957,7 @@ fn report_borrow_conflicts_with_destructor(
// Only give this note and suggestion if they could be relevant.
let
explanation
=
self
.explain_why_borrow_contains_point
(
context
,
borrow
,
kind
.map
(|
k
|
(
k
,
place
)));
self
.explain_why_borrow_contains_point
(
location
,
borrow
,
kind
.map
(|
k
|
(
k
,
place
)));
match
explanation
{
BorrowExplanation
::
UsedLater
{
..
}
|
BorrowExplanation
::
UsedLaterWhenDropped
{
..
}
=>
{
...
...
@@ -998,7 +998,7 @@ fn report_thread_local_value_does_not_live_long_enough(
fn
report_temporary_value_does_not_live_long_enough
(
&
mut
self
,
context
:
Context
,
location
:
Location
,
scope_tree
:
&
'tcx
ScopeTree
,
borrow
:
&
BorrowData
<
'tcx
>
,
drop_span
:
Span
,
...
...
@@ -1010,7 +1010,7 @@ fn report_temporary_value_does_not_live_long_enough(
"report_temporary_value_does_not_live_long_enough(
\
{:?}, {:?}, {:?}, {:?}, {:?}
\
)"
,
context
,
scope_tree
,
borrow
,
drop_span
,
proper_span
location
,
scope_tree
,
borrow
,
drop_span
,
proper_span
);
if
let
BorrowExplanation
::
MustBeValidFor
{
...
...
@@ -1246,12 +1246,12 @@ fn report_escaping_data(
err
}
fn
get_moved_indexes
(
&
mut
self
,
context
:
Context
,
mpi
:
MovePathIndex
)
->
Vec
<
MoveSite
>
{
fn
get_moved_indexes
(
&
mut
self
,
location
:
Location
,
mpi
:
MovePathIndex
)
->
Vec
<
MoveSite
>
{
let
mir
=
self
.mir
;
let
mut
stack
=
Vec
::
new
();
stack
.extend
(
mir
.predecessor_locations
(
context
.loc
)
.map
(|
predecessor
|
{
let
is_back_edge
=
context
.loc
.dominates
(
predecessor
,
&
self
.dominators
);
stack
.extend
(
mir
.predecessor_locations
(
location
)
.map
(|
predecessor
|
{
let
is_back_edge
=
location
.dominates
(
predecessor
,
&
self
.dominators
);
(
predecessor
,
is_back_edge
)
}));
...
...
@@ -1348,7 +1348,7 @@ fn get_moved_indexes(&mut self, context: Context, mpi: MovePathIndex) -> Vec<Mov
pub
(
super
)
fn
report_illegal_mutation_of_borrowed
(
&
mut
self
,
context
:
Context
,
location
:
Location
,
(
place
,
span
):
(
&
Place
<
'tcx
>
,
Span
),
loan
:
&
BorrowData
<
'tcx
>
,
)
{
...
...
@@ -1386,7 +1386,7 @@ pub(super) fn report_illegal_mutation_of_borrowed(
format!
(
"borrow occurs due to use{}"
,
loan_spans
.describe
()),
);
self
.explain_why_borrow_contains_point
(
context
,
loan
,
None
)
self
.explain_why_borrow_contains_point
(
location
,
loan
,
None
)
.add_explanation_to_diagnostic
(
self
.infcx.tcx
,
self
.mir
,
&
mut
err
,
""
,
None
);
err
.buffer
(
&
mut
self
.errors_buffer
);
...
...
@@ -1400,7 +1400,7 @@ pub(super) fn report_illegal_mutation_of_borrowed(
/// assignment to `x.f`).
pub
(
super
)
fn
report_illegal_reassignment
(
&
mut
self
,
_
context
:
Context
,
_
location
:
Location
,
(
place
,
span
):
(
&
Place
<
'tcx
>
,
Span
),
assigned_span
:
Span
,
err_place
:
&
Place
<
'tcx
>
,
...
...
src/librustc_mir/borrow_check/mod.rs
浏览文件 @
99ebb7a5
此差异已折叠。
点击以展开。
src/librustc_mir/borrow_check/nll/explain_borrow/mod.rs
浏览文件 @
99ebb7a5
...
...
@@ -4,7 +4,7 @@
use
crate
::
borrow_check
::
error_reporting
::
UseSpans
;
use
crate
::
borrow_check
::
nll
::
region_infer
::{
Cause
,
RegionName
};
use
crate
::
borrow_check
::
nll
::
ConstraintDescription
;
use
crate
::
borrow_check
::{
Context
,
MirBorrowckCtxt
,
WriteKind
};
use
crate
::
borrow_check
::{
MirBorrowckCtxt
,
WriteKind
};
use
rustc
::
mir
::{
CastKind
,
ConstraintCategory
,
FakeReadCause
,
Local
,
Location
,
Mir
,
Operand
,
Place
,
PlaceBase
,
Projection
,
ProjectionElem
,
Rvalue
,
Statement
,
StatementKind
,
TerminatorKind
,
...
...
@@ -209,13 +209,13 @@ pub(in crate::borrow_check) fn add_explanation_to_diagnostic<'cx, 'gcx, 'tcx>(
impl
<
'cx
,
'gcx
,
'tcx
>
MirBorrowckCtxt
<
'cx
,
'gcx
,
'tcx
>
{
/// Returns structured explanation for *why* the borrow contains the
/// point from `
context
`. This is key for the "3-point errors"
/// point from `
location
`. This is key for the "3-point errors"
/// [described in the NLL RFC][d].
///
/// # Parameters
///
/// - `borrow`: the borrow in question
/// - `
context
`: where the borrow occurs
/// - `
location
`: where the borrow occurs
/// - `kind_place`: if Some, this describes the statement that triggered the error.
/// - first half is the kind of write, if any, being performed
/// - second half is the place being accessed
...
...
@@ -223,13 +223,13 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
/// [d]: https://rust-lang.github.io/rfcs/2094-nll.html#leveraging-intuition-framing-errors-in-terms-of-points
pub
(
in
crate
::
borrow_check
)
fn
explain_why_borrow_contains_point
(
&
self
,
context
:
Context
,
location
:
Location
,
borrow
:
&
BorrowData
<
'tcx
>
,
kind_place
:
Option
<
(
WriteKind
,
&
Place
<
'tcx
>
)
>
,
)
->
BorrowExplanation
{
debug!
(
"explain_why_borrow_contains_point(
context
={:?}, borrow={:?}, kind_place={:?})"
,
context
,
borrow
,
kind_place
"explain_why_borrow_contains_point(
location
={:?}, borrow={:?}, kind_place={:?})"
,
location
,
borrow
,
kind_place
);
let
regioncx
=
&
self
.nonlexical_regioncx
;
...
...
@@ -242,20 +242,20 @@ pub(in crate::borrow_check) fn explain_why_borrow_contains_point(
borrow_region_vid
);
let
region_sub
=
regioncx
.find_sub_region_live_at
(
borrow_region_vid
,
context
.loc
);
let
region_sub
=
regioncx
.find_sub_region_live_at
(
borrow_region_vid
,
location
);
debug!
(
"explain_why_borrow_contains_point: region_sub={:?}"
,
region_sub
);
match
find_use
::
find
(
mir
,
regioncx
,
tcx
,
region_sub
,
context
.loc
)
{
match
find_use
::
find
(
mir
,
regioncx
,
tcx
,
region_sub
,
location
)
{
Some
(
Cause
::
LiveVar
(
local
,
location
))
=>
{
let
span
=
mir
.source_info
(
location
)
.span
;
let
spans
=
self
.move_spans
(
&
Place
::
Base
(
PlaceBase
::
Local
(
local
)),
location
)
.or_else
(||
self
.borrow_spans
(
span
,
location
));
let
borrow_location
=
context
.loc
;
let
borrow_location
=
location
;
if
self
.is_use_in_later_iteration_of_loop
(
borrow_location
,
location
)
{
let
later_use
=
self
.later_use_kind
(
borrow
,
spans
,
location
);
BorrowExplanation
::
UsedLaterInLoop
(
later_use
.0
,
later_use
.1
)
...
...
src/librustc_mir/borrow_check/nll/invalidation.rs
浏览文件 @
99ebb7a5
...
...
@@ -3,7 +3,6 @@
use
crate
::
borrow_check
::{
JustWrite
,
WriteAndRead
};
use
crate
::
borrow_check
::{
AccessDepth
,
Deep
,
Shallow
};
use
crate
::
borrow_check
::{
ReadOrWrite
,
Activation
,
Read
,
Reservation
,
Write
};
use
crate
::
borrow_check
::{
Context
,
ContextKind
};
use
crate
::
borrow_check
::{
LocalMutationIsAllowed
,
MutateMode
};
use
crate
::
borrow_check
::
ArtificialField
;
use
crate
::
borrow_check
::{
ReadKind
,
WriteKind
};
...
...
@@ -66,12 +65,12 @@ fn visit_statement(
match
statement
.kind
{
StatementKind
::
Assign
(
ref
lhs
,
ref
rhs
)
=>
{
self
.consume_rvalue
(
ContextKind
::
AssignRhs
.new
(
location
)
,
location
,
rhs
,
);
self
.mutate_place
(
ContextKind
::
AssignLhs
.new
(
location
)
,
location
,
lhs
,
Shallow
(
None
),
JustWrite
...
...
@@ -85,27 +84,26 @@ fn visit_statement(
variant_index
:
_
,
}
=>
{
self
.mutate_place
(
ContextKind
::
SetDiscrim
.new
(
location
)
,
location
,
place
,
Shallow
(
None
),
JustWrite
,
);
}
StatementKind
::
InlineAsm
(
ref
asm
)
=>
{
let
context
=
ContextKind
::
InlineAsm
.new
(
location
);
for
(
o
,
output
)
in
asm
.asm.outputs
.iter
()
.zip
(
asm
.outputs
.iter
())
{
if
o
.is_indirect
{
// FIXME(eddyb) indirect inline asm outputs should
// be encoded through MIR place derefs instead.
self
.access_place
(
context
,
location
,
output
,
(
Deep
,
Read
(
ReadKind
::
Copy
)),
LocalMutationIsAllowed
::
No
,
);
}
else
{
self
.mutate_place
(
context
,
location
,
output
,
if
o
.is_rw
{
Deep
}
else
{
Shallow
(
None
)
},
if
o
.is_rw
{
WriteAndRead
}
else
{
JustWrite
},
...
...
@@ -113,7 +111,7 @@ fn visit_statement(
}
}
for
(
_
,
input
)
in
asm
.inputs
.iter
()
{
self
.consume_operand
(
context
,
input
);
self
.consume_operand
(
location
,
input
);
}
}
StatementKind
::
Nop
|
...
...
@@ -125,7 +123,7 @@ fn visit_statement(
}
StatementKind
::
StorageDead
(
local
)
=>
{
self
.access_place
(
ContextKind
::
StorageDead
.new
(
location
)
,
location
,
&
Place
::
Base
(
PlaceBase
::
Local
(
local
)),
(
Shallow
(
None
),
Write
(
WriteKind
::
StorageDeadOrDrop
)),
LocalMutationIsAllowed
::
Yes
,
...
...
@@ -150,7 +148,7 @@ fn visit_terminator_kind(
values
:
_
,
targets
:
_
,
}
=>
{
self
.consume_operand
(
ContextKind
::
SwitchInt
.new
(
location
)
,
discr
);
self
.consume_operand
(
location
,
discr
);
}
TerminatorKind
::
Drop
{
location
:
ref
drop_place
,
...
...
@@ -158,7 +156,7 @@ fn visit_terminator_kind(
unwind
:
_
,
}
=>
{
self
.access_place
(
ContextKind
::
Drop
.new
(
location
)
,
location
,
drop_place
,
(
AccessDepth
::
Drop
,
Write
(
WriteKind
::
StorageDeadOrDrop
)),
LocalMutationIsAllowed
::
Yes
,
...
...
@@ -171,13 +169,13 @@ fn visit_terminator_kind(
unwind
:
_
,
}
=>
{
self
.mutate_place
(
ContextKind
::
DropAndReplace
.new
(
location
)
,
location
,
drop_place
,
Deep
,
JustWrite
,
);
self
.consume_operand
(
ContextKind
::
DropAndReplace
.new
(
location
)
,
location
,
new_value
,
);
}
...
...
@@ -188,13 +186,13 @@ fn visit_terminator_kind(
cleanup
:
_
,
from_hir_call
:
_
,
}
=>
{
self
.consume_operand
(
ContextKind
::
CallOperator
.new
(
location
)
,
func
);
self
.consume_operand
(
location
,
func
);
for
arg
in
args
{
self
.consume_operand
(
ContextKind
::
CallOperand
.new
(
location
)
,
arg
);
self
.consume_operand
(
location
,
arg
);
}
if
let
Some
((
ref
dest
,
_
/*bb*/
))
=
*
destination
{
self
.mutate_place
(
ContextKind
::
CallDest
.new
(
location
)
,
location
,
dest
,
Deep
,
JustWrite
,
...
...
@@ -208,11 +206,11 @@ fn visit_terminator_kind(
target
:
_
,
cleanup
:
_
,
}
=>
{
self
.consume_operand
(
ContextKind
::
Assert
.new
(
location
)
,
cond
);
self
.consume_operand
(
location
,
cond
);
use
rustc
::
mir
::
interpret
::
InterpError
::
BoundsCheck
;
if
let
BoundsCheck
{
ref
len
,
ref
index
}
=
*
msg
{
self
.consume_operand
(
ContextKind
::
Assert
.new
(
location
)
,
len
);
self
.consume_operand
(
ContextKind
::
Assert
.new
(
location
)
,
index
);
self
.consume_operand
(
location
,
len
);
self
.consume_operand
(
location
,
index
);
}
}
TerminatorKind
::
Yield
{
...
...
@@ -220,7 +218,7 @@ fn visit_terminator_kind(
resume
,
drop
:
_
,
}
=>
{
self
.consume_operand
(
ContextKind
::
Yield
.new
(
location
)
,
value
);
self
.consume_operand
(
location
,
value
);
// Invalidate all borrows of local places
let
borrow_set
=
self
.borrow_set
.clone
();
...
...
@@ -264,13 +262,13 @@ impl<'cg, 'cx, 'tcx, 'gcx> InvalidationGenerator<'cx, 'tcx, 'gcx> {
/// Simulates mutation of a place.
fn
mutate_place
(
&
mut
self
,
context
:
Context
,
location
:
Location
,
place
:
&
Place
<
'tcx
>
,
kind
:
AccessDepth
,
_
mode
:
MutateMode
,
)
{
self
.access_place
(
context
,
location
,
place
,
(
kind
,
Write
(
WriteKind
::
Mutate
)),
LocalMutationIsAllowed
::
ExceptUpvars
,
...
...
@@ -280,13 +278,13 @@ fn mutate_place(
/// Simulates consumption of an operand.
fn
consume_operand
(
&
mut
self
,
context
:
Context
,
location
:
Location
,
operand
:
&
Operand
<
'tcx
>
,
)
{
match
*
operand
{
Operand
::
Copy
(
ref
place
)
=>
{
self
.access_place
(
context
,
location
,
place
,
(
Deep
,
Read
(
ReadKind
::
Copy
)),
LocalMutationIsAllowed
::
No
,
...
...
@@ -294,7 +292,7 @@ fn consume_operand(
}
Operand
::
Move
(
ref
place
)
=>
{
self
.access_place
(
context
,
location
,
place
,
(
Deep
,
Write
(
WriteKind
::
Move
)),
LocalMutationIsAllowed
::
Yes
,
...
...
@@ -307,7 +305,7 @@ fn consume_operand(
// Simulates consumption of an rvalue
fn
consume_rvalue
(
&
mut
self
,
context
:
Context
,
location
:
Location
,
rvalue
:
&
Rvalue
<
'tcx
>
,
)
{
match
*
rvalue
{
...
...
@@ -328,7 +326,7 @@ fn consume_rvalue(
};
self
.access_place
(
context
,
location
,
place
,
access_kind
,
LocalMutationIsAllowed
::
No
,
...
...
@@ -339,7 +337,7 @@ fn consume_rvalue(
|
Rvalue
::
Repeat
(
ref
operand
,
_
)
|
Rvalue
::
UnaryOp
(
_
/*un_op*/
,
ref
operand
)
|
Rvalue
::
Cast
(
_
/*cast_kind*/
,
ref
operand
,
_
/*ty*/
)
=>
{
self
.consume_operand
(
context
,
operand
)
self
.consume_operand
(
location
,
operand
)
}
Rvalue
::
Len
(
ref
place
)
|
Rvalue
::
Discriminant
(
ref
place
)
=>
{
...
...
@@ -349,7 +347,7 @@ fn consume_rvalue(
_
=>
unreachable!
(),
};
self
.access_place
(
context
,
location
,
place
,
(
Shallow
(
af
),
Read
(
ReadKind
::
Copy
)),
LocalMutationIsAllowed
::
No
,
...
...
@@ -358,8 +356,8 @@ fn consume_rvalue(
Rvalue
::
BinaryOp
(
_
bin_op
,
ref
operand1
,
ref
operand2
)
|
Rvalue
::
CheckedBinaryOp
(
_
bin_op
,
ref
operand1
,
ref
operand2
)
=>
{
self
.consume_operand
(
context
,
operand1
);
self
.consume_operand
(
context
,
operand2
);
self
.consume_operand
(
location
,
operand1
);
self
.consume_operand
(
location
,
operand2
);
}
Rvalue
::
NullaryOp
(
_
op
,
_
ty
)
=>
{
...
...
@@ -367,7 +365,7 @@ fn consume_rvalue(
Rvalue
::
Aggregate
(
_
,
ref
operands
)
=>
{
for
operand
in
operands
{
self
.consume_operand
(
context
,
operand
);
self
.consume_operand
(
location
,
operand
);
}
}
}
...
...
@@ -376,27 +374,27 @@ fn consume_rvalue(
/// Simulates an access to a place.
fn
access_place
(
&
mut
self
,
context
:
Context
,
location
:
Location
,
place
:
&
Place
<
'tcx
>
,
kind
:
(
AccessDepth
,
ReadOrWrite
),
_
is_local_mutation_allowed
:
LocalMutationIsAllowed
,
)
{
let
(
sd
,
rw
)
=
kind
;
// note: not doing check_access_permissions checks because they don't generate invalidates
self
.check_access_for_conflict
(
context
,
place
,
sd
,
rw
);
self
.check_access_for_conflict
(
location
,
place
,
sd
,
rw
);
}
fn
check_access_for_conflict
(
&
mut
self
,
context
:
Context
,
location
:
Location
,
place
:
&
Place
<
'tcx
>
,
sd
:
AccessDepth
,
rw
:
ReadOrWrite
,
)
{
debug!
(
"invalidation::check_access_for_conflict(
context
={:?}, place={:?}, sd={:?},
\
"invalidation::check_access_for_conflict(
location
={:?}, place={:?}, sd={:?},
\
rw={:?})"
,
context
,
location
,
place
,
sd
,
rw
,
...
...
@@ -409,7 +407,7 @@ fn check_access_for_conflict(
self
,
tcx
,
mir
,
context
,
location
,
(
sd
,
place
),
&
borrow_set
.clone
(),
indices
,
...
...
@@ -435,7 +433,7 @@ fn check_access_for_conflict(
(
Read
(
_
),
BorrowKind
::
Unique
)
|
(
Read
(
_
),
BorrowKind
::
Mut
{
..
})
=>
{
// Reading from mere reservations of mutable-borrows is OK.
if
!
is_active
(
&
this
.dominators
,
borrow
,
context
.loc
)
{
if
!
is_active
(
&
this
.dominators
,
borrow
,
location
)
{
// If the borrow isn't active yet, reads don't invalidate it
assert
!
(
allow_two_phase_borrow
(
borrow
.kind
));
return
Control
::
Continue
;
...
...
@@ -443,7 +441,7 @@ fn check_access_for_conflict(
// Unique and mutable borrows are invalidated by reads from any
// involved path
this
.generate_invalidates
(
borrow_index
,
context
.loc
);
this
.generate_invalidates
(
borrow_index
,
location
);
}
(
Reservation
(
_
),
_
)
...
...
@@ -453,7 +451,7 @@ fn check_access_for_conflict(
// Reservations count as writes since we need to check
// that activating the borrow will be OK
// FIXME(bob_twinkles) is this actually the right thing to do?
this
.generate_invalidates
(
borrow_index
,
context
.loc
);
this
.generate_invalidates
(
borrow_index
,
location
);
}
}
Control
::
Continue
...
...
@@ -485,7 +483,7 @@ fn check_activations(
});
self
.access_place
(
ContextKind
::
Activation
.new
(
location
)
,
location
,
&
borrow
.borrowed_place
,
(
Deep
,
...
...
src/librustc_mir/borrow_check/path_utils.rs
浏览文件 @
99ebb7a5
use
crate
::
borrow_check
::
borrow_set
::{
BorrowSet
,
BorrowData
,
TwoPhaseActivation
};
use
crate
::
borrow_check
::
places_conflict
;
use
crate
::
borrow_check
::
Context
;
use
crate
::
borrow_check
::
AccessDepth
;
use
crate
::
dataflow
::
indexes
::
BorrowIndex
;
use
rustc
::
mir
::{
BasicBlock
,
Location
,
Mir
,
Place
,
PlaceBase
};
...
...
@@ -27,7 +26,7 @@ pub(super) fn each_borrow_involving_path<'a, 'tcx, 'gcx: 'tcx, F, I, S> (
s
:
&
mut
S
,
tcx
:
TyCtxt
<
'a
,
'gcx
,
'tcx
>
,
mir
:
&
Mir
<
'tcx
>
,
_
context
:
Context
,
_
location
:
Location
,
access_place
:
(
AccessDepth
,
&
Place
<
'tcx
>
),
borrow_set
:
&
BorrowSet
<
'tcx
>
,
candidates
:
I
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录