Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
d3f981b1
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,发现更多精彩内容 >>
未验证
提交
d3f981b1
编写于
9月 15, 2021
作者:
D
Deadbeef
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Move is_const_fn to under TyCtxt
上级
cdeba02f
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
26 addition
and
26 deletion
+26
-26
compiler/rustc_const_eval/src/const_eval/fn_queries.rs
compiler/rustc_const_eval/src/const_eval/fn_queries.rs
+1
-18
compiler/rustc_const_eval/src/transform/promote_consts.rs
compiler/rustc_const_eval/src/transform/promote_consts.rs
+2
-4
compiler/rustc_middle/src/ty/context.rs
compiler/rustc_middle/src/ty/context.rs
+20
-0
src/librustdoc/clean/mod.rs
src/librustdoc/clean/mod.rs
+2
-2
src/tools/clippy/clippy_utils/src/lib.rs
src/tools/clippy/clippy_utils/src/lib.rs
+0
-1
src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs
src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs
+1
-1
未找到文件。
compiler/rustc_const_eval/src/const_eval/fn_queries.rs
浏览文件 @
d3f981b1
...
...
@@ -6,23 +6,6 @@
use
rustc_span
::
symbol
::
Symbol
;
use
rustc_target
::
spec
::
abi
::
Abi
;
/// Whether the `def_id` counts as const fn in your current crate, considering all active
/// feature gates
pub
fn
is_const_fn
(
tcx
:
TyCtxt
<
'_
>
,
def_id
:
DefId
)
->
bool
{
tcx
.is_const_fn_raw
(
def_id
)
&&
match
is_unstable_const_fn
(
tcx
,
def_id
)
{
Some
(
feature_name
)
=>
{
// has a `rustc_const_unstable` attribute, check whether the user enabled the
// corresponding feature gate.
tcx
.features
()
.declared_lib_features
.iter
()
.any
(|
&
(
sym
,
_
)|
sym
==
feature_name
)
}
// functions without const stability are either stable user written
// const fn or the user is using feature gates and we thus don't
// care what they do
None
=>
true
,
}
}
/// Whether the `def_id` is an unstable const fn and what feature gate is necessary to enable it
pub
fn
is_unstable_const_fn
(
tcx
:
TyCtxt
<
'_
>
,
def_id
:
DefId
)
->
Option
<
Symbol
>
{
if
tcx
.is_const_fn_raw
(
def_id
)
{
...
...
@@ -77,7 +60,7 @@ fn is_const_fn_raw(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
}
fn
is_promotable_const_fn
(
tcx
:
TyCtxt
<
'_
>
,
def_id
:
DefId
)
->
bool
{
is_const_fn
(
tcx
,
def_id
)
tcx
.is_const_fn
(
def_id
)
&&
match
tcx
.lookup_const_stability
(
def_id
)
{
Some
(
stab
)
=>
{
if
cfg!
(
debug_assertions
)
&&
stab
.promotable
{
...
...
compiler/rustc_const_eval/src/transform/promote_consts.rs
浏览文件 @
d3f981b1
...
...
@@ -26,7 +26,6 @@
use
std
::
cell
::
Cell
;
use
std
::{
cmp
,
iter
,
mem
};
use
crate
::
const_eval
::{
is_const_fn
,
is_unstable_const_fn
};
use
crate
::
transform
::
check_consts
::{
is_lang_panic_fn
,
qualifs
,
ConstCx
};
use
crate
::
transform
::
MirPass
;
...
...
@@ -656,8 +655,7 @@ fn validate_call(
let
is_const_fn
=
match
*
fn_ty
.kind
()
{
ty
::
FnDef
(
def_id
,
_
)
=>
{
is_const_fn
(
self
.tcx
,
def_id
)
||
is_unstable_const_fn
(
self
.tcx
,
def_id
)
.is_some
()
self
.tcx
.is_const_fn_raw
(
def_id
)
||
is_lang_panic_fn
(
self
.tcx
,
def_id
)
}
_
=>
false
,
...
...
@@ -1079,7 +1077,7 @@ pub fn is_const_fn_in_array_repeat_expression<'tcx>(
if
let
ty
::
FnDef
(
def_id
,
_
)
=
*
literal
.ty
()
.kind
()
{
if
let
Some
((
destination_place
,
_
))
=
destination
{
if
destination_place
==
place
{
if
is_const_fn
(
ccx
.tcx
,
def_id
)
{
if
ccx
.tcx
.is_const_fn
(
def_id
)
{
return
true
;
}
}
...
...
compiler/rustc_middle/src/ty/context.rs
浏览文件 @
d3f981b1
...
...
@@ -2741,6 +2741,26 @@ pub fn late_bound_vars(self, id: HirId) -> &'tcx List<ty::BoundVariableKind> {
pub
fn
lifetime_scope
(
self
,
id
:
HirId
)
->
Option
<
LifetimeScopeForPath
>
{
self
.lifetime_scope_map
(
id
.owner
)
.and_then
(|
mut
map
|
map
.remove
(
&
id
.local_id
))
}
/// Whether the `def_id` counts as const fn in the current crate, considering all active
/// feature gates
pub
fn
is_const_fn
(
self
,
def_id
:
DefId
)
->
bool
{
if
self
.is_const_fn_raw
(
def_id
)
{
match
self
.lookup_const_stability
(
def_id
)
{
Some
(
stability
)
if
stability
.level
.is_unstable
()
=>
{
// has a `rustc_const_unstable` attribute, check whether the user enabled the
// corresponding feature gate.
self
.features
()
.declared_lib_features
.iter
()
.any
(|
&
(
sym
,
_
)|
sym
==
stability
.feature
)
}
// functions without const stability are either stable user written
// const fn or the user is using feature gates and we thus don't
// care what they do
_
=>
true
,
}
}
else
{
false
}
}
}
impl
TyCtxtAt
<
'tcx
>
{
...
...
src/librustdoc/clean/mod.rs
浏览文件 @
d3f981b1
...
...
@@ -11,7 +11,7 @@
use
rustc_ast
as
ast
;
use
rustc_attr
as
attr
;
use
rustc_const_eval
::
const_eval
::
{
is_const_fn
,
is_unstable_const_fn
}
;
use
rustc_const_eval
::
const_eval
::
is_unstable_const_fn
;
use
rustc_data_structures
::
fx
::{
FxHashMap
,
FxHashSet
};
use
rustc_hir
as
hir
;
use
rustc_hir
::
def
::{
CtorKind
,
DefKind
,
Res
};
...
...
@@ -787,7 +787,7 @@ fn clean_fn_or_proc_macro(
let
mut
func
=
(
sig
,
generics
,
body_id
)
.clean
(
cx
);
let
def_id
=
item
.def_id
.to_def_id
();
func
.header.constness
=
if
is_const_fn
(
cx
.tcx
,
def_id
)
&&
is_unstable_const_fn
(
cx
.tcx
,
def_id
)
.is_none
()
{
if
cx
.tcx
.is_const_fn
(
def_id
)
&&
is_unstable_const_fn
(
cx
.tcx
,
def_id
)
.is_none
()
{
hir
::
Constness
::
Const
}
else
{
hir
::
Constness
::
NotConst
...
...
src/tools/clippy/clippy_utils/src/lib.rs
浏览文件 @
d3f981b1
...
...
@@ -18,7 +18,6 @@
extern
crate
rustc_ast
;
extern
crate
rustc_ast_pretty
;
extern
crate
rustc_attr
;
extern
crate
rustc_const_eval
;
extern
crate
rustc_data_structures
;
extern
crate
rustc_errors
;
extern
crate
rustc_hir
;
...
...
src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs
浏览文件 @
d3f981b1
...
...
@@ -364,7 +364,7 @@ fn check_terminator(
}
fn
is_const_fn
(
tcx
:
TyCtxt
<
'_
>
,
def_id
:
DefId
,
msrv
:
Option
<&
RustcVersion
>
)
->
bool
{
rustc_const_eval
::
const_eval
::
is_const_fn
(
tcx
,
def_id
)
tcx
.is_const_fn
(
def_id
)
&&
tcx
.lookup_const_stability
(
def_id
)
.map_or
(
true
,
|
const_stab
|
{
if
let
rustc_attr
::
StabilityLevel
::
Stable
{
since
}
=
const_stab
.level
{
// Checking MSRV is manually necessary because `rustc` has no such concept. This entire
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录