-
Notifications
You must be signed in to change notification settings - Fork 13.4k
const_eval_checked: Support as casts in abstract consts #86130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
18 changes: 18 additions & 0 deletions
18
src/test/ui/const-generics/const_evaluatable_checked/abstract-const-as-cast-1.rs
This file contains hidden or 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,18 @@ | ||
// check-pass | ||
#![feature(const_evaluatable_checked, const_generics)] | ||
#![allow(incomplete_features)] | ||
|
||
struct Foo<const N: u8>([u8; N as usize]) | ||
where | ||
[(); N as usize]:; | ||
|
||
struct Bar<const N: u8>([u8; (N + 2) as usize]) where [(); (N + 2) as usize]:; | ||
|
||
// unifying with subtrees | ||
struct Evaluatable<const N: u16>; | ||
fn foo<const N: u8>() where Evaluatable<{N as usize as u16 }>: { | ||
let _ = Foo::<N>([1; N as usize]); | ||
} | ||
|
||
|
||
fn main() {} |
20 changes: 20 additions & 0 deletions
20
src/test/ui/const-generics/const_evaluatable_checked/abstract-const-as-cast-2.rs
This file contains hidden or 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,20 @@ | ||
#![feature(const_evaluatable_checked, const_generics)] | ||
#![allow(incomplete_features)] | ||
|
||
struct Evaluatable<const N: u128> {} | ||
|
||
struct Foo<const N: u8>([u8; N as usize]) | ||
//~^ Error: unconstrained generic constant | ||
//~| help: try adding a `where` bound using this expression: `where [(); N as usize]:` | ||
where | ||
Evaluatable<{N as u128}>:; | ||
|
||
struct Foo2<const N: u8>(Evaluatable::<{N as u128}>) where Evaluatable<{N as usize as u128 }>:; | ||
//~^ Error: unconstrained generic constant | ||
//~| help: try adding a `where` bound using this expression: `where [(); {N as u128}]:` | ||
|
||
struct Bar<const N: u8>([u8; (N + 2) as usize]) where [(); (N + 1) as usize]:; | ||
//~^ Error: unconstrained generic constant | ||
//~| help: try adding a `where` bound using this expression: `where [(); (N + 2) as usize]:` | ||
|
||
fn main() {} | ||
oli-obk marked this conversation as resolved.
Show resolved
Hide resolved
|
26 changes: 26 additions & 0 deletions
26
src/test/ui/const-generics/const_evaluatable_checked/abstract-const-as-cast-2.stderr
This file contains hidden or 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,26 @@ | ||
error: unconstrained generic constant | ||
--> $DIR/abstract-const-as-cast-2.rs:6:25 | ||
| | ||
LL | struct Foo<const N: u8>([u8; N as usize]) | ||
| ^^^^^^^^^^^^^^^^ | ||
| | ||
= help: try adding a `where` bound using this expression: `where [(); N as usize]:` | ||
|
||
error: unconstrained generic constant | ||
--> $DIR/abstract-const-as-cast-2.rs:12:26 | ||
| | ||
LL | struct Foo2<const N: u8>(Evaluatable::<{N as u128}>) where Evaluatable<{N as usize as u128 }>:; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= help: try adding a `where` bound using this expression: `where [(); {N as u128}]:` | ||
|
||
error: unconstrained generic constant | ||
--> $DIR/abstract-const-as-cast-2.rs:16:25 | ||
| | ||
LL | struct Bar<const N: u8>([u8; (N + 2) as usize]) where [(); (N + 1) as usize]:; | ||
| ^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= help: try adding a `where` bound using this expression: `where [(); (N + 2) as usize]:` | ||
|
||
error: aborting due to 3 previous errors | ||
|
47 changes: 47 additions & 0 deletions
47
src/test/ui/const-generics/const_evaluatable_checked/abstract-const-as-cast-3.rs
This file contains hidden or 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,47 @@ | ||
#![feature(const_generics, const_evaluatable_checked)] | ||
#![allow(incomplete_features)] | ||
|
||
trait Trait {} | ||
pub struct EvaluatableU128<const N: u128>; | ||
|
||
struct HasCastInTraitImpl<const N: usize, const M: u128>; | ||
impl<const O: usize> Trait for HasCastInTraitImpl<O, { O as u128 }> {} | ||
|
||
pub fn use_trait_impl<const N: usize>() | ||
where | ||
[(); { N + 1}]:, | ||
EvaluatableU128<{N as u128}>:, { | ||
fn assert_impl<T: Trait>() {} | ||
|
||
// errors are bad but seems to be pre-existing issue #86198 | ||
assert_impl::<HasCastInTraitImpl<{ N + 1 }, { N as u128 }>>(); | ||
//~^ Error: mismatched types | ||
//~^^ Error: unconstrained generic constant | ||
assert_impl::<HasCastInTraitImpl<{ N + 1 }, { N as _ }>>(); | ||
//~^ Error: mismatched types | ||
//~^^ Error: unconstrained generic constant | ||
assert_impl::<HasCastInTraitImpl<13, { 12 as u128 }>>(); | ||
//~^ Error: mismatched types | ||
assert_impl::<HasCastInTraitImpl<14, 13>>(); | ||
//~^ Error: mismatched types | ||
} | ||
pub fn use_trait_impl_2<const N: usize>() | ||
where | ||
[(); { N + 1}]:, | ||
EvaluatableU128<{N as _}>:, { | ||
fn assert_impl<T: Trait>() {} | ||
|
||
// errors are bad but seems to be pre-existing issue #86198 | ||
assert_impl::<HasCastInTraitImpl<{ N + 1 }, { N as u128 }>>(); | ||
//~^ Error: mismatched types | ||
//~^^ Error: unconstrained generic constant | ||
assert_impl::<HasCastInTraitImpl<{ N + 1 }, { N as _ }>>(); | ||
//~^ Error: mismatched types | ||
//~^^ Error: unconstrained generic constant | ||
assert_impl::<HasCastInTraitImpl<13, { 12 as u128 }>>(); | ||
//~^ Error: mismatched types | ||
assert_impl::<HasCastInTraitImpl<14, 13>>(); | ||
//~^ Error: mismatched types | ||
} | ||
|
||
fn main() {} |
139 changes: 139 additions & 0 deletions
139
src/test/ui/const-generics/const_evaluatable_checked/abstract-const-as-cast-3.stderr
This file contains hidden or 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,139 @@ | ||
error: unconstrained generic constant | ||
--> $DIR/abstract-const-as-cast-3.rs:17:5 | ||
| | ||
LL | fn assert_impl<T: Trait>() {} | ||
| ----- required by this bound in `use_trait_impl::assert_impl` | ||
... | ||
LL | assert_impl::<HasCastInTraitImpl<{ N + 1 }, { N as u128 }>>(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= help: try adding a `where` bound using this expression: `where [(); { O as u128 }]:` | ||
note: required because of the requirements on the impl of `Trait` for `HasCastInTraitImpl<{ N + 1 }, { N as u128 }>` | ||
--> $DIR/abstract-const-as-cast-3.rs:8:22 | ||
| | ||
LL | impl<const O: usize> Trait for HasCastInTraitImpl<O, { O as u128 }> {} | ||
| ^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/abstract-const-as-cast-3.rs:17:5 | ||
| | ||
LL | assert_impl::<HasCastInTraitImpl<{ N + 1 }, { N as u128 }>>(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `{ N as u128 }`, found `{ O as u128 }` | ||
| | ||
= note: expected type `{ N as u128 }` | ||
found type `{ O as u128 }` | ||
|
||
error: unconstrained generic constant | ||
--> $DIR/abstract-const-as-cast-3.rs:20:5 | ||
| | ||
LL | fn assert_impl<T: Trait>() {} | ||
| ----- required by this bound in `use_trait_impl::assert_impl` | ||
... | ||
LL | assert_impl::<HasCastInTraitImpl<{ N + 1 }, { N as _ }>>(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= help: try adding a `where` bound using this expression: `where [(); { O as u128 }]:` | ||
note: required because of the requirements on the impl of `Trait` for `HasCastInTraitImpl<{ N + 1 }, { N as _ }>` | ||
--> $DIR/abstract-const-as-cast-3.rs:8:22 | ||
| | ||
LL | impl<const O: usize> Trait for HasCastInTraitImpl<O, { O as u128 }> {} | ||
| ^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/abstract-const-as-cast-3.rs:20:5 | ||
| | ||
LL | assert_impl::<HasCastInTraitImpl<{ N + 1 }, { N as _ }>>(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `{ N as _ }`, found `{ O as u128 }` | ||
| | ||
= note: expected type `{ N as _ }` | ||
found type `{ O as u128 }` | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/abstract-const-as-cast-3.rs:23:5 | ||
| | ||
LL | assert_impl::<HasCastInTraitImpl<13, { 12 as u128 }>>(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `12_u128`, found `13_u128` | ||
| | ||
= note: expected type `12_u128` | ||
found type `13_u128` | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/abstract-const-as-cast-3.rs:25:5 | ||
| | ||
LL | assert_impl::<HasCastInTraitImpl<14, 13>>(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `13_u128`, found `14_u128` | ||
| | ||
= note: expected type `13_u128` | ||
found type `14_u128` | ||
|
||
error: unconstrained generic constant | ||
--> $DIR/abstract-const-as-cast-3.rs:35:5 | ||
| | ||
LL | fn assert_impl<T: Trait>() {} | ||
| ----- required by this bound in `use_trait_impl_2::assert_impl` | ||
... | ||
LL | assert_impl::<HasCastInTraitImpl<{ N + 1 }, { N as u128 }>>(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= help: try adding a `where` bound using this expression: `where [(); { O as u128 }]:` | ||
note: required because of the requirements on the impl of `Trait` for `HasCastInTraitImpl<{ N + 1 }, { N as u128 }>` | ||
--> $DIR/abstract-const-as-cast-3.rs:8:22 | ||
| | ||
LL | impl<const O: usize> Trait for HasCastInTraitImpl<O, { O as u128 }> {} | ||
| ^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/abstract-const-as-cast-3.rs:35:5 | ||
| | ||
LL | assert_impl::<HasCastInTraitImpl<{ N + 1 }, { N as u128 }>>(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `{ N as u128 }`, found `{ O as u128 }` | ||
| | ||
= note: expected type `{ N as u128 }` | ||
found type `{ O as u128 }` | ||
|
||
error: unconstrained generic constant | ||
--> $DIR/abstract-const-as-cast-3.rs:38:5 | ||
| | ||
LL | fn assert_impl<T: Trait>() {} | ||
| ----- required by this bound in `use_trait_impl_2::assert_impl` | ||
... | ||
LL | assert_impl::<HasCastInTraitImpl<{ N + 1 }, { N as _ }>>(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= help: try adding a `where` bound using this expression: `where [(); { O as u128 }]:` | ||
note: required because of the requirements on the impl of `Trait` for `HasCastInTraitImpl<{ N + 1 }, { N as _ }>` | ||
--> $DIR/abstract-const-as-cast-3.rs:8:22 | ||
| | ||
LL | impl<const O: usize> Trait for HasCastInTraitImpl<O, { O as u128 }> {} | ||
| ^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/abstract-const-as-cast-3.rs:38:5 | ||
| | ||
LL | assert_impl::<HasCastInTraitImpl<{ N + 1 }, { N as _ }>>(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `{ N as _ }`, found `{ O as u128 }` | ||
| | ||
= note: expected type `{ N as _ }` | ||
found type `{ O as u128 }` | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/abstract-const-as-cast-3.rs:41:5 | ||
| | ||
LL | assert_impl::<HasCastInTraitImpl<13, { 12 as u128 }>>(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `12_u128`, found `13_u128` | ||
| | ||
= note: expected type `12_u128` | ||
found type `13_u128` | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/abstract-const-as-cast-3.rs:43:5 | ||
| | ||
LL | assert_impl::<HasCastInTraitImpl<14, 13>>(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `13_u128`, found `14_u128` | ||
| | ||
= note: expected type `13_u128` | ||
found type `14_u128` | ||
|
||
error: aborting due to 12 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0308`. |
29 changes: 29 additions & 0 deletions
29
src/test/ui/const-generics/const_evaluatable_checked/abstract-const-as-cast-4.rs
This file contains hidden or 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,29 @@ | ||
// check-pass | ||
#![feature(const_evaluatable_checked, const_generics)] | ||
#![allow(incomplete_features)] | ||
|
||
trait Trait {} | ||
pub struct EvaluatableU128<const N: u128>; | ||
|
||
struct HasCastInTraitImpl<const N: usize, const M: u128>; | ||
impl<const O: usize> Trait for HasCastInTraitImpl<O, { O as u128 }> {} | ||
|
||
pub fn use_trait_impl<const N: usize>() where EvaluatableU128<{N as u128}>:, { | ||
fn assert_impl<T: Trait>() {} | ||
|
||
assert_impl::<HasCastInTraitImpl<N, { N as u128 }>>(); | ||
assert_impl::<HasCastInTraitImpl<N, { N as _ }>>(); | ||
assert_impl::<HasCastInTraitImpl<12, { 12 as u128 }>>(); | ||
assert_impl::<HasCastInTraitImpl<13, 13>>(); | ||
} | ||
pub fn use_trait_impl_2<const N: usize>() where EvaluatableU128<{N as _}>:, { | ||
fn assert_impl<T: Trait>() {} | ||
|
||
assert_impl::<HasCastInTraitImpl<N, { N as u128 }>>(); | ||
assert_impl::<HasCastInTraitImpl<N, { N as _ }>>(); | ||
assert_impl::<HasCastInTraitImpl<12, { 12 as u128 }>>(); | ||
assert_impl::<HasCastInTraitImpl<13, 13>>(); | ||
} | ||
|
||
|
||
fn main() {} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.