Support [x; n] expressions in concat_bytes! by Smittyvb · Pull Request #92066 ·...
source link: https://github.com/rust-lang/rust/pull/92066
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Currently trying to use concat_bytes!
with a repeating array value like [42; 5]
results in an error:
error: expected a byte literal
--> src/main.rs:3:27
|
3 | let x = concat_bytes!([3; 4]);
| ^^^^^^
|
= note: only byte literals (like `b"foo"`, `b's'`, and `[3, 4, 5]`) can be passed to `concat_bytes!()`
This makes it so repeating array syntax can be used the same way normal arrays can be. The RFC doesn't explicitly mention repeat expressions, but it seems reasonable to allow them as well, since normal arrays are allowed.
It is possible to make the compiler get stuck compiling forever with concat_bytes!([3; 999999999])
, but I don't think that's much of an issue since you can do that already with const X: [u8; 999999999] = [3; 999999999];
.
Contributes to #87555.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK