Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
ab37e496
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,发现更多精彩内容 >>
未验证
提交
ab37e496
编写于
8月 31, 2021
作者:
M
Mara Bos
提交者:
GitHub
8月 31, 2021
浏览文件
操作
浏览文件
下载
差异文件
Rollup merge of #88418 - fee1-dead:trait-assoc-tilde-const, r=oli-obk
Allow `~const` bounds on trait assoc functions r? `@oli-obk`
上级
4d089088
ee02c8e2
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
180 addition
and
8 deletion
+180
-8
compiler/rustc_ast_passes/src/ast_validation.rs
compiler/rustc_ast_passes/src/ast_validation.rs
+2
-2
src/test/ui/rfc-2632-const-trait-impl/tilde-const-invalid-places.stderr
...c-2632-const-trait-impl/tilde-const-invalid-places.stderr
+6
-6
src/test/ui/rfc-2632-const-trait-impl/trait-where-clause-run.rs
...st/ui/rfc-2632-const-trait-impl/trait-where-clause-run.rs
+41
-0
src/test/ui/rfc-2632-const-trait-impl/trait-where-clause-self-referential.rs
...2-const-trait-impl/trait-where-clause-self-referential.rs
+24
-0
src/test/ui/rfc-2632-const-trait-impl/trait-where-clause.rs
src/test/ui/rfc-2632-const-trait-impl/trait-where-clause.rs
+40
-0
src/test/ui/rfc-2632-const-trait-impl/trait-where-clause.stderr
...st/ui/rfc-2632-const-trait-impl/trait-where-clause.stderr
+67
-0
未找到文件。
compiler/rustc_ast_passes/src/ast_validation.rs
浏览文件 @
ab37e496
...
...
@@ -1442,7 +1442,7 @@ fn visit_param_bound(&mut self, bound: &'a GenericBound) {
if
!
self
.is_tilde_const_allowed
{
self
.err_handler
()
.struct_span_err
(
bound
.span
(),
"`~const` is not allowed here"
)
.note
(
"only allowed on bounds on traits' associated types, const fns, const impls and its associated functions"
)
.note
(
"only allowed on bounds on traits' associated types
and functions
, const fns, const impls and its associated functions"
)
.emit
();
}
}
...
...
@@ -1616,7 +1616,7 @@ fn visit_assoc_item(&mut self, item: &'a AssocItem, ctxt: AssocCtxt) {
walk_list!
(
self
,
visit_ty
,
ty
);
}
AssocItemKind
::
Fn
(
box
FnKind
(
_
,
ref
sig
,
ref
generics
,
ref
body
))
if
self
.in_const_trait_impl
=>
if
self
.in_const_trait_impl
||
ctxt
==
AssocCtxt
::
Trait
=>
{
self
.visit_vis
(
&
item
.vis
);
self
.visit_ident
(
item
.ident
);
...
...
src/test/ui/rfc-2632-const-trait-impl/tilde-const-invalid-places.stderr
浏览文件 @
ab37e496
...
...
@@ -4,7 +4,7 @@ error: `~const` is not allowed here
LL | fn rpit() -> impl ~const T { S }
| ^^^^^^^^
|
= note: only allowed on bounds on traits' associated types, const fns, const impls and its associated functions
= note: only allowed on bounds on traits' associated types
and functions
, const fns, const impls and its associated functions
error: `~const` is not allowed here
--> $DIR/tilde-const-invalid-places.rs:11:17
...
...
@@ -12,7 +12,7 @@ error: `~const` is not allowed here
LL | fn apit(_: impl ~const T) {}
| ^^^^^^^^
|
= note: only allowed on bounds on traits' associated types, const fns, const impls and its associated functions
= note: only allowed on bounds on traits' associated types
and functions
, const fns, const impls and its associated functions
error: `~const` is not allowed here
--> $DIR/tilde-const-invalid-places.rs:14:50
...
...
@@ -20,7 +20,7 @@ error: `~const` is not allowed here
LL | fn rpit_assoc_bound() -> impl IntoIterator<Item: ~const T> { Some(S) }
| ^^^^^^^^
|
= note: only allowed on bounds on traits' associated types, const fns, const impls and its associated functions
= note: only allowed on bounds on traits' associated types
and functions
, const fns, const impls and its associated functions
error: `~const` is not allowed here
--> $DIR/tilde-const-invalid-places.rs:17:48
...
...
@@ -28,7 +28,7 @@ error: `~const` is not allowed here
LL | fn apit_assoc_bound(_: impl IntoIterator<Item: ~const T>) {}
| ^^^^^^^^
|
= note: only allowed on bounds on traits' associated types, const fns, const impls and its associated functions
= note: only allowed on bounds on traits' associated types
and functions
, const fns, const impls and its associated functions
error: `~const` is not allowed here
--> $DIR/tilde-const-invalid-places.rs:20:15
...
...
@@ -36,7 +36,7 @@ error: `~const` is not allowed here
LL | fn generic<P: ~const T>() {}
| ^^^^^^^^
|
= note: only allowed on bounds on traits' associated types, const fns, const impls and its associated functions
= note: only allowed on bounds on traits' associated types
and functions
, const fns, const impls and its associated functions
error: `~const` is not allowed here
--> $DIR/tilde-const-invalid-places.rs:23:31
...
...
@@ -44,7 +44,7 @@ error: `~const` is not allowed here
LL | fn where_clause<P>() where P: ~const T {}
| ^^^^^^^^
|
= note: only allowed on bounds on traits' associated types, const fns, const impls and its associated functions
= note: only allowed on bounds on traits' associated types
and functions
, const fns, const impls and its associated functions
error: `~const` and `?` are mutually exclusive
--> $DIR/tilde-const-invalid-places.rs:26:25
...
...
src/test/ui/rfc-2632-const-trait-impl/trait-where-clause-run.rs
0 → 100644
浏览文件 @
ab37e496
// run-pass
#![feature(const_trait_impl)]
#![feature(const_fn_trait_bound)]
trait
Bar
{
fn
bar
()
->
u8
;
}
trait
Foo
{
#[default_method_body_is_const]
fn
foo
()
->
u8
where
Self
:
~
const
Bar
{
<
Self
as
Bar
>
::
bar
()
*
6
}
}
struct
NonConst
;
struct
Const
;
impl
Bar
for
NonConst
{
fn
bar
()
->
u8
{
3
}
}
impl
Foo
for
NonConst
{}
impl
const
Bar
for
Const
{
fn
bar
()
->
u8
{
4
}
}
impl
const
Foo
for
Const
{}
fn
main
()
{
const
ANS1
:
u8
=
Const
::
foo
();
let
ans2
=
NonConst
::
foo
();
assert_eq!
(
ANS1
+
ans2
,
42
);
}
src/test/ui/rfc-2632-const-trait-impl/trait-where-clause-self-referential.rs
0 → 100644
浏览文件 @
ab37e496
// check-pass
#![feature(const_trait_impl)]
#![feature(const_fn_trait_bound)]
trait
Foo
{
fn
bar
()
where
Self
:
~
const
Foo
;
}
struct
S
;
impl
Foo
for
S
{
fn
bar
()
{}
}
fn
baz
<
T
:
Foo
>
()
{
T
::
bar
();
}
const
fn
qux
<
T
:
~
const
Foo
>
()
{
T
::
bar
();
}
fn
main
()
{}
src/test/ui/rfc-2632-const-trait-impl/trait-where-clause.rs
0 → 100644
浏览文件 @
ab37e496
#![feature(const_fn_trait_bound)]
#![feature(const_trait_impl)]
trait
Bar
{}
trait
Foo
{
fn
a
();
fn
b
()
where
Self
:
~
const
Bar
;
fn
c
<
T
:
~
const
Bar
>
();
}
const
fn
test1
<
T
:
~
const
Foo
+
Bar
>
()
{
T
::
a
();
T
::
b
();
//~^ ERROR the trait bound
T
::
c
::
<
T
>
();
//~^ ERROR the trait bound
}
const
fn
test2
<
T
:
~
const
Foo
+
~
const
Bar
>
()
{
T
::
a
();
T
::
b
();
T
::
c
::
<
T
>
();
}
fn
test3
<
T
:
Foo
>
()
{
T
::
a
();
T
::
b
();
//~^ ERROR the trait bound
T
::
c
::
<
T
>
();
//~^ ERROR the trait bound
}
fn
test4
<
T
:
Foo
+
Bar
>
()
{
T
::
a
();
T
::
b
();
T
::
c
::
<
T
>
();
}
fn
main
()
{}
src/test/ui/rfc-2632-const-trait-impl/trait-where-clause.stderr
0 → 100644
浏览文件 @
ab37e496
error[E0277]: the trait bound `T: Bar` is not satisfied
--> $DIR/trait-where-clause.rs:14:5
|
LL | T::b();
| ^^^^ the trait `Bar` is not implemented for `T`
|
note: required by `Foo::b`
--> $DIR/trait-where-clause.rs:8:5
|
LL | fn b() where Self: ~const Bar;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: consider further restricting this bound
|
LL | const fn test1<T: ~const Foo + Bar + Bar>() {
| +++++
error[E0277]: the trait bound `T: Bar` is not satisfied
--> $DIR/trait-where-clause.rs:16:5
|
LL | T::c::<T>();
| ^^^^^^^^^ the trait `Bar` is not implemented for `T`
|
note: required by `Foo::c`
--> $DIR/trait-where-clause.rs:9:5
|
LL | fn c<T: ~const Bar>();
| ^^^^^^^^^^^^^^^^^^^^^^
help: consider further restricting this bound
|
LL | const fn test1<T: ~const Foo + Bar + Bar>() {
| +++++
error[E0277]: the trait bound `T: Bar` is not satisfied
--> $DIR/trait-where-clause.rs:28:5
|
LL | T::b();
| ^^^^ the trait `Bar` is not implemented for `T`
|
note: required by `Foo::b`
--> $DIR/trait-where-clause.rs:8:5
|
LL | fn b() where Self: ~const Bar;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: consider further restricting this bound
|
LL | fn test3<T: Foo + Bar>() {
| +++++
error[E0277]: the trait bound `T: Bar` is not satisfied
--> $DIR/trait-where-clause.rs:30:5
|
LL | T::c::<T>();
| ^^^^^^^^^ the trait `Bar` is not implemented for `T`
|
note: required by `Foo::c`
--> $DIR/trait-where-clause.rs:9:5
|
LL | fn c<T: ~const Bar>();
| ^^^^^^^^^^^^^^^^^^^^^^
help: consider further restricting this bound
|
LL | fn test3<T: Foo + Bar>() {
| +++++
error: aborting due to 4 previous errors
For more information about this error, try `rustc --explain E0277`.
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录