Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
c81935e6
R
Rust
项目概览
int
/
Rust
12 个月 前同步成功
通知
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,发现更多精彩内容 >>
提交
c81935e6
编写于
8月 06, 2020
作者:
B
Bastian Kauschke
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
make `ConstEvaluatable` more strict
上级
7bc0bf72
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
133 addition
and
26 deletion
+133
-26
compiler/rustc_middle/src/mir/mod.rs
compiler/rustc_middle/src/mir/mod.rs
+23
-4
compiler/rustc_trait_selection/src/traits/fulfill.rs
compiler/rustc_trait_selection/src/traits/fulfill.rs
+10
-8
compiler/rustc_trait_selection/src/traits/mod.rs
compiler/rustc_trait_selection/src/traits/mod.rs
+1
-0
compiler/rustc_trait_selection/src/traits/select/mod.rs
compiler/rustc_trait_selection/src/traits/select/mod.rs
+11
-9
src/librustc_trait_selection/traits/const_evaluatable.rs
src/librustc_trait_selection/traits/const_evaluatable.rs
+54
-0
src/test/ui/const_evaluatable/associated_const.rs
src/test/ui/const_evaluatable/associated_const.rs
+11
-0
src/test/ui/enum-discriminant/issue-70453-polymorphic-ctfe.rs
...test/ui/enum-discriminant/issue-70453-polymorphic-ctfe.rs
+1
-2
src/test/ui/enum-discriminant/issue-70453-polymorphic-ctfe.stderr
.../ui/enum-discriminant/issue-70453-polymorphic-ctfe.stderr
+10
-0
src/test/ui/impl-trait/issue-56445.rs
src/test/ui/impl-trait/issue-56445.rs
+1
-2
src/test/ui/lazy_normalization_consts/issue-73980.rs
src/test/ui/lazy_normalization_consts/issue-73980.rs
+1
-1
src/test/ui/lazy_normalization_consts/issue-73980.stderr
src/test/ui/lazy_normalization_consts/issue-73980.stderr
+10
-0
未找到文件。
compiler/rustc_middle/src/mir/mod.rs
浏览文件 @
c81935e6
...
...
@@ -186,6 +186,19 @@ pub struct Body<'tcx> {
/// FIXME(oli-obk): rewrite the promoted during promotion to eliminate the cell components.
pub
ignore_interior_mut_in_const_validation
:
bool
,
/// Does this body use generic parameters. This is used for the `ConstEvaluatable` check.
///
/// Note that this does not actually mean that this body is not computable right now.
/// The repeat count in the following example is polymorphic, but can still be evaluated
/// without knowing anything about the type parameter `T`.
///
/// ```rust
/// fn test<T>() {
/// let _ = [0; std::mem::size_of::<*mut T>()];
/// }
/// ```
pub
is_polymorphic
:
bool
,
predecessor_cache
:
PredecessorCache
,
}
...
...
@@ -208,7 +221,7 @@ pub fn new(
local_decls
.len
()
);
Body
{
let
mut
body
=
Body
{
phase
:
MirPhase
::
Build
,
basic_blocks
,
source_scopes
,
...
...
@@ -224,8 +237,11 @@ pub fn new(
span
,
required_consts
:
Vec
::
new
(),
ignore_interior_mut_in_const_validation
:
false
,
is_polymorphic
:
false
,
predecessor_cache
:
PredecessorCache
::
new
(),
}
};
body
.is_polymorphic
=
body
.has_param_types_or_consts
();
body
}
/// Returns a partially initialized MIR body containing only a list of basic blocks.
...
...
@@ -234,7 +250,7 @@ pub fn new(
/// is only useful for testing but cannot be `#[cfg(test)]` because it is used in a different
/// crate.
pub
fn
new_cfg_only
(
basic_blocks
:
IndexVec
<
BasicBlock
,
BasicBlockData
<
'tcx
>>
)
->
Self
{
Body
{
let
mut
body
=
Body
{
phase
:
MirPhase
::
Build
,
basic_blocks
,
source_scopes
:
IndexVec
::
new
(),
...
...
@@ -250,8 +266,11 @@ pub fn new_cfg_only(basic_blocks: IndexVec<BasicBlock, BasicBlockData<'tcx>>) ->
generator_kind
:
None
,
var_debug_info
:
Vec
::
new
(),
ignore_interior_mut_in_const_validation
:
false
,
is_polymorphic
:
false
,
predecessor_cache
:
PredecessorCache
::
new
(),
}
};
body
.is_polymorphic
=
body
.has_param_types_or_consts
();
body
}
#[inline]
...
...
compiler/rustc_trait_selection/src/traits/fulfill.rs
浏览文件 @
c81935e6
...
...
@@ -10,6 +10,7 @@
use
rustc_middle
::
ty
::{
self
,
Binder
,
Const
,
Ty
,
TypeFoldable
};
use
std
::
marker
::
PhantomData
;
use
super
::
const_evaluatable
;
use
super
::
project
;
use
super
::
select
::
SelectionContext
;
use
super
::
wf
;
...
...
@@ -458,16 +459,17 @@ fn process_obligation(
}
ty
::
PredicateAtom
::
ConstEvaluatable
(
def_id
,
substs
)
=>
{
match
self
.selcx
.infcx
()
.const_eval_resolv
e
(
obligation
.param_env
,
const_evaluatable
::
is_const_evaluatabl
e
(
self
.selcx
.infcx
()
,
def_id
,
substs
,
None
,
Some
(
obligation
.cause.span
),
)
{
Ok
(
_
)
=>
ProcessResult
::
Changed
(
vec!
[]),
Err
(
err
)
=>
ProcessResult
::
Error
(
CodeSelectionError
(
ConstEvalFailure
(
err
))),
}
obligation
.param_env
,
obligation
.cause.span
,
)
.map_or_else
(
|
e
|
ProcessResult
::
Error
(
CodeSelectionError
(
ConstEvalFailure
(
e
))),
|()|
ProcessResult
::
Changed
(
vec!
[]),
)
}
ty
::
PredicateAtom
::
ConstEquate
(
c1
,
c2
)
=>
{
...
...
compiler/rustc_trait_selection/src/traits/mod.rs
浏览文件 @
c81935e6
...
...
@@ -7,6 +7,7 @@
mod
chalk_fulfill
;
pub
mod
codegen
;
mod
coherence
;
mod
const_evaluatable
;
mod
engine
;
pub
mod
error_reporting
;
mod
fulfill
;
...
...
compiler/rustc_trait_selection/src/traits/select/mod.rs
浏览文件 @
c81935e6
...
...
@@ -6,6 +6,7 @@
use
self
::
SelectionCandidate
::
*
;
use
super
::
coherence
::{
self
,
Conflict
};
use
super
::
const_evaluatable
;
use
super
::
project
;
use
super
::
project
::
normalize_with_depth_to
;
use
super
::
util
;
...
...
@@ -542,17 +543,18 @@ fn evaluate_predicate_recursively<'o>(
}
ty
::
PredicateAtom
::
ConstEvaluatable
(
def_id
,
substs
)
=>
{
match
self
.tcx
()
.const_eval_resolv
e
(
obligation
.param_env
,
const_evaluatable
::
is_const_evaluatabl
e
(
self
.infcx
,
def_id
,
substs
,
None
,
None
,
)
{
Ok
(
_
)
=>
Ok
(
EvaluatedToOk
),
Err
(
ErrorHandled
::
TooGeneric
)
=>
Ok
(
EvaluatedToAmbig
),
Err
(
_
)
=>
Ok
(
EvaluatedToErr
),
}
obligation
.param_env
,
obligation
.cause.span
,
)
.map
(|()|
EvaluatedToOk
)
.or_else
(|
e
|
match
e
{
ErrorHandled
::
TooGeneric
=>
Ok
(
EvaluatedToAmbig
),
_
=>
Ok
(
EvaluatedToErr
),
})
}
ty
::
PredicateAtom
::
ConstEquate
(
c1
,
c2
)
=>
{
...
...
src/librustc_trait_selection/traits/const_evaluatable.rs
0 → 100644
浏览文件 @
c81935e6
use
rustc_middle
::
ty
::{
self
,
TypeFoldable
};
use
rustc_infer
::
infer
::
InferCtxt
;
use
rustc_middle
::
ty
::
subst
::
SubstsRef
;
use
rustc_span
::
Span
;
use
rustc_span
::
def_id
::
DefId
;
use
rustc_middle
::
mir
::
interpret
::
ErrorHandled
;
use
rustc_hir
::
def
::
DefKind
;
pub
fn
is_const_evaluatable
<
'cx
,
'tcx
>
(
infcx
:
&
InferCtxt
<
'cx
,
'tcx
>
,
def
:
ty
::
WithOptConstParam
<
DefId
>
,
substs
:
SubstsRef
<
'tcx
>
,
param_env
:
ty
::
ParamEnv
<
'tcx
>
,
span
:
Span
,
)
->
Result
<
(),
ErrorHandled
>
{
let
def_kind
=
infcx
.tcx
.def_kind
(
def
.did
);
match
def_kind
{
DefKind
::
AnonConst
=>
{
let
mir_body
=
if
let
Some
(
def
)
=
def
.as_const_arg
()
{
infcx
.tcx
.optimized_mir_of_const_arg
(
def
)
}
else
{
infcx
.tcx
.optimized_mir
(
def
.did
)
};
if
mir_body
.is_polymorphic
{
return
Err
(
ErrorHandled
::
TooGeneric
);
}
}
_
=>
{
if
substs
.has_param_types_or_consts
()
{
return
Err
(
ErrorHandled
::
TooGeneric
);
}
}
}
match
infcx
.const_eval_resolve
(
param_env
,
def
,
substs
,
None
,
Some
(
span
),
)
{
Ok
(
_
)
=>
Ok
(()),
Err
(
err
)
=>
{
if
matches!
(
err
,
ErrorHandled
::
TooGeneric
)
{
infcx
.tcx.sess
.delay_span_bug
(
span
,
&
format!
(
"ConstEvaluatable too generic: {:?}, {:?}, {:?}"
,
def
,
substs
,
param_env
),
);
}
Err
(
err
)
}
}
}
\ No newline at end of file
src/test/ui/const_evaluatable/associated_const.rs
0 → 100644
浏览文件 @
c81935e6
// check-pass
struct
Foo
<
T
>
(
T
);
impl
<
T
>
Foo
<
T
>
{
const
VALUE
:
usize
=
std
::
mem
::
size_of
::
<
T
>
();
}
fn
test
<
T
>
()
{
let
_
=
[
0
;
Foo
::
<
u8
>
::
VALUE
];
}
fn
main
()
{}
src/test/ui/enum-discriminant/issue-70453-polymorphic-ctfe.rs
浏览文件 @
c81935e6
// run-pass
#![feature(arbitrary_enum_discriminant,
core_intrinsics)]
extern
crate
core
;
...
...
@@ -9,6 +7,7 @@
enum
MyWeirdOption
<
T
>
{
None
=
0
,
Some
(
T
)
=
core
::
mem
::
size_of
::
<*
mut
T
>
(),
//~^ ERROR constant expression depends on a generic parameter
}
fn
main
()
{
...
...
src/test/ui/enum-discriminant/issue-70453-polymorphic-ctfe.stderr
0 → 100644
浏览文件 @
c81935e6
error: constant expression depends on a generic parameter
--> $DIR/issue-70453-polymorphic-ctfe.rs:9:15
|
LL | Some(T) = core::mem::size_of::<*mut T>(),
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this may fail depending on what value the parameter takes
error: aborting due to previous error
src/test/ui/impl-trait/issue-56445.rs
浏览文件 @
c81935e6
...
...
@@ -5,8 +5,7 @@
use
std
::
marker
::
PhantomData
;
pub
struct
S
<
'a
>
{
pub
struct
S
<
'a
>
{
pub
m1
:
PhantomData
<&
'a
u8
>
,
pub
m2
:
[
u8
;
S
::
size
()],
}
...
...
src/test/ui/lazy_normalization_consts/issue-73980.rs
浏览文件 @
c81935e6
// check-pass
#![feature(lazy_normalization_consts)]
#![allow(incomplete_features)]
...
...
@@ -10,5 +9,6 @@ impl<T: ?Sized> L<T> {
}
impl
<
T
>
X
<
T
,
[
u8
;
L
::
<
T
>
::
S
]
>
{}
//~^ ERROR constant expression depends on a generic parameter
fn
main
()
{}
src/test/ui/lazy_normalization_consts/issue-73980.stderr
0 → 100644
浏览文件 @
c81935e6
error: constant expression depends on a generic parameter
--> $DIR/issue-73980.rs:11:9
|
LL | impl<T> X<T, [u8; L::<T>::S]> {}
| ^^^^^^^^^^^^^^^^^^^^^
|
= note: this may fail depending on what value the parameter takes
error: aborting due to previous error
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录