Skip to content

a missing semicolon can mess up the whole diagnostics #5924

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
0x8f701 opened this issue Sep 1, 2020 · 5 comments
Closed

a missing semicolon can mess up the whole diagnostics #5924

0x8f701 opened this issue Sep 1, 2020 · 5 comments

Comments

@0x8f701
Copy link

0x8f701 commented Sep 1, 2020

The following example has a missing semicolon, this semicolon has broken the whole diagnostic, The Butterfly Effect makes it hard to understand what's exactly happening and give a really bad develop experience.

Code:

use std::sync::{Arc, RwLock};

async fn test(data: Arc<RwLock<usize>>) -> usize {
    *data.write().unwrap() += 2;
    *data.write().unwrap()
}

#[async_std::main]
async fn main() -> Result<(), ()> {
    let data = Arc::new(RwLock::new(1)) // missing semicolon :)
    println!("{}", test(data).await);
    println!("Hello, world!");
    Ok(())
}

What's showing as diagnostics:

image

image

image

@bjorn3
Copy link
Member

bjorn3 commented Sep 1, 2020

The main function not found are coming from rustc. They are caused by the fact that #[async_std::main] can't be expanded due to the syntax error, which means that rustc will just completely ignore the function.

@0x8f701
Copy link
Author

0x8f701 commented Sep 1, 2020

@bjorn3 great thanks on your quick reply~ I'm wondering what can be done on this? As an user it's frustrating to see this kind of meaningless information

@bjorn3
Copy link
Member

bjorn3 commented Sep 1, 2020

As an heuristic if a function is called main and couldn't be parsed, then a dummy fn main() {} could be inserted by rustc without any attributes.

@jonas-schievink
Copy link
Contributor

Also rustc's "main not found" diagnostic encompasses the entire source file for some reason

@lnicola
Copy link
Member

lnicola commented Oct 15, 2020

I think this is an upstream issue and we shouldn't try to do anything about it.

I filed rust-lang/rust#77968 upstream (maybe someone can add the A-diagnostics label).

@lnicola lnicola closed this as completed Oct 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants