Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
46c00a21
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,发现更多精彩内容 >>
提交
46c00a21
编写于
11月 26, 2019
作者:
O
Oliver Scherer
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Move all intrinsic whitelists into the constness check file
上级
52be0b07
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
42 addition
and
56 deletion
+42
-56
src/librustc/ty/constness.rs
src/librustc/ty/constness.rs
+35
-0
src/librustc_mir/transform/qualify_min_const_fn.rs
src/librustc_mir/transform/qualify_min_const_fn.rs
+3
-52
src/test/ui/consts/const-extern-fn/const-extern-fn-call-extern-fn.rs
.../consts/const-extern-fn/const-extern-fn-call-extern-fn.rs
+2
-2
src/test/ui/consts/const-extern-fn/const-extern-fn-call-extern-fn.stderr
...sts/const-extern-fn/const-extern-fn-call-extern-fn.stderr
+2
-2
未找到文件。
src/librustc/ty/constness.rs
浏览文件 @
46c00a21
...
...
@@ -36,12 +36,47 @@ pub fn is_unstable_const_fn(self, def_id: DefId) -> Option<Symbol> {
}
}
/// Returns `true` if the `def_id` refers to an intrisic which we've whitelisted
/// for being called from stable `const fn`s (`min_const_fn`).
///
/// Adding more intrinsics requires sign-off from @rust-lang/lang.
fn
is_intrinsic_min_const_fn
(
self
,
def_id
:
DefId
)
->
bool
{
match
self
.item_name
(
def_id
)
{
|
sym
::
size_of
|
sym
::
min_align_of
|
sym
::
needs_drop
// Arithmetic:
|
sym
::
add_with_overflow
// ~> .overflowing_add
|
sym
::
sub_with_overflow
// ~> .overflowing_sub
|
sym
::
mul_with_overflow
// ~> .overflowing_mul
|
sym
::
wrapping_add
// ~> .wrapping_add
|
sym
::
wrapping_sub
// ~> .wrapping_sub
|
sym
::
wrapping_mul
// ~> .wrapping_mul
|
sym
::
saturating_add
// ~> .saturating_add
|
sym
::
saturating_sub
// ~> .saturating_sub
|
sym
::
unchecked_shl
// ~> .wrapping_shl
|
sym
::
unchecked_shr
// ~> .wrapping_shr
|
sym
::
rotate_left
// ~> .rotate_left
|
sym
::
rotate_right
// ~> .rotate_right
|
sym
::
ctpop
// ~> .count_ones
|
sym
::
ctlz
// ~> .leading_zeros
|
sym
::
cttz
// ~> .trailing_zeros
|
sym
::
bswap
// ~> .swap_bytes
|
sym
::
bitreverse
// ~> .reverse_bits
=>
true
,
_
=>
false
,
}
}
/// Returns `true` if this function must conform to `min_const_fn`
pub
fn
is_min_const_fn
(
self
,
def_id
:
DefId
)
->
bool
{
// Bail out if the signature doesn't contain `const`
if
!
self
.is_const_fn_raw
(
def_id
)
{
return
false
;
}
if
let
Abi
::
RustIntrinsic
=
self
.fn_sig
(
def_id
)
.abi
()
{
return
self
.is_intrinsic_min_const_fn
(
def_id
);
}
if
self
.features
()
.staged_api
{
// in order for a libstd function to be considered min_const_fn
...
...
src/librustc_mir/transform/qualify_min_const_fn.rs
浏览文件 @
46c00a21
...
...
@@ -2,7 +2,6 @@
use
rustc
::
hir
;
use
rustc
::
mir
::
*
;
use
rustc
::
ty
::{
self
,
Predicate
,
Ty
,
TyCtxt
,
adjustment
::{
PointerCast
}};
use
rustc_target
::
spec
::
abi
;
use
std
::
borrow
::
Cow
;
use
syntax_pos
::
Span
;
use
syntax
::
symbol
::{
sym
,
Symbol
};
...
...
@@ -356,18 +355,8 @@ fn check_terminator(
}
=>
{
let
fn_ty
=
func
.ty
(
body
,
tcx
);
if
let
ty
::
FnDef
(
def_id
,
_
)
=
fn_ty
.kind
{
// some intrinsics are waved through if called inside the
// standard library. Users never need to call them directly
match
tcx
.fn_sig
(
def_id
)
.abi
()
{
abi
::
Abi
::
RustIntrinsic
=>
if
!
is_intrinsic_whitelisted
(
tcx
,
def_id
)
{
return
Err
((
span
,
"can only call a curated list of intrinsics in `min_const_fn`"
.into
(),
))
},
abi
::
Abi
::
Rust
if
tcx
.is_min_const_fn
(
def_id
)
=>
{},
abi
::
Abi
::
Rust
=>
return
Err
((
if
!
tcx
.is_min_const_fn
(
def_id
)
{
return
Err
((
span
,
format!
(
"can only call other `const fn` within a `const fn`,
\
...
...
@@ -375,14 +364,7 @@ fn check_terminator(
func
,
)
.into
(),
)),
abi
=>
return
Err
((
span
,
format!
(
"cannot call functions with `{}` abi in `min_const_fn`"
,
abi
,
)
.into
(),
)),
));
}
check_operand
(
tcx
,
func
,
span
,
def_id
,
body
)
?
;
...
...
@@ -410,34 +392,3 @@ fn check_terminator(
}
}
/// Returns `true` if the `def_id` refers to an intrisic which we've whitelisted
/// for being called from stable `const fn`s (`min_const_fn`).
///
/// Adding more intrinsics requires sign-off from @rust-lang/lang.
fn
is_intrinsic_whitelisted
(
tcx
:
TyCtxt
<
'tcx
>
,
def_id
:
DefId
)
->
bool
{
match
tcx
.item_name
(
def_id
)
{
|
sym
::
size_of
|
sym
::
min_align_of
|
sym
::
needs_drop
// Arithmetic:
|
sym
::
add_with_overflow
// ~> .overflowing_add
|
sym
::
sub_with_overflow
// ~> .overflowing_sub
|
sym
::
mul_with_overflow
// ~> .overflowing_mul
|
sym
::
wrapping_add
// ~> .wrapping_add
|
sym
::
wrapping_sub
// ~> .wrapping_sub
|
sym
::
wrapping_mul
// ~> .wrapping_mul
|
sym
::
saturating_add
// ~> .saturating_add
|
sym
::
saturating_sub
// ~> .saturating_sub
|
sym
::
unchecked_shl
// ~> .wrapping_shl
|
sym
::
unchecked_shr
// ~> .wrapping_shr
|
sym
::
rotate_left
// ~> .rotate_left
|
sym
::
rotate_right
// ~> .rotate_right
|
sym
::
ctpop
// ~> .count_ones
|
sym
::
ctlz
// ~> .leading_zeros
|
sym
::
cttz
// ~> .trailing_zeros
|
sym
::
bswap
// ~> .swap_bytes
|
sym
::
bitreverse
// ~> .reverse_bits
=>
true
,
_
=>
false
,
}
}
src/test/ui/consts/const-extern-fn/const-extern-fn-call-extern-fn.rs
浏览文件 @
46c00a21
...
...
@@ -7,7 +7,7 @@
const
extern
fn
bar
()
{
unsafe
{
regular_in_block
();
//~^ ERROR: can
not call functions with `"C"` abi in `min_const_
fn`
//~^ ERROR: can
only call other `const fn` within a `const
fn`
}
}
...
...
@@ -16,7 +16,7 @@
const
extern
fn
foo
()
{
unsafe
{
regular
();
//~^ ERROR: can
not call functions with `"C"` abi in `min_const_
fn`
//~^ ERROR: can
only call other `const fn` within a `const
fn`
}
}
...
...
src/test/ui/consts/const-extern-fn/const-extern-fn-call-extern-fn.stderr
浏览文件 @
46c00a21
error[E0723]: can
not call functions with `"C"` abi in `min_const_
fn`
error[E0723]: can
only call other `const fn` within a `const fn`, but `const regular_in_block` is not stable as `const
fn`
--> $DIR/const-extern-fn-call-extern-fn.rs:9:9
|
LL | regular_in_block();
...
...
@@ -7,7 +7,7 @@ LL | regular_in_block();
= note: for more information, see issue https://github.com/rust-lang/rust/issues/57563
= help: add `#![feature(const_fn)]` to the crate attributes to enable
error[E0723]: can
not call functions with `"C"` abi in `min_const_
fn`
error[E0723]: can
only call other `const fn` within a `const fn`, but `const regular` is not stable as `const
fn`
--> $DIR/const-extern-fn-call-extern-fn.rs:18:9
|
LL | regular();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录