Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
ceb634a7
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,发现更多精彩内容 >>
未验证
提交
ceb634a7
编写于
1月 29, 2018
作者:
O
Oliver Schneider
提交者:
Oliver Schneider
3月 08, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update tests
上级
45abb1ba
变更
16
隐藏空白更改
内联
并排
Showing
16 changed file
with
75 addition
and
57 deletion
+75
-57
src/librustc_mir/hair/pattern/_match.rs
src/librustc_mir/hair/pattern/_match.rs
+4
-4
src/librustc_mir/transform/const_prop.rs
src/librustc_mir/transform/const_prop.rs
+4
-3
src/test/compile-fail/array_const_index-0.rs
src/test/compile-fail/array_const_index-0.rs
+1
-0
src/test/compile-fail/array_const_index-1.rs
src/test/compile-fail/array_const_index-1.rs
+1
-0
src/test/compile-fail/const-err-early.rs
src/test/compile-fail/const-err-early.rs
+10
-1
src/test/compile-fail/const-err-multi.rs
src/test/compile-fail/const-err-multi.rs
+5
-0
src/test/compile-fail/const-err.rs
src/test/compile-fail/const-err.rs
+1
-0
src/test/compile-fail/const-eval-overflow2.rs
src/test/compile-fail/const-eval-overflow2.rs
+14
-14
src/test/compile-fail/const-eval-overflow2b.rs
src/test/compile-fail/const-eval-overflow2b.rs
+14
-14
src/test/compile-fail/const-eval-overflow2c.rs
src/test/compile-fail/const-eval-overflow2c.rs
+14
-14
src/test/compile-fail/const-slice-oob.rs
src/test/compile-fail/const-slice-oob.rs
+1
-0
src/test/compile-fail/lint-exceeding-bitshifts.rs
src/test/compile-fail/lint-exceeding-bitshifts.rs
+0
-1
src/test/compile-fail/lint-exceeding-bitshifts2.rs
src/test/compile-fail/lint-exceeding-bitshifts2.rs
+3
-3
src/test/compile-fail/lint-type-overflow2.rs
src/test/compile-fail/lint-type-overflow2.rs
+0
-1
src/test/ui/error-codes/E0080.rs
src/test/ui/error-codes/E0080.rs
+1
-0
src/test/ui/infinite-recursion-const-fn.rs
src/test/ui/infinite-recursion-const-fn.rs
+2
-2
未找到文件。
src/librustc_mir/hair/pattern/_match.rs
浏览文件 @
ceb634a7
...
...
@@ -185,7 +185,7 @@ fn lower_byte_str_pattern<'p>(&mut self, pat: &'p Pattern<'tcx>) -> Vec<&'p Patt
match
b
{
Value
::
ByVal
(
PrimVal
::
Ptr
(
ptr
))
=>
{
let
is_array_ptr
=
ty
.builtin_deref
(
true
,
ty
::
NoPreference
)
.builtin_deref
(
true
)
.and_then
(|
t
|
t
.ty
.builtin_index
())
.map_or
(
false
,
|
t
|
t
==
tcx
.types.u8
);
assert
!
(
is_array_ptr
);
...
...
@@ -560,7 +560,7 @@ fn max_slice_length<'p, 'a: 'p, 'tcx: 'a, I>(
}
}
=>
{
let
is_array_ptr
=
ty
.builtin_deref
(
true
,
ty
::
NoPreference
)
.builtin_deref
(
true
)
.and_then
(|
t
|
t
.ty
.builtin_index
())
.map_or
(
false
,
|
t
|
t
==
cx
.tcx.types.u8
);
if
is_array_ptr
{
...
...
@@ -949,7 +949,7 @@ fn slice_pat_covered_by_constructor(tcx: TyCtxt, _span: Span,
Value
::
ByVal
(
PrimVal
::
Ptr
(
ptr
))
),
ty
})
=>
{
let
is_array_ptr
=
ty
.builtin_deref
(
true
,
ty
::
NoPreference
)
.builtin_deref
(
true
)
.and_then
(|
t
|
t
.ty
.builtin_index
())
.map_or
(
false
,
|
t
|
t
==
tcx
.types.u8
);
assert
!
(
is_array_ptr
);
...
...
@@ -1089,7 +1089,7 @@ fn specialize<'p, 'a: 'p, 'tcx: 'a>(
Slice
(
..
)
=>
match
value
.val
{
ConstVal
::
Value
(
Value
::
ByVal
(
PrimVal
::
Ptr
(
ptr
)))
=>
{
let
is_array_ptr
=
value
.ty
.builtin_deref
(
true
,
ty
::
NoPreference
)
.builtin_deref
(
true
)
.and_then
(|
t
|
t
.ty
.builtin_index
())
.map_or
(
false
,
|
t
|
t
==
cx
.tcx.types.u8
);
assert
!
(
is_array_ptr
);
...
...
src/librustc_mir/transform/const_prop.rs
浏览文件 @
ceb634a7
...
...
@@ -198,7 +198,6 @@ fn const_prop(
Rvalue
::
CheckedBinaryOp
(
op
,
ref
left
,
ref
right
)
|
Rvalue
::
BinaryOp
(
op
,
ref
left
,
ref
right
)
=>
{
trace!
(
"rvalue binop {:?} for {:?} and {:?}"
,
op
,
left
,
right
);
let
left
=
self
.eval_operand
(
left
)
?
;
let
right
=
self
.eval_operand
(
right
)
?
;
let
def_id
=
if
self
.tcx
.is_closure
(
self
.source.def_id
)
{
self
.tcx
.closure_base_def_id
(
self
.source.def_id
)
...
...
@@ -218,8 +217,8 @@ fn const_prop(
let
r
=
ecx
.value_to_primval
(
ValTy
{
value
:
right
.0
,
ty
:
right
.1
})
.ok
()
?
;
if
op
==
BinOp
::
Shr
||
op
==
BinOp
::
Shl
{
let
param_env
=
self
.tcx
.param_env
(
self
.source.def_id
);
let
bits
=
(
self
.tcx
,
param_env
)
.layout_of
(
left
.1
)
.unwrap
()
.size
.bits
();
if
r
.to_bytes
()
.ok
()
?
>=
bits
as
u128
{
let
bits
=
(
self
.tcx
,
param_env
)
.layout_of
(
place_ty
)
.unwrap
()
.size
.bits
();
if
r
.to_bytes
()
.ok
()
.map_or
(
false
,
|
b
|
b
>=
bits
as
u128
)
{
let
scope_info
=
match
self
.mir.visibility_scope_info
{
ClearCrossCrate
::
Set
(
ref
data
)
=>
data
,
ClearCrossCrate
::
Clear
=>
return
None
,
...
...
@@ -230,8 +229,10 @@ fn const_prop(
node_id
,
span
,
"bitshift exceeds the type's number of bits"
);
return
None
;
}
}
let
left
=
self
.eval_operand
(
left
)
?
;
let
l
=
ecx
.value_to_primval
(
ValTy
{
value
:
left
.0
,
ty
:
left
.1
})
.ok
()
?
;
trace!
(
"const evaluating {:?} for {:?} and {:?}"
,
op
,
left
,
right
);
match
ecx
.binary_op
(
op
,
l
,
left
.1
,
r
,
right
.1
)
{
...
...
src/test/compile-fail/array_const_index-0.rs
浏览文件 @
ceb634a7
...
...
@@ -11,6 +11,7 @@
const
A
:
&
'static
[
i32
]
=
&
[];
const
B
:
i32
=
(
&
A
)[
1
];
//~^ ERROR constant evaluation error
//~| ERROR E0080
//~| index out of bounds: the len is 0 but the index is 1
fn
main
()
{
...
...
src/test/compile-fail/array_const_index-1.rs
浏览文件 @
ceb634a7
...
...
@@ -11,6 +11,7 @@
const
A
:
[
i32
;
0
]
=
[];
const
B
:
i32
=
A
[
1
];
//~^ ERROR constant evaluation error
//~| ERROR E0080
//~| index out of bounds: the len is 0 but the index is 1
fn
main
()
{
...
...
src/test/compile-fail/const-err-early.rs
浏览文件 @
ceb634a7
...
...
@@ -8,18 +8,27 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(const_indexing)]
#![deny(const_err)]
pub
const
A
:
i8
=
-
std
::
i8
::
MIN
;
//~ ERROR E0080
//~| ERROR const_err
//~| ERROR const_err
//~| ERROR E0080
pub
const
B
:
u8
=
200u8
+
200u8
;
//~ ERROR E0080
//~| ERROR E0080
pub
const
C
:
u8
=
200u8
*
4
;
//~ ERROR E0080
//~| ERROR E0080
pub
const
D
:
u8
=
42u8
-
(
42u8
+
1
);
//~ ERROR E0080
//~| ERROR E0080
pub
const
E
:
u8
=
[
5u8
][
1
];
//~^ ERROR E0080
//~| ERROR E0080
fn
main
()
{
let
_
a
=
A
;
let
_
b
=
B
;
let
_
c
=
C
;
let
_
d
=
D
;
let
_
e
=
E
;
let
_
e
=
[
6u8
][
1
];
}
src/test/compile-fail/const-err-multi.rs
浏览文件 @
ceb634a7
...
...
@@ -14,12 +14,17 @@
//~^ ERROR E0080
//~| ERROR const_err
//~| ERROR const_err
//~| ERROR E0080
pub
const
B
:
i8
=
A
;
//~^ ERROR E0080
//~| ERROR E0080
pub
const
C
:
u8
=
A
as
u8
;
//~^ ERROR E0080
//~| ERROR E0080
pub
const
D
:
i8
=
50
-
A
;
//~^ ERROR E0080
//~| ERROR E0080
fn
main
()
{
let
_
=
(
A
,
B
,
C
,
D
);
}
src/test/compile-fail/const-err.rs
浏览文件 @
ceb634a7
...
...
@@ -24,6 +24,7 @@ fn black_box<T>(_: T) {
const
FOO
:
u8
=
[
5u8
][
1
];
//~^ ERROR constant evaluation error
//~| index out of bounds: the len is 1 but the index is 1
//~| ERROR E0080
fn
main
()
{
black_box
((
FOO
,
FOO
));
...
...
src/test/compile-fail/const-eval-overflow2.rs
浏览文件 @
ceb634a7
...
...
@@ -22,57 +22,57 @@
use
std
::{
u8
,
u16
,
u32
,
u64
,
usize
};
const
VALS_I8
:
(
i8
,)
=
(
i8
::
MIN
-
1
,
//~^ ERROR constant evaluation error
//~| attempt to subtract with overflow
(
i8
::
MIN
-
1
,
);
const
VALS_I16
:
(
i16
,)
=
(
i16
::
MIN
-
1
,
//~^ ERROR constant evaluation error
//~| attempt to subtract with overflow
(
i16
::
MIN
-
1
,
);
const
VALS_I32
:
(
i32
,)
=
(
i32
::
MIN
-
1
,
//~^ ERROR constant evaluation error
//~| attempt to subtract with overflow
(
i32
::
MIN
-
1
,
);
const
VALS_I64
:
(
i64
,)
=
(
i64
::
MIN
-
1
,
//~^ ERROR constant evaluation error
//~| attempt to subtract with overflow
(
i64
::
MIN
-
1
,
);
const
VALS_U8
:
(
u8
,)
=
(
u8
::
MIN
-
1
,
//~^ ERROR constant evaluation error
//~| attempt to subtract with overflow
(
u8
::
MIN
-
1
,
);
const
VALS_U16
:
(
u16
,)
=
(
u16
::
MIN
-
1
,
//~^ ERROR constant evaluation error
//~| attempt to subtract with overflow
u16
::
MIN
-
1
,
);
const
VALS_U32
:
(
u32
,)
=
(
u32
::
MIN
-
1
,
//~^ ERROR constant evaluation error
//~| attempt to subtract with overflow
u32
::
MIN
-
1
,
);
const
VALS_U64
:
(
u64
,)
=
(
u64
::
MIN
-
1
,
//~^ ERROR constant evaluation error
//~| attempt to subtract with overflow
(
u64
::
MIN
-
1
,
);
fn
main
()
{
...
...
src/test/compile-fail/const-eval-overflow2b.rs
浏览文件 @
ceb634a7
...
...
@@ -22,57 +22,57 @@
use
std
::{
u8
,
u16
,
u32
,
u64
,
usize
};
const
VALS_I8
:
(
i8
,)
=
(
i8
::
MAX
+
1
,
//~^ ERROR constant evaluation error
//~| attempt to add with overflow
(
i8
::
MAX
+
1
,
);
const
VALS_I16
:
(
i16
,)
=
(
i16
::
MAX
+
1
,
//~^ ERROR constant evaluation error
//~| attempt to add with overflow
(
i16
::
MAX
+
1
,
);
const
VALS_I32
:
(
i32
,)
=
(
i32
::
MAX
+
1
,
//~^ ERROR constant evaluation error
//~| attempt to add with overflow
(
i32
::
MAX
+
1
,
);
const
VALS_I64
:
(
i64
,)
=
(
i64
::
MAX
+
1
,
//~^ ERROR constant evaluation error
//~| attempt to add with overflow
(
i64
::
MAX
+
1
,
);
const
VALS_U8
:
(
u8
,)
=
(
u8
::
MAX
+
1
,
//~^ ERROR constant evaluation error
//~| attempt to add with overflow
(
u8
::
MAX
+
1
,
);
const
VALS_U16
:
(
u16
,)
=
(
u16
::
MAX
+
1
,
//~^ ERROR constant evaluation error
//~| attempt to add with overflow
u16
::
MAX
+
1
,
);
const
VALS_U32
:
(
u32
,)
=
(
u32
::
MAX
+
1
,
//~^ ERROR constant evaluation error
//~| attempt to add with overflow
u32
::
MAX
+
1
,
);
const
VALS_U64
:
(
u64
,)
=
(
u64
::
MAX
+
1
,
//~^ ERROR constant evaluation error
//~| attempt to add with overflow
(
u64
::
MAX
+
1
,
);
fn
main
()
{
...
...
src/test/compile-fail/const-eval-overflow2c.rs
浏览文件 @
ceb634a7
...
...
@@ -22,57 +22,57 @@
use
std
::{
u8
,
u16
,
u32
,
u64
,
usize
};
const
VALS_I8
:
(
i8
,)
=
(
i8
::
MIN
*
2
,
//~^ ERROR constant evaluation error
//~| attempt to multiply with overflow
(
i8
::
MIN
*
2
,
);
const
VALS_I16
:
(
i16
,)
=
(
i16
::
MIN
*
2
,
//~^ ERROR constant evaluation error
//~| attempt to multiply with overflow
(
i16
::
MIN
*
2
,
);
const
VALS_I32
:
(
i32
,)
=
(
i32
::
MIN
*
2
,
//~^ ERROR constant evaluation error
//~| attempt to multiply with overflow
(
i32
::
MIN
*
2
,
);
const
VALS_I64
:
(
i64
,)
=
(
i64
::
MIN
*
2
,
//~^ ERROR constant evaluation error
//~| attempt to multiply with overflow
(
i64
::
MIN
*
2
,
);
const
VALS_U8
:
(
u8
,)
=
(
u8
::
MAX
*
2
,
//~^ ERROR constant evaluation error
//~| attempt to multiply with overflow
(
u8
::
MAX
*
2
,
);
const
VALS_U16
:
(
u16
,)
=
(
u16
::
MAX
*
2
,
//~^ ERROR constant evaluation error
//~| attempt to multiply with overflow
u16
::
MAX
*
2
,
);
const
VALS_U32
:
(
u32
,)
=
(
u32
::
MAX
*
2
,
//~^ ERROR constant evaluation error
//~| attempt to multiply with overflow
u32
::
MAX
*
2
,
);
const
VALS_U64
:
(
u64
,)
=
(
u64
::
MAX
*
2
,
//~^ ERROR constant evaluation error
//~| attempt to multiply with overflow
(
u64
::
MAX
*
2
,
);
fn
main
()
{
...
...
src/test/compile-fail/const-slice-oob.rs
浏览文件 @
ceb634a7
...
...
@@ -13,6 +13,7 @@
const
FOO
:
&
'static
[
u32
]
=
&
[
1
,
2
,
3
];
const
BAR
:
u32
=
FOO
[
5
];
//~^ ERROR constant evaluation error [E0080]
//~| ERROR constant evaluation error [E0080]
//~| index out of bounds: the len is 3 but the index is 5
fn
main
()
{
...
...
src/test/compile-fail/lint-exceeding-bitshifts.rs
浏览文件 @
ceb634a7
...
...
@@ -11,7 +11,6 @@
#![deny(exceeding_bitshifts)]
#![allow(unused_variables)]
#![allow(dead_code,
const_err)]
#![feature(const_indexing)]
fn
main
()
{
let
n
=
1u8
<<
7
;
...
...
src/test/compile-fail/lint-exceeding-bitshifts2.rs
浏览文件 @
ceb634a7
...
...
@@ -14,7 +14,7 @@
fn
main
()
{
let
n
=
1u8
<<
(
4
+
3
);
let
n
=
1u8
<<
(
4
+
4
);
//~ ERROR:
const_err
let
n
=
1u8
<<
(
4
+
4
);
//~ ERROR:
bitshift exceeds
let
n
=
1i64
>>
[
63
][
0
];
let
n
=
1i64
>>
[
64
][
0
];
// should be linting, needs to wait for const propagation
...
...
@@ -22,6 +22,6 @@ fn main() {
const
BITS
:
usize
=
32
;
#[cfg(target_pointer_width
=
"64"
)]
const
BITS
:
usize
=
64
;
let
n
=
1_
isize
<<
BITS
;
//~ ERROR:
const_err
let
n
=
1_u
size
<<
BITS
;
//~ ERROR:
const_err
let
n
=
1_
isize
<<
BITS
;
//~ ERROR:
bitshift exceeds
let
n
=
1_u
size
<<
BITS
;
//~ ERROR:
bitshift exceeds
}
src/test/compile-fail/lint-type-overflow2.rs
浏览文件 @
ceb634a7
...
...
@@ -17,7 +17,6 @@
#[rustc_error]
fn
main
()
{
//~ ERROR: compilation successful
let
x2
:
i8
=
--
128
;
//~ warn: literal out of range for i8
//~^ WARN constant evaluation error
let
x
=
-
3.40282357e+38_f32
;
//~ warn: literal out of range for f32
let
x
=
3.40282357e+38_f32
;
//~ warn: literal out of range for f32
...
...
src/test/ui/error-codes/E0080.rs
浏览文件 @
ceb634a7
...
...
@@ -10,6 +10,7 @@
enum
Enum
{
X
=
(
1
<<
500
),
//~ ERROR E0080
//~| ERROR bitshift exceeds
//~| shift left with overflow
Y
=
(
1
/
0
)
//~ ERROR E0080
//~| const_err
...
...
src/test/ui/infinite-recursion-const-fn.rs
浏览文件 @
ceb634a7
...
...
@@ -11,8 +11,8 @@
//https://github.com/rust-lang/rust/issues/31364
#![feature(const_fn)]
const
fn
a
()
->
usize
{
b
()
}
const
fn
a
()
->
usize
{
b
()
}
//~ ERROR constant evaluation error
const
fn
b
()
->
usize
{
a
()
}
const
ARR
:
[
i32
;
a
()]
=
[
5
;
6
];
//~ ERROR constant evaluation error
const
ARR
:
[
i32
;
a
()]
=
[
5
;
6
];
fn
main
(){}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录