Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
710270d9
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,发现更多精彩内容 >>
提交
710270d9
编写于
5月 28, 2015
作者:
N
Niko Matsakis
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add feature-gate to calling const fn
上级
3a433b96
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
30 addition
and
7 deletion
+30
-7
src/librustc/middle/check_const.rs
src/librustc/middle/check_const.rs
+18
-3
src/libsyntax/feature_gate.rs
src/libsyntax/feature_gate.rs
+6
-3
src/test/compile-fail/const-fn-stability.rs
src/test/compile-fail/const-fn-stability.rs
+6
-1
未找到文件。
src/librustc/middle/check_const.rs
浏览文件 @
710270d9
...
...
@@ -199,8 +199,23 @@ fn add_qualif(&mut self, qualif: ConstQualif) {
}
/// Returns true if the call is to a const fn or method.
fn
handle_const_fn_call
(
&
mut
self
,
def_id
:
ast
::
DefId
,
ret_ty
:
Ty
<
'tcx
>
)
->
bool
{
fn
handle_const_fn_call
(
&
mut
self
,
expr
:
&
ast
::
Expr
,
def_id
:
ast
::
DefId
,
ret_ty
:
Ty
<
'tcx
>
)
->
bool
{
if
let
Some
(
fn_like
)
=
const_eval
::
lookup_const_fn_by_id
(
self
.tcx
,
def_id
)
{
if
self
.mode
!=
Mode
::
Var
&&
!
self
.tcx.sess.features
.borrow
()
.const_fn
{
self
.tcx.sess
.span_err
(
expr
.span
,
&
format!
(
"const fns are an unstable feature"
));
fileline_help!
(
self
.tcx.sess
,
expr
.span
,
"in Nightly builds, add `#![feature(const_fn)]` to the crate
\
attributes to enable"
);
}
let
qualif
=
self
.fn_like
(
fn_like
.kind
(),
fn_like
.decl
(),
fn_like
.body
(),
...
...
@@ -657,7 +672,7 @@ fn check_expr<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>,
}
Some
(
def
::
DefMethod
(
did
,
def
::
FromImpl
(
_
)))
|
Some
(
def
::
DefFn
(
did
,
_
))
=>
{
v
.handle_const_fn_call
(
did
,
node_ty
)
v
.handle_const_fn_call
(
e
,
did
,
node_ty
)
}
_
=>
false
};
...
...
@@ -677,7 +692,7 @@ fn check_expr<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>,
_
=>
None
};
let
is_const
=
match
method_did
{
Some
(
did
)
=>
v
.handle_const_fn_call
(
did
,
node_ty
),
Some
(
did
)
=>
v
.handle_const_fn_call
(
e
,
did
,
node_ty
),
None
=>
false
};
if
!
is_const
{
...
...
src/libsyntax/feature_gate.rs
浏览文件 @
710270d9
...
...
@@ -332,7 +332,8 @@ pub struct Features {
/// spans of #![feature] attrs for stable language features. for error reporting
pub
declared_stable_lang_features
:
Vec
<
Span
>
,
/// #![feature] attrs for non-language (library) features
pub
declared_lib_features
:
Vec
<
(
InternedString
,
Span
)
>
pub
declared_lib_features
:
Vec
<
(
InternedString
,
Span
)
>
,
pub
const_fn
:
bool
,
}
impl
Features
{
...
...
@@ -352,7 +353,8 @@ pub fn new() -> Features {
unmarked_api
:
false
,
negate_unsigned
:
false
,
declared_stable_lang_features
:
Vec
::
new
(),
declared_lib_features
:
Vec
::
new
()
declared_lib_features
:
Vec
::
new
(),
const_fn
:
false
,
}
}
}
...
...
@@ -802,7 +804,8 @@ fn check_crate_inner<F>(cm: &CodeMap, span_handler: &SpanHandler,
unmarked_api
:
cx
.has_feature
(
"unmarked_api"
),
negate_unsigned
:
cx
.has_feature
(
"negate_unsigned"
),
declared_stable_lang_features
:
accepted_features
,
declared_lib_features
:
unknown_features
declared_lib_features
:
unknown_features
,
const_fn
:
cx
.has_feature
(
"const_fn"
),
}
}
...
...
src/test/compile-fail/const-fn-stability.rs
浏览文件 @
710270d9
...
...
@@ -25,4 +25,9 @@ impl Foo for u32 {
const
fn
foo
()
->
u32
{
0
}
//~ ERROR const fn is unstable
}
fn
main
()
{
}
static
FOO
:
usize
=
foo
();
const
BAR
:
usize
=
foo
();
fn
main
()
{
let
x
:
[
usize
;
foo
()]
=
[];
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录