Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
234b9301
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,发现更多精彩内容 >>
提交
234b9301
编写于
12月 28, 2019
作者:
M
Mark Mansi
提交者:
mark
1月 12, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
rename nonlexical_regioncx -> regioncx
上级
66c5d5b7
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
34 addition
and
48 deletion
+34
-48
src/librustc_mir/borrow_check/diagnostics/explain_borrow.rs
src/librustc_mir/borrow_check/diagnostics/explain_borrow.rs
+4
-11
src/librustc_mir/borrow_check/diagnostics/region_errors.rs
src/librustc_mir/borrow_check/diagnostics/region_errors.rs
+15
-17
src/librustc_mir/borrow_check/diagnostics/region_name.rs
src/librustc_mir/borrow_check/diagnostics/region_name.rs
+12
-16
src/librustc_mir/borrow_check/mod.rs
src/librustc_mir/borrow_check/mod.rs
+3
-4
未找到文件。
src/librustc_mir/borrow_check/diagnostics/explain_borrow.rs
浏览文件 @
234b9301
...
...
@@ -260,17 +260,11 @@ fn free_region_constraint_info(
borrow_region
:
RegionVid
,
outlived_region
:
RegionVid
,
)
->
(
ConstraintCategory
,
bool
,
Span
,
Option
<
RegionName
>
)
{
let
(
category
,
from_closure
,
span
)
=
self
.
nonlexical_
regioncx
.best_blame_constraint
(
let
(
category
,
from_closure
,
span
)
=
self
.regioncx
.best_blame_constraint
(
&
self
.body
,
borrow_region
,
NLLRegionVariableOrigin
::
FreeRegion
,
|
r
|
{
self
.nonlexical_regioncx
.provides_universal_region
(
r
,
borrow_region
,
outlived_region
,
)
},
|
r
|
self
.regioncx
.provides_universal_region
(
r
,
borrow_region
,
outlived_region
),
);
let
mut
renctx
=
RegionErrorNamingCtx
::
new
();
...
...
@@ -303,15 +297,14 @@ pub(in crate::borrow_check) fn explain_why_borrow_contains_point(
location
,
borrow
,
kind_place
);
let
regioncx
=
&
self
.
nonlexical_
regioncx
;
let
regioncx
=
&
self
.regioncx
;
let
body
:
&
Body
<
'_
>
=
&
self
.body
;
let
tcx
=
self
.infcx.tcx
;
let
borrow_region_vid
=
borrow
.region
;
debug!
(
"explain_why_borrow_contains_point: borrow_region_vid={:?}"
,
borrow_region_vid
);
let
region_sub
=
self
.nonlexical_regioncx
.find_sub_region_live_at
(
borrow_region_vid
,
location
);
let
region_sub
=
self
.regioncx
.find_sub_region_live_at
(
borrow_region_vid
,
location
);
debug!
(
"explain_why_borrow_contains_point: region_sub={:?}"
,
region_sub
);
match
find_use
::
find
(
body
,
regioncx
,
tcx
,
region_sub
,
location
)
{
...
...
src/librustc_mir/borrow_check/diagnostics/region_errors.rs
浏览文件 @
234b9301
...
...
@@ -112,19 +112,18 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
/// to find a good name from that. Returns `None` if we can't find
/// one (e.g., this is just some random part of the CFG).
pub
(
super
)
fn
to_error_region
(
&
self
,
r
:
RegionVid
)
->
Option
<
ty
::
Region
<
'tcx
>>
{
self
.to_error_region_vid
(
r
)
.and_then
(|
r
|
self
.nonlexical_regioncx
.region_definition
(
r
)
.external_name
)
self
.to_error_region_vid
(
r
)
.and_then
(|
r
|
self
.regioncx
.region_definition
(
r
)
.external_name
)
}
/// Returns the `RegionVid` corresponding to the region returned by
/// `to_error_region`.
pub
(
super
)
fn
to_error_region_vid
(
&
self
,
r
:
RegionVid
)
->
Option
<
RegionVid
>
{
if
self
.
nonlexical_
regioncx
.universal_regions
()
.is_universal_region
(
r
)
{
if
self
.regioncx
.universal_regions
()
.is_universal_region
(
r
)
{
Some
(
r
)
}
else
{
let
upper_bound
=
self
.
nonlexical_
regioncx
.universal_upper_bound
(
r
);
let
upper_bound
=
self
.regioncx
.universal_upper_bound
(
r
);
if
self
.
nonlexical_
regioncx
.upper_bound_in_region_scc
(
r
,
upper_bound
)
{
if
self
.regioncx
.upper_bound_in_region_scc
(
r
,
upper_bound
)
{
self
.to_error_region_vid
(
upper_bound
)
}
else
{
None
...
...
@@ -137,7 +136,7 @@ fn is_closure_fn_mut(&self, fr: RegionVid) -> bool {
if
let
Some
(
ty
::
ReFree
(
free_region
))
=
self
.to_error_region
(
fr
)
{
if
let
ty
::
BoundRegion
::
BrEnv
=
free_region
.bound_region
{
if
let
DefiningTy
::
Closure
(
def_id
,
substs
)
=
self
.
nonlexical_
regioncx
.universal_regions
()
.defining_ty
self
.regioncx
.universal_regions
()
.defining_ty
{
let
closure_kind_ty
=
substs
.as_closure
()
.kind_ty
(
def_id
,
self
.infcx.tcx
);
return
Some
(
ty
::
ClosureKind
::
FnMut
)
==
closure_kind_ty
.to_opt_closure_kind
();
...
...
@@ -219,11 +218,10 @@ pub(in crate::borrow_check) fn report_region_errors(&mut self, nll_errors: Regio
fr_origin
,
error_element
,
}
=>
{
let
error_region
=
self
.nonlexical_regioncx
.region_from_element
(
longer_fr
,
error_element
);
let
error_region
=
self
.regioncx
.region_from_element
(
longer_fr
,
error_element
);
// Find the code to blame for the fact that `longer_fr` outlives `error_fr`.
let
(
_
,
span
)
=
self
.
nonlexical_
regioncx
.find_outlives_blame_span
(
let
(
_
,
span
)
=
self
.regioncx
.find_outlives_blame_span
(
&
self
.body
,
longer_fr
,
fr_origin
,
...
...
@@ -286,8 +284,8 @@ pub(in crate::borrow_check) fn report_error(
debug!
(
"report_error(fr={:?}, outlived_fr={:?})"
,
fr
,
outlived_fr
);
let
(
category
,
_
,
span
)
=
self
.
nonlexical_
regioncx
.best_blame_constraint
(
&
self
.body
,
fr
,
fr_origin
,
|
r
|
{
self
.
nonlexical_
regioncx
.provides_universal_region
(
r
,
fr
,
outlived_fr
)
self
.regioncx
.best_blame_constraint
(
&
self
.body
,
fr
,
fr_origin
,
|
r
|
{
self
.regioncx
.provides_universal_region
(
r
,
fr
,
outlived_fr
)
});
debug!
(
"report_error: category={:?} {:?}"
,
category
,
span
);
...
...
@@ -302,8 +300,8 @@ pub(in crate::borrow_check) fn report_error(
}
let
(
fr_is_local
,
outlived_fr_is_local
):
(
bool
,
bool
)
=
(
self
.
nonlexical_
regioncx
.universal_regions
()
.is_local_free_region
(
fr
),
self
.
nonlexical_
regioncx
.universal_regions
()
.is_local_free_region
(
outlived_fr
),
self
.regioncx
.universal_regions
()
.is_local_free_region
(
fr
),
self
.regioncx
.universal_regions
()
.is_local_free_region
(
outlived_fr
),
);
debug!
(
...
...
@@ -378,7 +376,7 @@ fn report_fnmut_error(
// We should check if the return type of this closure is in fact a closure - in that
// case, we can special case the error further.
let
return_type_is_closure
=
self
.
nonlexical_
regioncx
.universal_regions
()
.unnormalized_output_ty
.is_closure
();
self
.regioncx
.universal_regions
()
.unnormalized_output_ty
.is_closure
();
let
message
=
if
return_type_is_closure
{
"returns a closure that contains a reference to a captured variable, which then
\
escapes the closure body"
...
...
@@ -430,14 +428,14 @@ fn report_escaping_data_error(
)
->
DiagnosticBuilder
<
'tcx
>
{
let
ErrorConstraintInfo
{
span
,
category
,
..
}
=
errci
;
let
fr_name_and_span
=
self
.
nonlexical_
regioncx
.get_var_name_and_span_for_region
(
let
fr_name_and_span
=
self
.regioncx
.get_var_name_and_span_for_region
(
self
.infcx.tcx
,
&
self
.body
,
&
self
.local_names
,
&
self
.upvars
,
errci
.fr
,
);
let
outlived_fr_name_and_span
=
self
.
nonlexical_
regioncx
.get_var_name_and_span_for_region
(
let
outlived_fr_name_and_span
=
self
.regioncx
.get_var_name_and_span_for_region
(
self
.infcx.tcx
,
&
self
.body
,
&
self
.local_names
,
...
...
@@ -445,7 +443,7 @@ fn report_escaping_data_error(
errci
.outlived_fr
,
);
let
escapes_from
=
match
self
.
nonlexical_
regioncx
.universal_regions
()
.defining_ty
{
let
escapes_from
=
match
self
.regioncx
.universal_regions
()
.defining_ty
{
DefiningTy
::
Closure
(
..
)
=>
"closure"
,
DefiningTy
::
Generator
(
..
)
=>
"generator"
,
DefiningTy
::
FnDef
(
..
)
=>
"function"
,
...
...
src/librustc_mir/borrow_check/diagnostics/region_name.rs
浏览文件 @
234b9301
...
...
@@ -191,7 +191,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
)
->
Option
<
RegionName
>
{
debug!
(
"give_region_a_name(fr={:?}, counter={:?})"
,
fr
,
renctx
.counter
);
assert
!
(
self
.
nonlexical_
regioncx
.universal_regions
()
.is_universal_region
(
fr
));
assert
!
(
self
.regioncx
.universal_regions
()
.is_universal_region
(
fr
));
if
let
Some
(
value
)
=
renctx
.get
(
&
fr
)
{
return
Some
(
value
.clone
());
...
...
@@ -277,7 +277,7 @@ fn give_name_from_error_region(
.hir
()
.as_local_hir_id
(
self
.mir_def_id
)
.expect
(
"non-local mir"
);
let
def_ty
=
self
.
nonlexical_
regioncx
.universal_regions
()
.defining_ty
;
let
def_ty
=
self
.regioncx
.universal_regions
()
.defining_ty
;
if
let
DefiningTy
::
Closure
(
def_id
,
substs
)
=
def_ty
{
let
args_span
=
if
let
hir
::
ExprKind
::
Closure
(
_
,
_
,
_
,
span
,
_
)
=
...
...
@@ -344,12 +344,10 @@ fn give_name_if_anonymous_region_appears_in_arguments(
fr
:
RegionVid
,
renctx
:
&
mut
RegionErrorNamingCtx
,
)
->
Option
<
RegionName
>
{
let
implicit_inputs
=
self
.nonlexical_regioncx
.universal_regions
()
.defining_ty
.implicit_inputs
();
let
argument_index
=
self
.nonlexical_regioncx
.get_argument_index_for_region
(
self
.infcx.tcx
,
fr
)
?
;
let
implicit_inputs
=
self
.regioncx
.universal_regions
()
.defining_ty
.implicit_inputs
();
let
argument_index
=
self
.regioncx
.get_argument_index_for_region
(
self
.infcx.tcx
,
fr
)
?
;
let
arg_ty
=
self
.
nonlexical_
regioncx
.universal_regions
()
.unnormalized_input_tys
let
arg_ty
=
self
.regioncx
.universal_regions
()
.unnormalized_input_tys
[
implicit_inputs
+
argument_index
];
if
let
Some
(
region_name
)
=
self
.give_name_if_we_can_match_hir_ty_from_argument
(
fr
,
arg_ty
,
argument_index
,
renctx
)
...
...
@@ -415,10 +413,9 @@ fn give_name_if_we_cannot_match_hir_ty(
);
let
assigned_region_name
=
if
type_name
.find
(
&
format!
(
"'{}"
,
counter
))
.is_some
()
{
// Only add a label if we can confirm that a region was labelled.
let
argument_index
=
self
.nonlexical_regioncx
.get_argument_index_for_region
(
self
.infcx.tcx
,
needle_fr
)
?
;
let
(
_
,
span
)
=
self
.nonlexical_regioncx
.get_argument_name_and_span_for_region
(
let
argument_index
=
self
.regioncx
.get_argument_index_for_region
(
self
.infcx.tcx
,
needle_fr
)
?
;
let
(
_
,
span
)
=
self
.regioncx
.get_argument_name_and_span_for_region
(
&
self
.body
,
&
self
.local_names
,
argument_index
,
...
...
@@ -658,9 +655,8 @@ fn give_name_if_anonymous_region_appears_in_upvars(
fr
:
RegionVid
,
renctx
:
&
mut
RegionErrorNamingCtx
,
)
->
Option
<
RegionName
>
{
let
upvar_index
=
self
.nonlexical_regioncx
.get_upvar_index_for_region
(
self
.infcx.tcx
,
fr
)
?
;
let
(
upvar_name
,
upvar_span
)
=
self
.nonlexical_regioncx
.get_upvar_name_and_span_for_region
(
let
upvar_index
=
self
.regioncx
.get_upvar_index_for_region
(
self
.infcx.tcx
,
fr
)
?
;
let
(
upvar_name
,
upvar_span
)
=
self
.regioncx
.get_upvar_name_and_span_for_region
(
self
.infcx.tcx
,
&
self
.upvars
,
upvar_index
,
...
...
@@ -684,7 +680,7 @@ fn give_name_if_anonymous_region_appears_in_output(
)
->
Option
<
RegionName
>
{
let
tcx
=
self
.infcx.tcx
;
let
return_ty
=
self
.
nonlexical_
regioncx
.universal_regions
()
.unnormalized_output_ty
;
let
return_ty
=
self
.regioncx
.universal_regions
()
.unnormalized_output_ty
;
debug!
(
"give_name_if_anonymous_region_appears_in_output: return_ty = {:?}"
,
return_ty
);
if
!
tcx
.any_free_region_meets
(
&
return_ty
,
|
r
|
r
.to_region_vid
()
==
fr
)
{
return
None
;
...
...
@@ -734,7 +730,7 @@ fn give_name_if_anonymous_region_appears_in_yield_ty(
)
->
Option
<
RegionName
>
{
// Note: generators from `async fn` yield `()`, so we don't have to
// worry about them here.
let
yield_ty
=
self
.
nonlexical_
regioncx
.universal_regions
()
.yield_ty
?
;
let
yield_ty
=
self
.regioncx
.universal_regions
()
.yield_ty
?
;
debug!
(
"give_name_if_anonymous_region_appears_in_yield_ty: yield_ty = {:?}"
,
yield_ty
,);
let
tcx
=
self
.infcx.tcx
;
...
...
src/librustc_mir/borrow_check/mod.rs
浏览文件 @
234b9301
...
...
@@ -283,7 +283,7 @@ fn do_mir_borrowck<'a, 'tcx>(
move_error_reported
:
BTreeMap
::
new
(),
uninitialized_error_reported
:
Default
::
default
(),
errors_buffer
,
nonlexical_regioncx
:
regioncx
,
regioncx
,
used_mut
:
Default
::
default
(),
used_mut_upvars
:
SmallVec
::
new
(),
borrow_set
,
...
...
@@ -474,10 +474,9 @@ fn do_mir_borrowck<'a, 'tcx>(
/// If the function we're checking is a closure, then we'll need to report back the list of
/// mutable upvars that have been used. This field keeps track of them.
used_mut_upvars
:
SmallVec
<
[
Field
;
8
]
>
,
/// Non-lexical region inference context, if NLL is enabled. This
/// contains the results from region inference and lets us e.g.
/// Region inference context. This contains the results from region inference and lets us e.g.
/// find out which CFG points are contained in each borrow region.
nonlexical_
regioncx
:
Rc
<
RegionInferenceContext
<
'tcx
>>
,
regioncx
:
Rc
<
RegionInferenceContext
<
'tcx
>>
,
/// The set of borrows extracted from the MIR
borrow_set
:
Rc
<
BorrowSet
<
'tcx
>>
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录