【问题标题】:How to disable "unnecessary path disambiguator" warning?如何禁用“不必要的路径消歧器”警告?
【发布时间】:2019-07-09 16:24:33
【问题描述】:

我正在使用宏生成代码,其中包含完全限定的类型路径,如下所示:

let vec: Vec::<String>;

注意&lt;String&gt; 之前的额外::。这是必要的,因此相同的输入标记也可以用于构造函数,方法是附加 ::new():

Vec::<String>::new()

但是,这会产生警告:

warning: unnecessary path disambiguator
 --> src/main.rs:4:17
  |
4 |     let vec: Vec::<String>;
  |                 ^^ try removing `::`

我无法删除::,因为我收到错误消息:

error: chained comparison operators require parentheses
 --> src/main.rs:6:14
  |
6 |     vec = Vec<String>::new();
  |              ^^^^^^^^^^
  |
  = help: use `::<...>` instead of `<...>` if you meant to specify type arguments
  = help: or use `(...)` if you meant to specify fn arguments

error[E0423]: expected value, found struct `Vec`
 --> src/main.rs:6:11
  |
6 |     vec = Vec<String>::new();
  |           ^^^
  |           |
  |           did you mean `vec`?
  |           did you mean `Vec { /* fields */ }`?

如何仅针对这一行禁用警告?

【问题讨论】:

  • 我想这似乎是一个悬而未决的问题,因为它从deny(warnings)allow(warnings) 滑落。这是open_issue

标签: rust compiler-warnings rust-macros


【解决方案1】:

目前这是一个未解决的问题。

此 lint 当前正在忽略这些属性,例如 #![allow(warnings)]

Reference

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-06
    • 1970-01-01
    • 2013-03-17
    • 2016-04-12
    • 1970-01-01
    相关资源
    最近更新 更多