Skip to content
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

Closed
eZioPan opened this issue Jan 10, 2019 · 4 comments
Closed
Labels
第二章 第二章 表意问题 语言表达有问题,有歧义或难理解

Comments

@eZioPan
Copy link

eZioPan commented Jan 10, 2019

页码与行数

  • 第 20 页
  • 2.4.5 小节 最后一段 第三句

文本或排版错误

Rust 编译器目前可以支持的常量表达式有:……只包含单行代码的块表达式……

我觉得这里的描述可能不太准确,多行代码的块表达式也可以存在,只要每行代码在编译期均可确定求值即可。

@eZioPan eZioPan changed the title 「第二章」2.4.5 CTFE 机制 常量表示式的部分描述不准确 「第二章」2.4.5 CTFE 机制 常量表达式的部分描述不准确 Jan 10, 2019
@ZhangHanDong ZhangHanDong added the 待确认 待确认的问题 label Jan 10, 2019
@ZhangHanDong
Copy link
Owner

@eZioPan 感谢反馈。

Rust现在应该不支持多行的块表达式做为常量,最好自己代码尝试一下。

@eZioPan
Copy link
Author

eZioPan commented Jan 11, 2019

这是我测试的代码,可以编译成功的,我用的 rustc1.31.1 的版本,不知道是不是版本的问题呢?

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
}

@ZhangHanDong
Copy link
Owner

ZhangHanDong commented Jan 11, 2019

@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
    }
}

@ZhangHanDong
Copy link
Owner

可能需要补清楚说明,加个注释

@ZhangHanDong ZhangHanDong added 表意问题 语言表达有问题,有歧义或难理解 and removed 待确认 待确认的问题 labels Jan 11, 2019
@ZhangHanDong ZhangHanDong added this to the 第三次印刷 milestone Jan 11, 2019
@ZhangHanDong ZhangHanDong added the 第二章 第二章 label Jan 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
第二章 第二章 表意问题 语言表达有问题,有歧义或难理解
Projects
None yet
Development

No branches or pull requests

2 participants