Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
101a2f59
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,发现更多精彩内容 >>
提交
101a2f59
编写于
6月 15, 2019
作者:
M
Matthew Jasper
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use `as_temp` to evaluate statement expressions
上级
62bec714
变更
17
隐藏空白更改
内联
并排
Showing
17 changed file
with
96 addition
and
81 deletion
+96
-81
src/librustc_mir/build/block.rs
src/librustc_mir/build/block.rs
+2
-2
src/librustc_mir/build/expr/stmt.rs
src/librustc_mir/build/expr/stmt.rs
+35
-45
src/librustc_mir/build/scope.rs
src/librustc_mir/build/scope.rs
+0
-21
src/librustc_mir/hair/cx/block.rs
src/librustc_mir/hair/cx/block.rs
+0
-3
src/librustc_mir/hair/mod.rs
src/librustc_mir/hair/mod.rs
+0
-4
src/test/mir-opt/box_expr.rs
src/test/mir-opt/box_expr.rs
+3
-1
src/test/mir-opt/copy_propagation_arg.rs
src/test/mir-opt/copy_propagation_arg.rs
+2
-0
src/test/mir-opt/generator-drop-cleanup.rs
src/test/mir-opt/generator-drop-cleanup.rs
+2
-0
src/test/mir-opt/generator-storage-dead-unwind.rs
src/test/mir-opt/generator-storage-dead-unwind.rs
+6
-0
src/test/mir-opt/issue-38669.rs
src/test/mir-opt/issue-38669.rs
+3
-0
src/test/mir-opt/issue-41110.rs
src/test/mir-opt/issue-41110.rs
+1
-1
src/test/mir-opt/issue-49232.rs
src/test/mir-opt/issue-49232.rs
+3
-1
src/test/mir-opt/loop_test.rs
src/test/mir-opt/loop_test.rs
+1
-0
src/test/mir-opt/match_test.rs
src/test/mir-opt/match_test.rs
+1
-0
src/test/mir-opt/nll/region-subtyping-basic.rs
src/test/mir-opt/nll/region-subtyping-basic.rs
+3
-3
src/test/mir-opt/storage_ranges.rs
src/test/mir-opt/storage_ranges.rs
+2
-0
src/test/ui/generator/issue-61442-stmt-expr-with-drop.rs
src/test/ui/generator/issue-61442-stmt-expr-with-drop.rs
+32
-0
未找到文件。
src/librustc_mir/build/block.rs
浏览文件 @
101a2f59
...
...
@@ -78,7 +78,7 @@ fn ast_block_stmts(&mut self,
let
source_info
=
this
.source_info
(
span
);
for
stmt
in
stmts
{
let
Stmt
{
kind
,
opt_destruction_scope
,
span
:
stmt_span
}
=
this
.hir
.mirror
(
stmt
);
let
Stmt
{
kind
,
opt_destruction_scope
}
=
this
.hir
.mirror
(
stmt
);
match
kind
{
StmtKind
::
Expr
{
scope
,
expr
}
=>
{
this
.block_context
.push
(
BlockFrame
::
Statement
{
ignores_expr_result
:
true
});
...
...
@@ -87,7 +87,7 @@ fn ast_block_stmts(&mut self,
let
si
=
(
scope
,
source_info
);
this
.in_scope
(
si
,
LintLevel
::
Inherited
,
|
this
|
{
let
expr
=
this
.hir
.mirror
(
expr
);
this
.stmt_expr
(
block
,
expr
,
Some
(
s
tmt_span
))
this
.stmt_expr
(
block
,
expr
,
Some
(
s
cope
))
})
}));
}
...
...
src/librustc_mir/build/expr/stmt.rs
浏览文件 @
101a2f59
use
crate
::
build
::
scope
::
BreakableScope
;
use
crate
::
build
::{
BlockAnd
,
BlockAndExtension
,
BlockFrame
,
Builder
};
use
crate
::
hair
::
*
;
use
rustc
::
middle
::
region
;
use
rustc
::
mir
::
*
;
impl
<
'a
,
'tcx
>
Builder
<
'a
,
'tcx
>
{
...
...
@@ -8,14 +9,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
/// If the original expression was an AST statement,
/// (e.g., `some().code(&here());`) then `opt_stmt_span` is the
/// span of that statement (including its semicolon, if any).
/// Diagnostics use this span (which may be larger than that of
/// `expr`) to identify when statement temporaries are dropped.
pub
fn
stmt_expr
(
&
mut
self
,
mut
block
:
BasicBlock
,
expr
:
Expr
<
'tcx
>
,
opt_stmt_span
:
Option
<
StatementSpan
>
)
->
BlockAnd
<
()
>
{
/// The scope is used if a statement temporary must be dropped.
pub
fn
stmt_expr
(
&
mut
self
,
mut
block
:
BasicBlock
,
expr
:
Expr
<
'tcx
>
,
statement_scope
:
Option
<
region
::
Scope
>
,
)
->
BlockAnd
<
()
>
{
let
this
=
self
;
let
expr_span
=
expr
.span
;
let
source_info
=
this
.source_info
(
expr
.span
);
...
...
@@ -30,7 +30,7 @@ pub fn stmt_expr(&mut self,
}
=>
{
let
value
=
this
.hir
.mirror
(
value
);
this
.in_scope
((
region_scope
,
source_info
),
lint_level
,
|
this
|
{
this
.stmt_expr
(
block
,
value
,
opt_stmt_span
)
this
.stmt_expr
(
block
,
value
,
statement_scope
)
})
}
ExprKind
::
Assign
{
lhs
,
rhs
}
=>
{
...
...
@@ -199,7 +199,11 @@ pub fn stmt_expr(&mut self,
block
.unit
()
}
_
=>
{
let
expr_ty
=
expr
.ty
;
assert
!
(
statement_scope
.is_some
(),
"Should not be calling `stmt_expr` on a general expression
\
without a statement scope"
,
);
// Issue #54382: When creating temp for the value of
// expression like:
...
...
@@ -208,48 +212,34 @@ pub fn stmt_expr(&mut self,
//
// it is usually better to focus on `the_value` rather
// than the entirety of block(s) surrounding it.
let
mut
temp_span
=
expr_span
;
let
mut
temp_in_tail_of_block
=
false
;
if
let
ExprKind
::
Block
{
body
}
=
expr
.kind
{
if
let
Some
(
tail_expr
)
=
&
body
.expr
{
let
mut
expr
=
tail_expr
;
while
let
rustc
::
hir
::
ExprKind
::
Block
(
subblock
,
_
label
)
=
&
expr
.node
{
if
let
Some
(
subtail_expr
)
=
&
subblock
.expr
{
expr
=
subtail_expr
}
else
{
break
;
let
adjusted_span
=
(||
{
if
let
ExprKind
::
Block
{
body
}
=
expr
.kind
{
if
let
Some
(
tail_expr
)
=
&
body
.expr
{
let
mut
expr
=
tail_expr
;
while
let
rustc
::
hir
::
ExprKind
::
Block
(
subblock
,
_
label
)
=
&
expr
.node
{
if
let
Some
(
subtail_expr
)
=
&
subblock
.expr
{
expr
=
subtail_expr
}
else
{
break
;
}
}
}
temp_span
=
expr
.span
;
temp_in_tail_of_block
=
true
;
}
}
let
temp
=
{
let
mut
local_decl
=
LocalDecl
::
new_temp
(
expr
.ty
.clone
(),
temp_span
);
if
temp_in_tail_of_block
{
if
this
.block_context
.currently_ignores_tail_results
()
{
local_decl
=
local_decl
.block_tail
(
BlockTailInfo
{
this
.block_context
.push
(
BlockFrame
::
TailExpr
{
tail_result_is_ignored
:
true
});
return
Some
(
expr
.span
);
}
}
let
temp
=
this
.local_decls
.push
(
local_decl
);
let
place
=
Place
::
from
(
temp
);
debug!
(
"created temp {:?} for expr {:?} in block_context: {:?}"
,
temp
,
expr
,
this
.block_context
);
place
};
unpack!
(
block
=
this
.into
(
&
temp
,
block
,
expr
));
None
})();
let
temp
=
unpack!
(
block
=
this
.as_temp
(
block
,
statement_scope
,
expr
,
Mutability
::
Not
));
// Attribute drops of the statement's temps to the
// semicolon at the statement's end.
let
drop_point
=
this
.hir
.tcx
()
.sess
.source_map
()
.end_point
(
match
opt_stmt_span
{
None
=>
expr_span
,
Some
(
StatementSpan
(
span
))
=>
span
,
});
if
let
Some
(
span
)
=
adjusted_span
{
this
.local_decls
[
temp
]
.source_info.span
=
span
;
this
.block_context
.pop
();
}
unpack!
(
block
=
this
.build_drop
(
block
,
drop_point
,
temp
,
expr_ty
));
block
.unit
()
}
}
...
...
src/librustc_mir/build/scope.rs
浏览文件 @
101a2f59
...
...
@@ -805,27 +805,6 @@ fn diverge_cleanup_gen(&mut self, generator_drop: bool) -> BasicBlock {
target
}
/// Utility function for *non*-scope code to build their own drops
pub
fn
build_drop
(
&
mut
self
,
block
:
BasicBlock
,
span
:
Span
,
location
:
Place
<
'tcx
>
,
ty
:
Ty
<
'tcx
>
)
->
BlockAnd
<
()
>
{
if
!
self
.hir
.needs_drop
(
ty
)
{
return
block
.unit
();
}
let
source_info
=
self
.source_info
(
span
);
let
next_target
=
self
.cfg
.start_new_block
();
let
diverge_target
=
self
.diverge_cleanup
();
self
.cfg
.terminate
(
block
,
source_info
,
TerminatorKind
::
Drop
{
location
,
target
:
next_target
,
unwind
:
Some
(
diverge_target
),
});
next_target
.unit
()
}
/// Utility function for *non*-scope code to build their own drops
pub
fn
build_drop_and_replace
(
&
mut
self
,
block
:
BasicBlock
,
...
...
src/librustc_mir/hair/cx/block.rs
浏览文件 @
101a2f59
...
...
@@ -49,7 +49,6 @@ fn mirror_stmts<'a, 'tcx>(
for
(
index
,
stmt
)
in
stmts
.iter
()
.enumerate
()
{
let
hir_id
=
stmt
.hir_id
;
let
opt_dxn_ext
=
cx
.region_scope_tree
.opt_destruction_scope
(
hir_id
.local_id
);
let
stmt_span
=
StatementSpan
(
cx
.tcx
.hir
()
.span
(
hir_id
));
match
stmt
.node
{
hir
::
StmtKind
::
Expr
(
ref
expr
)
|
hir
::
StmtKind
::
Semi
(
ref
expr
)
=>
{
...
...
@@ -62,7 +61,6 @@ fn mirror_stmts<'a, 'tcx>(
expr
:
expr
.to_ref
(),
},
opt_destruction_scope
:
opt_dxn_ext
,
span
:
stmt_span
,
})))
}
hir
::
StmtKind
::
Item
(
..
)
=>
{
...
...
@@ -107,7 +105,6 @@ fn mirror_stmts<'a, 'tcx>(
lint_level
:
LintLevel
::
Explicit
(
local
.hir_id
),
},
opt_destruction_scope
:
opt_dxn_ext
,
span
:
stmt_span
,
})));
}
}
...
...
src/librustc_mir/hair/mod.rs
浏览文件 @
101a2f59
...
...
@@ -55,14 +55,10 @@ pub enum StmtRef<'tcx> {
Mirror
(
Box
<
Stmt
<
'tcx
>>
),
}
#[derive(Clone,
Debug)]
pub
struct
StatementSpan
(
pub
Span
);
#[derive(Clone,
Debug)]
pub
struct
Stmt
<
'tcx
>
{
pub
kind
:
StmtKind
<
'tcx
>
,
pub
opt_destruction_scope
:
Option
<
region
::
Scope
>
,
pub
span
:
StatementSpan
,
}
#[derive(Clone,
Debug)]
...
...
src/test/mir-opt/box_expr.rs
浏览文件 @
101a2f59
...
...
@@ -24,7 +24,7 @@ fn drop(&mut self) {
// let mut _0: ();
// let _1: std::boxed::Box<S>;
// let mut _2: std::boxed::Box<S>;
// let
mut
_3: ();
// let _3: ();
// let mut _4: std::boxed::Box<S>;
// scope 1 {
// }
...
...
@@ -50,6 +50,7 @@ fn drop(&mut self) {
//
// bb4: {
// StorageDead(_2);
// StorageLive(_3);
// StorageLive(_4);
// _4 = move _1;
// _3 = const std::mem::drop::<std::boxed::Box<S>>(move _4) -> [return: bb5, unwind: bb7];
...
...
@@ -69,6 +70,7 @@ fn drop(&mut self) {
//
// bb8: {
// StorageDead(_4);
// StorageDead(_3);
// _0 = ();
// drop(_1) -> bb9;
// }
...
...
src/test/mir-opt/copy_propagation_arg.rs
浏览文件 @
101a2f59
...
...
@@ -61,12 +61,14 @@ fn main() {
// END rustc.foo.CopyPropagation.after.mir
// START rustc.bar.CopyPropagation.before.mir
// bb0: {
// StorageLive(_2);
// StorageLive(_3);
// _3 = _1;
// _2 = const dummy(move _3) -> bb1;
// }
// bb1: {
// StorageDead(_3);
// StorageDead(_2);
// _1 = const 5u8;
// ...
// return;
...
...
src/test/mir-opt/generator-drop-cleanup.rs
浏览文件 @
101a2f59
...
...
@@ -18,6 +18,7 @@ fn main() {
// }
// bb1: {
// StorageDead(_3);
// StorageDead(_2);
// goto -> bb5;
// }
// bb2: {
...
...
@@ -36,6 +37,7 @@ fn main() {
// goto -> bb3;
// }
// bb7: {
// StorageLive(_2);
// StorageLive(_3);
// goto -> bb1;
// }
...
...
src/test/mir-opt/generator-storage-dead-unwind.rs
浏览文件 @
101a2f59
...
...
@@ -54,6 +54,7 @@ fn main() {
// }
// bb2: {
// ...
// StorageLive(_6);
// StorageLive(_7);
// _7 = move _2;
// _6 = const take::<Foo>(move _7) -> [return: bb9, unwind: bb8];
...
...
@@ -81,16 +82,20 @@ fn main() {
// }
// bb8 (cleanup): {
// StorageDead(_7);
// StorageDead(_6);
// goto -> bb7;
// }
// bb9: {
// StorageDead(_7);
// StorageDead(_6);
// StorageLive(_8);
// StorageLive(_9);
// _9 = move _3;
// _8 = const take::<Bar>(move _9) -> [return: bb10, unwind: bb11];
// }
// bb10: {
// StorageDead(_9);
// StorageDead(_8);
// ...
// StorageDead(_3);
// StorageDead(_2);
...
...
@@ -98,6 +103,7 @@ fn main() {
// }
// bb11 (cleanup): {
// StorageDead(_9);
// StorageDead(_8);
// goto -> bb7;
// }
// bb12: {
...
...
src/test/mir-opt/issue-38669.rs
浏览文件 @
101a2f59
...
...
@@ -25,6 +25,7 @@ fn main() {
// falseUnwind -> [real: bb3, cleanup: bb1];
// }
// bb3: {
// StorageLive(_3);
// StorageLive(_4);
// _4 = _1;
// FakeRead(ForMatchedPlace, _4);
...
...
@@ -34,6 +35,7 @@ fn main() {
// bb5: {
// _3 = ();
// StorageDead(_4);
// StorageDead(_3);
// _1 = const true;
// _2 = ();
// goto -> bb2;
...
...
@@ -41,6 +43,7 @@ fn main() {
// bb6: {
// _0 = ();
// StorageDead(_4);
// StorageDead(_3);
// StorageDead(_1);
// return;
// }
...
...
src/test/mir-opt/issue-41110.rs
浏览文件 @
101a2f59
...
...
@@ -42,7 +42,7 @@ fn other(self, s: Self) {}
// START rustc.test.ElaborateDrops.after.mir
// let mut _0: ();
// let _1: S;
// let
mut
_3: ();
// let _3: ();
// let mut _4: S;
// let mut _5: S;
// let mut _6: bool;
...
...
src/test/mir-opt/issue-49232.rs
浏览文件 @
101a2f59
...
...
@@ -21,7 +21,7 @@ fn main() {
// let _2: i32;
// let mut _3: bool;
// let mut _4: !;
// let
mut
_5: ();
// let _5: ();
// let mut _6: &i32;
// scope 1 {
// }
...
...
@@ -73,12 +73,14 @@ fn main() {
// bb12: {
// FakeRead(ForLet, _2);
// StorageDead(_3);
// StorageLive(_5);
// StorageLive(_6);
// _6 = &_2;
// _5 = const std::mem::drop::<&i32>(move _6) -> [return: bb13, unwind: bb4];
// }
// bb13: {
// StorageDead(_6);
// StorageDead(_5);
// _1 = ();
// StorageDead(_2);
// goto -> bb1;
...
...
src/test/mir-opt/loop_test.rs
浏览文件 @
101a2f59
...
...
@@ -25,6 +25,7 @@ fn main() {
// bb3: { // Entry into the loop
// _1 = ();
// StorageDead(_2);
// StorageDead(_1);
// goto -> bb5;
// }
// ...
...
...
src/test/mir-opt/match_test.rs
浏览文件 @
101a2f59
...
...
@@ -75,6 +75,7 @@ fn main() {
// goto -> bb14;
// }
// bb14: {
// StorageDead(_3);
// _0 = ();
// StorageDead(_2);
// StorageDead(_1);
...
...
src/test/mir-opt/nll/region-subtyping-basic.rs
浏览文件 @
101a2f59
...
...
@@ -22,9 +22,9 @@ fn main() {
// END RUST SOURCE
// START rustc.main.nll.0.mir
// | '_#2r | U0 | {bb2[0..=8], bb3[0], bb5[0..=
1
]}
// | '_#3r | U0 | {bb2[1..=8], bb3[0], bb5[0..=
1
]}
// | '_#4r | U0 | {bb2[4..=8], bb3[0], bb5[0..=
1
]}
// | '_#2r | U0 | {bb2[0..=8], bb3[0], bb5[0..=
2
]}
// | '_#3r | U0 | {bb2[1..=8], bb3[0], bb5[0..=
2
]}
// | '_#4r | U0 | {bb2[4..=8], bb3[0], bb5[0..=
2
]}
// END rustc.main.nll.0.mir
// START rustc.main.nll.0.mir
// let _2: &'_#3r usize;
...
...
src/test/mir-opt/storage_ranges.rs
浏览文件 @
101a2f59
...
...
@@ -12,6 +12,7 @@ fn main() {
// StorageLive(_1);
// _1 = const 0i32;
// FakeRead(ForLet, _1);
// StorageLive(_2);
// StorageLive(_3);
// StorageLive(_4);
// StorageLive(_5);
...
...
@@ -23,6 +24,7 @@ fn main() {
// _2 = ();
// StorageDead(_4);
// StorageDead(_3);
// StorageDead(_2);
// StorageLive(_6);
// _6 = const 1i32;
// FakeRead(ForLet, _6);
...
...
src/test/ui/generator/issue-61442-stmt-expr-with-drop.rs
0 → 100644
浏览文件 @
101a2f59
// Test that we don't consider temporaries for statement expressions as live
// across yields
// check-pass
// edition:2018
#![feature(async_await,
generators,
generator_trait)]
use
std
::
ops
::
Generator
;
async
fn
drop_and_await
()
{
async
{};
async
{}
.await
;
}
fn
drop_and_yield
()
{
let
x
=
||
{
String
::
new
();
yield
;
};
Box
::
pin
(
x
)
.as_mut
()
.resume
();
let
y
=
static
||
{
String
::
new
();
yield
;
};
Box
::
pin
(
y
)
.as_mut
()
.resume
();
}
fn
main
()
{
drop_and_await
();
drop_and_yield
();
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录