【问题标题】:How do I specify the edition to use when compiling code using rustc?使用 rustc 编译代码时如何指定要使用的版本?
【发布时间】:2022-06-19 17:23:12
【问题描述】:

我想使用rustc 编译一个用 Rust 2018 编写的项目,但我不知道如何从默认版本切换编译器。 rustc 的联机帮助页没有提及版本,builtin attributes 似乎也不包含任何相关内容。我正在使用今年早些时候构建的 Debian 版本的 rustc (1.58.1),因此它应该支持所有三个版本。

我需要做什么才能让rustc 将我的代码视为 Rust '18?

【问题讨论】:

    标签: rust


    【解决方案1】:

    至少在 Debian 上,Rust 附带的手册页是不完整的。将--help 传递给rustc 表明要设置的相关标志是--edition

    Usage: rustc [OPTIONS] INPUT
    
    Options:
        -h, --help          Display this message
            --cfg SPEC      Configure the compilation environment
    [...]
            --edition 2015|2018|2021
                            Specify which edition of the compiler to use when
                            compiling code.
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-29
      • 1970-01-01
      • 2021-10-17
      相关资源
      最近更新 更多