Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
64051221
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,发现更多精彩内容 >>
提交
64051221
编写于
11月 20, 2015
作者:
O
Oliver Schneider
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add feature gate `const_indexing`
tracking issue is #29947
上级
6683fa4d
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
22 addition
and
0 deletion
+22
-0
src/librustc/middle/const_eval.rs
src/librustc/middle/const_eval.rs
+11
-0
src/libsyntax/feature_gate.rs
src/libsyntax/feature_gate.rs
+6
-0
src/test/compile-fail/const-array-oob-arith.rs
src/test/compile-fail/const-array-oob-arith.rs
+2
-0
src/test/compile-fail/const-array-oob.rs
src/test/compile-fail/const-array-oob.rs
+2
-0
src/test/run-pass/array_const_index-1.rs
src/test/run-pass/array_const_index-1.rs
+1
-0
未找到文件。
src/librustc/middle/const_eval.rs
浏览文件 @
64051221
...
...
@@ -1137,6 +1137,17 @@ fn fromb(b: bool) -> ConstVal { Int(b as i64) }
hir
::
ExprTup
(
_
)
=>
Tuple
(
e
.id
),
hir
::
ExprStruct
(
..
)
=>
Struct
(
e
.id
),
hir
::
ExprIndex
(
ref
arr
,
ref
idx
)
=>
{
if
!
tcx
.sess.features
.borrow
()
.const_indexing
{
tcx
.sess
.span_err
(
e
.span
,
"const indexing is an unstable feature"
);
fileline_help!
(
tcx
.sess
,
e
.span
,
"in Nightly builds, add `#![feature(const_indexing)]` to the crate
\
attributes to enable"
);
signal!
(
e
,
NonConstPath
)
}
let
arr_hint
=
if
let
ExprTypeChecked
=
ty_hint
{
ExprTypeChecked
}
else
{
...
...
src/libsyntax/feature_gate.rs
浏览文件 @
64051221
...
...
@@ -179,6 +179,9 @@
// Allows the definition of `const fn` functions.
(
"const_fn"
,
"1.2.0"
,
Some
(
24111
),
Active
),
// Allows indexing into constant arrays.
(
"const_indexing"
,
"1.4.0"
,
Some
(
29947
),
Active
),
// Allows using #[prelude_import] on glob `use` items.
//
// rustc internal
...
...
@@ -494,6 +497,7 @@ pub struct Features {
/// #![feature] attrs for non-language (library) features
pub
declared_lib_features
:
Vec
<
(
InternedString
,
Span
)
>
,
pub
const_fn
:
bool
,
pub
const_indexing
:
bool
,
pub
static_recursion
:
bool
,
pub
default_type_parameter_fallback
:
bool
,
pub
type_macros
:
bool
,
...
...
@@ -525,6 +529,7 @@ pub fn new() -> Features {
declared_stable_lang_features
:
Vec
::
new
(),
declared_lib_features
:
Vec
::
new
(),
const_fn
:
false
,
const_indexing
:
false
,
static_recursion
:
false
,
default_type_parameter_fallback
:
false
,
type_macros
:
false
,
...
...
@@ -1097,6 +1102,7 @@ fn check_crate_inner<F>(cm: &CodeMap, span_handler: &SpanHandler,
declared_stable_lang_features
:
accepted_features
,
declared_lib_features
:
unknown_features
,
const_fn
:
cx
.has_feature
(
"const_fn"
),
const_indexing
:
cx
.has_feature
(
"const_indexing"
),
static_recursion
:
cx
.has_feature
(
"static_recursion"
),
default_type_parameter_fallback
:
cx
.has_feature
(
"default_type_parameter_fallback"
),
type_macros
:
cx
.has_feature
(
"type_macros"
),
...
...
src/test/compile-fail/const-array-oob-arith.rs
浏览文件 @
64051221
...
...
@@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(const_indexing)]
const
ARR
:
[
i32
;
6
]
=
[
42
,
43
,
44
,
45
,
46
,
47
];
const
IDX
:
usize
=
3
;
const
VAL
:
i32
=
ARR
[
IDX
];
...
...
src/test/compile-fail/const-array-oob.rs
浏览文件 @
64051221
...
...
@@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(const_indexing)]
const
FOO
:
[
u32
;
3
]
=
[
1
,
2
,
3
];
const
BAR
:
u32
=
FOO
[
5
];
// no error, because the error below occurs before regular const eval
...
...
src/test/run-pass/array_const_index-1.rs
浏览文件 @
64051221
...
...
@@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(const_indexing)]
fn
main
()
{
const
ARR
:
[
i32
;
6
]
=
[
42
,
43
,
44
,
45
,
46
,
47
];
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录