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

Error output improvement: when using semicolon, it leads to more than one possibility where developer might be going wrong. #111316

Open
porwal-ayush opened this issue May 7, 2023 · 3 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@porwal-ayush
Copy link

Code

use std::env;

fn main() {
    let args: Vec<String> = env::args().collect();
    dbg!(args) // missing the semi colon here gives rise to two cases, either developer is missing the semi colon or he is actually passing a wrong return type
}

Current output

Compiling rustgrep v0.1.0 (C:\Users\<user>\Documents\Personal Workspace\rustgrep)
error[E0308]: mismatched types
 --> src\main.rs:5:5
  |
3 | fn main() {
  |           - expected `()` because of default return type
4 |     let args: Vec<String> = env::args().collect();
5 |     dbg!(args)
  |     ^^^^^^^^^^ expected `()`, found struct `Vec`
  |
  = note: expected unit type `()`
                found struct `Vec<String>`
  = note: this error originates in the macro `dbg` (in Nightly builds, run with -Z macro-backtrace for more info)

For more information about this error, try `rustc --explain E0308`.

Desired output

the desired output would be to allow the user to know all the possible cases that he might want to do. The current behaviour isn't wrong and it does help in a way.

Still, rust is a language where sometimes you put a semicolon and sometimes you don't, depending on the use case. I feel it would be more developer friendly if error messages were defined well in this case.

For example: (roughly saying what should be expected in output)
Hey developer, missing a semicolon had led to two possible things you might be doing wrong ->
Case 1: you are returning the wrong type to the main function
Case 2: you are returning the right thing but possibly you don't want the last statement as an expression. Please use a semicolon here on this line bla bla.

Rationale and extra context

No response

Other cases

No response

Anything else?

No response

@porwal-ayush porwal-ayush added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 7, 2023
@john-h-k
Copy link
Contributor

john-h-k commented May 7, 2023

Remove dbg! and you get the expected help, the issue is that post-expansion, dbg!(foo) looks like

match foo {
            tmp => {
                eprintln!("[{}:{}] {} = {:#?}", file!(), line!(), stringify!(foo), &tmp);
                tmp
            }
        }

and this expression isn't eligible for suggest_missing_semicolon. The rules around when missing semicolon is suggested would need to be relaxed

@john-h-k
Copy link
Contributor

john-h-k commented May 7, 2023

Nevermind, it's actually to do with a restriction around suggesting semicolons on external macros

see #81943

@porwal-ayush
Copy link
Author

Nevermind, it's actually to do with a restriction around suggesting semicolons on external macros

see #81943

Ahh, so I guess nothing to be done at present? I will just keep this open then.

@jyn514 jyn514 added the A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) label May 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants