-
Notifications
You must be signed in to change notification settings - Fork 173
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
「第二章」2.4.5 CTFE 机制
常量表达式的部分描述不准确
#54
Comments
eZioPan
changed the title
「第二章」
「第二章」Jan 10, 2019
2.4.5 CTFE 机制
常量表示式的部分描述不准确2.4.5 CTFE 机制
常量表达式的部分描述不准确
@eZioPan 感谢反馈。 Rust现在应该不支持多行的块表达式做为常量,最好自己代码尝试一下。 |
这是我测试的代码,可以编译成功的,我用的 const V: usize = 5;
fn main() {
let arr1: [u8; ctfe_f(V)] = [0, 1, 2, 3, 4, 5, 6, 7];
println!("{:?}", arr1);
}
const fn ctfe_f(v: usize) -> usize {
const A: usize = 1;
const B: usize = A * 2;
v + A + B
} |
@eZioPan 感谢反馈。可能是我没有说明白。 我书里说不支持「多行表达式」是指这个:rust-lang/rust#48821 对应代码: const V: usize = 5;
fn main() {
let arr1: [u8; ctfe_f(V)] = [0, 1, 2, 3, 4, 5, 6, 7];
println!("{:?}", arr1);
}
const fn ctfe_f(v: usize) -> usize {
{
1;
2;
3
}
} |
可能需要补清楚说明,加个注释 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
页码与行数
文本或排版错误
我觉得这里的描述可能不太准确,多行代码的块表达式也可以存在,只要每行代码在编译期均可确定求值即可。
The text was updated successfully, but these errors were encountered: