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

Macros not resolving #6847

Closed
MaxBeaud opened this issue Dec 12, 2020 · 16 comments
Closed

Macros not resolving #6847

MaxBeaud opened this issue Dec 12, 2020 · 16 comments
Labels
A-macro macro expansion S-unactionable Issue requires feedback, design decisions or is blocked on other work

Comments

@MaxBeaud
Copy link

MaxBeaud commented Dec 12, 2020

At the beginning of my program: use statement and start of the main function, rust-analyzer tells me it has failed to import certain macros. However this is purely rust-analyzer as the program can compile with no problem and the compiler throws no error.

Screenshot 2020-12-12 151040
Screenshot 2020-12-12 151056
Screenshot 2020-12-12 151312

@bjorn3
Copy link
Member

bjorn3 commented Dec 12, 2020

You can enable proc-macro support using

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

@erichgess
Copy link

I'm having the same issue, but enabling those two features did not resolve the errors.

@flodiebold
Copy link
Member

This is probably a duplicate of #6716. It should be fixed on nightly, or with the release tomorrow.

@lnicola lnicola added the A-macro macro expansion label Dec 13, 2020
@erichgess
Copy link

I updated my VSCode settings to use nightly (VSCode now shows the version as rust-analyzer version: nightly (4998807)), but I still get the error.

@AngelOfSol
Copy link

I tried updating to nightly, because I have a similar issue, but some macro imports are still broken for me:
image

RA tends to highlight them only when a file that has the errors in question gets opened, and it only seems to be broken for one package (in my case).

@flodiebold
Copy link
Member

@AngelOfSol do you have the settings mentioned above turned on?

@erichgess Can you provide more information about which errors you're still seeing? These errors aren't all the same bug.

@AngelOfSol
Copy link

@fannheyward Yes I do, this is my settings list:

{
    "editor.formatOnSave": true,
    "workbench.colorTheme": "Monokai Pro (Filter Spectrum)",
    "vim.useCtrlKeys": false,
    "window.zoomLevel": 0,
    "rust-analyzer.excludeGlobs": [
        "resources/*",
    ],
    "rust-analyzer.checkOnSave.overrideCommand": null,
    "rust-analyzer.files.watcher": "notify",
    "rust-analyzer.cargo.loadOutDirsFromCheck": true,
    "rust-analyzer.procMacro.enable": true,
    "rust-analyzer.files.exclude": [
        "resources/*"
    ],
    "editor.fontSize": 18,
    "rust-analyzer.checkOnSave.command": "clippy",
    "rust-analyzer.cargo.allFeatures": true,
    "rust-analyzer.updates.channel": "nightly"
}

@rimutaka
Copy link

Version: v0.3.415-nightly

Doesn't seem to resolve any macro's for me at all.

use tracing::{info, trace};
info!(
            "Loading config file for file_types from {} and munchers from {}",
            file_type_dir, muncher_dir
        );

error: could not resolve macro 'callsite'

image

@flodiebold
Copy link
Member

@rimutaka I can't reproduce this. Note that function-local imports don't work, but if the use is outside the function, the tracing::info macro works for me. Please open a separate issue with a minimal reproduction if you're still experiencing this on current nightly.

@MaxBeaud Is this still happening for you on the current version?

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

AngelOfSol commented Dec 15, 2020

Here's a git repo that is a minimal repro of my issue: https://github.com/AngelOfSol/strum-macro-not-resolve, it has a capture of what my VS-Code looks like at when looking at the src file.

@yaymukund
Copy link
Contributor

yaymukund commented Dec 16, 2020

I experience the same behavior when using crossterm's queue!() macro. Rust analyzer (nightly at eb9ba45) complains that write_ansi_code isn't found. Here's a minimal repro which also includes a png of my error in vim:

https://git.sr.ht/~yaymukund/crossterm-macro-not-resolve
https://github.com/crossterm-rs/crossterm/blob/0.18/src/macros.rs#L131

@flodiebold
Copy link
Member

@AngelOfSol This might be caused by the way the strum proc macro is defined, since we don't support cfg_attr yet. Could you open a separate issue for your problem?

@yaymukund The queue! macro expands to a local use $crate::{write_ansi_code, Command} internally, and we don't support local imports yet (#1165).

@wpbrown
Copy link

wpbrown commented Dec 17, 2020

I've been using nightly for months and seeing the issues from cfg_attr on strum, but as of latest nightly (nightly (554dd21)) now also seeing no macros working even slog::info, similiar to @rimutaka above. Stable is okay.

@flodiebold
Copy link
Member

@wpbrown can you please provide a minimal reproduction, in a separate issue?

@flodiebold
Copy link
Member

I'm going to close this issue because I believe the original problem was fixed, and this is becoming a general dumping ground for macro error false positives.

@MaxBeaud
Copy link
Author

@flodiebold In my case, I just downloaded the rust-analyzer update on vsCode and my using statement errors are gone. Furthermore the update for some reason caught some oddities it didn't before and has fixed some UB I could not for the life of me find out what it's cause was. I realize this issue is closed however, thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-macro macro expansion S-unactionable Issue requires feedback, design decisions or is blocked on other work
Projects
None yet
Development

No branches or pull requests

9 participants