Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
0ac6fd04
R
Rust
项目概览
int
/
Rust
11 个月 前同步成功
通知
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,发现更多精彩内容 >>
提交
0ac6fd04
编写于
6月 01, 2020
作者:
R
Ralf Jung
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix const_prop spans and re-bless tests
上级
dc6ffaeb
变更
14
隐藏空白更改
内联
并排
Showing
14 changed file
with
61 addition
and
52 deletion
+61
-52
src/librustc_mir/const_eval/error.rs
src/librustc_mir/const_eval/error.rs
+3
-2
src/librustc_mir/const_eval/eval_queries.rs
src/librustc_mir/const_eval/eval_queries.rs
+2
-2
src/librustc_mir/interpret/cast.rs
src/librustc_mir/interpret/cast.rs
+2
-5
src/librustc_mir/interpret/eval_context.rs
src/librustc_mir/interpret/eval_context.rs
+3
-3
src/librustc_mir/interpret/place.rs
src/librustc_mir/interpret/place.rs
+20
-7
src/librustc_mir/transform/const_prop.rs
src/librustc_mir/transform/const_prop.rs
+2
-7
src/test/ui/consts/const-eval/infinite_loop.stderr
src/test/ui/consts/const-eval/infinite_loop.stderr
+2
-2
src/test/ui/consts/const_limit/const_eval_limit_reached.stderr
...est/ui/consts/const_limit/const_eval_limit_reached.stderr
+13
-10
src/test/ui/consts/recursive-zst-static.default.stderr
src/test/ui/consts/recursive-zst-static.default.stderr
+2
-2
src/test/ui/consts/recursive-zst-static.unleash.stderr
src/test/ui/consts/recursive-zst-static.unleash.stderr
+2
-2
src/test/ui/consts/uninhabited-const-issue-61744.rs
src/test/ui/consts/uninhabited-const-issue-61744.rs
+2
-2
src/test/ui/consts/uninhabited-const-issue-61744.stderr
src/test/ui/consts/uninhabited-const-issue-61744.stderr
+4
-4
src/test/ui/recursion/recursive-static-definition.stderr
src/test/ui/recursion/recursive-static-definition.stderr
+2
-2
src/test/ui/write-to-static-mut-in-static.stderr
src/test/ui/write-to-static-mut-in-static.stderr
+2
-2
未找到文件。
src/librustc_mir/const_eval/error.rs
浏览文件 @
0ac6fd04
...
...
@@ -2,7 +2,7 @@
use
std
::
fmt
;
use
rustc_middle
::
mir
::
AssertKind
;
use
rustc_span
::
Symbol
;
use
rustc_span
::
{
Span
,
Symbol
}
;
use
super
::
InterpCx
;
use
crate
::
interpret
::{
ConstEvalErr
,
InterpErrorInfo
,
Machine
};
...
...
@@ -53,8 +53,9 @@ impl Error for ConstEvalErrKind {}
pub
fn
error_to_const_error
<
'mir
,
'tcx
:
'mir
,
M
:
Machine
<
'mir
,
'tcx
>>
(
ecx
:
&
InterpCx
<
'mir
,
'tcx
,
M
>
,
error
:
InterpErrorInfo
<
'tcx
>
,
span
:
Option
<
Span
>
,
)
->
ConstEvalErr
<
'tcx
>
{
error
.print_backtrace
();
let
stacktrace
=
ecx
.generate_stacktrace
();
ConstEvalErr
{
error
:
error
.kind
,
stacktrace
,
span
:
ecx
.cur_span
(
)
}
ConstEvalErr
{
error
:
error
.kind
,
stacktrace
,
span
:
span
.unwrap_or_else
(||
ecx
.cur_span
()
)
}
}
src/librustc_mir/const_eval/eval_queries.rs
浏览文件 @
0ac6fd04
...
...
@@ -213,7 +213,7 @@ fn validate_and_turn_into_const<'tcx>(
})();
val
.map_err
(|
error
|
{
let
err
=
error_to_const_error
(
&
ecx
,
error
);
let
err
=
error_to_const_error
(
&
ecx
,
error
,
None
);
err
.struct_error
(
ecx
.tcx_at
(),
"it is undefined behavior to use this value"
,
|
mut
diag
|
{
diag
.note
(
note_on_undefined_behavior_error
());
diag
.emit
();
...
...
@@ -312,7 +312,7 @@ pub fn const_eval_raw_provider<'tcx>(
res
.and_then
(|
body
|
eval_body_using_ecx
(
&
mut
ecx
,
cid
,
&
body
))
.map
(|
place
|
RawConst
{
alloc_id
:
place
.ptr
.assert_ptr
()
.alloc_id
,
ty
:
place
.layout.ty
})
.map_err
(|
error
|
{
let
err
=
error_to_const_error
(
&
ecx
,
error
);
let
err
=
error_to_const_error
(
&
ecx
,
error
,
None
);
// errors in statics are always emitted as fatal errors
if
is_static
{
// Ensure that if the above error was either `TooGeneric` or `Reported`
...
...
src/librustc_mir/interpret/cast.rs
浏览文件 @
0ac6fd04
...
...
@@ -268,11 +268,8 @@ fn unsize_into_ptr(
(
&
ty
::
Array
(
_
,
length
),
&
ty
::
Slice
(
_
))
=>
{
let
ptr
=
self
.read_immediate
(
src
)
?
.to_scalar
()
?
;
// u64 cast is from usize to u64, which is always good
let
val
=
Immediate
::
new_slice
(
ptr
,
length
.eval_usize
(
self
.tcx
,
self
.param_env
),
self
,
);
let
val
=
Immediate
::
new_slice
(
ptr
,
length
.eval_usize
(
self
.tcx
,
self
.param_env
),
self
);
self
.write_immediate
(
val
,
dest
)
}
(
&
ty
::
Dynamic
(
..
),
&
ty
::
Dynamic
(
..
))
=>
{
...
...
src/librustc_mir/interpret/eval_context.rs
浏览文件 @
0ac6fd04
...
...
@@ -314,8 +314,7 @@ pub fn new(
#[inline(always)]
pub
fn
cur_span
(
&
self
)
->
Span
{
self
.stack
()
self
.stack
()
.last
()
.and_then
(|
f
|
f
.current_source_info
())
.map
(|
si
|
si
.span
)
...
...
@@ -419,7 +418,8 @@ pub fn load_mir(
let
did
=
instance
.def_id
();
if
let
Some
(
did
)
=
did
.as_local
()
{
if
self
.tcx_at
()
.has_typeck_tables
(
did
)
{
if
let
Some
(
error_reported
)
=
self
.tcx_at
()
.typeck_tables_of
(
did
)
.tainted_by_errors
{
if
let
Some
(
error_reported
)
=
self
.tcx_at
()
.typeck_tables_of
(
did
)
.tainted_by_errors
{
throw_inval!
(
TypeckError
(
error_reported
))
}
}
...
...
src/librustc_mir/interpret/place.rs
浏览文件 @
0ac6fd04
...
...
@@ -404,7 +404,10 @@ pub fn mplace_field(
// to get some code to work that probably ought to work.
field_layout
.align.abi
}
None
=>
span_bug!
(
self
.cur_span
(),
"cannot compute offset for extern type field at non-0 offset"
),
None
=>
span_bug!
(
self
.cur_span
(),
"cannot compute offset for extern type field at non-0 offset"
),
};
(
base
.meta
,
offset
.align_to
(
align
))
}
else
{
...
...
@@ -440,7 +443,11 @@ pub fn mplace_index(
assert
!
(
!
field_layout
.is_unsized
());
base
.offset
(
offset
,
MemPlaceMeta
::
None
,
field_layout
,
self
)
}
_
=>
span_bug!
(
self
.cur_span
(),
"`mplace_index` called on non-array type {:?}"
,
base
.layout.ty
),
_
=>
span_bug!
(
self
.cur_span
(),
"`mplace_index` called on non-array type {:?}"
,
base
.layout.ty
),
}
}
...
...
@@ -484,7 +491,9 @@ fn mplace_subslice(
// (that have count 0 in their layout).
let
from_offset
=
match
base
.layout.fields
{
FieldsShape
::
Array
{
stride
,
..
}
=>
stride
*
from
,
// `Size` multiplication is checked
_
=>
span_bug!
(
self
.cur_span
(),
"unexpected layout of index access: {:#?}"
,
base
.layout
),
_
=>
{
span_bug!
(
self
.cur_span
(),
"unexpected layout of index access: {:#?}"
,
base
.layout
)
}
};
// Compute meta and new layout
...
...
@@ -497,7 +506,9 @@ fn mplace_subslice(
let
len
=
Scalar
::
from_machine_usize
(
inner_len
,
self
);
(
MemPlaceMeta
::
Meta
(
len
),
base
.layout.ty
)
}
_
=>
span_bug!
(
self
.cur_span
(),
"cannot subslice non-array type: `{:?}`"
,
base
.layout.ty
),
_
=>
{
span_bug!
(
self
.cur_span
(),
"cannot subslice non-array type: `{:?}`"
,
base
.layout.ty
)
}
};
let
layout
=
self
.layout_of
(
ty
)
?
;
base
.offset
(
from_offset
,
meta
,
layout
,
self
)
...
...
@@ -776,9 +787,11 @@ fn write_immediate_to_mplace_no_validate(
Immediate
::
Scalar
(
scalar
)
=>
{
match
dest
.layout.abi
{
Abi
::
Scalar
(
_
)
=>
{}
// fine
_
=>
{
span_bug!
(
self
.cur_span
(),
"write_immediate_to_mplace: invalid Scalar layout: {:#?}"
,
dest
.layout
)
}
_
=>
span_bug!
(
self
.cur_span
(),
"write_immediate_to_mplace: invalid Scalar layout: {:#?}"
,
dest
.layout
),
}
self
.memory
.get_raw_mut
(
ptr
.alloc_id
)
?
.write_scalar
(
&
tcx
,
...
...
src/librustc_mir/transform/const_prop.rs
浏览文件 @
0ac6fd04
...
...
@@ -405,7 +405,7 @@ fn eval_constant(&mut self, c: &Constant<'tcx>, source_info: SourceInfo) -> Opti
Ok
(
op
)
=>
Some
(
op
),
Err
(
error
)
=>
{
let
tcx
=
self
.ecx.tcx
.at
(
c
.span
);
let
err
=
error_to_const_error
(
&
self
.ecx
,
error
);
let
err
=
error_to_const_error
(
&
self
.ecx
,
error
,
Some
(
c
.span
)
);
if
let
Some
(
lint_root
)
=
self
.lint_root
(
source_info
)
{
let
lint_only
=
match
c
.literal.val
{
// Promoteds must lint and not error as the user didn't ask for them
...
...
@@ -417,12 +417,7 @@ fn eval_constant(&mut self, c: &Constant<'tcx>, source_info: SourceInfo) -> Opti
if
lint_only
{
// Out of backwards compatibility we cannot report hard errors in unused
// generic functions using associated constants of the generic parameters.
err
.report_as_lint
(
tcx
,
"erroneous constant used"
,
lint_root
,
Some
(
c
.span
),
);
err
.report_as_lint
(
tcx
,
"erroneous constant used"
,
lint_root
,
Some
(
c
.span
));
}
else
{
err
.report_as_error
(
tcx
,
"erroneous constant used"
);
}
...
...
src/test/ui/consts/const-eval/infinite_loop.stderr
浏览文件 @
0ac6fd04
...
...
@@ -23,10 +23,10 @@ LL | n = if n % 2 == 0 { n/2 } else { 3*n + 1 };
= help: add `#![feature(const_if_match)]` to the crate attributes to enable
error[E0080]: evaluation of constant value failed
--> $DIR/infinite_loop.rs:8:
20
--> $DIR/infinite_loop.rs:8:
17
|
LL | n = if n % 2 == 0 { n/2 } else { 3*n + 1 };
|
^^^^^^^^^^ exceeded interpreter step limit (see `#[const_eval_limit]`)
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^ exceeded interpreter step limit (see `#[const_eval_limit]`)
error: aborting due to 3 previous errors
...
...
src/test/ui/consts/const_limit/const_eval_limit_reached.stderr
浏览文件 @
0ac6fd04
error: any use of this value will cause an error
--> $DIR/const_eval_limit_reached.rs:8:
11
--> $DIR/const_eval_limit_reached.rs:8:
5
|
LL | / const X: usize = {
LL | | let mut x = 0;
LL | | while x != 1000 {
| | ^^^^^^^^^ exceeded interpreter step limit (see `#[const_eval_limit]`)
LL | |
... |
LL | | x
LL | | };
| |__-
LL | / const X: usize = {
LL | | let mut x = 0;
LL | | while x != 1000 {
| |_____^
LL | ||
LL | || x += 1;
LL | || }
| ||_____^ exceeded interpreter step limit (see `#[const_eval_limit]`)
LL | |
LL | | x
LL | | };
| |__-
|
= note: `#[deny(const_err)]` on by default
...
...
src/test/ui/consts/recursive-zst-static.default.stderr
浏览文件 @
0ac6fd04
error[E0391]: cycle detected when const-evaluating `FOO`
--> $DIR/recursive-zst-static.rs:10:1
8
--> $DIR/recursive-zst-static.rs:10:1
|
LL | static FOO: () = FOO;
|
^^^
|
^^^^^^^^^^^^^^^^^^
^^^
|
note: ...which requires const-evaluating `FOO`...
--> $DIR/recursive-zst-static.rs:10:1
...
...
src/test/ui/consts/recursive-zst-static.unleash.stderr
浏览文件 @
0ac6fd04
error[E0391]: cycle detected when const-evaluating `FOO`
--> $DIR/recursive-zst-static.rs:10:1
8
--> $DIR/recursive-zst-static.rs:10:1
|
LL | static FOO: () = FOO;
|
^^^
|
^^^^^^^^^^^^^^^^^^
^^^
|
note: ...which requires const-evaluating `FOO`...
--> $DIR/recursive-zst-static.rs:10:1
...
...
src/test/ui/consts/uninhabited-const-issue-61744.rs
浏览文件 @
0ac6fd04
// build-fail
pub
const
unsafe
fn
fake_type
<
T
>
()
->
T
{
hint_unreachable
()
hint_unreachable
()
//~ ERROR evaluation of constant value failed
}
pub
const
unsafe
fn
hint_unreachable
()
->
!
{
fake_type
()
//~ ERROR evaluation of constant value failed
fake_type
()
}
trait
Const
{
...
...
src/test/ui/consts/uninhabited-const-issue-61744.stderr
浏览文件 @
0ac6fd04
error[E0080]: evaluation of constant value failed
--> $DIR/uninhabited-const-issue-61744.rs:
8
:5
--> $DIR/uninhabited-const-issue-61744.rs:
4
:5
|
LL | hint_unreachable()
|
------------------
|
^^^^^^^^^^^^^^^^^^
| |
| reached the configured maximum number of stack frames
| inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
| inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
| inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
...
...
@@ -71,9 +72,8 @@ LL | hint_unreachable()
| inside `fake_type::<i32>` at $DIR/uninhabited-const-issue-61744.rs:4:5
...
LL | fake_type()
|
^^^^^^^^^^^
|
-----------
| |
| reached the configured maximum number of stack frames
| inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:8:5
| inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:8:5
| inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:8:5
...
...
src/test/ui/recursion/recursive-static-definition.stderr
浏览文件 @
0ac6fd04
error[E0391]: cycle detected when const-evaluating `FOO`
--> $DIR/recursive-static-definition.rs:1:
23
--> $DIR/recursive-static-definition.rs:1:
1
|
LL | pub static FOO: u32 = FOO;
|
^^^
|
^^^^^^^^^^^^^^^^^^^^^^^
^^^
|
note: ...which requires const-evaluating `FOO`...
--> $DIR/recursive-static-definition.rs:1:1
...
...
src/test/ui/write-to-static-mut-in-static.stderr
浏览文件 @
0ac6fd04
...
...
@@ -5,10 +5,10 @@ LL | pub static mut B: () = unsafe { A = 1; };
| ^^^^^ modifying a static's initial value from another static's initializer
error[E0391]: cycle detected when const-evaluating `C`
--> $DIR/write-to-static-mut-in-static.rs:5:
34
--> $DIR/write-to-static-mut-in-static.rs:5:
1
|
LL | pub static mut C: u32 = unsafe { C = 1; 0 };
|
^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^
|
note: ...which requires const-evaluating `C`...
--> $DIR/write-to-static-mut-in-static.rs:5:1
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录