-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reject 'escaping' gen params in the ty of assoc consts in eq bounds
- Loading branch information
Showing
5 changed files
with
175 additions
and
2 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(associated_const_equality): The error messages below aren't super great at the moment: | ||
// Here, `Self` is a type parameter of the trait `Project`, not of the function `take3` | ||
// unlike the cases above. We should mention the APIT / the parameter `P` instead. | ||
|
||
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 `Self` | ||
|
||
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 `Self` | ||
|
||
fn main() {} |
38 changes: 38 additions & 0 deletions
38
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,38 @@ | ||
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:30:26 | ||
| | ||
LL | fn take3(_: impl Project<S = {}>) {} | ||
| ^ its type must not depend on the type parameter `Self` | ||
|
||
error: the type of the associated constant `S` must not depend on generic parameters | ||
--> $DIR/assoc-const-eq-param-in-ty.rs:34:21 | ||
| | ||
LL | fn take4<P: Project<S = {}>>(_: P) {} | ||
| ^ its type must not depend on the type parameter `Self` | ||
|
||
error: aborting due to 5 previous errors | ||
|