Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
a9ffe67f
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,发现更多精彩内容 >>
提交
a9ffe67f
编写于
3月 07, 2016
作者:
B
bors
浏览文件
操作
浏览文件
下载
差异文件
Auto merge of #31606 - Ms2ger:ClosureKind, r=eddyb
Rename ClosureKind variants and stop re-exporting them.
上级
8b7c3f20
c6474af9
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
56 addition
and
57 deletion
+56
-57
src/librustc/middle/lang_items.rs
src/librustc/middle/lang_items.rs
+3
-3
src/librustc/middle/mem_categorization.rs
src/librustc/middle/mem_categorization.rs
+6
-6
src/librustc/middle/ty/mod.rs
src/librustc/middle/ty/mod.rs
+12
-13
src/librustc_borrowck/borrowck/mod.rs
src/librustc_borrowck/borrowck/mod.rs
+1
-1
src/librustc_mir/hair/cx/expr.rs
src/librustc_mir/hair/cx/expr.rs
+3
-3
src/librustc_mir/mir_map.rs
src/librustc_mir/mir_map.rs
+3
-3
src/librustc_trans/trans/base.rs
src/librustc_trans/trans/base.rs
+3
-3
src/librustc_trans/trans/callee.rs
src/librustc_trans/trans/callee.rs
+2
-2
src/librustc_trans/trans/closure.rs
src/librustc_trans/trans/closure.rs
+8
-8
src/librustc_typeck/check/method/probe.rs
src/librustc_typeck/check/method/probe.rs
+3
-3
src/librustc_typeck/check/upvar.rs
src/librustc_typeck/check/upvar.rs
+12
-12
未找到文件。
src/librustc/middle/lang_items.rs
浏览文件 @
a9ffe67f
...
...
@@ -120,9 +120,9 @@ pub fn to_builtin_kind(&self, id: DefId) -> Option<ty::BuiltinBound> {
pub
fn
fn_trait_kind
(
&
self
,
id
:
DefId
)
->
Option
<
ty
::
ClosureKind
>
{
let
def_id_kinds
=
[
(
self
.fn_trait
(),
ty
::
FnClosureKind
),
(
self
.fn_mut_trait
(),
ty
::
FnMutClosureKind
),
(
self
.fn_once_trait
(),
ty
::
FnOnceClosureKind
),
(
self
.fn_trait
(),
ty
::
ClosureKind
::
Fn
),
(
self
.fn_mut_trait
(),
ty
::
ClosureKind
::
FnMut
),
(
self
.fn_once_trait
(),
ty
::
ClosureKind
::
FnOnce
),
];
for
&
(
opt_def_id
,
kind
)
in
&
def_id_kinds
{
...
...
src/librustc/middle/mem_categorization.rs
浏览文件 @
a9ffe67f
...
...
@@ -670,13 +670,13 @@ fn cat_upvar(&self,
// conceptually a `&mut` or `&` reference, so we have to add a
// deref.
let
cmt_result
=
match
kind
{
ty
::
FnOnceClosureKind
=>
{
ty
::
ClosureKind
::
FnOnce
=>
{
cmt_result
}
ty
::
FnMutClosureKind
=>
{
ty
::
ClosureKind
::
FnMut
=>
{
self
.env_deref
(
id
,
span
,
upvar_id
,
var_mutbl
,
ty
::
MutBorrow
,
cmt_result
)
}
ty
::
FnClosureKind
=>
{
ty
::
ClosureKind
::
Fn
=>
{
self
.env_deref
(
id
,
span
,
upvar_id
,
var_mutbl
,
ty
::
ImmBorrow
,
cmt_result
)
}
};
...
...
@@ -1630,9 +1630,9 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
impl
fmt
::
Display
for
Upvar
{
fn
fmt
(
&
self
,
f
:
&
mut
fmt
::
Formatter
)
->
fmt
::
Result
{
let
kind
=
match
self
.kind
{
ty
::
FnClosureKind
=>
"Fn"
,
ty
::
FnMutClosureKind
=>
"FnMut"
,
ty
::
FnOnceClosureKind
=>
"FnOnce"
,
ty
::
ClosureKind
::
Fn
=>
"Fn"
,
ty
::
ClosureKind
::
FnMut
=>
"FnMut"
,
ty
::
ClosureKind
::
FnOnce
=>
"FnOnce"
,
};
write!
(
f
,
"captured outer variable in an `{}` closure"
,
kind
)
}
...
...
src/librustc/middle/ty/mod.rs
浏览文件 @
a9ffe67f
...
...
@@ -9,7 +9,6 @@
// except according to those terms.
pub
use
self
::
ImplOrTraitItemId
::
*
;
pub
use
self
::
ClosureKind
::
*
;
pub
use
self
::
Variance
::
*
;
pub
use
self
::
DtorKind
::
*
;
pub
use
self
::
ImplOrTraitItemContainer
::
*
;
...
...
@@ -1699,19 +1698,19 @@ pub enum ClosureKind {
// Warning: Ordering is significant here! The ordering is chosen
// because the trait Fn is a subtrait of FnMut and so in turn, and
// hence we order it so that Fn < FnMut < FnOnce.
Fn
ClosureKind
,
FnMut
ClosureKind
,
FnOnce
ClosureKind
,
Fn
,
FnMut
,
FnOnce
,
}
impl
ClosureKind
{
pub
fn
trait_did
(
&
self
,
cx
:
&
TyCtxt
)
->
DefId
{
let
result
=
match
*
self
{
FnClosureKind
=>
cx
.lang_items
.require
(
FnTraitLangItem
),
FnMutClosureKind
=>
{
ClosureKind
::
Fn
=>
cx
.lang_items
.require
(
FnTraitLangItem
),
ClosureKind
::
FnMut
=>
{
cx
.lang_items
.require
(
FnMutTraitLangItem
)
}
FnOnceClosureKind
=>
{
ClosureKind
::
FnOnce
=>
{
cx
.lang_items
.require
(
FnOnceTraitLangItem
)
}
};
...
...
@@ -1725,12 +1724,12 @@ pub fn trait_did(&self, cx: &TyCtxt) -> DefId {
/// must also implement `other`.
pub
fn
extends
(
self
,
other
:
ty
::
ClosureKind
)
->
bool
{
match
(
self
,
other
)
{
(
FnClosureKind
,
FnClosureKind
)
=>
true
,
(
FnClosureKind
,
FnMutClosureKind
)
=>
true
,
(
FnClosureKind
,
FnOnceClosureKind
)
=>
true
,
(
FnMutClosureKind
,
FnMutClosureKind
)
=>
true
,
(
FnMutClosureKind
,
FnOnceClosureKind
)
=>
true
,
(
FnOnceClosureKind
,
FnOnceClosureKind
)
=>
true
,
(
ClosureKind
::
Fn
,
ClosureKind
::
Fn
)
=>
true
,
(
ClosureKind
::
Fn
,
ClosureKind
::
FnMut
)
=>
true
,
(
ClosureKind
::
Fn
,
ClosureKind
::
FnOnce
)
=>
true
,
(
ClosureKind
::
FnMut
,
ClosureKind
::
FnMut
)
=>
true
,
(
ClosureKind
::
FnMut
,
ClosureKind
::
FnOnce
)
=>
true
,
(
ClosureKind
::
FnOnce
,
ClosureKind
::
FnOnce
)
=>
true
,
_
=>
false
,
}
}
...
...
src/librustc_borrowck/borrowck/mod.rs
浏览文件 @
a9ffe67f
...
...
@@ -1009,7 +1009,7 @@ pub fn note_and_explain_bckerr(&self, db: &mut DiagnosticBuilder, err: BckError<
Categorization
::
Upvar
(
mc
::
Upvar
{
kind
,
..
})
=>
kind
,
_
=>
unreachable!
()
};
if
kind
==
ty
::
FnClosureKind
{
if
kind
==
ty
::
ClosureKind
::
Fn
{
db
.span_help
(
self
.tcx.map
.span
(
upvar_id
.closure_expr_id
),
"consider changing this closure to take
\
...
...
src/librustc_mir/hair/cx/expr.rs
浏览文件 @
a9ffe67f
...
...
@@ -725,7 +725,7 @@ fn convert_var<'a, 'tcx: 'a>(cx: &mut Cx<'a, 'tcx>,
let
region
=
cx
.tcx
.mk_region
(
region
);
let
self_expr
=
match
cx
.tcx
.closure_kind
(
cx
.tcx.map
.local_def_id
(
closure_expr_id
))
{
ty
::
ClosureKind
::
Fn
ClosureKind
=>
{
ty
::
ClosureKind
::
Fn
=>
{
let
ref_closure_ty
=
cx
.tcx
.mk_ref
(
region
,
ty
::
TypeAndMut
{
ty
:
closure_ty
,
...
...
@@ -744,7 +744,7 @@ fn convert_var<'a, 'tcx: 'a>(cx: &mut Cx<'a, 'tcx>,
}
}
}
ty
::
ClosureKind
::
FnMut
ClosureKind
=>
{
ty
::
ClosureKind
::
FnMut
=>
{
let
ref_closure_ty
=
cx
.tcx
.mk_ref
(
region
,
ty
::
TypeAndMut
{
ty
:
closure_ty
,
...
...
@@ -763,7 +763,7 @@ fn convert_var<'a, 'tcx: 'a>(cx: &mut Cx<'a, 'tcx>,
}
}
}
ty
::
ClosureKind
::
FnOnce
ClosureKind
=>
{
ty
::
ClosureKind
::
FnOnce
=>
{
Expr
{
ty
:
closure_ty
,
temp_lifetime
:
temp_lifetime
,
...
...
src/librustc_mir/mir_map.rs
浏览文件 @
a9ffe67f
...
...
@@ -252,15 +252,15 @@ fn closure_self_ty<'a, 'tcx>(tcx: &TyCtxt<'tcx>,
let
region
=
tcx
.mk_region
(
region
);
match
tcx
.closure_kind
(
tcx
.map
.local_def_id
(
closure_expr_id
))
{
ty
::
ClosureKind
::
Fn
ClosureKind
=>
ty
::
ClosureKind
::
Fn
=>
tcx
.mk_ref
(
region
,
ty
::
TypeAndMut
{
ty
:
closure_ty
,
mutbl
:
hir
::
MutImmutable
}),
ty
::
ClosureKind
::
FnMut
ClosureKind
=>
ty
::
ClosureKind
::
FnMut
=>
tcx
.mk_ref
(
region
,
ty
::
TypeAndMut
{
ty
:
closure_ty
,
mutbl
:
hir
::
MutMutable
}),
ty
::
ClosureKind
::
FnOnce
ClosureKind
=>
ty
::
ClosureKind
::
FnOnce
=>
closure_ty
}
}
src/librustc_trans/trans/base.rs
浏览文件 @
a9ffe67f
...
...
@@ -216,13 +216,13 @@ pub fn self_type_for_closure<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
->
Ty
<
'tcx
>
{
let
closure_kind
=
ccx
.tcx
()
.closure_kind
(
closure_id
);
match
closure_kind
{
ty
::
FnClosureKind
=>
{
ty
::
ClosureKind
::
Fn
=>
{
ccx
.tcx
()
.mk_imm_ref
(
ccx
.tcx
()
.mk_region
(
ty
::
ReStatic
),
fn_ty
)
}
ty
::
FnMutClosureKind
=>
{
ty
::
ClosureKind
::
FnMut
=>
{
ccx
.tcx
()
.mk_mut_ref
(
ccx
.tcx
()
.mk_region
(
ty
::
ReStatic
),
fn_ty
)
}
ty
::
FnOnceClosureKind
=>
fn_ty
,
ty
::
ClosureKind
::
FnOnce
=>
fn_ty
,
}
}
...
...
src/librustc_trans/trans/callee.rs
浏览文件 @
a9ffe67f
...
...
@@ -270,8 +270,8 @@ pub fn trans_fn_pointer_shim<'a, 'tcx>(
// If this is an impl of `Fn` or `FnMut` trait, the receiver is `&self`.
let
is_by_ref
=
match
closure_kind
{
ty
::
FnClosureKind
|
ty
::
FnMutClosureKind
=>
true
,
ty
::
FnOnceClosureKind
=>
false
,
ty
::
ClosureKind
::
Fn
|
ty
::
ClosureKind
::
FnMut
=>
true
,
ty
::
ClosureKind
::
FnOnce
=>
false
,
};
let
bare_fn_ty_maybe_ref
=
if
is_by_ref
{
tcx
.mk_imm_ref
(
tcx
.mk_region
(
ty
::
ReStatic
),
bare_fn_ty
)
...
...
src/librustc_trans/trans/closure.rs
浏览文件 @
a9ffe67f
...
...
@@ -49,7 +49,7 @@ fn load_closure_environment<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
let
closure_ty
=
node_id_type
(
bcx
,
bcx
.fcx.id
);
let
self_type
=
self_type_for_closure
(
bcx
.ccx
(),
closure_def_id
,
closure_ty
);
let
kind
=
kind_for_closure
(
bcx
.ccx
(),
closure_def_id
);
let
llenv
=
if
kind
==
ty
::
FnOnceClosureKind
&&
let
llenv
=
if
kind
==
ty
::
ClosureKind
::
FnOnce
&&
!
arg_is_indirect
(
bcx
.ccx
(),
self_type
)
{
let
datum
=
rvalue_scratch_datum
(
bcx
,
self_type
,
...
...
@@ -85,7 +85,7 @@ fn load_closure_environment<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
let
node_id
=
freevar
.def
.var_id
();
bcx
.fcx.llupvars
.borrow_mut
()
.insert
(
node_id
,
upvar_ptr
);
if
kind
==
ty
::
FnOnceClosureKind
&&
!
captured_by_ref
{
if
kind
==
ty
::
ClosureKind
::
FnOnce
&&
!
captured_by_ref
{
let
hint
=
bcx
.fcx.lldropflag_hints
.borrow
()
.hint_datum
(
upvar_id
.var_id
);
bcx
.fcx
.schedule_drop_mem
(
arg_scope_id
,
upvar_ptr
,
...
...
@@ -300,20 +300,20 @@ fn trans_closure_adapter_shim<'a, 'tcx>(
ccx
.tn
()
.val_to_string
(
llfn
));
match
(
llfn_closure_kind
,
trait_closure_kind
)
{
(
ty
::
FnClosureKind
,
ty
::
FnClosureKind
)
|
(
ty
::
FnMutClosureKind
,
ty
::
FnMutClosureKind
)
|
(
ty
::
FnOnceClosureKind
,
ty
::
FnOnceClosureKind
)
=>
{
(
ty
::
ClosureKind
::
Fn
,
ty
::
ClosureKind
::
Fn
)
|
(
ty
::
ClosureKind
::
FnMut
,
ty
::
ClosureKind
::
FnMut
)
|
(
ty
::
ClosureKind
::
FnOnce
,
ty
::
ClosureKind
::
FnOnce
)
=>
{
// No adapter needed.
llfn
}
(
ty
::
FnClosureKind
,
ty
::
FnMutClosureKind
)
=>
{
(
ty
::
ClosureKind
::
Fn
,
ty
::
ClosureKind
::
FnMut
)
=>
{
// The closure fn `llfn` is a `fn(&self, ...)`. We want a
// `fn(&mut self, ...)`. In fact, at trans time, these are
// basically the same thing, so we can just return llfn.
llfn
}
(
ty
::
FnClosureKind
,
ty
::
FnOnceClosureKind
)
|
(
ty
::
FnMutClosureKind
,
ty
::
FnOnceClosureKind
)
=>
{
(
ty
::
ClosureKind
::
Fn
,
ty
::
ClosureKind
::
FnOnce
)
|
(
ty
::
ClosureKind
::
FnMut
,
ty
::
ClosureKind
::
FnOnce
)
=>
{
// The closure fn `llfn` is a `fn(&self, ...)` or `fn(&mut
// self, ...)`. We want a `fn(self, ...)`. We can produce
// this by doing something like:
...
...
src/librustc_typeck/check/method/probe.rs
浏览文件 @
a9ffe67f
...
...
@@ -697,11 +697,11 @@ fn assemble_closure_candidates(&mut self,
// Check if this is one of the Fn,FnMut,FnOnce traits.
let
tcx
=
self
.tcx
();
let
kind
=
if
Some
(
trait_def_id
)
==
tcx
.lang_items
.fn_trait
()
{
ty
::
FnClosureKind
ty
::
ClosureKind
::
Fn
}
else
if
Some
(
trait_def_id
)
==
tcx
.lang_items
.fn_mut_trait
()
{
ty
::
FnMutClosureKind
ty
::
ClosureKind
::
FnMut
}
else
if
Some
(
trait_def_id
)
==
tcx
.lang_items
.fn_once_trait
()
{
ty
::
FnOnceClosureKind
ty
::
ClosureKind
::
FnOnce
}
else
{
return
Ok
(());
};
...
...
src/librustc_typeck/check/upvar.rs
浏览文件 @
a9ffe67f
...
...
@@ -131,7 +131,7 @@ fn check_closure(&mut self,
if
!
self
.fcx.inh.tables
.borrow
()
.closure_kinds
.contains_key
(
&
closure_def_id
)
{
self
.closures_with_inferred_kinds
.insert
(
expr
.id
);
self
.fcx.inh.tables
.borrow_mut
()
.closure_kinds
.insert
(
closure_def_id
,
ty
::
FnClosureKind
);
.insert
(
closure_def_id
,
ty
::
ClosureKind
::
Fn
);
debug!
(
"check_closure: adding closure_id={:?} to closures_with_inferred_kinds"
,
closure_def_id
);
}
...
...
@@ -301,7 +301,7 @@ fn adjust_upvar_borrow_kind_for_consume(&self,
upvar_id
);
// to move out of an upvar, this must be a FnOnce closure
self
.adjust_closure_kind
(
upvar_id
.closure_expr_id
,
ty
::
FnOnceClosureKind
);
self
.adjust_closure_kind
(
upvar_id
.closure_expr_id
,
ty
::
ClosureKind
::
FnOnce
);
let
upvar_capture_map
=
&
mut
self
.fcx.inh.tables
.borrow_mut
()
.upvar_capture_map
;
...
...
@@ -314,7 +314,7 @@ fn adjust_upvar_borrow_kind_for_consume(&self,
// must still adjust the kind of the closure
// to be a FnOnce closure to permit moves out
// of the environment.
self
.adjust_closure_kind
(
upvar_id
.closure_expr_id
,
ty
::
FnOnceClosureKind
);
self
.adjust_closure_kind
(
upvar_id
.closure_expr_id
,
ty
::
ClosureKind
::
FnOnce
);
}
mc
::
NoteNone
=>
{
}
...
...
@@ -418,7 +418,7 @@ fn try_adjust_upvar_deref(&self,
}
// also need to be in an FnMut closure since this is not an ImmBorrow
self
.adjust_closure_kind
(
upvar_id
.closure_expr_id
,
ty
::
FnMutClosureKind
);
self
.adjust_closure_kind
(
upvar_id
.closure_expr_id
,
ty
::
ClosureKind
::
FnMut
);
true
}
...
...
@@ -426,7 +426,7 @@ fn try_adjust_upvar_deref(&self,
// this kind of deref occurs in a `move` closure, or
// for a by-value upvar; in either case, to mutate an
// upvar, we need to be an FnMut closure
self
.adjust_closure_kind
(
upvar_id
.closure_expr_id
,
ty
::
FnMutClosureKind
);
self
.adjust_closure_kind
(
upvar_id
.closure_expr_id
,
ty
::
ClosureKind
::
FnMut
);
true
}
...
...
@@ -488,16 +488,16 @@ fn adjust_closure_kind(&self,
closure_id
,
existing_kind
,
new_kind
);
match
(
existing_kind
,
new_kind
)
{
(
ty
::
FnClosureKind
,
ty
::
FnClosureKind
)
|
(
ty
::
FnMutClosureKind
,
ty
::
FnClosureKind
)
|
(
ty
::
FnMutClosureKind
,
ty
::
FnMutClosureKind
)
|
(
ty
::
FnOnceClosureKind
,
_
)
=>
{
(
ty
::
ClosureKind
::
Fn
,
ty
::
ClosureKind
::
Fn
)
|
(
ty
::
ClosureKind
::
FnMut
,
ty
::
ClosureKind
::
Fn
)
|
(
ty
::
ClosureKind
::
FnMut
,
ty
::
ClosureKind
::
FnMut
)
|
(
ty
::
ClosureKind
::
FnOnce
,
_
)
=>
{
// no change needed
}
(
ty
::
FnClosureKind
,
ty
::
FnMutClosureKind
)
|
(
ty
::
FnClosureKind
,
ty
::
FnOnceClosureKind
)
|
(
ty
::
FnMutClosureKind
,
ty
::
FnOnceClosureKind
)
=>
{
(
ty
::
ClosureKind
::
Fn
,
ty
::
ClosureKind
::
FnMut
)
|
(
ty
::
ClosureKind
::
Fn
,
ty
::
ClosureKind
::
FnOnce
)
|
(
ty
::
ClosureKind
::
FnMut
,
ty
::
ClosureKind
::
FnOnce
)
=>
{
// new kind is stronger than the old kind
closure_kinds
.insert
(
closure_def_id
,
new_kind
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录