Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
276bba90
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,发现更多精彩内容 >>
提交
276bba90
编写于
3月 09, 2017
作者:
N
Niko Matsakis
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor if so that the "then type" is an expression
上级
fe151194
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
26 addition
and
36 deletion
+26
-36
src/librustc/cfg/construct.rs
src/librustc/cfg/construct.rs
+2
-2
src/librustc/hir/intravisit.rs
src/librustc/hir/intravisit.rs
+1
-1
src/librustc/hir/lowering.rs
src/librustc/hir/lowering.rs
+4
-1
src/librustc/hir/mod.rs
src/librustc/hir/mod.rs
+1
-1
src/librustc/hir/print.rs
src/librustc/hir/print.rs
+3
-3
src/librustc/middle/expr_use_visitor.rs
src/librustc/middle/expr_use_visitor.rs
+2
-2
src/librustc/middle/liveness.rs
src/librustc/middle/liveness.rs
+1
-1
src/librustc_mir/hair/cx/expr.rs
src/librustc_mir/hair/cx/expr.rs
+1
-1
src/librustc_typeck/check/mod.rs
src/librustc_typeck/check/mod.rs
+11
-24
未找到文件。
src/librustc/cfg/construct.rs
浏览文件 @
276bba90
...
...
@@ -195,7 +195,7 @@ fn expr(&mut self, expr: &hir::Expr, pred: CFGIndex) -> CFGIndex {
// [..expr..]
//
let
cond_exit
=
self
.expr
(
&
cond
,
pred
);
// 1
let
then_exit
=
self
.
block
(
&
then
,
cond_exit
);
// 2
let
then_exit
=
self
.
expr
(
&
then
,
cond_exit
);
// 2
self
.add_ast_node
(
expr
.id
,
&
[
cond_exit
,
then_exit
])
// 3,4
}
...
...
@@ -215,7 +215,7 @@ fn expr(&mut self, expr: &hir::Expr, pred: CFGIndex) -> CFGIndex {
// [..expr..]
//
let
cond_exit
=
self
.expr
(
&
cond
,
pred
);
// 1
let
then_exit
=
self
.
block
(
&
then
,
cond_exit
);
// 2
let
then_exit
=
self
.
expr
(
&
then
,
cond_exit
);
// 2
let
else_exit
=
self
.expr
(
&
otherwise
,
cond_exit
);
// 3
self
.add_ast_node
(
expr
.id
,
&
[
then_exit
,
else_exit
])
// 4, 5
}
...
...
src/librustc/hir/intravisit.rs
浏览文件 @
276bba90
...
...
@@ -960,7 +960,7 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) {
}
ExprIf
(
ref
head_expression
,
ref
if_block
,
ref
optional_else
)
=>
{
visitor
.visit_expr
(
head_expression
);
visitor
.visit_
block
(
if_block
);
visitor
.visit_
expr
(
if_block
);
walk_list!
(
visitor
,
visit_expr
,
optional_else
);
}
ExprWhile
(
ref
subexpression
,
ref
block
,
ref
opt_sp_name
)
=>
{
...
...
src/librustc/hir/lowering.rs
浏览文件 @
276bba90
...
...
@@ -1856,7 +1856,10 @@ fn lower_expr(&mut self, e: &Expr) -> hir::Expr {
}
});
hir
::
ExprIf
(
P
(
self
.lower_expr
(
cond
)),
self
.lower_block
(
blk
,
None
),
else_opt
)
let
then_blk
=
self
.lower_block
(
blk
,
None
);
let
then_expr
=
self
.expr_block
(
then_blk
,
ThinVec
::
new
());
hir
::
ExprIf
(
P
(
self
.lower_expr
(
cond
)),
P
(
then_expr
),
else_opt
)
}
ExprKind
::
While
(
ref
cond
,
ref
body
,
opt_ident
)
=>
{
self
.with_loop_scope
(
e
.id
,
|
this
|
...
...
src/librustc/hir/mod.rs
浏览文件 @
276bba90
...
...
@@ -994,7 +994,7 @@ pub enum Expr_ {
/// An `if` block, with an optional else block
///
/// `if expr { block } else { expr }`
ExprIf
(
P
<
Expr
>
,
P
<
Block
>
,
Option
<
P
<
Expr
>>
),
ExprIf
(
P
<
Expr
>
,
P
<
Expr
>
,
Option
<
P
<
Expr
>>
),
/// A while loop, with an optional label
///
/// `'label: while expr { block }`
...
...
src/librustc/hir/print.rs
浏览文件 @
276bba90
...
...
@@ -1036,7 +1036,7 @@ fn print_else(&mut self, els: Option<&hir::Expr>) -> io::Result<()> {
word
(
&
mut
self
.s
,
" else if "
)
?
;
self
.print_expr
(
&
i
)
?
;
space
(
&
mut
self
.s
)
?
;
self
.print_
block
(
&
then
)
?
;
self
.print_
expr
(
&
then
)
?
;
self
.print_else
(
e
.as_ref
()
.map
(|
e
|
&**
e
))
}
// "final else"
...
...
@@ -1058,13 +1058,13 @@ fn print_else(&mut self, els: Option<&hir::Expr>) -> io::Result<()> {
pub
fn
print_if
(
&
mut
self
,
test
:
&
hir
::
Expr
,
blk
:
&
hir
::
Block
,
blk
:
&
hir
::
Expr
,
elseopt
:
Option
<&
hir
::
Expr
>
)
->
io
::
Result
<
()
>
{
self
.head
(
"if"
)
?
;
self
.print_expr
(
test
)
?
;
space
(
&
mut
self
.s
)
?
;
self
.print_
block
(
blk
)
?
;
self
.print_
expr
(
blk
)
?
;
self
.print_else
(
elseopt
)
}
...
...
src/librustc/middle/expr_use_visitor.rs
浏览文件 @
276bba90
...
...
@@ -414,9 +414,9 @@ pub fn walk_expr(&mut self, expr: &hir::Expr) {
self
.consume_exprs
(
exprs
);
}
hir
::
ExprIf
(
ref
cond_expr
,
ref
then_
blk
,
ref
opt_else_expr
)
=>
{
hir
::
ExprIf
(
ref
cond_expr
,
ref
then_
expr
,
ref
opt_else_expr
)
=>
{
self
.consume_expr
(
&
cond_expr
);
self
.walk_
block
(
&
then_blk
);
self
.walk_
expr
(
&
then_expr
);
if
let
Some
(
ref
else_expr
)
=
*
opt_else_expr
{
self
.consume_expr
(
&
else_expr
);
}
...
...
src/librustc/middle/liveness.rs
浏览文件 @
276bba90
...
...
@@ -951,7 +951,7 @@ fn propagate_through_expr(&mut self, expr: &Expr, succ: LiveNode)
// ( succ )
//
let
else_ln
=
self
.propagate_through_opt_expr
(
els
.as_ref
()
.map
(|
e
|
&**
e
),
succ
);
let
then_ln
=
self
.propagate_through_
block
(
&
then
,
succ
);
let
then_ln
=
self
.propagate_through_
expr
(
&
then
,
succ
);
let
ln
=
self
.live_node
(
expr
.id
,
expr
.span
);
self
.init_from_succ
(
ln
,
else_ln
);
self
.merge_from_succ
(
ln
,
then_ln
,
false
);
...
...
src/librustc_mir/hair/cx/expr.rs
浏览文件 @
276bba90
...
...
@@ -636,7 +636,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
hir
::
ExprIf
(
ref
cond
,
ref
then
,
ref
otherwise
)
=>
{
ExprKind
::
If
{
condition
:
cond
.to_ref
(),
then
:
block
::
to_expr_ref
(
cx
,
then
),
then
:
then
.to_ref
(
),
otherwise
:
otherwise
.to_ref
(),
}
}
...
...
src/librustc_typeck/check/mod.rs
浏览文件 @
276bba90
...
...
@@ -2739,7 +2739,7 @@ fn check_method_call(&self,
// or if-else.
fn
check_then_else
(
&
self
,
cond_expr
:
&
'gcx
hir
::
Expr
,
then_
blk
:
&
'gcx
hir
::
Block
,
then_
expr
:
&
'gcx
hir
::
Expr
,
opt_else_expr
:
Option
<&
'gcx
hir
::
Expr
>
,
sp
:
Span
,
expected
:
Expectation
<
'tcx
>
)
->
Ty
<
'tcx
>
{
...
...
@@ -2748,7 +2748,7 @@ fn check_then_else(&self,
self
.diverges
.set
(
Diverges
::
Maybe
);
let
expected
=
expected
.adjust_for_branches
(
self
);
let
then_ty
=
self
.check_
block_with_expected
(
then_blk
,
expected
);
let
then_ty
=
self
.check_
expr_with_expectation
(
then_expr
,
expected
);
let
then_diverges
=
self
.diverges
.get
();
self
.diverges
.set
(
Diverges
::
Maybe
);
...
...
@@ -2763,26 +2763,13 @@ fn check_then_else(&self,
// to assign coercions to, otherwise it's () or diverging.
expected_ty
=
then_ty
;
found_ty
=
else_ty
;
result
=
if
let
Some
(
ref
then
)
=
then_blk
.expr
{
let
res
=
self
.try_find_coercion_lub
(
&
cause
,
||
Some
(
&**
then
),
then_ty
,
else_expr
,
else_ty
);
// In case we did perform an adjustment, we have to update
// the type of the block, because old trans still uses it.
if
res
.is_ok
()
{
let
adj
=
self
.tables
.borrow
()
.adjustments
.get
(
&
then
.id
)
.cloned
();
if
let
Some
(
adj
)
=
adj
{
self
.write_ty
(
then_blk
.id
,
adj
.target
);
}
}
res
}
else
{
self
.commit_if_ok
(|
_
|
{
let
trace
=
TypeTrace
::
types
(
&
cause
,
true
,
then_ty
,
else_ty
);
self
.lub
(
true
,
trace
,
&
then_ty
,
&
else_ty
)
.map
(|
ok
|
self
.register_infer_ok_obligations
(
ok
))
})
let
coerce_to
=
expected
.only_has_type
(
self
)
.unwrap_or
(
then_ty
);
result
=
{
self
.try_coerce
(
then_expr
,
then_ty
,
coerce_to
)
.and_then
(|
t
|
{
self
.try_find_coercion_lub
(
&
cause
,
||
Some
(
then_expr
),
t
,
else_expr
,
else_ty
)
})
};
// We won't diverge unless both branches do (or the condition does).
...
...
@@ -3587,9 +3574,9 @@ fn check_expr_kind(&self,
tcx
.mk_nil
()
}
}
hir
::
ExprIf
(
ref
cond
,
ref
then_
blk
,
ref
opt_else_expr
)
=>
{
self
.check_then_else
(
&
cond
,
&
then_blk
,
opt_else_expr
.as_ref
()
.map
(|
e
|
&**
e
),
expr
.span
,
expected
)
hir
::
ExprIf
(
ref
cond
,
ref
then_
expr
,
ref
opt_else_expr
)
=>
{
self
.check_then_else
(
&
cond
,
then_expr
,
opt_else_expr
.as_ref
()
.map
(|
e
|
&**
e
),
expr
.span
,
expected
)
}
hir
::
ExprWhile
(
ref
cond
,
ref
body
,
_
)
=>
{
let
unified
=
self
.tcx
.mk_nil
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录