rust - 运行 `rustc` 检查程序而不生成任何文件

标签 rust

cargo check 所示,检查您的程序是否格式正确而无需实际生成代码(通常是一项非常耗时的任务)通常很有用。我想直接用 rustc 检查单个(库)Rust 文件(我不能使用 Cargo!)。

cargo check 显然是通过调用这个来工作的:

rustc --emit=metadata -Z no-codegen

这只会发出元数据,一个 .rmeta 文件。 Cargo 实际上需要它来检查依赖于已检查箱子的箱子。就我而言,我真的不需要元数据文件。

我尝试了以下方法:

rustc --crate-type=lib --emit=
rustc --crate-type=lib --emit=nothing

但是两者都不起作用。我使用 --crate-type=lib 因为我的文件没有 main 函数。我需要一个独立于平台的解决方案(我不只是想在我的机器上使用它,而是在公共(public)脚本中使用它)。

如何让 rustc 不写入单个文件?

最佳答案

您可以跳过 --emit 标志。

最后的命令将是:rustc -Z no-codegen rust.rs

关于rust - 运行 `rustc` 检查程序而不生成任何文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51485765/

相关文章:

multithreading - Send 只能为结构/枚举类型实现,不能为特征实现

rust - 保存文件后, cargo 测试会警告未使用的代码

rust - 如何使用 Rust 创建死锁?

multithreading - 如何在线程共享的简单fifo上通知并等待condvar

rust - 错误 : `line` does not live long enough but it's ok in playground

rust - Change selector in match when selector is a mutable reference

c++ - 通过 Qt 中的线程调用 Rust 库

Rust - 嵌套循环仅在内循环内进行一次

rust - 为什么编译器假定返回的引用与结构具有相同的生命周期?

compiler-errors - 奇怪地重复出现的通用特征模式 : overflow evaluating the requirement