简体   繁体   中英

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! {} , which exports Result , ResultExt , Error and ErrorKind .

If I use self::errors::* , IntelliJ thinks that I'm using the default Result ( std::result::Result , I think). However, if I explicitly import the types using use self::errors::{Result, ...} , everything works out hunky dory.

I can tell because the standard result has two type params, but the error_chain one has only one.

In either case, it still compiles.

I'm using the standard Rust IntelliJ plugin, version 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. 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 ).

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! 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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