-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reject escaping bound vars in the type of assoc const bindings
- Loading branch information
Showing
8 changed files
with
212 additions
and
20 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
25 changes: 25 additions & 0 deletions
25
tests/ui/associated-consts/assoc-const-eq-bound-var-in-ty-not-wf.rs
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,25 @@ | ||
// Check that we eventually catch types of assoc const bounds | ||
// (containing late-bound vars) that are ill-formed. | ||
#![feature(associated_const_equality)] | ||
|
||
trait Trait<T> { | ||
const K: T; | ||
} | ||
|
||
fn take( | ||
_: impl Trait< | ||
<<for<'a> fn(&'a str) -> &'a str as Project>::Out as Discard>::Out, | ||
K = { () } | ||
>, | ||
) {} | ||
//~^^^^^^ ERROR implementation of `Project` is not general enough | ||
//~^^^^ ERROR higher-ranked subtype error | ||
//~| ERROR higher-ranked subtype error | ||
|
||
trait Project { type Out; } | ||
impl<T> Project for fn(T) -> T { type Out = T; } | ||
|
||
trait Discard { type Out; } | ||
impl<T: ?Sized> Discard for T { type Out = (); } | ||
|
||
fn main() {} |
25 changes: 25 additions & 0 deletions
25
tests/ui/associated-consts/assoc-const-eq-bound-var-in-ty-not-wf.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,25 @@ | ||
error: higher-ranked subtype error | ||
--> $DIR/assoc-const-eq-bound-var-in-ty-not-wf.rs:12:13 | ||
| | ||
LL | K = { () } | ||
| ^^^^^^ | ||
|
||
error: higher-ranked subtype error | ||
--> $DIR/assoc-const-eq-bound-var-in-ty-not-wf.rs:12:13 | ||
| | ||
LL | K = { () } | ||
| ^^^^^^ | ||
| | ||
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` | ||
|
||
error: implementation of `Project` is not general enough | ||
--> $DIR/assoc-const-eq-bound-var-in-ty-not-wf.rs:9:4 | ||
| | ||
LL | fn take( | ||
| ^^^^ implementation of `Project` is not general enough | ||
| | ||
= note: `Project` would have to be implemented for the type `for<'a> fn(&'a str) -> &'a str` | ||
= note: ...but `Project` is actually implemented for the type `fn(&'0 str) -> &'0 str`, for some specific lifetime `'0` | ||
|
||
error: aborting due to 3 previous errors | ||
|
22 changes: 22 additions & 0 deletions
22
tests/ui/associated-consts/assoc-const-eq-bound-var-in-ty.rs
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,22 @@ | ||
// Check that we don't reject non-escaping late-bound vars in the type of assoc const bindings. | ||
// There's no reason why we should disallow them. | ||
// | ||
//@ check-pass | ||
|
||
#![feature(associated_const_equality)] | ||
|
||
trait Trait<T> { | ||
const K: T; | ||
} | ||
|
||
fn take( | ||
_: impl Trait< | ||
<for<'a> fn(&'a str) -> &'a str as Discard>::Out, | ||
K = { () } | ||
>, | ||
) {} | ||
|
||
trait Discard { type Out; } | ||
impl<T: ?Sized> Discard for T { type Out = (); } | ||
|
||
fn main() {} |
15 changes: 15 additions & 0 deletions
15
tests/ui/associated-consts/assoc-const-eq-esc-bound-var-in-ty.rs
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,15 @@ | ||
// Detect and reject escaping late-bound generic params in | ||
// the type of assoc consts used in an equality bound. | ||
#![feature(associated_const_equality)] | ||
|
||
trait Trait<'a> { | ||
const K: &'a (); | ||
} | ||
|
||
fn take(_: impl for<'r> Trait<'r, K = { &() }>) {} | ||
//~^ ERROR the type of the associated constant `K` cannot capture late-bound generic parameters | ||
//~| NOTE its type cannot capture the late-bound lifetime parameter `'r` | ||
//~| NOTE the late-bound lifetime parameter `'r` is defined here | ||
//~| NOTE `K` has type `&'r ()` | ||
|
||
fn main() {} |
12 changes: 12 additions & 0 deletions
12
tests/ui/associated-consts/assoc-const-eq-esc-bound-var-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,12 @@ | ||
error: the type of the associated constant `K` cannot capture late-bound generic parameters | ||
--> $DIR/assoc-const-eq-esc-bound-var-in-ty.rs:9:35 | ||
| | ||
LL | fn take(_: impl for<'r> Trait<'r, K = { &() }>) {} | ||
| -- ^ its type cannot capture the late-bound lifetime parameter `'r` | ||
| | | ||
| the late-bound lifetime parameter `'r` is defined here | ||
| | ||
= note: `K` has type `&'r ()` | ||
|
||
error: aborting due to 1 previous error | ||
|