Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
6ef625fb
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,发现更多精彩内容 >>
提交
6ef625fb
编写于
11月 26, 2019
作者:
D
David Haig
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove duplication using single variant for error
上级
88821ed5
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
22 addition
and
38 deletion
+22
-38
src/librustc/mir/interpret/error.rs
src/librustc/mir/interpret/error.rs
+11
-11
src/librustc/mir/mod.rs
src/librustc/mir/mod.rs
+2
-4
src/librustc/mir/visit.rs
src/librustc/mir/visit.rs
+1
-2
src/librustc_mir/interpret/terminator.rs
src/librustc_mir/interpret/terminator.rs
+2
-4
src/librustc_mir/transform/generator.rs
src/librustc_mir/transform/generator.rs
+6
-17
未找到文件。
src/librustc/mir/interpret/error.rs
浏览文件 @
6ef625fb
...
...
@@ -13,7 +13,7 @@
use
rustc_target
::
spec
::
abi
::
Abi
;
use
syntax_pos
::{
Pos
,
Span
};
use
syntax
::
symbol
::
Symbol
;
use
hir
::
GeneratorKind
;
use
std
::{
fmt
,
env
};
use
rustc_error_codes
::
*
;
...
...
@@ -264,10 +264,8 @@ pub enum PanicInfo<O> {
OverflowNeg
,
DivisionByZero
,
RemainderByZero
,
GeneratorResumedAfterReturn
,
GeneratorResumedAfterPanic
,
AsyncResumedAfterReturn
,
AsyncResumedAfterPanic
,
ResumedAfterReturn
(
GeneratorKind
),
ResumedAfterPanic
(
GeneratorKind
),
}
/// Type for MIR `Assert` terminator error messages.
...
...
@@ -302,14 +300,16 @@ pub fn description(&self) -> &'static str {
"attempt to divide by zero"
,
RemainderByZero
=>
"attempt to calculate the remainder with a divisor of zero"
,
GeneratorResumedAfterReturn
=>
ResumedAfterReturn
(
GeneratorKind
::
Gen
)
=>
"generator resumed after completion"
,
GeneratorResumedAfterPanic
=>
"generator resumed after panicking"
,
AsyncResumedAfterReturn
=>
// FIXME: Do we want a separate message for each Async variant (Block, Closure, Fn)?
ResumedAfterReturn
(
GeneratorKind
::
Async
(
_
))
=>
"`async fn` resumed after completion"
,
AsyncResumedAfterPanic
=>
"`async fn` resumed after panic"
,
ResumedAfterPanic
(
GeneratorKind
::
Gen
)
=>
"generator resumed after panicking"
,
// FIXME: Do we want a separate message for each Async variant (Block, Closure, Fn)?
ResumedAfterPanic
(
GeneratorKind
::
Async
(
_
))
=>
"`async fn` resumed after panicking"
,
Panic
{
..
}
|
BoundsCheck
{
..
}
=>
bug!
(
"Unexpected PanicInfo"
),
}
...
...
src/librustc/mir/mod.rs
浏览文件 @
6ef625fb
...
...
@@ -2981,8 +2981,7 @@ fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
index
:
index
.fold_with
(
folder
),
},
Panic
{
..
}
|
Overflow
(
_
)
|
OverflowNeg
|
DivisionByZero
|
RemainderByZero
|
GeneratorResumedAfterReturn
|
GeneratorResumedAfterPanic
|
AsyncResumedAfterReturn
|
AsyncResumedAfterPanic
=>
ResumedAfterReturn
(
_
)
|
ResumedAfterPanic
(
_
)
=>
msg
.clone
(),
};
Assert
{
cond
:
cond
.fold_with
(
folder
),
expected
,
msg
,
target
,
cleanup
}
...
...
@@ -3028,8 +3027,7 @@ fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
len
.visit_with
(
visitor
)
||
index
.visit_with
(
visitor
),
Panic
{
..
}
|
Overflow
(
_
)
|
OverflowNeg
|
DivisionByZero
|
RemainderByZero
|
GeneratorResumedAfterReturn
|
GeneratorResumedAfterPanic
|
AsyncResumedAfterReturn
|
AsyncResumedAfterPanic
=>
ResumedAfterReturn
(
_
)
|
ResumedAfterPanic
(
_
)
=>
false
}
}
else
{
...
...
src/librustc/mir/visit.rs
浏览文件 @
6ef625fb
...
...
@@ -517,8 +517,7 @@ fn super_assert_message(&mut self,
self
.visit_operand
(
index
,
location
);
}
Panic
{
..
}
|
Overflow
(
_
)
|
OverflowNeg
|
DivisionByZero
|
RemainderByZero
|
GeneratorResumedAfterReturn
|
GeneratorResumedAfterPanic
|
AsyncResumedAfterReturn
|
AsyncResumedAfterPanic
=>
{
ResumedAfterReturn
(
_
)
|
ResumedAfterPanic
(
_
)
=>
{
// Nothing to visit
}
}
...
...
src/librustc_mir/interpret/terminator.rs
浏览文件 @
6ef625fb
...
...
@@ -142,10 +142,8 @@ pub(super) fn eval_terminator(
OverflowNeg
=>
err_panic!
(
OverflowNeg
),
DivisionByZero
=>
err_panic!
(
DivisionByZero
),
RemainderByZero
=>
err_panic!
(
RemainderByZero
),
GeneratorResumedAfterReturn
=>
err_panic!
(
GeneratorResumedAfterReturn
),
GeneratorResumedAfterPanic
=>
err_panic!
(
GeneratorResumedAfterPanic
),
AsyncResumedAfterReturn
=>
err_panic!
(
AsyncResumedAfterReturn
),
AsyncResumedAfterPanic
=>
err_panic!
(
AsyncResumedAfterPanic
),
ResumedAfterReturn
(
generator_kind
)
=>
err_panic!
(
ResumedAfterReturn
(
*
generator_kind
)),
ResumedAfterPanic
(
generator_kind
)
=>
err_panic!
(
ResumedAfterPanic
(
*
generator_kind
)),
Panic
{
..
}
=>
bug!
(
"`Panic` variant cannot occur in MIR"
),
}
.into
());
...
...
src/librustc_mir/transform/generator.rs
浏览文件 @
6ef625fb
...
...
@@ -50,7 +50,7 @@
//! Otherwise it drops all the values in scope at the last suspension point.
use
rustc
::
hir
;
use
rustc
::
hir
::
{
def_id
::
DefId
,
GeneratorKind
}
;
use
rustc
::
hir
::
def_id
::
DefId
;
use
rustc
::
mir
::
*
;
use
rustc
::
mir
::
visit
::{
PlaceContext
,
Visitor
,
MutVisitor
};
use
rustc
::
ty
::{
self
,
TyCtxt
,
AdtDef
,
Ty
};
...
...
@@ -1056,28 +1056,17 @@ fn create_generator_resume_function<'tcx>(
let
mut
cases
=
create_cases
(
body
,
&
transform
,
|
point
|
Some
(
point
.resume
));
use
rustc
::
mir
::
interpret
::
PanicInfo
::{
GeneratorResumedAfterPanic
,
GeneratorResumedAfterReturn
,
AsyncResumedAfterReturn
,
AsyncResumedAfterPanic
,
ResumedAfterPanic
,
ResumedAfterReturn
,
};
// Jump to the entry point on the unresumed
cases
.insert
(
0
,
(
UNRESUMED
,
BasicBlock
::
new
(
0
)));
// Panic when resumed on the returned or poisoned state
match
body
.generator_kind
{
Some
(
GeneratorKind
::
Async
(
_
))
=>
{
cases
.insert
(
1
,
(
RETURNED
,
insert_panic_block
(
tcx
,
body
,
AsyncResumedAfterReturn
)));
cases
.insert
(
2
,
(
POISONED
,
insert_panic_block
(
tcx
,
body
,
AsyncResumedAfterPanic
)));
},
Some
(
GeneratorKind
::
Gen
)
=>
{
cases
.insert
(
1
,
(
RETURNED
,
insert_panic_block
(
tcx
,
body
,
GeneratorResumedAfterReturn
)));
cases
.insert
(
2
,
(
POISONED
,
insert_panic_block
(
tcx
,
body
,
GeneratorResumedAfterPanic
)));
},
None
=>
{
// N/A because we would never create a resume function if there was no generator_kind
}
if
let
Some
(
generator_kind
)
=
body
.generator_kind
{
cases
.insert
(
1
,
(
RETURNED
,
insert_panic_block
(
tcx
,
body
,
ResumedAfterReturn
(
generator_kind
))));
cases
.insert
(
2
,
(
POISONED
,
insert_panic_block
(
tcx
,
body
,
ResumedAfterPanic
(
generator_kind
))));
};
insert_switch
(
body
,
cases
,
&
transform
,
TerminatorKind
::
Unreachable
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录