Is there a way to detect the compiler version from within a Rust program?

后端 未结 1 1683
执笔经年
执笔经年 2020-12-19 02:54

In C++, you could use something like __clang_version__. Is there something similar for Rust? I searched on the internet, but found nothing.

相关标签:
1条回答
  • 2020-12-19 03:32

    Not directly.

    There is the rustc_version crate which tells you the version of rustc accessible on the command-line; this is designed to be used in a build script. There's also rustc_version_runtime which does something similar, but exposes the information as a runtime call (i.e. it detects the compiler version at compile time, but exposes it at runtime).

    Standard disclaimer: be very careful writing anything that depends on compiler version. You should ideally only test for minimum versions for which features are supported using semver (which both of the above libraries support directly).

    0 讨论(0)
提交回复
热议问题