Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
splade
rust
提交
e1f408e6
R
rust
项目概览
splade
/
rust
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rust
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
e1f408e6
编写于
9月 22, 2020
作者:
B
Bastian Kauschke
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
const_evaluatable_checked: collect predicates from fn_sig
上级
78a08948
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
72 addition
and
6 deletion
+72
-6
compiler/rustc_typeck/src/collect.rs
compiler/rustc_typeck/src/collect.rs
+18
-5
src/test/ui/const-generics/const_evaluatable_checked/cross_crate_predicate.rs
...nerics/const_evaluatable_checked/cross_crate_predicate.rs
+1
-0
src/test/ui/const-generics/const_evaluatable_checked/cross_crate_predicate.stderr
...cs/const_evaluatable_checked/cross_crate_predicate.stderr
+19
-1
src/test/ui/const-generics/const_evaluatable_checked/from-sig-fail.rs
...const-generics/const_evaluatable_checked/from-sig-fail.rs
+11
-0
src/test/ui/const-generics/const_evaluatable_checked/from-sig-fail.stderr
...t-generics/const_evaluatable_checked/from-sig-fail.stderr
+9
-0
src/test/ui/const-generics/const_evaluatable_checked/from-sig.rs
...t/ui/const-generics/const_evaluatable_checked/from-sig.rs
+14
-0
未找到文件。
compiler/rustc_typeck/src/collect.rs
浏览文件 @
e1f408e6
...
...
@@ -1678,8 +1678,10 @@ fn predicates_defined_on(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicate
if
tcx
.features
()
.const_evaluatable_checked
{
let
const_evaluatable
=
const_evaluatable_predicates_of
(
tcx
,
def_id
,
&
result
);
result
.predicates
=
tcx
.arena
.alloc_from_iter
(
result
.predicates
.iter
()
.copied
()
.chain
(
const_evaluatable
));
if
!
const_evaluatable
.is_empty
()
{
result
.predicates
=
tcx
.arena
.alloc_from_iter
(
result
.predicates
.iter
()
.copied
()
.chain
(
const_evaluatable
));
}
}
debug!
(
"predicates_defined_on({:?}) = {:?}"
,
def_id
,
result
);
...
...
@@ -1690,7 +1692,7 @@ pub fn const_evaluatable_predicates_of<'tcx>(
tcx
:
TyCtxt
<
'tcx
>
,
def_id
:
DefId
,
predicates
:
&
ty
::
GenericPredicates
<
'tcx
>
,
)
->
impl
Iterator
<
Item
=
(
ty
::
Predicate
<
'tcx
>
,
Span
)
>
{
)
->
Vec
<
(
ty
::
Predicate
<
'tcx
>
,
Span
)
>
{
#[derive(Default)]
struct
ConstCollector
<
'tcx
>
{
ct
:
SmallVec
<
[(
ty
::
WithOptConstParam
<
DefId
>
,
SubstsRef
<
'tcx
>
,
Span
);
4
]
>
,
...
...
@@ -1711,10 +1713,21 @@ fn visit_const(&mut self, ct: &'tcx Const<'tcx>) -> bool {
collector
.curr_span
=
span
;
pred
.visit_with
(
&
mut
collector
);
}
warn!
(
"const_evaluatable_predicates_of({:?}) = {:?}"
,
def_id
,
collector
.ct
);
match
tcx
.def_kind
(
def_id
)
{
DefKind
::
Fn
|
DefKind
::
AssocFn
=>
{
tcx
.fn_sig
(
def_id
)
.visit_with
(
&
mut
collector
);
}
_
=>
(),
}
debug!
(
"const_evaluatable_predicates_of({:?}) = {:?}"
,
def_id
,
collector
.ct
);
// We only want unique const evaluatable predicates.
collector
.ct
.sort
();
collector
.ct
.dedup
();
collector
.ct
.into_iter
()
.map
(
move
|(
def_id
,
subst
,
span
)|
{
(
ty
::
PredicateAtom
::
ConstEvaluatable
(
def_id
,
subst
)
.to_predicate
(
tcx
),
span
)
})
})
.collect
()
}
/// Returns a list of all type predicates (explicit and implicit) for the definition with
...
...
src/test/ui/const-generics/const_evaluatable_checked/cross_crate_predicate.rs
浏览文件 @
e1f408e6
...
...
@@ -8,6 +8,7 @@ fn user<T>() {
//~^ ERROR constant expression depends
//~| ERROR constant expression depends
//~| ERROR constant expression depends
//~| ERROR constant expression depends
}
fn
main
()
{}
src/test/ui/const-generics/const_evaluatable_checked/cross_crate_predicate.stderr
浏览文件 @
e1f408e6
...
...
@@ -11,6 +11,19 @@ LL | [u8; std::mem::size_of::<T>() - 1]: Sized,
|
= note: this may fail depending on what value the parameter takes
error: constant expression depends on a generic parameter
--> $DIR/cross_crate_predicate.rs:7:13
|
LL | let _ = const_evaluatable_lib::test1::<T>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
::: $DIR/auxiliary/const_evaluatable_lib.rs:6:41
|
LL | [u8; std::mem::size_of::<T>() - 1]: Sized,
| ----- required by this bound in `test1`
|
= note: this may fail depending on what value the parameter takes
error: constant expression depends on a generic parameter
--> $DIR/cross_crate_predicate.rs:7:13
|
...
...
@@ -29,8 +42,13 @@ error: constant expression depends on a generic parameter
|
LL | let _ = const_evaluatable_lib::test1::<T>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
::: $DIR/auxiliary/const_evaluatable_lib.rs:6:41
|
LL | [u8; std::mem::size_of::<T>() - 1]: Sized,
| ----- required by this bound in `test1::{{constant}}#1`
|
= note: this may fail depending on what value the parameter takes
error: aborting due to
3
previous errors
error: aborting due to
4
previous errors
src/test/ui/const-generics/const_evaluatable_checked/from-sig-fail.rs
0 → 100644
浏览文件 @
e1f408e6
#![feature(const_generics,
const_evaluatable_checked)]
#![allow(incomplete_features)]
fn
test
<
const
N
:
usize
>
()
->
[
u8
;
N
-
1
]
{
//~^ ERROR evaluation of constant
todo!
()
}
fn
main
()
{
test
::
<
0
>
();
}
src/test/ui/const-generics/const_evaluatable_checked/from-sig-fail.stderr
0 → 100644
浏览文件 @
e1f408e6
error[E0080]: evaluation of constant value failed
--> $DIR/from-sig-fail.rs:4:35
|
LL | fn test<const N: usize>() -> [u8; N - 1] {
| ^^^^^ attempt to compute `0_usize - 1_usize` which would overflow
error: aborting due to previous error
For more information about this error, try `rustc --explain E0080`.
src/test/ui/const-generics/const_evaluatable_checked/from-sig.rs
0 → 100644
浏览文件 @
e1f408e6
// run-pass
#![feature(const_generics,
const_evaluatable_checked)]
#![allow(incomplete_features)]
struct
Foo
<
const
B
:
bool
>
;
fn
test
<
const
N
:
usize
>
()
->
Foo
<
{
N
>
10
}
>
{
Foo
}
fn
main
()
{
let
_
:
Foo
<
true
>
=
test
::
<
12
>
();
let
_
:
Foo
<
false
>
=
test
::
<
9
>
();
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录