简体   繁体   English

使用 rustc 编译代码时如何指定要使用的版本?

[英]How do I specify the edition to use when compiling code using rustc?

I want to use rustc to compile a project written in Rust 2018 but I don't know how to switch the compiler from the default edition.我想使用rustc编译一个用 Rust 2018 编写的项目,但我不知道如何从默认版本切换编译器。 The manpage for rustc mentions nothing about editions and the builtin attributes don't seem to contain anything relevant either. rustc的联机帮助页没有提及版本,并且内置属性似乎也不包含任何相关内容。 I'm using the Debian version of rustc (1.58.1) which was built earlier this year so it should support all three editions.我正在使用今年早些时候构建的 Debian 版本的 rustc (1.58.1),因此它应该支持所有三个版本。

What do I need to do to get rustc to treat my code as Rust '18?我需要做什么才能让rustc将我的代码视为 Rust '18?

At least on Debian, the manual page that ships with Rust is incomplete.至少在 Debian 上,Rust 附带的手册页是不完整的。 Passing --help to rustc shows that the relavent flag to set is --edition :--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.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM