Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unresolved import for a re-exported macro #6478

Closed
hulloitskai opened this issue Nov 6, 2020 · 5 comments
Closed

Unresolved import for a re-exported macro #6478

hulloitskai opened this issue Nov 6, 2020 · 5 comments
Labels
S-unactionable Issue requires feedback, design decisions or is blocked on other work

Comments

@hulloitskai
Copy link

hulloitskai commented Nov 6, 2020

Hi, rust-analyzer appears to be giving me unresolved import when importing tokio::main:

use anyhow::Result;
use tokio::main as wrapper; // unresolved import

#[wrapper]
async fn main()Result<()> {
  // ...
}

I do know that directly using #[tokio::main] instead of use-aliasing it will avoid the complaints from rust-analyzer; however, I believe this error points to a deeper issue with specific imports that should be addressed.

However, the code compiles properly. Upon closer inspection of the source containing the tokio::main macro, I see that it is embedded with several layers of macros to handle cfg (to only export the macro when certain tokio features are enabled):

cfg_macros! {
    /// Implementation detail of the `select!` macro. This macro is **not**
    /// intended to be used as part of the public API and is permitted to
    /// change.
    #[doc(hidden)]
    pub use tokio_macros::select_priv_declare_output_enum;

    cfg_rt! {
        cfg_rt_multi_thread! {
            // This is the docs.rs case (with all features) so make sure macros
            // is included in doc(cfg).

            #[cfg(not(test))] // Work around for rust-lang/rust#62127
            #[cfg_attr(docsrs, doc(cfg(feature = "macros")))]
            pub use tokio_macros::main;

            #[cfg_attr(docsrs, doc(cfg(feature = "macros")))]
            pub use tokio_macros::test;
        }

        cfg_not_rt_multi_thread! {
            #[cfg(not(test))] // Work around for rust-lang/rust#62127
            pub use tokio_macros::main_rt as main;
            pub use tokio_macros::test_rt as test;
        }
    }

    // Always fail if rt is not enabled.
    cfg_not_rt! {
        #[cfg(not(test))]
        pub use tokio_macros::main_fail as main;
        pub use tokio_macros::test_fail as test;
    }
}

Perhaps it is the expansion of these macros, or the #[cfg(not(test))], that is tripping up rust-analyzer?

@ArifRoktim
Copy link
Contributor

Does adding

    "rust-analyzer.procMacro.enable": true,
    "rust-analyzer.cargo.loadOutDirsFromCheck": true,

to your configuration fix the issue? Proc Macro support is disabled by default.

@hulloitskai
Copy link
Author

hulloitskai commented Nov 8, 2020 via email

@jonas-schievink
Copy link
Contributor

Perhaps it is the expansion of these macros, or the #[cfg(not(test))], that is tripping up rust-analyzer?

It is the #[cfg(not(test))]. rust-analyzer always enables the test cfg.

However it seems that the Rust issue this is working around, rust-lang/rust#62127, has been fixed, so the workaround in tokio can probably be removed now.

@jonas-schievink
Copy link
Contributor

Ah nevermind it was closed as wontfix.

@flodiebold flodiebold added the S-unactionable Issue requires feedback, design decisions or is blocked on other work label Dec 21, 2020
@Veykril
Copy link
Member

Veykril commented Oct 30, 2021

This can be worked around by adding tokio-macros to the rust-analyzer.cargo.unsetTest setting now.

@Veykril Veykril closed this as completed Oct 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-unactionable Issue requires feedback, design decisions or is blocked on other work
Projects
None yet
Development

No branches or pull requests

5 participants