Allow ~const
bounds on trait assoc functions
This commit is contained in:
parent
ac50a53359
commit
523490e94a
4 changed files with 76 additions and 8 deletions
|
@ -1442,7 +1442,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
|
||||||
if !self.is_tilde_const_allowed {
|
if !self.is_tilde_const_allowed {
|
||||||
self.err_handler()
|
self.err_handler()
|
||||||
.struct_span_err(bound.span(), "`~const` is not allowed here")
|
.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();
|
.emit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1616,7 +1616,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
|
||||||
walk_list!(self, visit_ty, ty);
|
walk_list!(self, visit_ty, ty);
|
||||||
}
|
}
|
||||||
AssocItemKind::Fn(box FnKind(_, ref sig, ref generics, ref body))
|
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_vis(&item.vis);
|
||||||
self.visit_ident(item.ident);
|
self.visit_ident(item.ident);
|
||||||
|
|
|
@ -4,7 +4,7 @@ error: `~const` is not allowed here
|
||||||
LL | fn rpit() -> impl ~const T { S }
|
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
|
error: `~const` is not allowed here
|
||||||
--> $DIR/tilde-const-invalid-places.rs:11:17
|
--> $DIR/tilde-const-invalid-places.rs:11:17
|
||||||
|
@ -12,7 +12,7 @@ error: `~const` is not allowed here
|
||||||
LL | fn apit(_: impl ~const T) {}
|
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
|
error: `~const` is not allowed here
|
||||||
--> $DIR/tilde-const-invalid-places.rs:14:50
|
--> $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) }
|
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
|
error: `~const` is not allowed here
|
||||||
--> $DIR/tilde-const-invalid-places.rs:17:48
|
--> $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>) {}
|
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
|
error: `~const` is not allowed here
|
||||||
--> $DIR/tilde-const-invalid-places.rs:20:15
|
--> $DIR/tilde-const-invalid-places.rs:20:15
|
||||||
|
@ -36,7 +36,7 @@ error: `~const` is not allowed here
|
||||||
LL | fn generic<P: ~const T>() {}
|
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
|
error: `~const` is not allowed here
|
||||||
--> $DIR/tilde-const-invalid-places.rs:23:31
|
--> $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 {}
|
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
|
error: `~const` and `?` are mutually exclusive
|
||||||
--> $DIR/tilde-const-invalid-places.rs:26:25
|
--> $DIR/tilde-const-invalid-places.rs:26:25
|
||||||
|
|
33
src/test/ui/rfc-2632-const-trait-impl/trait-where-clause.rs
Normal file
33
src/test/ui/rfc-2632-const-trait-impl/trait-where-clause.rs
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
#![feature(const_fn_trait_bound)]
|
||||||
|
#![feature(const_trait_impl)]
|
||||||
|
|
||||||
|
trait Bar {}
|
||||||
|
|
||||||
|
trait Foo {
|
||||||
|
fn a();
|
||||||
|
fn b() where Self: ~const Bar;
|
||||||
|
}
|
||||||
|
|
||||||
|
const fn test1<T: ~const Foo + Bar>() {
|
||||||
|
T::a();
|
||||||
|
T::b();
|
||||||
|
//~^ ERROR the trait bound
|
||||||
|
}
|
||||||
|
|
||||||
|
const fn test2<T: ~const Foo + ~const Bar>() {
|
||||||
|
T::a();
|
||||||
|
T::b();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test3<T: Foo>() {
|
||||||
|
T::a();
|
||||||
|
T::b();
|
||||||
|
//~^ ERROR the trait bound
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test4<T: Foo + Bar>() {
|
||||||
|
T::a();
|
||||||
|
T::b();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
|
@ -0,0 +1,35 @@
|
||||||
|
error[E0277]: the trait bound `T: Bar` is not satisfied
|
||||||
|
--> $DIR/trait-where-clause.rs:13: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:24: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: aborting due to 2 previous errors
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0277`.
|
Loading…
Add table
Add a link
Reference in a new issue