struct SemanticDirection;

fn main() {}
warning: struct is never used: `SemanticDirection`
 --> src/main.rs:1:1
  |
1 | struct SemanticDirection;
  | ^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: #[warn(dead_code)] on by default

对于任何严重的事情,我都会重新打开这些警告,但我只是在修改语言,这让我快疯了.

我try 在代码中添加#[allow(dead_code)],但没有成功.

推荐答案

你可以:

  • 在 struct 、模块、函数等上添加allow属性:

    #[allow(dead_code)]
    struct SemanticDirection;
    
  • 加上crate-level allow attribute;注意!:

    #![allow(dead_code)]
    
  • 把它传给rustc:

    rustc -A dead_code main.rs
    
  • 使用cargo通过RUSTFLAGS环境变量传递:

    RUSTFLAGS="$RUSTFLAGS -A dead_code" cargo build
    

Rust相关问答推荐

如何从polars DataFrame中获取一个列作为Option String?<>

为什么要在WASM库中查看Rust函数需要`#[no_mangle]`?

无法在线程之间安全地发送future (&Q;)&错误

如果A == B,则将Rc A下推到Rc B

如何为utoipa中的可选查询参数生成OpenAPI模式?

支持TLS的模拟HTTP服务器

获取已知数量的输入

Rust与_有何区别?

Rust typestate 模式:实现多个状态?

如何将 C++ 程序链接到 Rust 程序,然后将该 Rust 程序链接回 C++ 程序? (cpp -> rust -> cpp)

简单 TCP 服务器的连接由对等重置错误,mio 负载较小

从 Axum IntoResponse 获取请求标头

在 Rust 中,我如何处理请求 javascript 的页面?

为什么我可以同时传递可变和不可变引用?

使用 serde_json 进一步处理字段

为什么 no_std crate 可以依赖于使用 std 的 crate?

如何存储返回 Future 的闭包列表并在 Rust 中的线程之间共享它?

为什么我可以从读取的可变自引用中移出?

如何从 many0 传播 Nom 失败上下文?

在 Rust 中组合特征的不同方法是否等效?