-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
177 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Regression test for issue #108271. | ||
// Detect and reject generic params in the type of assoc consts used in an equality bound. | ||
#![feature(associated_const_equality)] | ||
|
||
trait Trait<'a, T, const N: usize> { | ||
const K: &'a [T; N]; | ||
} | ||
|
||
fn take0<'r>(_: impl Trait<'r, (), 0, K = { &[] }>) {} | ||
//~^ ERROR the type of the associated constant `K` must not depend on generic parameters | ||
//~| NOTE its type must not depend on the lifetime parameter `'r` | ||
//~| NOTE the lifetime parameter `'r` is defined here | ||
fn take1<A>(_: impl Trait<'static, A, 0, K = { &[] }>) {} | ||
//~^ ERROR the type of the associated constant `K` must not depend on generic parameters | ||
//~| NOTE its type must not depend on the type parameter `A` | ||
//~| NOTE the type parameter `A` is defined here | ||
fn take2<const Q: usize>(_: impl Trait<'static, (), Q, K = { [] }>) {} | ||
//~^ ERROR the type of the associated constant `K` must not depend on generic parameters | ||
//~| NOTE its type must not depend on the const parameter `Q` | ||
//~| NOTE the const parameter `Q` is defined here | ||
|
||
trait Project { | ||
const S: Self; | ||
} | ||
|
||
// FIXME(fmease): Clean this up, treat synthetic type parameters differently in diags. | ||
|
||
fn take3(_: impl Project<S = {}>) {} | ||
//~^ ERROR the type of the associated constant `S` must not depend on generic parameters | ||
//~| NOTE its type must not depend on the type parameter `impl Project<S = const {}>` | ||
//~| NOTE the type parameter `impl Project<S = const {}>` is defined here | ||
|
||
fn take4<P: Project<S = {}>>(_: P) {} | ||
//~^ ERROR the type of the associated constant `S` must not depend on generic parameters | ||
//~| NOTE its type must not depend on the type parameter `P` | ||
//~| NOTE the type parameter `P` is defined here | ||
|
||
fn main() {} |
43 changes: 43 additions & 0 deletions
43
tests/ui/associated-consts/assoc-const-eq-param-in-ty.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
error: the type of the associated constant `K` must not depend on generic parameters | ||
--> $DIR/assoc-const-eq-param-in-ty.rs:9:39 | ||
| | ||
LL | fn take0<'r>(_: impl Trait<'r, (), 0, K = { &[] }>) {} | ||
| -- ^ its type must not depend on the lifetime parameter `'r` | ||
| | | ||
| the lifetime parameter `'r` is defined here | ||
|
||
error: the type of the associated constant `K` must not depend on generic parameters | ||
--> $DIR/assoc-const-eq-param-in-ty.rs:13:42 | ||
| | ||
LL | fn take1<A>(_: impl Trait<'static, A, 0, K = { &[] }>) {} | ||
| - ^ its type must not depend on the type parameter `A` | ||
| | | ||
| the type parameter `A` is defined here | ||
|
||
error: the type of the associated constant `K` must not depend on generic parameters | ||
--> $DIR/assoc-const-eq-param-in-ty.rs:17:56 | ||
| | ||
LL | fn take2<const Q: usize>(_: impl Trait<'static, (), Q, K = { [] }>) {} | ||
| - ^ its type must not depend on the const parameter `Q` | ||
| | | ||
| the const parameter `Q` is defined here | ||
|
||
error: the type of the associated constant `S` must not depend on generic parameters | ||
--> $DIR/assoc-const-eq-param-in-ty.rs:28:26 | ||
| | ||
LL | fn take3(_: impl Project<S = {}>) {} | ||
| -------------^------ | ||
| | | | ||
| | its type must not depend on the type parameter `impl Project<S = const {}>` | ||
| the type parameter `impl Project<S = const {}>` is defined here | ||
|
||
error: the type of the associated constant `S` must not depend on generic parameters | ||
--> $DIR/assoc-const-eq-param-in-ty.rs:33:21 | ||
| | ||
LL | fn take4<P: Project<S = {}>>(_: P) {} | ||
| - ^ its type must not depend on the type parameter `P` | ||
| | | ||
| the type parameter `P` is defined here | ||
|
||
error: aborting due to 5 previous errors | ||
|