Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
ad722478
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,发现更多精彩内容 >>
未验证
提交
ad722478
编写于
5月 25, 2021
作者:
G
Guillaume Gomez
提交者:
GitHub
5月 25, 2021
浏览文件
操作
浏览文件
下载
差异文件
Rollup merge of #85605 - ptrojahn:closure_struct, r=matthewjasper
Replace Local::new(1) with CAPTURE_STRUCT_LOCAL
上级
6b0b81b0
0a80cc4d
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
20 addition
and
19 deletion
+20
-19
compiler/rustc_middle/src/ty/closure.rs
compiler/rustc_middle/src/ty/closure.rs
+5
-1
compiler/rustc_mir/src/borrow_check/diagnostics/conflict_errors.rs
...rustc_mir/src/borrow_check/diagnostics/conflict_errors.rs
+4
-3
compiler/rustc_mir/src/borrow_check/diagnostics/mutability_errors.rs
...stc_mir/src/borrow_check/diagnostics/mutability_errors.rs
+7
-8
compiler/rustc_mir_build/src/build/expr/as_place.rs
compiler/rustc_mir_build/src/build/expr/as_place.rs
+1
-3
compiler/rustc_mir_build/src/build/expr/as_rvalue.rs
compiler/rustc_mir_build/src/build/expr/as_rvalue.rs
+1
-1
compiler/rustc_mir_build/src/build/mod.rs
compiler/rustc_mir_build/src/build/mod.rs
+2
-3
未找到文件。
compiler/rustc_middle/src/ty/closure.rs
浏览文件 @
ad722478
use
crate
::
hir
::
place
::{
Place
as
HirPlace
,
PlaceBase
as
HirPlaceBase
,
ProjectionKind
as
HirProjectionKind
,
};
use
crate
::
ty
;
use
crate
::
{
mir
,
ty
}
;
use
rustc_data_structures
::
fx
::{
FxHashMap
,
FxIndexMap
};
use
rustc_hir
as
hir
;
...
...
@@ -12,6 +12,10 @@
use
self
::
BorrowKind
::
*
;
// Captures are represented using fields inside a structure.
// This represents accessing self in the closure structure
pub
const
CAPTURE_STRUCT_LOCAL
:
mir
::
Local
=
mir
::
Local
::
from_u32
(
1
);
#[derive(
Clone,
Copy,
...
...
compiler/rustc_mir/src/borrow_check/diagnostics/conflict_errors.rs
浏览文件 @
ad722478
...
...
@@ -4,10 +4,9 @@
use
rustc_hir
as
hir
;
use
rustc_hir
::
def_id
::
DefId
;
use
rustc_hir
::{
AsyncGeneratorKind
,
GeneratorKind
};
use
rustc_index
::
vec
::
Idx
;
use
rustc_middle
::
mir
::{
self
,
AggregateKind
,
BindingForm
,
BorrowKind
,
ClearCrossCrate
,
ConstraintCategory
,
FakeReadCause
,
Local
,
Local
Decl
,
LocalInfo
,
LocalKind
,
Location
,
Operand
,
Place
,
PlaceRef
,
FakeReadCause
,
LocalDecl
,
LocalInfo
,
LocalKind
,
Location
,
Operand
,
Place
,
PlaceRef
,
ProjectionElem
,
Rvalue
,
Statement
,
StatementKind
,
Terminator
,
TerminatorKind
,
VarBindingForm
,
};
use
rustc_middle
::
ty
::{
self
,
suggest_constraining_type_param
,
Ty
,
TypeFoldable
};
...
...
@@ -1274,7 +1273,9 @@ fn try_report_cannot_return_reference_to_local(
bug!
(
"temporary or return pointer with a name"
)
}
LocalKind
::
Var
=>
"local variable "
,
LocalKind
::
Arg
if
!
self
.upvars
.is_empty
()
&&
local
==
Local
::
new
(
1
)
=>
{
LocalKind
::
Arg
if
!
self
.upvars
.is_empty
()
&&
local
==
ty
::
CAPTURE_STRUCT_LOCAL
=>
{
"variable captured by `move` "
}
LocalKind
::
Arg
=>
"function parameter "
,
...
...
compiler/rustc_mir/src/borrow_check/diagnostics/mutability_errors.rs
浏览文件 @
ad722478
use
rustc_hir
as
hir
;
use
rustc_hir
::
Node
;
use
rustc_index
::
vec
::
Idx
;
use
rustc_middle
::
hir
::
map
::
Map
;
use
rustc_middle
::
mir
::{
Mutability
,
Place
,
PlaceRef
,
ProjectionElem
};
use
rustc_middle
::
ty
::{
self
,
Ty
,
TyCtxt
};
...
...
@@ -115,12 +114,14 @@ pub(crate) fn report_mutability_error(
}
}
PlaceRef
{
local
:
_
,
projection
:
[
proj_base
@
..
,
ProjectionElem
::
Deref
]
}
=>
{
if
the_place_err
.local
==
Local
::
new
(
1
)
if
the_place_err
.local
==
ty
::
CAPTURE_STRUCT_LOCAL
&&
proj_base
.is_empty
()
&&
!
self
.upvars
.is_empty
()
{
item_msg
=
format!
(
"`{}`"
,
access_place_desc
.unwrap
());
debug_assert!
(
self
.body.local_decls
[
Local
::
new
(
1
)]
.ty
.is_region_ptr
());
debug_assert!
(
self
.body.local_decls
[
ty
::
CAPTURE_STRUCT_LOCAL
]
.ty
.is_region_ptr
()
);
debug_assert!
(
is_closure_or_generator
(
Place
::
ty_from
(
the_place_err
.local
,
...
...
@@ -478,11 +479,9 @@ pub(crate) fn report_mutability_error(
}
}
PlaceRef
{
local
,
projection
:
[
ProjectionElem
::
Deref
],
// FIXME document what is this 1 magic number about
}
if
local
==
Local
::
new
(
1
)
&&
!
self
.upvars
.is_empty
()
=>
{
PlaceRef
{
local
,
projection
:
[
ProjectionElem
::
Deref
]
}
if
local
==
ty
::
CAPTURE_STRUCT_LOCAL
&&
!
self
.upvars
.is_empty
()
=>
{
self
.expected_fn_found_fn_mut_call
(
&
mut
err
,
span
,
act
);
}
...
...
compiler/rustc_mir_build/src/build/expr/as_place.rs
浏览文件 @
ad722478
...
...
@@ -209,9 +209,7 @@ fn to_upvars_resolved_place_builder<'a, 'tcx>(
match
from_builder
.base
{
PlaceBase
::
Local
(
_
)
=>
Ok
(
from_builder
),
PlaceBase
::
Upvar
{
var_hir_id
,
closure_def_id
,
closure_kind
}
=>
{
// Captures are represented using fields inside a structure.
// This represents accessing self in the closure structure
let
mut
upvar_resolved_place_builder
=
PlaceBuilder
::
from
(
Local
::
new
(
1
));
let
mut
upvar_resolved_place_builder
=
PlaceBuilder
::
from
(
ty
::
CAPTURE_STRUCT_LOCAL
);
match
closure_kind
{
ty
::
ClosureKind
::
Fn
|
ty
::
ClosureKind
::
FnMut
=>
{
upvar_resolved_place_builder
=
upvar_resolved_place_builder
.deref
();
...
...
compiler/rustc_mir_build/src/build/expr/as_rvalue.rs
浏览文件 @
ad722478
...
...
@@ -446,7 +446,7 @@ fn limit_capture_mutability(
}
=>
{
// Not in a closure
debug_assert!
(
local
==
Local
::
new
(
1
)
,
local
==
ty
::
CAPTURE_STRUCT_LOCAL
,
"Expected local to be Local(1), found {:?}"
,
local
);
...
...
compiler/rustc_mir_build/src/build/mod.rs
浏览文件 @
ad722478
...
...
@@ -953,9 +953,8 @@ fn args_and_body(
// the given closure and use the necessary information to create upvar
// debuginfo and to fill `self.upvar_mutbls`.
if
hir_typeck_results
.closure_min_captures
.get
(
&
fn_def_id
)
.is_some
()
{
let
closure_env_arg
=
Local
::
new
(
1
);
let
mut
closure_env_projs
=
vec!
[];
let
mut
closure_ty
=
self
.local_decls
[
closure_env_arg
]
.ty
;
let
mut
closure_ty
=
self
.local_decls
[
ty
::
CAPTURE_STRUCT_LOCAL
]
.ty
;
if
let
ty
::
Ref
(
_
,
ty
,
_
)
=
closure_ty
.kind
()
{
closure_env_projs
.push
(
ProjectionElem
::
Deref
);
closure_ty
=
ty
;
...
...
@@ -1001,7 +1000,7 @@ fn args_and_body(
name
,
source_info
:
SourceInfo
::
outermost
(
tcx_hir
.span
(
var_id
)),
value
:
VarDebugInfoContents
::
Place
(
Place
{
local
:
closure_env_arg
,
local
:
ty
::
CAPTURE_STRUCT_LOCAL
,
projection
:
tcx
.intern_place_elems
(
&
projs
),
}),
});
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录