简体   繁体   English

Rust IDE没有检测到error_chain的结果,认为我正在使用std :: result :: Result

[英]Rust IDE not detecting Result from error_chain, thinks I'm using the std::result::Result

I have an errors.rs file with error_chain! {} 我有一个带error_chain! {}errors.rs文件error_chain! {} error_chain! {} , which exports Result , ResultExt , Error and ErrorKind . error_chain! {} ,导出ResultResultExtErrorErrorKind

If I use self::errors::* , IntelliJ thinks that I'm using the default Result ( std::result::Result , I think). 如果我use self::errors::* ,IntelliJ认为我使用的是默认Resultstd::result::Result ,我认为)。 However, if I explicitly import the types using use self::errors::{Result, ...} , everything works out hunky dory. 但是,如果我使用use self::errors::{Result, ...}显式导入类型,那么一切都会变成hunky dory。

I can tell because the standard result has two type params, but the error_chain one has only one. 我可以告诉,因为标准结果有两个类型参数,但error_chain只有一个。

In either case, it still compiles. 在任何一种情况下,它仍然编译。

I'm using the standard Rust IntelliJ plugin, version 0.1.0.1991 . 我正在使用标准的Rust IntelliJ插件,版本0.1.0.1991

Help! 救命! Does anyone know how to get the plugin to understand what the macro is doing? 有谁知道如何让插件了解宏正在做什么?

The IntelliJ-Rust plugin uses its own code parser. IntelliJ-Rust插件使用自己的代码解析器。 It allows to leverage all the IntelliJ platform capabilities (like code navigation, formatting, refactoring, inspections, quick documentation, markers and many others) but requires implementing all the language features, which is not a simple task for Rust (you can find a more in-depth discussion of the Rust compiler parser versus IDE parser in this reddit post ). 它允许利用所有IntelliJ平台功能(如代码导航,格式化,重构,检查,快速文档,标记和许多其他功能),但需要实现所有语言功能,这对Rust来说不是一项简单的任务(你可以找到更多在这个reddit帖子中深入讨论Rust编译器解析器与IDE解析器的关系。

Macros expansion is probably the biggest language feature that is not supported by the plugin parser at the moment. 宏扩展可能是目前插件解析器不支持的最大语言功能。 That is, the plugin sees this error_chain! 也就是说,插件看到了这个error_chain! call, can resolve it to its definition, but doesn't expand it to the actual code and hence doesn't know about the new Result struct that shadows the one from stdlib. call,可以将其解析为其定义,但不会将其扩展为实际代码,因此不知道从stdlib中隐藏一个的新Result结构。 Unfortunately, in some cases it leads to such false positive error messages. 不幸的是,在某些情况下,它会导致这种误报错误消息。

I've converted this error annotation into an inspection, so in the next plugin version you'll be able to switch it off entirely or for the particular code block. 我已将此错误注释转换为检查,因此在下一个插件版本中,您将能够完全关闭它或为特定代码块关闭它。 The work on macros expansion is also in progress. 宏扩展的工作也在进行中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM