-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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 #132118 - compiler-errors:tilde-const-item-bounds, r=…
…lcnr Add support for `~const` item bounds Supports the only missing capability of `~const` associated types that I can think of now (this is obviously excluding `~const` opaques, which I see as an extension to this; I'll probably do that next). r? ``@lcnr`` mostly b/c it changes candidate assembly, or reassign cc ``@fee1-dead``
- Loading branch information
Showing
11 changed files
with
191 additions
and
25 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
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
15 changes: 0 additions & 15 deletions
15
tests/ui/traits/const-traits/assoc-type-const-bound-usage-0.stderr
This file was deleted.
Oops, something went wrong.
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
35 changes: 35 additions & 0 deletions
35
tests/ui/traits/const-traits/assoc-type-const-bound-usage-fail-2.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,35 @@ | ||
//@ compile-flags: -Znext-solver | ||
|
||
// Check that `~const` item bounds only hold if the where clauses on the | ||
// associated type are also const. | ||
// i.e. check that we validate the const conditions for the associated type | ||
// when considering one of implied const bounds. | ||
|
||
#![allow(incomplete_features)] | ||
#![feature(const_trait_impl, effects)] | ||
|
||
#[const_trait] | ||
trait Trait { | ||
type Assoc<U>: ~const Trait | ||
where | ||
U: ~const Other; | ||
|
||
fn func(); | ||
} | ||
|
||
#[const_trait] | ||
trait Other {} | ||
|
||
const fn fails<T: ~const Trait, U: Other>() { | ||
T::Assoc::<U>::func(); | ||
//~^ ERROR the trait bound `<T as Trait>::Assoc<U>: ~const Trait` is not satisfied | ||
<T as Trait>::Assoc::<U>::func(); | ||
//~^ ERROR the trait bound `<T as Trait>::Assoc<U>: ~const Trait` is not satisfied | ||
} | ||
|
||
const fn works<T: ~const Trait, U: ~const Other>() { | ||
T::Assoc::<U>::func(); | ||
<T as Trait>::Assoc::<U>::func(); | ||
} | ||
|
||
fn main() {} |
15 changes: 15 additions & 0 deletions
15
tests/ui/traits/const-traits/assoc-type-const-bound-usage-fail-2.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,15 @@ | ||
error[E0277]: the trait bound `<T as Trait>::Assoc<U>: ~const Trait` is not satisfied | ||
--> $DIR/assoc-type-const-bound-usage-fail-2.rs:24:5 | ||
| | ||
LL | T::Assoc::<U>::func(); | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error[E0277]: the trait bound `<T as Trait>::Assoc<U>: ~const Trait` is not satisfied | ||
--> $DIR/assoc-type-const-bound-usage-fail-2.rs:26:5 | ||
| | ||
LL | <T as Trait>::Assoc::<U>::func(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0277`. |
28 changes: 28 additions & 0 deletions
28
tests/ui/traits/const-traits/assoc-type-const-bound-usage-fail.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,28 @@ | ||
//@ compile-flags: -Znext-solver | ||
|
||
// Check that `~const` item bounds only hold if the parent trait is `~const`. | ||
// i.e. check that we validate the const conditions for the associated type | ||
// when considering one of implied const bounds. | ||
|
||
#![allow(incomplete_features)] | ||
#![feature(const_trait_impl, effects)] | ||
|
||
#[const_trait] | ||
trait Trait { | ||
type Assoc: ~const Trait; | ||
fn func(); | ||
} | ||
|
||
const fn unqualified<T: Trait>() { | ||
T::Assoc::func(); | ||
//~^ ERROR the trait bound `T: ~const Trait` is not satisfied | ||
<T as Trait>::Assoc::func(); | ||
//~^ ERROR the trait bound `T: ~const Trait` is not satisfied | ||
} | ||
|
||
const fn works<T: ~const Trait>() { | ||
T::Assoc::func(); | ||
<T as Trait>::Assoc::func(); | ||
} | ||
|
||
fn main() {} |
15 changes: 15 additions & 0 deletions
15
tests/ui/traits/const-traits/assoc-type-const-bound-usage-fail.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,15 @@ | ||
error[E0277]: the trait bound `T: ~const Trait` is not satisfied | ||
--> $DIR/assoc-type-const-bound-usage-fail.rs:17:5 | ||
| | ||
LL | T::Assoc::func(); | ||
| ^^^^^^^^^^^^^^^^ | ||
|
||
error[E0277]: the trait bound `T: ~const Trait` is not satisfied | ||
--> $DIR/assoc-type-const-bound-usage-fail.rs:19:5 | ||
| | ||
LL | <T as Trait>::Assoc::func(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0277`. |