Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
42150fb8
R
Rust
项目概览
int
/
Rust
11 个月 前同步成功
通知
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,发现更多精彩内容 >>
提交
42150fb8
编写于
1月 24, 2021
作者:
B
Bastian Kauschke
提交者:
lcnr
3月 27, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
combine: stop eagerly evaluating consts
上级
aef11409
变更
14
隐藏空白更改
内联
并排
Showing
14 changed file
with
106 addition
and
27 deletion
+106
-27
compiler/rustc_infer/src/infer/combine.rs
compiler/rustc_infer/src/infer/combine.rs
+20
-8
compiler/rustc_middle/src/ty/relate.rs
compiler/rustc_middle/src/ty/relate.rs
+1
-10
src/test/ui/const-generics/issues/issue-69654-run-pass.rs
src/test/ui/const-generics/issues/issue-69654-run-pass.rs
+1
-1
src/test/ui/const-generics/issues/issue-69654-run-pass.stderr
...test/ui/const-generics/issues/issue-69654-run-pass.stderr
+15
-0
src/test/ui/const-generics/issues/issue-69654.rs
src/test/ui/const-generics/issues/issue-69654.rs
+1
-0
src/test/ui/const-generics/issues/issue-69654.stderr
src/test/ui/const-generics/issues/issue-69654.stderr
+15
-2
src/test/ui/const-generics/occurs-check/unused-substs-1.rs
src/test/ui/const-generics/occurs-check/unused-substs-1.rs
+1
-2
src/test/ui/const-generics/occurs-check/unused-substs-1.stderr
...est/ui/const-generics/occurs-check/unused-substs-1.stderr
+17
-0
src/test/ui/const-generics/occurs-check/unused-substs-2.rs
src/test/ui/const-generics/occurs-check/unused-substs-2.rs
+2
-1
src/test/ui/const-generics/occurs-check/unused-substs-2.stderr
...est/ui/const-generics/occurs-check/unused-substs-2.stderr
+9
-0
src/test/ui/const-generics/occurs-check/unused-substs-3.rs
src/test/ui/const-generics/occurs-check/unused-substs-3.rs
+2
-1
src/test/ui/const-generics/occurs-check/unused-substs-3.stderr
...est/ui/const-generics/occurs-check/unused-substs-3.stderr
+12
-0
src/test/ui/const-generics/occurs-check/unused-substs-4.rs
src/test/ui/const-generics/occurs-check/unused-substs-4.rs
+1
-2
src/test/ui/const-generics/occurs-check/unused-substs-4.stderr
...est/ui/const-generics/occurs-check/unused-substs-4.stderr
+9
-0
未找到文件。
compiler/rustc_infer/src/infer/combine.rs
浏览文件 @
42150fb8
...
...
@@ -543,10 +543,6 @@ fn a_is_expected(&self) -> bool {
true
}
fn
visit_ct_substs
(
&
self
)
->
bool
{
true
}
fn
binders
<
T
>
(
&
mut
self
,
a
:
ty
::
Binder
<
T
>
,
...
...
@@ -737,6 +733,16 @@ fn consts(
}
}
}
ty
::
ConstKind
::
Unevaluated
(
ty
::
Unevaluated
{
def
,
substs
,
promoted
})
if
self
.tcx
()
.lazy_normalization
()
=>
{
assert_eq!
(
promoted
,
None
);
let
substs
=
self
.relate_with_variance
(
ty
::
Variance
::
Invariant
,
substs
,
substs
)
?
;
Ok
(
self
.tcx
()
.mk_const
(
ty
::
Const
{
ty
:
c
.ty
,
val
:
ty
::
ConstKind
::
Unevaluated
(
ty
::
Unevaluated
{
def
,
substs
,
promoted
}),
}))
}
_
=>
relate
::
super_relate_consts
(
self
,
c
,
c
),
}
}
...
...
@@ -822,10 +828,6 @@ fn a_is_expected(&self) -> bool {
true
}
fn
visit_ct_substs
(
&
self
)
->
bool
{
true
}
fn
relate_with_variance
<
T
:
Relate
<
'tcx
>>
(
&
mut
self
,
_
variance
:
ty
::
Variance
,
...
...
@@ -959,6 +961,16 @@ fn consts(
}
}
}
ty
::
ConstKind
::
Unevaluated
(
ty
::
Unevaluated
{
def
,
substs
,
promoted
})
if
self
.tcx
()
.lazy_normalization
()
=>
{
assert_eq!
(
promoted
,
None
);
let
substs
=
self
.relate_with_variance
(
ty
::
Variance
::
Invariant
,
substs
,
substs
)
?
;
Ok
(
self
.tcx
()
.mk_const
(
ty
::
Const
{
ty
:
c
.ty
,
val
:
ty
::
ConstKind
::
Unevaluated
(
ty
::
Unevaluated
{
def
,
substs
,
promoted
}),
}))
}
_
=>
relate
::
super_relate_consts
(
self
,
c
,
c
),
}
}
...
...
compiler/rustc_middle/src/ty/relate.rs
浏览文件 @
42150fb8
...
...
@@ -33,15 +33,6 @@ pub trait TypeRelation<'tcx>: Sized {
/// relation. Just affects error messages.
fn
a_is_expected
(
&
self
)
->
bool
;
/// Whether we should look into the substs of unevaluated constants
/// even if `feature(const_evaluatable_checked)` is active.
///
/// This is needed in `combine` to prevent accidentially creating
/// infinite types as we abuse `TypeRelation` to walk a type there.
fn
visit_ct_substs
(
&
self
)
->
bool
{
false
}
fn
with_cause
<
F
,
R
>
(
&
mut
self
,
_
cause
:
Cause
,
f
:
F
)
->
R
where
F
:
FnOnce
(
&
mut
Self
)
->
R
,
...
...
@@ -532,7 +523,7 @@ pub fn super_relate_consts<R: TypeRelation<'tcx>>(
}
(
ty
::
ConstKind
::
Unevaluated
(
au
),
ty
::
ConstKind
::
Unevaluated
(
bu
))
if
tcx
.features
()
.const_evaluatable_checked
&&
!
relation
.visit_ct_substs
()
=>
if
tcx
.features
()
.const_evaluatable_checked
=>
{
tcx
.try_unify_abstract_consts
(((
au
.def
,
au
.substs
),
(
bu
.def
,
bu
.substs
)))
}
...
...
src/test/ui/const-generics/issues/issue-69654-run-pass.rs
浏览文件 @
42150fb8
// run-pass
#![feature(const_generics)]
#![allow(incomplete_features,
unused_braces)]
...
...
@@ -15,4 +14,5 @@ fn foo() {}
fn
main
()
{
Foo
::
foo
();
//~^ ERROR no function or associated item
}
src/test/ui/const-generics/issues/issue-69654-run-pass.stderr
0 → 100644
浏览文件 @
42150fb8
error[E0599]: no function or associated item named `foo` found for struct `Foo<{_: usize}>` in the current scope
--> $DIR/issue-69654-run-pass.rs:16:10
|
LL | struct Foo<const N: usize> {}
| -------------------------- function or associated item `foo` not found for this
...
LL | Foo::foo();
| ^^^ function or associated item not found in `Foo<{_: usize}>`
|
= note: the method `foo` exists but the following trait bounds were not satisfied:
`[u8; _]: Bar<[(); _]>`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0599`.
src/test/ui/const-generics/issues/issue-69654.rs
浏览文件 @
42150fb8
...
...
@@ -15,4 +15,5 @@ fn foo() {}
fn
main
()
{
Foo
::
foo
();
//~^ ERROR no function or associated item
}
src/test/ui/const-generics/issues/issue-69654.stderr
浏览文件 @
42150fb8
...
...
@@ -4,6 +4,19 @@ error[E0423]: expected value, found type parameter `T`
LL | impl<T> Bar<T> for [u8; T] {}
| ^ not a value
error: aborting due to previous error
error[E0599]: no function or associated item named `foo` found for struct `Foo<{_: usize}>` in the current scope
--> $DIR/issue-69654.rs:17:10
|
LL | struct Foo<const N: usize> {}
| -------------------------- function or associated item `foo` not found for this
...
LL | Foo::foo();
| ^^^ function or associated item not found in `Foo<{_: usize}>`
|
= note: the method `foo` exists but the following trait bounds were not satisfied:
`[u8; _]: Bar<[(); _]>`
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0423`.
Some errors have detailed explanations: E0423, E0599.
For more information about an error, try `rustc --explain E0423`.
src/test/ui/const-generics/occurs-check/unused-substs-1.rs
浏览文件 @
42150fb8
// build-pass
#![feature(const_generics)]
#![allow(incomplete_features)]
...
...
@@ -10,5 +9,5 @@ struct A<const N: usize>
A
<
N
>
:
Bar
<
N
>
;
fn
main
()
{
let
_
=
A
;
let
_
=
A
;
//~ERROR the trait bound
}
src/test/ui/const-generics/occurs-check/unused-substs-1.stderr
0 → 100644
浏览文件 @
42150fb8
error[E0277]: the trait bound `A<{_: usize}>: Bar<{_: usize}>` is not satisfied
--> $DIR/unused-substs-1.rs:12:13
|
LL | / struct A<const N: usize>
LL | | where
LL | | A<N>: Bar<N>;
| |_________________- required by `A`
...
LL | let _ = A;
| ^ the trait `Bar<{_: usize}>` is not implemented for `A<{_: usize}>`
|
= help: the following implementations were found:
<A<7_usize> as Bar<N>>
error: aborting due to previous error
For more information about this error, try `rustc --explain E0277`.
src/test/ui/const-generics/occurs-check/unused-substs-2.rs
浏览文件 @
42150fb8
// check-pass
#![feature(const_generics)]
#![allow(incomplete_features)]
...
...
@@ -24,4 +23,6 @@ fn main() {
// `t` is `ty::Infer(TyVar(_#1t))`
// `foo` contains `ty::Infer(TyVar(_#1t))` in its substs
t
=
foo
;
//~^ ERROR mismatched types
//~| NOTE cyclic type
}
src/test/ui/const-generics/occurs-check/unused-substs-2.stderr
0 → 100644
浏览文件 @
42150fb8
error[E0308]: mismatched types
--> $DIR/unused-substs-2.rs:25:9
|
LL | t = foo;
| ^^^ cyclic type of infinite size
error: aborting due to previous error
For more information about this error, try `rustc --explain E0308`.
src/test/ui/const-generics/occurs-check/unused-substs-3.rs
浏览文件 @
42150fb8
// check-pass
#![feature(const_generics)]
#![allow(incomplete_features)]
...
...
@@ -15,4 +14,6 @@ fn main() {
// `t` is `ty::Infer(TyVar(_#1t))`
// `foo` contains `ty::Infer(TyVar(_#1t))` in its substs
t
=
foo
;
//~^ ERROR mismatched types
//~| NOTE cyclic type
}
src/test/ui/const-generics/occurs-check/unused-substs-3.stderr
0 → 100644
浏览文件 @
42150fb8
error[E0308]: mismatched types
--> $DIR/unused-substs-3.rs:16:9
|
LL | t = foo;
| ^^^
| |
| cyclic type of infinite size
| help: try using a conversion method: `foo.to_vec()`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0308`.
src/test/ui/const-generics/occurs-check/unused-substs-4.rs
浏览文件 @
42150fb8
// build-pass
#![feature(const_generics)]
#![allow(incomplete_features)]
...
...
@@ -8,5 +7,5 @@
fn
main
()
{
let
mut
arr
=
Default
::
default
();
arr
=
bind
(
arr
);
arr
=
bind
(
arr
);
//~ ERROR mismatched type
}
src/test/ui/const-generics/occurs-check/unused-substs-4.stderr
0 → 100644
浏览文件 @
42150fb8
error[E0308]: mismatched types
--> $DIR/unused-substs-4.rs:10:11
|
LL | arr = bind(arr);
| ^^^^^^^^^ encountered a self-referencing constant
error: aborting due to previous error
For more information about this error, try `rustc --explain E0308`.
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录