Skip to content

postgres-query proc macro not resolved #6740

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

Closed
yokujin opened this issue Dec 7, 2020 · 14 comments
Closed

postgres-query proc macro not resolved #6740

yokujin opened this issue Dec 7, 2020 · 14 comments
Labels
A-macro macro expansion C-bug Category: bug S-actionable Someone could pick this issue up and work on it right now

Comments

@yokujin
Copy link

yokujin commented Dec 7, 2020

Using the following macro:

#[macro_export]
macro_rules! query_dyn {
    ($($tt:tt)*) => {
        $crate::__query_dynamic!($($tt)*)
    };
}

error flagged in rust-analyzer: could not resolve macro $crate::__query_dynamic rust-analyzer(macro-error).

Rust compiler compiles that code without any error. cargo check/cargo clippy find no errors/warnings.

Latest release version of rust-analyzer (2020-11-30) does not flag this error either.

@lnicola lnicola added the A-macro macro expansion label Dec 7, 2020
@lnicola
Copy link
Member

lnicola commented Dec 7, 2020

Probably duplicate of #6716.

@jonas-schievink
Copy link
Contributor

I think we need more info here. How do you invoke query_dyn, and what's the definition of __query_dynamic?

@yokujin
Copy link
Author

yokujin commented Dec 7, 2020

query_dyn macro is a part of postgres-query crate.

Invoked as specified in documentation:

let mut bindings = Vec::new();
// some code
let query: Query = query_dyn!(&sql, ..bindings)?;

Macro defined here.

__query_dynamic is several lines below.

@flodiebold
Copy link
Member

@yokujin Does this still occur with current rust-analyzer?

@yokujin
Copy link
Author

yokujin commented Dec 15, 2020

nightly version - nothing changed...
Screenshot_20201215_165117

Still, the only working version is 2020-11-30.

@flodiebold
Copy link
Member

The __query_dynamic macro is a proc macro and uses proc_macro_hack. The problem is probably the proc_macro_hack, but do you have rust-analyzer.procMacro.enable and rust-analyzer.cargo.loadOutDirsFromCheck enabled?

@flodiebold flodiebold changed the title could not resolve macro postgres-query proc macro not resolved Dec 15, 2020
@yokujin
Copy link
Author

yokujin commented Dec 15, 2020

"rust-analyzer.procMacro.enable": true

Cargo: Load Out Dirs From Check is unchecked

@flodiebold
Copy link
Member

You'll need to enable both for proc macros to work.

@yokujin
Copy link
Author

yokujin commented Dec 20, 2020

I enabled all the required options and updated to nightly...
It gets even worse... Even macrros from slog, slog_scope crates flag errors.

/// Log a debug level message using current scope logger
#[macro_export]
macro_rules! debug( ($($args:tt)+) => {
    $crate::with_logger(|logger| $crate::slog_debug![logger, $($args)+])
};);

@flodiebold
Copy link
Member

That's #6955, a different bug.

@edwin0cheng
Copy link
Member

OTOH, , proc_macro_hack is not support for now due to we have not support proc macro attributes yet.

@lnicola lnicola added the S-actionable Someone could pick this issue up and work on it right now label Dec 20, 2020
@stabler
Copy link

stabler commented Dec 29, 2020

I'm having the same issue with the select_biased! macro in the futures crate (which calls select_biased_internal, which uses proc_macro_hack)

bors bot added a commit that referenced this issue Jun 3, 2021
9128: feat: expand procedural attribute macros r=jonas-schievink a=jonas-schievink

This adds experimental support for attribute macros. They can be enabled by setting `rust-analyzer.experimental.procAttrMacros` to `true`.

Known issues:
* Tokens aren't remapped, presumably because we edit the input syntax tree (this causes IDE features to not work inside items with attribute macros on them)
* Macro errors aren't reported correctly

Closes #8971
Fixes #8964 / la10736/rstest#120
Fixes #2984
Fixes #5412
Fixes #6029
Fixes #6687

#6740 is still not fixed – we now expand `#[proc_macro_hack]`, but fail to expand the resulting `proc_macro_call!()` macro.

Co-authored-by: Jonas Schievink <[email protected]>
bors bot added a commit that referenced this issue Jun 3, 2021
9128: feat: expand procedural attribute macros r=jonas-schievink a=jonas-schievink

This adds experimental support for attribute macros. They can be enabled by setting `rust-analyzer.experimental.procAttrMacros` to `true`.

Known issues:
* Tokens aren't remapped, presumably because we edit the input syntax tree (this causes IDE features to not work inside items with attribute macros on them)
* Macro errors aren't reported correctly

Closes #8971
Fixes #8964 / la10736/rstest#120
Fixes #2984
Fixes #5412
Fixes #6029
Fixes #6687

#6740 is still not fixed – we now expand `#[proc_macro_hack]`, but fail to expand the resulting `proc_macro_call!()` macro.

Co-authored-by: Jonas Schievink <[email protected]>
@Ciantic
Copy link

Ciantic commented Jul 28, 2021

It's hard to tell which macro issues are related, but I'm having problems with importing "parse_macro_input":

image

Not sure if it's related, but I wish not open a new issue until I know.

I have also this in my settings.json:

{
    "rust-analyzer.updates.channel": "nightly",
    "rust-analyzer.experimental.procAttrMacros": true
}

@flodiebold flodiebold added the C-bug Category: bug label Jun 29, 2022
@Veykril
Copy link
Member

Veykril commented Dec 6, 2023

This now works

@Veykril Veykril closed this as completed Dec 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-macro macro expansion C-bug Category: bug S-actionable Someone could pick this issue up and work on it right now
Projects
None yet
Development

No branches or pull requests

8 participants