rust-lang / rust-lang/rust-analyzer

Errnous "unexpected token in input"

Open
#8,828 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-macro A-nameres E-hard S-actionable
Dominant language
Rust
Stars
16.9k
Forks
2.2k
Avg merge
1d 12h
Merged PRs (30d)
72

Description

rust-analyzer version: fd109fb58 2021-05-10 stable

Given the following piece of test code:

    macro_rules! test_driver {
        ($driver_name:ident, $setup:expr) => {
            concat_idents!(
                test_name = "test_",
                $driver_name,
                "_driver_raises_malformed_error_when_migration_has_both_change_and_up_steps",
                {
                    #[test]
                    fn test_name() -> Result<(), String> {
                        let mut driver = $setup;
                        match driver.apply(&malformed_migration()) {
                            Ok(_) => Err(format!("engine did not report malformed error",)),
                            Err(e) => match e {
                                Error::MalformedMigration => Ok(()),
                                _ => Err(format!("Engine returned {:?}, unexpected", e)),
                            },
                        }?;
                        Ok(())
                    }
                }
            );
        };
    }

    // rust-analyzer bug here (?)
    // https://github.com/rust-analyzer/rust-analyzer/issues/6747
    test_driver!(noop_driver, { NoopDriver {} });
    test_driver!(succeed_or_fail_driver, { SucceedOrFailDriver {} });

image

This is the first time I wrote a macro, so very possible that I made a mistake, but I don't think so, as the example is more-or-less verbatim from the concat_idents crate docs.

I tried restarting the server, and confirmed that after a few seconds the error returns.

Googling led me to https://github.com/rust-analyzer/rust-analyzer/issues/6747, I don't see any other issues open now with "unexpected token in input" error.

I tried to reproduce minimally, but I cannot reproduce it. My best guess is that because Driver in my original example is a trait, something different happens?

Here is the repro case with simple empty structs, showing a clean vscode build, and the crate version for concat_idents

image

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the reported macro_rules! and concat_idents! example in VS Code with rust-analyzer version fd109fb58, then compare it with the minimal empty-struct case and the original trait-based case. Check whether the "unexpected token in input" diagnostic persists; done means the valid macro usage no longer receives that erroneous diagnostic.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.