forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#121258 - fmease:assoc-const-eq-reject-overly-generic-tys, r=compiler-errors Reject overly generic assoc const binding types Split off from rust-lang#119385 to make rust-lang#119385 easier to review. --- In the *instantiated* type of assoc const bindings 1. reject **early-bound generic params** * Provide a rich error message instead of ICE'ing ([rust-lang#108271](rust-lang#108271)). * This is a temporary and semi-artificial restriction until the arrival of *generic const generics*. * It's quite possible that rustc could already perfectly support this subset of generic const generics if we just removed some checks (some `.no_bound_vars().expect(…)`) but even if that was the case, I'd rather gate it behind a new feature flag. Reporting an error instead of ICE'ing is a good first step towards an eventual feature gate error. 2. reject **escaping late-bound generic params** * They lead to ICEs before & I'm pretty sure that they remain incorrect even in a world with *generic const generics* --- Together with rust-lang#118668 & rust-lang#119385, this supersedes rust-lang#118360. Fixes rust-lang#108271.
- Loading branch information
Showing
10 changed files
with
463 additions
and
11 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 | ||
|
Oops, something went wrong.