Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
87ecf84c
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,发现更多精彩内容 >>
提交
87ecf84c
编写于
6月 13, 2021
作者:
R
Rémy Rakic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Improve CTFE validation error message
上级
fb3ea63d
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
22 addition
and
12 deletion
+22
-12
compiler/rustc_middle/src/mir/interpret/error.rs
compiler/rustc_middle/src/mir/interpret/error.rs
+10
-4
compiler/rustc_mir/src/interpret/validity.rs
compiler/rustc_mir/src/interpret/validity.rs
+12
-8
未找到文件。
compiler/rustc_middle/src/mir/interpret/error.rs
浏览文件 @
87ecf84c
...
...
@@ -256,7 +256,10 @@ pub enum UndefinedBehaviorInfo<'tcx> {
/// The value validity check found a problem.
/// Should only be thrown by `validity.rs` and always point out which part of the value
/// is the problem.
ValidationFailure
(
String
),
ValidationFailure
{
path
:
Option
<
String
>
,
msg
:
String
,
},
/// Using a non-boolean `u8` as bool.
InvalidBool
(
u8
),
/// Using a non-character `u32` as character.
...
...
@@ -331,7 +334,10 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
),
WriteToReadOnly
(
a
)
=>
write!
(
f
,
"writing to {} which is read-only"
,
a
),
DerefFunctionPointer
(
a
)
=>
write!
(
f
,
"accessing {} which contains a function"
,
a
),
ValidationFailure
(
ref
err
)
=>
write!
(
f
,
"type validation failed: {}"
,
err
),
ValidationFailure
{
path
:
None
,
msg
}
=>
write!
(
f
,
"type validation failed: {}"
,
msg
),
ValidationFailure
{
path
:
Some
(
path
),
msg
}
=>
{
write!
(
f
,
"type validation failed at {}: {}"
,
path
,
msg
)
}
InvalidBool
(
b
)
=>
{
write!
(
f
,
"interpreting an invalid 8-bit value as a bool: 0x{:02x}"
,
b
)
}
...
...
@@ -499,13 +505,13 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
}
impl
InterpError
<
'_
>
{
/// Some errors
t
o string formatting even if the error is never printed.
/// Some errors
d
o string formatting even if the error is never printed.
/// To avoid performance issues, there are places where we want to be sure to never raise these formatting errors,
/// so this method lets us detect them and `bug!` on unexpected errors.
pub
fn
formatted_string
(
&
self
)
->
bool
{
match
self
{
InterpError
::
Unsupported
(
UnsupportedOpInfo
::
Unsupported
(
_
))
|
InterpError
::
UndefinedBehavior
(
UndefinedBehaviorInfo
::
ValidationFailure
(
_
)
)
|
InterpError
::
UndefinedBehavior
(
UndefinedBehaviorInfo
::
ValidationFailure
{
..
}
)
|
InterpError
::
UndefinedBehavior
(
UndefinedBehaviorInfo
::
Ub
(
_
))
=>
true
,
_
=>
false
,
}
...
...
compiler/rustc_mir/src/interpret/validity.rs
浏览文件 @
87ecf84c
...
...
@@ -26,23 +26,27 @@
macro_rules!
throw_validation_failure
{
(
$where:expr
,
{
$
(
$what_fmt:expr
),
+
}
$
(
expected
{
$
(
$expected_fmt:expr
),
+
}
)
?
)
=>
{{
let
msg
=
rustc_middle
::
ty
::
print
::
with_no_trimmed_paths
(||
{
let
(
path
,
msg
)
=
rustc_middle
::
ty
::
print
::
with_no_trimmed_paths
(||
{
let
mut
msg
=
String
::
new
();
msg
.push_str
(
"encountered "
);
write!
(
&
mut
msg
,
$
(
$what_fmt
),
+
)
.unwrap
();
let
where_
=
&
$where
;
if
!
where_
.is_empty
()
{
msg
.push_str
(
" at "
);
write_path
(
&
mut
msg
,
where_
);
}
$
(
msg
.push_str
(
", but expected "
);
write!
(
&
mut
msg
,
$
(
$expected_fmt
),
+
)
.unwrap
();
)
?
msg
let
where_
=
&
$where
;
let
path
=
if
!
where_
.is_empty
()
{
let
mut
path
=
String
::
new
();
write_path
(
&
mut
path
,
where_
);
Some
(
path
)
}
else
{
None
};
(
path
,
msg
)
});
throw_ub!
(
ValidationFailure
(
msg
)
)
throw_ub!
(
ValidationFailure
{
path
,
msg
}
)
}};
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录