Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
c3a772f5
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,发现更多精彩内容 >>
提交
c3a772f5
编写于
9月 10, 2020
作者:
B
Bastian Kauschke
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
use abstract consts when unifying ConstKind::Unevaluated
上级
d327fa11
变更
8
显示空白变更内容
内联
并排
Showing
8 changed file
with
96 addition
and
10 deletion
+96
-10
compiler/rustc_middle/src/query/mod.rs
compiler/rustc_middle/src/query/mod.rs
+10
-0
compiler/rustc_middle/src/ty/query/keys.rs
compiler/rustc_middle/src/ty/query/keys.rs
+16
-0
compiler/rustc_middle/src/ty/relate.rs
compiler/rustc_middle/src/ty/relate.rs
+14
-1
compiler/rustc_trait_selection/src/traits/const_evaluatable.rs
...ler/rustc_trait_selection/src/traits/const_evaluatable.rs
+21
-1
compiler/rustc_trait_selection/src/traits/fulfill.rs
compiler/rustc_trait_selection/src/traits/fulfill.rs
+19
-0
compiler/rustc_trait_selection/src/traits/mod.rs
compiler/rustc_trait_selection/src/traits/mod.rs
+1
-0
src/test/ui/const-generics/const_evaluatable_checked/simple.min.stderr
...onst-generics/const_evaluatable_checked/simple.min.stderr
+12
-4
src/test/ui/const-generics/const_evaluatable_checked/simple.rs
...est/ui/const-generics/const_evaluatable_checked/simple.rs
+3
-4
未找到文件。
compiler/rustc_middle/src/query/mod.rs
浏览文件 @
c3a772f5
...
...
@@ -263,6 +263,16 @@ fn describe_as_module(def_id: LocalDefId, tcx: TyCtxt<'_>) -> String {
}
}
query
try_unify_abstract_consts
(
key
:
(
(
ty
::
WithOptConstParam
<
DefId
>
,
SubstsRef
<
'tcx
>
),
(
ty
::
WithOptConstParam
<
DefId
>
,
SubstsRef
<
'tcx
>
)
))
->
bool
{
desc
{
|
tcx
|
"trying to unify the generic constants {} and {}"
,
tcx
.def_path_str
(
key
.0.0
.did
),
tcx
.def_path_str
(
key
.1.0
.did
)
}
}
query
mir_drops_elaborated_and_const_checked
(
key
:
ty
::
WithOptConstParam
<
LocalDefId
>
)
->
&
'tcx
Steal
<
mir
::
Body
<
'tcx
>>
{
...
...
compiler/rustc_middle/src/ty/query/keys.rs
浏览文件 @
c3a772f5
...
...
@@ -193,6 +193,22 @@ fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
}
}
impl
<
'tcx
>
Key
for
(
(
ty
::
WithOptConstParam
<
DefId
>
,
SubstsRef
<
'tcx
>
),
(
ty
::
WithOptConstParam
<
DefId
>
,
SubstsRef
<
'tcx
>
),
)
{
type
CacheSelector
=
DefaultCacheSelector
;
fn
query_crate
(
&
self
)
->
CrateNum
{
(
self
.0
)
.0
.did.krate
}
fn
default_span
(
&
self
,
tcx
:
TyCtxt
<
'_
>
)
->
Span
{
(
self
.0
)
.0
.did
.default_span
(
tcx
)
}
}
impl
<
'tcx
>
Key
for
(
LocalDefId
,
DefId
,
SubstsRef
<
'tcx
>
)
{
type
CacheSelector
=
DefaultCacheSelector
;
...
...
compiler/rustc_middle/src/ty/relate.rs
浏览文件 @
c3a772f5
...
...
@@ -576,7 +576,20 @@ pub fn super_relate_consts<R: TypeRelation<'tcx>>(
new_val
.map
(
ty
::
ConstKind
::
Value
)
}
// FIXME(const_generics): this is wrong, as it is a projection
(
ty
::
ConstKind
::
Unevaluated
(
a_def
,
a_substs
,
None
),
ty
::
ConstKind
::
Unevaluated
(
b_def
,
b_substs
,
None
),
)
if
tcx
.features
()
.const_evaluatable_checked
=>
{
if
tcx
.try_unify_abstract_consts
(((
a_def
,
a_substs
),
(
b_def
,
b_substs
)))
{
Ok
(
a
.val
)
}
else
{
Err
(
TypeError
::
ConstMismatch
(
expected_found
(
relation
,
a
,
b
)))
}
}
// While this is slightly incorrect, it shouldn't matter for `min_const_generics`
// and is the better alternative to waiting until `const_evaluatable_checked` can
// be stabilized.
(
ty
::
ConstKind
::
Unevaluated
(
a_def
,
a_substs
,
a_promoted
),
ty
::
ConstKind
::
Unevaluated
(
b_def
,
b_substs
,
b_promoted
),
...
...
compiler/rustc_trait_selection/src/traits/const_evaluatable.rs
浏览文件 @
c3a772f5
...
...
@@ -269,7 +269,27 @@ pub(super) fn mir_abstract_const<'tcx>(
}
}
pub
fn
try_unify
<
'tcx
>
(
tcx
:
TyCtxt
<
'tcx
>
,
a
:
AbstractConst
<
'tcx
>
,
b
:
AbstractConst
<
'tcx
>
)
->
bool
{
pub
(
super
)
fn
try_unify_abstract_consts
<
'tcx
>
(
tcx
:
TyCtxt
<
'tcx
>
,
((
a
,
a_substs
),
(
b
,
b_substs
)):
(
(
ty
::
WithOptConstParam
<
DefId
>
,
SubstsRef
<
'tcx
>
),
(
ty
::
WithOptConstParam
<
DefId
>
,
SubstsRef
<
'tcx
>
),
),
)
->
bool
{
if
let
Some
(
a
)
=
AbstractConst
::
new
(
tcx
,
a
,
a_substs
)
{
if
let
Some
(
b
)
=
AbstractConst
::
new
(
tcx
,
b
,
b_substs
)
{
return
try_unify
(
tcx
,
a
,
b
);
}
}
false
}
pub
(
super
)
fn
try_unify
<
'tcx
>
(
tcx
:
TyCtxt
<
'tcx
>
,
a
:
AbstractConst
<
'tcx
>
,
b
:
AbstractConst
<
'tcx
>
,
)
->
bool
{
match
(
a
.root
(),
b
.root
())
{
(
Node
::
Leaf
(
a_ct
),
Node
::
Leaf
(
b_ct
))
=>
{
let
a_ct
=
a_ct
.subst
(
tcx
,
a
.substs
);
...
...
compiler/rustc_trait_selection/src/traits/fulfill.rs
浏览文件 @
c3a772f5
...
...
@@ -476,6 +476,25 @@ fn process_obligation(
ty
::
PredicateAtom
::
ConstEquate
(
c1
,
c2
)
=>
{
debug!
(
"equating consts: c1={:?} c2={:?}"
,
c1
,
c2
);
if
self
.selcx
.tcx
()
.features
()
.const_evaluatable_checked
{
// FIXME: we probably should only try to unify abstract constants
// if the constants depend on generic parameters.
//
// Let's just see where this breaks :shrug:
if
let
(
ty
::
ConstKind
::
Unevaluated
(
a_def
,
a_substs
,
None
),
ty
::
ConstKind
::
Unevaluated
(
b_def
,
b_substs
,
None
),
)
=
(
c1
.val
,
c2
.val
)
{
if
self
.selcx
.tcx
()
.try_unify_abstract_consts
(((
a_def
,
a_substs
),
(
b_def
,
b_substs
)))
{
return
ProcessResult
::
Changed
(
vec!
[]);
}
}
}
let
stalled_on
=
&
mut
pending_obligation
.stalled_on
;
...
...
compiler/rustc_trait_selection/src/traits/mod.rs
浏览文件 @
c3a772f5
...
...
@@ -566,6 +566,7 @@ pub fn provide(providers: &mut ty::query::Providers) {
ty
::
WithOptConstParam
{
did
,
const_param_did
:
Some
(
param_did
)
},
)
},
try_unify_abstract_consts
:
const_evaluatable
::
try_unify_abstract_consts
,
..*
providers
};
}
src/test/ui/const-generics/const_evaluatable_checked/simple.min.stderr
浏览文件 @
c3a772f5
error: generic parameters must not be used inside of non trivial constant values
--> $DIR/simple.rs:8:
3
3
--> $DIR/simple.rs:8:
5
3
|
LL |
type Arr<const N: usize> = [u8; N - 1];
LL |
fn test<const N: usize>() -> [u8; N - 1] where [u8; N - 1]: Default {
| ^ non-trivial anonymous constants must not depend on the parameter `N`
|
= help: it is currently only allowed to use either `N` or `{ N }` as generic constants
error: aborting due to previous error
error: generic parameters must not be used inside of non trivial constant values
--> $DIR/simple.rs:8:35
|
LL | fn test<const N: usize>() -> [u8; N - 1] where [u8; N - 1]: Default {
| ^ non-trivial anonymous constants must not depend on the parameter `N`
|
= help: it is currently only allowed to use either `N` or `{ N }` as generic constants
error: aborting due to 2 previous errors
src/test/ui/const-generics/const_evaluatable_checked/simple.rs
浏览文件 @
c3a772f5
...
...
@@ -5,10 +5,9 @@
#![feature(const_evaluatable_checked)]
#![allow(incomplete_features)]
type
Arr
<
const
N
:
usize
>
=
[
u8
;
N
-
1
];
//[min]~^ ERROR generic parameters must not be used inside of non trivial constant values
fn
test
<
const
N
:
usize
>
()
->
Arr
<
N
>
where
Arr
<
N
>
:
Default
{
fn
test
<
const
N
:
usize
>
()
->
[
u8
;
N
-
1
]
where
[
u8
;
N
-
1
]:
Default
{
//[min]~^ ERROR generic parameters
//[min]~| ERROR generic parameters
Default
::
default
()
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录