-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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 #71109 - lcnr:generics_in_const_fn, r=eddyb
allow const generics in const fn This was explicitly forbidden before. As we were unable to think of a reason why this should still be the case, this check has been removed. r? @eddyb cc @varkor @Centril
- Loading branch information
Showing
3 changed files
with
5 additions
and
41 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
// run-pass | ||
#![feature(const_generics)] | ||
//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash | ||
|
||
const fn const_u32_identity<const X: u32>() -> u32 { | ||
//~^ ERROR const parameters are not permitted in const functions | ||
X | ||
} | ||
|
||
fn main() { | ||
println!("{:?}", const_u32_identity::<18>()); | ||
assert_eq!(const_u32_identity::<18>(), 18); | ||
} |
17 changes: 2 additions & 15 deletions
17
src/test/ui/const-generics/const-fn-with-const-param.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 |
---|---|---|
@@ -1,23 +1,10 @@ | ||
error: const parameters are not permitted in const functions | ||
--> $DIR/const-fn-with-const-param.rs:4:1 | ||
| | ||
LL | const fn const_u32_identity<const X: u32>() -> u32 { | ||
| ^---- | ||
| | | ||
| _`const` because of this | ||
| | | ||
LL | | | ||
LL | | X | ||
LL | | } | ||
| |_^ | ||
|
||
warning: the feature `const_generics` is incomplete and may cause the compiler to crash | ||
--> $DIR/const-fn-with-const-param.rs:1:12 | ||
--> $DIR/const-fn-with-const-param.rs:2:12 | ||
| | ||
LL | #![feature(const_generics)] | ||
| ^^^^^^^^^^^^^^ | ||
| | ||
= note: `#[warn(incomplete_features)]` on by default | ||
|
||
error: aborting due to previous error; 1 warning emitted | ||
warning: 1 warning emitted | ||
|