相关疑难解决方法(0)

如何在Rust中禁用未使用的代码警告?

struct SemanticDirection;

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

我会将这些警告重新发送给任何严肃的事情,但我只是在修补这种语言而这正在驱使我蝙蝠.

我尝试添加#[allow(dead_code)]到我的代码,但这不起作用.

warnings dead-code compiler-warnings rust

179
推荐指数
8
解决办法
6万
查看次数

如何在Rust中为单个语句安静警告?

假设有一个警告,例如path_statements,unused_variables.有没有办法忽略它的一个瞬间,而不将它们隔离成代码块或函数?

需要说明的是,代码中只有一个警告.我希望能够只安静警告,而不必针对特定警告进行特殊更改.并且在其他任何地方都没有这种安静的警告,甚至在同一个功能中也是如此.

使用GCC,可以按如下方式完成:

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat"
    /* Isolated region which doesn't raise warnings! */
    this_would_raise_Wformat(args);
#pragma GCC diagnostic pop
Run Code Online (Sandbox Code Playgroud)

Rust具有相同的功能吗?


请注意,我正在询问如何安静警告的一般情况.我知道有办法解决未使用的var警告,例如.

warnings rust

13
推荐指数
2
解决办法
1329
查看次数

标签 统计

rust ×2

warnings ×2

compiler-warnings ×1

dead-code ×1