Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
50eb3975
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,发现更多精彩内容 >>
提交
50eb3975
编写于
4月 13, 2020
作者:
B
Bastian Kauschke
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
allow const generics in const fn
上级
c58c5327
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
5 addition
and
41 deletion
+5
-41
src/librustc_ast_passes/ast_validation.rs
src/librustc_ast_passes/ast_validation.rs
+1
-24
src/test/ui/const-generics/const-fn-with-const-param.rs
src/test/ui/const-generics/const-fn-with-const-param.rs
+2
-2
src/test/ui/const-generics/const-fn-with-const-param.stderr
src/test/ui/const-generics/const-fn-with-const-param.stderr
+2
-15
未找到文件。
src/librustc_ast_passes/ast_validation.rs
浏览文件 @
50eb3975
...
...
@@ -561,28 +561,6 @@ fn check_c_varadic_type(&self, fk: FnKind<'a>) {
}
}
/// We currently do not permit const generics in `const fn`,
/// as this is tantamount to allowing compile-time dependent typing.
///
/// FIXME(const_generics): Is this really true / necessary? Discuss with @varkor.
/// At any rate, the restriction feels too syntactic. Consider moving it to e.g. typeck.
fn
check_const_fn_const_generic
(
&
self
,
span
:
Span
,
sig
:
&
FnSig
,
generics
:
&
Generics
)
{
if
let
Const
::
Yes
(
const_span
)
=
sig
.header.constness
{
// Look for const generics and error if we find any.
for
param
in
&
generics
.params
{
if
let
GenericParamKind
::
Const
{
..
}
=
param
.kind
{
self
.err_handler
()
.struct_span_err
(
span
,
"const parameters are not permitted in const functions"
,
)
.span_label
(
const_span
,
"`const` because of this"
)
.emit
();
}
}
}
}
fn
check_item_named
(
&
self
,
ident
:
Ident
,
kind
:
&
str
)
{
if
ident
.name
!=
kw
::
Underscore
{
return
;
...
...
@@ -966,9 +944,8 @@ fn visit_item(&mut self, item: &'a Item) {
.emit
();
}
}
ItemKind
::
Fn
(
def
,
ref
sig
,
ref
generics
,
ref
body
)
=>
{
ItemKind
::
Fn
(
def
,
_
,
_
,
ref
body
)
=>
{
self
.check_defaultness
(
item
.span
,
def
);
self
.check_const_fn_const_generic
(
item
.span
,
sig
,
generics
);
if
body
.is_none
()
{
let
msg
=
"free function without a body"
;
...
...
src/test/ui/const-generics/const-fn-with-const-param.rs
浏览文件 @
50eb3975
// run-pass
#![feature(const_generics)]
//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash
const
fn
const_u32_identity
<
const
X
:
u32
>
()
->
u32
{
//~^ ERROR const parameters are not permitted in const functions
X
}
fn
main
()
{
println!
(
"{:?}"
,
const_u32_identity
::
<
18
>
()
);
assert_eq!
(
const_u32_identity
::
<
18
>
(),
18
);
}
src/test/ui/const-generics/const-fn-with-const-param.stderr
浏览文件 @
50eb3975
error: const parameters are not permitted in const functions
--> $DIR/const-fn-with-const-param.rs:4:1
|
LL | const fn const_u32_identity<const X: u32>() -> u32 {
| ^----
| |
| _`const` because of this
| |
LL | |
LL | | X
LL | | }
| |_^
warning: the feature `const_generics` is incomplete and may cause the compiler to crash
--> $DIR/const-fn-with-const-param.rs:
1
:12
--> $DIR/const-fn-with-const-param.rs:
2
:12
|
LL | #![feature(const_generics)]
| ^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default
error: aborting due to previous error;
1 warning emitted
warning:
1 warning emitted
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录