-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reject escaping generic params in the type of assoc const bindings
- Loading branch information
Showing
5 changed files
with
273 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,55 @@ | ||
// 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: 'a, const N: usize> { | ||
const K: &'a [T; N]; | ||
} | ||
|
||
fn take0<'r, A: 'r, const Q: usize>(_: impl Trait<'r, A, Q, K = { loop {} }>) {} | ||
//~^ 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 | ||
//~| NOTE `K` has type `&'r [A; Q]` | ||
//~| 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 | ||
//~| NOTE `K` has type `&'r [A; Q]` | ||
//~| 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 | ||
//~| NOTE `K` has type `&'r [A; Q]` | ||
|
||
trait Project { | ||
const SELF: Self; | ||
} | ||
|
||
fn take1(_: impl Project<SELF = {}>) {} | ||
//~^ ERROR the type of the associated constant `SELF` must not depend on `impl Trait` | ||
//~| NOTE its type must not depend on `impl Trait` | ||
//~| NOTE the `impl Trait` is specified here | ||
|
||
fn take2<P: Project<SELF = {}>>(_: P) {} | ||
//~^ ERROR the type of the associated constant `SELF` 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 | ||
//~| NOTE `SELF` has type `P` | ||
|
||
trait Iface<'r> { | ||
//~^ NOTE the lifetime parameter `'r` is defined here | ||
type Assoc<const Q: usize>: Trait<'r, Self, Q, K = { loop {} }> | ||
//~^ 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 `K` has type `&'r [Self; Q]` | ||
//~| ERROR the type of the associated constant `K` must not depend on `Self` | ||
//~| NOTE its type must not depend on `Self` | ||
//~| NOTE `K` has type `&'r [Self; Q]` | ||
//~| 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 | ||
//~| NOTE `K` has type `&'r [Self; Q]` | ||
where | ||
Self: Sized + 'r; | ||
} | ||
|
||
fn main() {} |
76 changes: 76 additions & 0 deletions
76
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,76 @@ | ||
error: the type of the associated constant `K` must not depend on generic parameters | ||
--> $DIR/assoc-const-eq-param-in-ty.rs:9:61 | ||
| | ||
LL | fn take0<'r, A: 'r, const Q: usize>(_: impl Trait<'r, A, Q, K = { loop {} }>) {} | ||
| -- the lifetime parameter `'r` is defined here ^ its type must not depend on the lifetime parameter `'r` | ||
| | ||
= note: `K` has type `&'r [A; Q]` | ||
|
||
error: the type of the associated constant `K` must not depend on generic parameters | ||
--> $DIR/assoc-const-eq-param-in-ty.rs:9:61 | ||
| | ||
LL | fn take0<'r, A: 'r, const Q: usize>(_: impl Trait<'r, A, Q, K = { loop {} }>) {} | ||
| - the type parameter `A` is defined here ^ its type must not depend on the type parameter `A` | ||
| | ||
= note: `K` has type `&'r [A; Q]` | ||
|
||
error: the type of the associated constant `K` must not depend on generic parameters | ||
--> $DIR/assoc-const-eq-param-in-ty.rs:9:61 | ||
| | ||
LL | fn take0<'r, A: 'r, const Q: usize>(_: impl Trait<'r, A, Q, K = { loop {} }>) {} | ||
| - ^ its type must not depend on the const parameter `Q` | ||
| | | ||
| the const parameter `Q` is defined here | ||
| | ||
= note: `K` has type `&'r [A; Q]` | ||
|
||
error: the type of the associated constant `SELF` must not depend on `impl Trait` | ||
--> $DIR/assoc-const-eq-param-in-ty.rs:27:26 | ||
| | ||
LL | fn take1(_: impl Project<SELF = {}>) {} | ||
| -------------^^^^------ | ||
| | | | ||
| | its type must not depend on `impl Trait` | ||
| the `impl Trait` is specified here | ||
|
||
error: the type of the associated constant `SELF` must not depend on generic parameters | ||
--> $DIR/assoc-const-eq-param-in-ty.rs:32:21 | ||
| | ||
LL | fn take2<P: Project<SELF = {}>>(_: P) {} | ||
| - ^^^^ its type must not depend on the type parameter `P` | ||
| | | ||
| the type parameter `P` is defined here | ||
| | ||
= note: `SELF` has type `P` | ||
|
||
error: the type of the associated constant `K` must not depend on generic parameters | ||
--> $DIR/assoc-const-eq-param-in-ty.rs:40:52 | ||
| | ||
LL | trait Iface<'r> { | ||
| -- the lifetime parameter `'r` is defined here | ||
LL | | ||
LL | type Assoc<const Q: usize>: Trait<'r, Self, Q, K = { loop {} }> | ||
| ^ its type must not depend on the lifetime parameter `'r` | ||
| | ||
= note: `K` has type `&'r [Self; Q]` | ||
|
||
error: the type of the associated constant `K` must not depend on `Self` | ||
--> $DIR/assoc-const-eq-param-in-ty.rs:40:52 | ||
| | ||
LL | type Assoc<const Q: usize>: Trait<'r, Self, Q, K = { loop {} }> | ||
| ^ its type must not depend on `Self` | ||
| | ||
= note: `K` has type `&'r [Self; Q]` | ||
|
||
error: the type of the associated constant `K` must not depend on generic parameters | ||
--> $DIR/assoc-const-eq-param-in-ty.rs:40:52 | ||
| | ||
LL | type Assoc<const Q: usize>: Trait<'r, Self, Q, K = { loop {} }> | ||
| - ^ its type must not depend on the const parameter `Q` | ||
| | | ||
| the const parameter `Q` is defined here | ||
| | ||
= note: `K` has type `&'r [Self; Q]` | ||
|
||
error: aborting due to 8 previous errors | ||
|