-
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.
Auto merge of #77049 - lcnr:const-eval-function-signature, r=oli-obk
const_evaluatable_checked: extend predicate collection We now walk the hir instead of using `ty` so that we get better spans here, While I am still not completely sure if that's what we want in the end, it does seem a lot closer to the final goal than the previous version. We also look into type aliases (and use a `TypeVisitor` here), about which I am not completely sure, but we will see how well this works. We also look into fn decls, so the following should work now. ```rust fn test<T>() -> [u8; std::mem::size_of::<T>()] { [0; std::mem::size_of::<T>()] } ``` Additionally, we visit the optional trait and self type of impls. r? `@oli-obk`
- Loading branch information
Showing
9 changed files
with
206 additions
and
81 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
11 changes: 11 additions & 0 deletions
11
src/test/ui/const-generics/const_evaluatable_checked/from-sig-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,11 @@ | ||
#![feature(const_generics, const_evaluatable_checked)] | ||
#![allow(incomplete_features)] | ||
|
||
fn test<const N: usize>() -> [u8; N - 1] { | ||
//~^ ERROR evaluation of constant | ||
todo!() | ||
} | ||
|
||
fn main() { | ||
test::<0>(); | ||
} |
9 changes: 9 additions & 0 deletions
9
src/test/ui/const-generics/const_evaluatable_checked/from-sig-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,9 @@ | ||
error[E0080]: evaluation of constant value failed | ||
--> $DIR/from-sig-fail.rs:4:35 | ||
| | ||
LL | fn test<const N: usize>() -> [u8; N - 1] { | ||
| ^^^^^ attempt to compute `0_usize - 1_usize` which would overflow | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0080`. |
Oops, something went wrong.