-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow inline consts to reference generic params
- Loading branch information
Showing
8 changed files
with
91 additions
and
6 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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// build-fail | ||
#![feature(inline_const)] | ||
|
||
fn foo<T>() { | ||
const { assert!(std::mem::size_of::<T>() == 0); } //~ ERROR E0080 | ||
} | ||
|
||
fn bar<const N: usize>() -> usize { | ||
const { N - 1 } //~ ERROR E0080 | ||
} | ||
|
||
fn main() { | ||
foo::<i32>(); | ||
bar::<0>(); | ||
} |
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,29 @@ | ||
error[E0080]: evaluation of `foo::<i32>::{constant#0}` failed | ||
--> $DIR/const-expr-generic-err.rs:5:13 | ||
| | ||
LL | const { assert!(std::mem::size_of::<T>() == 0); } | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'assertion failed: std::mem::size_of::<T>() == 0', $DIR/const-expr-generic-err.rs:5:13 | ||
| | ||
= note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
note: the above error was encountered while instantiating `fn foo::<i32>` | ||
--> $DIR/const-expr-generic-err.rs:13:5 | ||
| | ||
LL | foo::<i32>(); | ||
| ^^^^^^^^^^^^ | ||
|
||
error[E0080]: evaluation of `bar::<0_usize>::{constant#0}` failed | ||
--> $DIR/const-expr-generic-err.rs:9:13 | ||
| | ||
LL | const { N - 1 } | ||
| ^^^^^ attempt to compute `0_usize - 1_usize`, which would overflow | ||
|
||
note: the above error was encountered while instantiating `fn bar::<0_usize>` | ||
--> $DIR/const-expr-generic-err.rs:14:5 | ||
| | ||
LL | bar::<0>(); | ||
| ^^^^^^^^^^ | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0080`. |
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,10 @@ | ||
#![feature(inline_const)] | ||
|
||
fn foo<T>() { | ||
let _ = [0u8; const { std::mem::size_of::<T>() }]; | ||
//~^ ERROR: constant expression depends on a generic parameter | ||
} | ||
|
||
fn main() { | ||
foo::<i32>(); | ||
} |
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,10 @@ | ||
error: constant expression depends on a generic parameter | ||
--> $DIR/const-expr-generic-err2.rs:4:19 | ||
| | ||
LL | let _ = [0u8; const { std::mem::size_of::<T>() }]; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: this may fail depending on what value the parameter takes | ||
|
||
error: aborting due to previous error | ||
|
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 @@ | ||
// check-pass | ||
#![feature(inline_const)] | ||
|
||
fn foo<T>() -> usize { | ||
const { std::mem::size_of::<T>() } | ||
} | ||
|
||
fn bar<const N: usize>() -> usize { | ||
const { N + 1 } | ||
} | ||
|
||
fn main() { | ||
foo::<i32>(); | ||
bar::<1>(); | ||
} |
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