Skip to content

Commit

Permalink
Update tests for refinements to ~const bounds validation.
Browse files Browse the repository at this point in the history
  • Loading branch information
Raekye committed Sep 27, 2023
1 parent d6a6f74 commit 38698c7
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ struct Foo<const N: usize>;

impl<const N: usize> Foo<N> {
fn add<A: ~const Add42>(self) -> Foo<{ A::add(N) }> {
//~^ ERROR mismatched types
//~^ ERROR `~const` is not allowed here
//~| ERROR mismatched types
Foo
}
}
Expand All @@ -30,7 +31,7 @@ fn bar<A: ~const Add42, const N: usize>(_: Foo<N>) -> Foo<{ A::add(N) }> {
}

fn main() {
let foo = Foo::<0>;
let foo = bar::<(), _>(foo);
let _foo = bar::<(), _>(foo);
let foo = Foo::<0>;
let foo = bar::<(), _>(foo);
let _foo = bar::<(), _>(foo);
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
error: `~const` is not allowed here
--> $DIR/tilde-const-and-const-params.rs:26:11
--> $DIR/tilde-const-and-const-params.rs:9:15
|
LL | fn add<A: ~const Add42>(self) -> Foo<{ A::add(N) }> {
| ^^^^^^^^^^^^
|
note: this function is not `const`, so it cannot have `~const` trait bounds
--> $DIR/tilde-const-and-const-params.rs:9:8
|
LL | fn add<A: ~const Add42>(self) -> Foo<{ A::add(N) }> {
| ^^^

error: `~const` is not allowed here
--> $DIR/tilde-const-and-const-params.rs:27:11
|
LL | fn bar<A: ~const Add42, const N: usize>(_: Foo<N>) -> Foo<{ A::add(N) }> {
| ^^^^^^^^^^^^
|
note: this function is not `const`, so it cannot have `~const` trait bounds
--> $DIR/tilde-const-and-const-params.rs:26:4
--> $DIR/tilde-const-and-const-params.rs:27:4
|
LL | fn bar<A: ~const Add42, const N: usize>(_: Foo<N>) -> Foo<{ A::add(N) }> {
| ^^^

error[E0308]: mismatched types
--> $DIR/tilde-const-and-const-params.rs:26:61
--> $DIR/tilde-const-and-const-params.rs:27:61
|
LL | fn bar<A: ~const Add42, const N: usize>(_: Foo<N>) -> Foo<{ A::add(N) }> {
| ^^^^^^^^^ expected `false`, found `true`
Expand All @@ -28,6 +40,6 @@ LL | fn add<A: ~const Add42>(self) -> Foo<{ A::add(N) }> {
= note: expected constant `false`
found constant `true`

error: aborting due to 3 previous errors
error: aborting due to 4 previous errors

For more information about this error, try `rustc --explain E0308`.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ trait Bar {}

trait Foo {
fn a();
fn b() where Self: ~const Bar;
fn b()
where
Self: ~const Bar;
//~^ ERROR `~const` is not allowed here
fn c<T: ~const Bar>();
//~^ ERROR `~const` is not allowed here
}

fn test1<T: Foo>() {
Expand Down
41 changes: 34 additions & 7 deletions tests/ui/rfcs/rfc-2632-const-trait-impl/trait-where-clause.stderr
Original file line number Diff line number Diff line change
@@ -1,27 +1,54 @@
error: `~const` is not allowed here
--> $DIR/trait-where-clause.rs:10:15
|
LL | Self: ~const Bar;
| ^^^^^^^^^^
|
note: this function is not `const`, so it cannot have `~const` trait bounds
--> $DIR/trait-where-clause.rs:8:8
|
LL | fn b()
| ^

error: `~const` is not allowed here
--> $DIR/trait-where-clause.rs:12:13
|
LL | fn c<T: ~const Bar>();
| ^^^^^^^^^^
|
note: this function is not `const`, so it cannot have `~const` trait bounds
--> $DIR/trait-where-clause.rs:12:8
|
LL | fn c<T: ~const Bar>();
| ^

error[E0277]: the trait bound `T: Bar` is not satisfied
--> $DIR/trait-where-clause.rs:14:5
--> $DIR/trait-where-clause.rs:18:5
|
LL | T::b();
| ^ the trait `Bar` is not implemented for `T`
|
note: required by a bound in `Foo::b`
--> $DIR/trait-where-clause.rs:8:24
--> $DIR/trait-where-clause.rs:10:15
|
LL | fn b() where Self: ~const Bar;
| ^^^^^^^^^^ required by this bound in `Foo::b`
LL | fn b()
| - required by a bound in this associated function
LL | where
LL | Self: ~const Bar;
| ^^^^^^^^^^ required by this bound in `Foo::b`
help: consider further restricting this bound
|
LL | fn test1<T: Foo + Bar>() {
| +++++

error[E0277]: the trait bound `T: Bar` is not satisfied
--> $DIR/trait-where-clause.rs:16:12
--> $DIR/trait-where-clause.rs:20:12
|
LL | T::c::<T>();
| ^ the trait `Bar` is not implemented for `T`
|
note: required by a bound in `Foo::c`
--> $DIR/trait-where-clause.rs:9:13
--> $DIR/trait-where-clause.rs:12:13
|
LL | fn c<T: ~const Bar>();
| ^^^^^^^^^^ required by this bound in `Foo::c`
Expand All @@ -30,6 +57,6 @@ help: consider further restricting this bound
LL | fn test1<T: Foo + Bar>() {
| +++++

error: aborting due to 2 previous errors
error: aborting due to 4 previous errors

For more information about this error, try `rustc --explain E0277`.

0 comments on commit 38698c7

Please sign in to comment.