Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
3f661d25
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,发现更多精彩内容 >>
提交
3f661d25
编写于
5月 11, 2020
作者:
B
Bastian Kauschke
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
borrowck `DefId` -> `LocalDefId`
上级
bad3bf62
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
59 addition
and
67 deletion
+59
-67
src/librustc_mir/borrow_check/diagnostics/conflict_errors.rs
src/librustc_mir/borrow_check/diagnostics/conflict_errors.rs
+42
-47
src/librustc_mir/borrow_check/diagnostics/move_errors.rs
src/librustc_mir/borrow_check/diagnostics/move_errors.rs
+1
-1
src/librustc_mir/borrow_check/diagnostics/mutability_errors.rs
...ibrustc_mir/borrow_check/diagnostics/mutability_errors.rs
+1
-1
src/librustc_mir/borrow_check/diagnostics/region_errors.rs
src/librustc_mir/borrow_check/diagnostics/region_errors.rs
+1
-1
src/librustc_mir/borrow_check/diagnostics/region_name.rs
src/librustc_mir/borrow_check/diagnostics/region_name.rs
+4
-5
src/librustc_mir/borrow_check/mod.rs
src/librustc_mir/borrow_check/mod.rs
+6
-8
src/librustc_mir/borrow_check/nll.rs
src/librustc_mir/borrow_check/nll.rs
+4
-4
未找到文件。
src/librustc_mir/borrow_check/diagnostics/conflict_errors.rs
浏览文件 @
3f661d25
...
...
@@ -214,7 +214,7 @@ pub(in crate::borrow_check) fn report_use_of_moved_or_uninitialized(
let
generics
=
tcx
.generics_of
(
self
.mir_def_id
);
let
param
=
generics
.type_param
(
&
param_ty
,
tcx
);
if
let
Some
(
generics
)
=
tcx
.hir
()
.get_generics
(
tcx
.closure_base_def_id
(
self
.mir_def_id
))
tcx
.hir
()
.get_generics
(
tcx
.closure_base_def_id
(
self
.mir_def_id
.to_def_id
()
))
{
suggest_constraining_type_param
(
tcx
,
...
...
@@ -865,49 +865,42 @@ fn report_local_value_does_not_live_long_enough(
format!
(
"`{}` would have to be valid for `{}`..."
,
name
,
region_name
),
);
if
let
Some
(
def_id
)
=
self
.mir_def_id
.as_local
()
{
let
fn_hir_id
=
self
.infcx.tcx
.hir
()
.as_local_hir_id
(
def_id
);
err
.span_label
(
drop_span
,
format!
(
"...but `{}` will be dropped here, when the {} returns"
,
name
,
self
.infcx
.tcx
.hir
()
.opt_name
(
fn_hir_id
)
.map
(|
name
|
format!
(
"function `{}`"
,
name
))
.unwrap_or_else
(||
{
match
&
self
.infcx
.tcx
.typeck_tables_of
(
def_id
)
.node_type
(
fn_hir_id
)
.kind
{
ty
::
Closure
(
..
)
=>
"enclosing closure"
,
ty
::
Generator
(
..
)
=>
"enclosing generator"
,
kind
=>
bug!
(
"expected closure or generator, found {:?}"
,
kind
),
}
.to_string
()
})
),
);
let
fn_hir_id
=
self
.infcx.tcx
.hir
()
.as_local_hir_id
(
self
.mir_def_id
);
err
.span_label
(
drop_span
,
format!
(
"...but `{}` will be dropped here, when the {} returns"
,
name
,
self
.infcx
.tcx
.hir
()
.opt_name
(
fn_hir_id
)
.map
(|
name
|
format!
(
"function `{}`"
,
name
))
.unwrap_or_else
(||
{
match
&
self
.infcx
.tcx
.typeck_tables_of
(
self
.mir_def_id
)
.node_type
(
fn_hir_id
)
.kind
{
ty
::
Closure
(
..
)
=>
"enclosing closure"
,
ty
::
Generator
(
..
)
=>
"enclosing generator"
,
kind
=>
bug!
(
"expected closure or generator, found {:?}"
,
kind
),
}
.to_string
()
})
),
);
err
.note
(
"functions cannot return a borrow to data owned within the function's scope,
\
functions can only return borrows to data passed as arguments"
,
);
err
.note
(
"to learn more, visit <https://doc.rust-lang.org/book/ch04-02-
\
references-and-borrowing.html#dangling-references>"
,
);
}
else
{
err
.span_label
(
drop_span
,
format!
(
"...but `{}` dropped here while still borrowed"
,
name
),
);
}
err
.note
(
"functions cannot return a borrow to data owned within the function's scope,
\
functions can only return borrows to data passed as arguments"
,
);
err
.note
(
"to learn more, visit <https://doc.rust-lang.org/book/ch04-02-
\
references-and-borrowing.html#dangling-references>"
,
);
if
let
BorrowExplanation
::
MustBeValidFor
{
..
}
=
explanation
{
}
else
{
...
...
@@ -1237,7 +1230,7 @@ fn report_escaping_data(
)
->
DiagnosticBuilder
<
'cx
>
{
let
tcx
=
self
.infcx.tcx
;
let
(
_
,
escapes_from
)
=
tcx
.article_and_description
(
self
.mir_def_id
);
let
(
_
,
escapes_from
)
=
tcx
.article_and_description
(
self
.mir_def_id
.to_def_id
()
);
let
mut
err
=
borrowck_errors
::
borrowed_data_escapes_closure
(
tcx
,
escape_span
,
escapes_from
);
...
...
@@ -1572,14 +1565,16 @@ fn annotate_argument_and_return_for_borrow(
)
->
Option
<
AnnotatedBorrowFnSignature
<
'tcx
>>
{
// Define a fallback for when we can't match a closure.
let
fallback
=
||
{
let
is_closure
=
self
.infcx.tcx
.is_closure
(
self
.mir_def_id
);
let
is_closure
=
self
.infcx.tcx
.is_closure
(
self
.mir_def_id
.to_def_id
()
);
if
is_closure
{
None
}
else
{
let
ty
=
self
.infcx.tcx
.type_of
(
self
.mir_def_id
);
match
ty
.kind
{
ty
::
FnDef
(
_
,
_
)
|
ty
::
FnPtr
(
_
)
=>
self
.annotate_fn_sig
(
self
.mir_def_id
,
self
.infcx.tcx
.fn_sig
(
self
.mir_def_id
)),
ty
::
FnDef
(
_
,
_
)
|
ty
::
FnPtr
(
_
)
=>
self
.annotate_fn_sig
(
self
.mir_def_id
.to_def_id
(),
self
.infcx.tcx
.fn_sig
(
self
.mir_def_id
),
),
_
=>
None
,
}
}
...
...
src/librustc_mir/borrow_check/diagnostics/move_errors.rs
浏览文件 @
3f661d25
...
...
@@ -331,7 +331,7 @@ fn report_cannot_move_from_borrowed_content(
self
.cannot_move_out_of_interior_noncopy
(
span
,
ty
,
None
)
}
ty
::
Closure
(
def_id
,
closure_substs
)
if
def_id
==
self
.mir_def_id
&&
upvar_field
.is_some
()
=>
if
def_id
.as_local
()
==
Some
(
self
.mir_def_id
)
&&
upvar_field
.is_some
()
=>
{
let
closure_kind_ty
=
closure_substs
.as_closure
()
.kind_ty
();
let
closure_kind
=
closure_kind_ty
.to_opt_closure_kind
();
...
...
src/librustc_mir/borrow_check/diagnostics/mutability_errors.rs
浏览文件 @
3f661d25
...
...
@@ -492,7 +492,7 @@ fn expected_fn_found_fn_mut_call(&self, err: &mut DiagnosticBuilder<'_>, sp: Spa
err
.span_label
(
sp
,
format!
(
"cannot {}"
,
act
));
let
hir
=
self
.infcx.tcx
.hir
();
let
closure_id
=
hir
.as_local_hir_id
(
self
.mir_def_id
.expect_local
()
);
let
closure_id
=
hir
.as_local_hir_id
(
self
.mir_def_id
);
let
fn_call_id
=
hir
.get_parent_node
(
closure_id
);
let
node
=
hir
.get
(
fn_call_id
);
let
item_id
=
hir
.get_parent_item
(
fn_call_id
);
...
...
src/librustc_mir/borrow_check/diagnostics/region_errors.rs
浏览文件 @
3f661d25
...
...
@@ -502,7 +502,7 @@ fn report_general_error(&self, errci: &ErrorConstraintInfo) -> DiagnosticBuilder
let
mut
diag
=
self
.infcx.tcx.sess
.struct_span_err
(
*
span
,
"lifetime may not live long enough"
);
let
(
_
,
mir_def_name
)
=
self
.infcx.tcx
.article_and_description
(
self
.mir_def_id
);
let
(
_
,
mir_def_name
)
=
self
.infcx.tcx
.article_and_description
(
self
.mir_def_id
.to_def_id
()
);
let
fr_name
=
self
.give_region_a_name
(
*
fr
)
.unwrap
();
fr_name
.highlight_region_name
(
&
mut
diag
);
...
...
src/librustc_mir/borrow_check/diagnostics/region_name.rs
浏览文件 @
3f661d25
...
...
@@ -237,8 +237,7 @@ fn give_name_from_error_region(&self, fr: RegionVid) -> Option<RegionName> {
}
ty
::
BoundRegion
::
BrEnv
=>
{
let
mir_hir_id
=
self
.infcx.tcx
.hir
()
.as_local_hir_id
(
self
.mir_def_id
.expect_local
());
let
mir_hir_id
=
self
.infcx.tcx
.hir
()
.as_local_hir_id
(
self
.mir_def_id
);
let
def_ty
=
self
.regioncx
.universal_regions
()
.defining_ty
;
if
let
DefiningTy
::
Closure
(
_
,
substs
)
=
def_ty
{
...
...
@@ -324,7 +323,7 @@ fn give_name_if_we_can_match_hir_ty_from_argument(
argument_ty
:
Ty
<
'tcx
>
,
argument_index
:
usize
,
)
->
Option
<
RegionName
>
{
let
mir_hir_id
=
self
.infcx.tcx
.hir
()
.as_local_hir_id
(
self
.mir_def_id
.as_local
()
?
);
let
mir_hir_id
=
self
.infcx.tcx
.hir
()
.as_local_hir_id
(
self
.mir_def_id
);
let
fn_decl
=
self
.infcx.tcx
.hir
()
.fn_decl_by_hir_id
(
mir_hir_id
)
?
;
let
argument_hir_ty
:
&
hir
::
Ty
<
'_
>
=
fn_decl
.inputs
.get
(
argument_index
)
?
;
match
argument_hir_ty
.kind
{
...
...
@@ -635,7 +634,7 @@ fn give_name_if_anonymous_region_appears_in_output(&self, fr: RegionVid) -> Opti
highlight
.highlighting_region_vid
(
fr
,
*
self
.next_region_name
.try_borrow
()
.unwrap
());
let
type_name
=
self
.infcx
.extract_type_name
(
&
return_ty
,
Some
(
highlight
))
.0
;
let
mir_hir_id
=
tcx
.hir
()
.as_local_hir_id
(
self
.mir_def_id
.expect_local
()
);
let
mir_hir_id
=
tcx
.hir
()
.as_local_hir_id
(
self
.mir_def_id
);
let
(
return_span
,
mir_description
)
=
match
tcx
.hir
()
.get
(
mir_hir_id
)
{
hir
::
Node
::
Expr
(
hir
::
Expr
{
...
...
@@ -687,7 +686,7 @@ fn give_name_if_anonymous_region_appears_in_yield_ty(
highlight
.highlighting_region_vid
(
fr
,
*
self
.next_region_name
.try_borrow
()
.unwrap
());
let
type_name
=
self
.infcx
.extract_type_name
(
&
yield_ty
,
Some
(
highlight
))
.0
;
let
mir_hir_id
=
tcx
.hir
()
.as_local_hir_id
(
self
.mir_def_id
.expect_local
()
);
let
mir_hir_id
=
tcx
.hir
()
.as_local_hir_id
(
self
.mir_def_id
);
let
yield_span
=
match
tcx
.hir
()
.get
(
mir_hir_id
)
{
hir
::
Node
::
Expr
(
hir
::
Expr
{
...
...
src/librustc_mir/borrow_check/mod.rs
浏览文件 @
3f661d25
...
...
@@ -4,10 +4,8 @@
use
rustc_data_structures
::
graph
::
dominators
::
Dominators
;
use
rustc_errors
::{
Applicability
,
Diagnostic
,
DiagnosticBuilder
,
ErrorReported
};
use
rustc_hir
as
hir
;
use
rustc_hir
::{
def_id
::{
DefId
,
LocalDefId
},
HirId
,
Node
,
};
use
rustc_hir
::
def_id
::
LocalDefId
;
use
rustc_hir
::{
HirId
,
Node
};
use
rustc_index
::
bit_set
::
BitSet
;
use
rustc_index
::
vec
::
IndexVec
;
use
rustc_infer
::
infer
::{
InferCtxt
,
TyCtxtInferExt
};
...
...
@@ -174,7 +172,7 @@ fn do_mir_borrowck<'a, 'tcx>(
let
mut
body
=
input_body
.clone
();
let
mut
promoted
=
input_promoted
.clone
();
let
free_regions
=
nll
::
replace_regions_in_mir
(
infcx
,
def_id
.to_def_id
()
,
param_env
,
&
mut
body
,
&
mut
promoted
);
nll
::
replace_regions_in_mir
(
infcx
,
def_id
,
param_env
,
&
mut
body
,
&
mut
promoted
);
let
body
=
&
body
;
// no further changes
let
location_table
=
&
LocationTable
::
new
(
&
body
);
...
...
@@ -275,7 +273,7 @@ fn do_mir_borrowck<'a, 'tcx>(
let
mut
promoted_mbcx
=
MirBorrowckCtxt
{
infcx
,
body
:
promoted_body
,
mir_def_id
:
def_id
.to_def_id
()
,
mir_def_id
:
def_id
,
move_data
:
&
move_data
,
location_table
:
&
LocationTable
::
new
(
promoted_body
),
movable_generator
,
...
...
@@ -307,7 +305,7 @@ fn do_mir_borrowck<'a, 'tcx>(
let
mut
mbcx
=
MirBorrowckCtxt
{
infcx
,
body
,
mir_def_id
:
def_id
.to_def_id
()
,
mir_def_id
:
def_id
,
move_data
:
&
mdpe
.move_data
,
location_table
,
movable_generator
,
...
...
@@ -459,7 +457,7 @@ fn do_mir_borrowck<'a, 'tcx>(
crate
struct
MirBorrowckCtxt
<
'cx
,
'tcx
>
{
crate
infcx
:
&
'cx
InferCtxt
<
'cx
,
'tcx
>
,
body
:
&
'cx
Body
<
'tcx
>
,
mir_def_id
:
DefId
,
mir_def_id
:
Local
DefId
,
move_data
:
&
'cx
MoveData
<
'tcx
>
,
/// Map from MIR `Location` to `LocationIndex`; created
...
...
src/librustc_mir/borrow_check/nll.rs
浏览文件 @
3f661d25
...
...
@@ -2,7 +2,7 @@
use
rustc_data_structures
::
fx
::
FxHashMap
;
use
rustc_errors
::
Diagnostic
;
use
rustc_hir
::
def_id
::
DefId
;
use
rustc_hir
::
def_id
::
{
DefId
,
LocalDefId
}
;
use
rustc_index
::
vec
::
IndexVec
;
use
rustc_infer
::
infer
::
InferCtxt
;
use
rustc_middle
::
mir
::{
...
...
@@ -58,7 +58,7 @@
/// `compute_regions`.
pub
(
in
crate
::
borrow_check
)
fn
replace_regions_in_mir
<
'cx
,
'tcx
>
(
infcx
:
&
InferCtxt
<
'cx
,
'tcx
>
,
def_id
:
DefId
,
def_id
:
Local
DefId
,
param_env
:
ty
::
ParamEnv
<
'tcx
>
,
body
:
&
mut
Body
<
'tcx
>
,
promoted
:
&
mut
IndexVec
<
Promoted
,
Body
<
'tcx
>>
,
...
...
@@ -66,12 +66,12 @@ pub(in crate::borrow_check) fn replace_regions_in_mir<'cx, 'tcx>(
debug!
(
"replace_regions_in_mir(def_id={:?})"
,
def_id
);
// Compute named region information. This also renumbers the inputs/outputs.
let
universal_regions
=
UniversalRegions
::
new
(
infcx
,
def_id
.expect_local
()
,
param_env
);
let
universal_regions
=
UniversalRegions
::
new
(
infcx
,
def_id
,
param_env
);
// Replace all remaining regions with fresh inference variables.
renumber
::
renumber_mir
(
infcx
,
body
,
promoted
);
let
source
=
MirSource
::
item
(
def_id
);
let
source
=
MirSource
::
item
(
def_id
.to_def_id
()
);
mir_util
::
dump_mir
(
infcx
.tcx
,
None
,
"renumber"
,
&
0
,
source
,
body
,
|
_
,
_
|
Ok
(()));
universal_regions
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录