Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
ea4db352
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,发现更多精彩内容 >>
提交
ea4db352
编写于
9月 28, 2017
作者:
N
Niko Matsakis
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
move `ty_of_closure` into `check/closure.rs`, its only caller
上级
11118dcf
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
69 addition
and
64 deletion
+69
-64
src/librustc_typeck/astconv.rs
src/librustc_typeck/astconv.rs
+0
-59
src/librustc_typeck/check/closure.rs
src/librustc_typeck/check/closure.rs
+69
-5
未找到文件。
src/librustc_typeck/astconv.rs
浏览文件 @
ea4db352
...
...
@@ -1206,65 +1206,6 @@ pub fn ty_of_fn(&self,
bare_fn_ty
}
pub
fn
ty_of_closure
(
&
self
,
unsafety
:
hir
::
Unsafety
,
decl
:
&
hir
::
FnDecl
,
abi
:
abi
::
Abi
,
expected_sig
:
Option
<
ty
::
FnSig
<
'tcx
>>
)
->
ty
::
PolyFnSig
<
'tcx
>
{
debug!
(
"ty_of_closure(expected_sig={:?})"
,
expected_sig
);
let
input_tys
=
decl
.inputs
.iter
()
.enumerate
()
.map
(|(
i
,
a
)|
{
let
expected_arg_ty
=
expected_sig
.as_ref
()
.and_then
(|
e
|
{
// no guarantee that the correct number of expected args
// were supplied
if
i
<
e
.inputs
()
.len
()
{
Some
(
e
.inputs
()[
i
])
}
else
{
None
}
});
let
input_ty
=
self
.ty_of_arg
(
a
,
expected_arg_ty
);
debug!
(
"ty_of_closure: i={} input_ty={:?} expected_arg_ty={:?}"
,
i
,
input_ty
,
expected_arg_ty
);
input_ty
});
let
expected_ret_ty
=
expected_sig
.as_ref
()
.map
(|
e
|
e
.output
());
let
output_ty
=
match
decl
.output
{
hir
::
Return
(
ref
output
)
=>
{
if
let
(
&
hir
::
TyInfer
,
Some
(
expected_ret_ty
))
=
(
&
output
.node
,
expected_ret_ty
)
{
self
.record_ty
(
output
.hir_id
,
expected_ret_ty
,
output
.span
);
expected_ret_ty
}
else
{
self
.ast_ty_to_ty
(
&
output
)
}
}
hir
::
DefaultReturn
(
span
)
=>
{
if
let
Some
(
expected_ret_ty
)
=
expected_ret_ty
{
expected_ret_ty
}
else
{
self
.ty_infer
(
span
)
}
}
};
debug!
(
"ty_of_closure: output_ty={:?}"
,
output_ty
);
ty
::
Binder
(
self
.tcx
()
.mk_fn_sig
(
input_tys
,
output_ty
,
decl
.variadic
,
unsafety
,
abi
))
}
/// Given the bounds on an object, determines what single region bound (if any) we can
/// use to summarize this type. The basic idea is that we will use the bound the user
/// provided, if they provided one, and otherwise search the supertypes of trait bounds
...
...
src/librustc_typeck/check/closure.rs
浏览文件 @
ea4db352
...
...
@@ -56,11 +56,7 @@ fn check_closure(&self,
expected_sig
);
let
expr_def_id
=
self
.tcx.hir
.local_def_id
(
expr
.id
);
let
sig
=
AstConv
::
ty_of_closure
(
self
,
hir
::
Unsafety
::
Normal
,
decl
,
Abi
::
RustCall
,
expected_sig
);
let
sig
=
self
.ty_of_closure
(
decl
,
expected_sig
);
debug!
(
"check_closure: ty_of_closure returns {:?}"
,
sig
);
...
...
@@ -274,4 +270,72 @@ fn self_type_matches_expected_vid(&self,
_
=>
None
,
}
}
/// Invoked to compute the signature of a closure expression. This
/// combines any user-provided type annotations (e.g., `|x: u32|
/// -> u32 { .. }`) with the expected signature.
///
/// The arguments here are a bit odd-ball:
///
/// - `decl`: the HIR declaration of the closure
/// - `expected_sig`: the expected signature (if any). Note that
/// this is missing a binder: that is, there may be late-bound
/// regions with depth 1, which are bound then by the closure.
fn
ty_of_closure
(
&
self
,
decl
:
&
hir
::
FnDecl
,
expected_sig
:
Option
<
ty
::
FnSig
<
'tcx
>>
)
->
ty
::
PolyFnSig
<
'tcx
>
{
let
astconv
:
&
AstConv
=
self
;
debug!
(
"ty_of_closure(expected_sig={:?})"
,
expected_sig
);
let
input_tys
=
decl
.inputs
.iter
()
.enumerate
()
.map
(|(
i
,
a
)|
{
let
expected_arg_ty
=
expected_sig
.as_ref
()
.and_then
(|
e
|
{
// no guarantee that the correct number of expected args
// were supplied
if
i
<
e
.inputs
()
.len
()
{
Some
(
e
.inputs
()[
i
])
}
else
{
None
}
});
let
input_ty
=
astconv
.ty_of_arg
(
a
,
expected_arg_ty
);
debug!
(
"ty_of_closure: i={} input_ty={:?} expected_arg_ty={:?}"
,
i
,
input_ty
,
expected_arg_ty
);
input_ty
});
let
expected_ret_ty
=
expected_sig
.as_ref
()
.map
(|
e
|
e
.output
());
let
output_ty
=
match
decl
.output
{
hir
::
Return
(
ref
output
)
=>
{
if
let
(
&
hir
::
TyInfer
,
Some
(
expected_ret_ty
))
=
(
&
output
.node
,
expected_ret_ty
)
{
astconv
.record_ty
(
output
.hir_id
,
expected_ret_ty
,
output
.span
);
expected_ret_ty
}
else
{
astconv
.ast_ty_to_ty
(
&
output
)
}
}
hir
::
DefaultReturn
(
span
)
=>
{
if
let
Some
(
expected_ret_ty
)
=
expected_ret_ty
{
expected_ret_ty
}
else
{
astconv
.ty_infer
(
span
)
}
}
};
debug!
(
"ty_of_closure: output_ty={:?}"
,
output_ty
);
ty
::
Binder
(
self
.tcx
.mk_fn_sig
(
input_tys
,
output_ty
,
decl
.variadic
,
hir
::
Unsafety
::
Normal
,
Abi
::
RustCall
))
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录