Skip to content

Rust-analyzer dies when there's an error in a tokio::select macro #10051

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
Tracked by #11387
FredrikNoren opened this issue Aug 27, 2021 · 8 comments · Fixed by #11403
Closed
Tracked by #11387

Rust-analyzer dies when there's an error in a tokio::select macro #10051

FredrikNoren opened this issue Aug 27, 2021 · 8 comments · Fixed by #11403
Labels
A-diagnostics diagnostics / error reporting A-macro macro expansion Broken Window Bugs / technical debt to be addressed immediately S-actionable Someone could pick this issue up and work on it right now

Comments

@FredrikNoren
Copy link

FredrikNoren commented Aug 27, 2021

Hi,

First of all; thanks for an amazing tool!

However, I'm having an issue that several times per day rust-analyzer just seems to die and stops showing the cargo check messages (only showing a few seemingly random warning messages but no errors). I usually try to restart rust-analyzer, restart VS Code, and re-save random files at this point, and sometimes that helps but sometimes that doesn't even seem to help (I have no idea what makes it come back to life after that, perhaps a rebuild).

This is on OSX, rust-analyzer version 0.2.718, VSCode version 1.59.1, but the problem has been around since I started using rust-analyzer about a year ago.

Edit: I've realized that this only happens when there's an error in a tokio::select! macro.

@jonas-schievink jonas-schievink added the A-diagnostics diagnostics / error reporting label Sep 1, 2021
@knopp
Copy link

knopp commented Sep 5, 2021

Somewhat relevant, recently cargo check seems to misbehave in multi project workspaces (it only shows errors from one project).

@FredrikNoren
Copy link
Author

I finally figured out when this is happening: it's when there's an error in a tokio::select! macro.

@FredrikNoren FredrikNoren changed the title Cargo check errors stop showing up Rust-analyzer dies when there's an error in a tokio::select macro Jan 6, 2022
@Veykril Veykril added A-macro macro expansion S-actionable Someone could pick this issue up and work on it right now labels Jan 6, 2022
@lnicola
Copy link
Member

lnicola commented Jan 28, 2022

@FredrikNoren can you make a test project which reproduces the issue? If not, I'll try to do it when I have some time.

@FredrikNoren
Copy link
Author

@lnicola This stops producing "problems" in vscode for me:

use std::time::Duration;

#[tokio::main]
async fn main() {
    tokio::select! {
        x = tokio::time::sleep(Duration::from_secs_f32(1.)) => {
            let x = ;
        }
    }
    println!("";
}

@lnicola
Copy link
Member

lnicola commented Jan 28, 2022

Confirmed, thanks for the lovely repro.

@lnicola lnicola added the Broken Window Bugs / technical debt to be addressed immediately label Jan 28, 2022
@lnicola lnicola mentioned this issue Jan 31, 2022
15 tasks
@Veykril
Copy link
Member

Veykril commented Feb 1, 2022

Just

fn main() {
    tokio::select! {
        x
    }
}

is enough to get diagnostics stuck.
For one we hit the macro expansion depth limit, which happens due to us doing a bad recovery job for picking a macro matcher, since no matcher matches. That somehow causes us to end in a recursive arm which we repick over and over again. Though it is odd that this seems to get diagnostics stuck

@Veykril
Copy link
Member

Veykril commented Feb 1, 2022

minimal macro that causes this

macro_rules! select {
    (@ { $($t:tt)* } ) => {
        // No `else` branch
        select!(@{ $($t)*; unreachable!() })
    };
    ( $p:pat = $($t:tt)* ) => {
        select!(@{ () } $p = $($t)*)
    };
    () => {};
}

fn main() {
    select! {
        x
    }
}

checking the server trace we do publish diagnostics though, so this is rather odd that they aren't being updated?.

@Veykril
Copy link
Member

Veykril commented Feb 1, 2022

Huh so this might be a code bug

macro_rules! f {
    () => {
        compile_error!("");
    };
}

f!();

breaks the diagnostics of the file, which I assume is because we post an empty diagnostics message(which also happens in the select macro, though I am not sure why that happens there)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics diagnostics / error reporting A-macro macro expansion Broken Window Bugs / technical debt to be addressed immediately S-actionable Someone could pick this issue up and work on it right now
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants