Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
f9489956
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,发现更多精彩内容 >>
提交
f9489956
编写于
4月 30, 2020
作者:
R
Ralf Jung
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
InterpError printing really is more Display than Debug
also tweak InvalidDiscriminant message
上级
671bc08e
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
29 addition
and
32 deletion
+29
-32
src/librustc_middle/mir/interpret/error.rs
src/librustc_middle/mir/interpret/error.rs
+27
-30
src/librustc_mir/transform/const_prop.rs
src/librustc_mir/transform/const_prop.rs
+2
-2
未找到文件。
src/librustc_middle/mir/interpret/error.rs
浏览文件 @
f9489956
...
...
@@ -285,7 +285,7 @@ pub enum InvalidProgramInfo<'tcx> {
TransmuteSizeDiff
(
Ty
<
'tcx
>
,
Ty
<
'tcx
>
),
}
impl
fmt
::
D
ebug
for
InvalidProgramInfo
<
'_
>
{
impl
fmt
::
D
isplay
for
InvalidProgramInfo
<
'_
>
{
fn
fmt
(
&
self
,
f
:
&
mut
fmt
::
Formatter
<
'_
>
)
->
fmt
::
Result
{
use
InvalidProgramInfo
::
*
;
match
self
{
...
...
@@ -310,8 +310,6 @@ pub enum UndefinedBehaviorInfo {
Ub
(
String
),
/// Unreachable code was executed.
Unreachable
,
/// An enum discriminant was set to a value which was outside the range of valid values.
InvalidDiscriminant
(
ScalarMaybeUndef
),
/// A slice/array index projection went out-of-bounds.
BoundsCheckFailed
{
len
:
u64
,
...
...
@@ -356,6 +354,8 @@ pub enum UndefinedBehaviorInfo {
InvalidBool
(
u8
),
/// Using a non-character `u32` as character.
InvalidChar
(
u32
),
/// An enum discriminant was set to a value which was outside the range of valid values.
InvalidDiscriminant
(
ScalarMaybeUndef
),
/// Using uninitialized data where it is not allowed.
InvalidUndefBytes
(
Option
<
Pointer
>
),
/// Working with a local that is not currently live.
...
...
@@ -367,29 +367,26 @@ pub enum UndefinedBehaviorInfo {
},
}
impl
fmt
::
D
ebug
for
UndefinedBehaviorInfo
{
impl
fmt
::
D
isplay
for
UndefinedBehaviorInfo
{
fn
fmt
(
&
self
,
f
:
&
mut
fmt
::
Formatter
<
'_
>
)
->
fmt
::
Result
{
use
UndefinedBehaviorInfo
::
*
;
match
self
{
Ub
(
msg
)
=>
write!
(
f
,
"{}"
,
msg
),
Unreachable
=>
write!
(
f
,
"entering unreachable code"
),
InvalidDiscriminant
(
val
)
=>
write!
(
f
,
"encountering invalid enum discriminant {}"
,
val
),
BoundsCheckFailed
{
ref
len
,
ref
index
}
=>
write!
(
f
,
"indexing out of bounds: the len is {:?} but the index is {:?}"
,
len
,
index
),
BoundsCheckFailed
{
ref
len
,
ref
index
}
=>
{
write!
(
f
,
"indexing out of bounds: the len is {} but the index is {}"
,
len
,
index
)
}
DivisionByZero
=>
write!
(
f
,
"dividing by zero"
),
RemainderByZero
=>
write!
(
f
,
"calculating the remainder with a divisor of zero"
),
PointerArithOverflow
=>
write!
(
f
,
"overflowing in-bounds pointer arithmetic"
),
InvalidMeta
(
msg
)
=>
write!
(
f
,
"invalid metadata in wide pointer: {}"
,
msg
),
UnterminatedCString
(
p
)
=>
write!
(
f
,
"reading a null-terminated string starting at {
:?
} with no null found before end of allocation"
,
"reading a null-terminated string starting at {} with no null found before end of allocation"
,
p
,
),
PointerUseAfterFree
(
a
)
=>
{
write!
(
f
,
"pointer to {
:?
} was dereferenced after this allocation got freed"
,
a
)
write!
(
f
,
"pointer to {} was dereferenced after this allocation got freed"
,
a
)
}
PointerOutOfBounds
{
ptr
,
msg
,
allocation_size
}
=>
write!
(
f
,
...
...
@@ -408,17 +405,18 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
has
.bytes
(),
required
.bytes
()
),
WriteToReadOnly
(
a
)
=>
write!
(
f
,
"writing to {
:?
} which is read-only"
,
a
),
WriteToReadOnly
(
a
)
=>
write!
(
f
,
"writing to {} which is read-only"
,
a
),
InvalidFunctionPointer
(
p
)
=>
{
write!
(
f
,
"using {
:?
} as function pointer but it does not point to a function"
,
p
)
write!
(
f
,
"using {} as function pointer but it does not point to a function"
,
p
)
}
DerefFunctionPointer
(
a
)
=>
write!
(
f
,
"accessing {
:?
} which contains a function"
,
a
),
DerefFunctionPointer
(
a
)
=>
write!
(
f
,
"accessing {} which contains a function"
,
a
),
ValidationFailure
(
ref
err
)
=>
write!
(
f
,
"type validation failed: {}"
,
err
),
InvalidBool
(
b
)
=>
write!
(
f
,
"interpreting an invalid 8-bit value as a bool: {}"
,
b
),
InvalidChar
(
c
)
=>
write!
(
f
,
"interpreting an invalid 32-bit value as a char: {}"
,
c
),
InvalidDiscriminant
(
val
)
=>
write!
(
f
,
"enum value has invalid discriminant: {}"
,
val
),
InvalidUndefBytes
(
Some
(
p
))
=>
write!
(
f
,
"reading uninitialized memory at {
:?
}, but this operation requires initialized memory"
,
"reading uninitialized memory at {}, but this operation requires initialized memory"
,
p
),
InvalidUndefBytes
(
None
)
=>
write!
(
...
...
@@ -455,7 +453,7 @@ pub enum UnsupportedOpInfo {
ReadBytesAsPointer
,
}
impl
fmt
::
D
ebug
for
UnsupportedOpInfo
{
impl
fmt
::
D
isplay
for
UnsupportedOpInfo
{
fn
fmt
(
&
self
,
f
:
&
mut
fmt
::
Formatter
<
'_
>
)
->
fmt
::
Result
{
use
UnsupportedOpInfo
::
*
;
match
self
{
...
...
@@ -481,7 +479,7 @@ pub enum ResourceExhaustionInfo {
StepLimitReached
,
}
impl
fmt
::
D
ebug
for
ResourceExhaustionInfo
{
impl
fmt
::
D
isplay
for
ResourceExhaustionInfo
{
fn
fmt
(
&
self
,
f
:
&
mut
fmt
::
Formatter
<
'_
>
)
->
fmt
::
Result
{
use
ResourceExhaustionInfo
::
*
;
match
self
{
...
...
@@ -499,7 +497,6 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
pub
trait
AsAny
:
Any
{
fn
as_any
(
&
self
)
->
&
dyn
Any
;
}
impl
<
T
:
Any
>
AsAny
for
T
{
#[inline(always)]
fn
as_any
(
&
self
)
->
&
dyn
Any
{
...
...
@@ -508,7 +505,7 @@ fn as_any(&self) -> &dyn Any {
}
/// A trait for machine-specific errors (or other "machine stop" conditions).
pub
trait
MachineStopType
:
AsAny
+
fmt
::
D
ebug
+
Send
{}
pub
trait
MachineStopType
:
AsAny
+
fmt
::
D
isplay
+
Send
{}
impl
MachineStopType
for
String
{}
impl
dyn
MachineStopType
{
...
...
@@ -538,21 +535,21 @@ pub enum InterpError<'tcx> {
impl
fmt
::
Display
for
InterpError
<
'_
>
{
fn
fmt
(
&
self
,
f
:
&
mut
fmt
::
Formatter
<
'_
>
)
->
fmt
::
Result
{
// Forward `Display` to `Debug`.
fmt
::
Debug
::
fmt
(
self
,
f
)
use
InterpError
::
*
;
match
*
self
{
Unsupported
(
ref
msg
)
=>
write!
(
f
,
"{}"
,
msg
),
InvalidProgram
(
ref
msg
)
=>
write!
(
f
,
"{}"
,
msg
),
UndefinedBehavior
(
ref
msg
)
=>
write!
(
f
,
"{}"
,
msg
),
ResourceExhaustion
(
ref
msg
)
=>
write!
(
f
,
"{}"
,
msg
),
MachineStop
(
ref
msg
)
=>
write!
(
f
,
"{}"
,
msg
),
}
}
}
// Forward `Debug` to `Display`, so it does not look awful.
impl
fmt
::
Debug
for
InterpError
<
'_
>
{
fn
fmt
(
&
self
,
f
:
&
mut
fmt
::
Formatter
<
'_
>
)
->
fmt
::
Result
{
use
InterpError
::
*
;
match
*
self
{
Unsupported
(
ref
msg
)
=>
write!
(
f
,
"{:?}"
,
msg
),
InvalidProgram
(
ref
msg
)
=>
write!
(
f
,
"{:?}"
,
msg
),
UndefinedBehavior
(
ref
msg
)
=>
write!
(
f
,
"{:?}"
,
msg
),
ResourceExhaustion
(
ref
msg
)
=>
write!
(
f
,
"{:?}"
,
msg
),
MachineStop
(
ref
msg
)
=>
write!
(
f
,
"{:?}"
,
msg
),
}
fmt
::
Display
::
fmt
(
self
,
f
)
}
}
...
...
src/librustc_mir/transform/const_prop.rs
浏览文件 @
f9489956
...
...
@@ -43,8 +43,8 @@
// We make a new local type for it. The type itself does not carry any information,
// but its vtable (for the `MachineStopType` trait) does.
struct
Zst
;
//
Debug-p
rinting this type shows the desired string.
impl
std
::
fmt
::
D
ebug
for
Zst
{
//
P
rinting this type shows the desired string.
impl
std
::
fmt
::
D
isplay
for
Zst
{
fn
fmt
(
&
self
,
f
:
&
mut
std
::
fmt
::
Formatter
<
'_
>
)
->
std
::
fmt
::
Result
{
write!
(
f
,
$
(
$tt
)
*
)
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录