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

Excess semicolon lint produces wrong diagnostics with async main and derive macro #63947

Closed
Kobzol opened this issue Aug 27, 2019 · 4 comments · Fixed by #64387
Closed

Excess semicolon lint produces wrong diagnostics with async main and derive macro #63947

Kobzol opened this issue Aug 27, 2019 · 4 comments · Fixed by #64387
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Kobzol
Copy link
Contributor

Kobzol commented Aug 27, 2019

The new lint for excess semicolons (#62984) has some weird behaviour when the lint is triggered inside an async function that is transformed using a procedural macro.

Rustc version: 1.39.0-nightly (9b91b9c 2019-08-26)

Compiling this:

#[tokio::main]
async fn main() -> Result<(), ()> {
    let mut workers = 5;;
    Ok(())
}

gives this output:

warning: unused variable: `workers`
 --> examples/test.rs:1:1
  |
1 | #[tokio::main]
  | ^ help: consider prefixing with an underscore: `_workers`
  |
  = note: `#[warn(unused_variables)]` on by default

warning: variable does not need to be mutable
 --> examples/test.rs:1:1
  |
1 | #[tokio::main]
  | ^ help: remove this `mut`
  |
  = note: `#[warn(unused_mut)]` on by default

note how the spans are all targeting the procedural macro instead of the correct line.

If I remove the procedural macro or if I remove the excess semicolon, the spans are fine. This leads me to believe that it's an error in the lint, not in the macro, but maybe I'm wrong.

@jonas-schievink jonas-schievink added A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 27, 2019
@estebank
Copy link
Contributor

It is the macro's responsibility to preserve spans. What we can do is silence warnings coming from macro's, but we do that on a lint by lint basis at the moment.

@Kobzol
Copy link
Contributor Author

Kobzol commented Aug 27, 2019

Without the excess semicolon the spans for the other warnings are correct even with the macro, which led me to believe that the macro itself is not the problem. Does that mean that the macro somehow needs to support this new lint (or some family of lints)?

@estebank
Copy link
Contributor

The fact that the other lints trigger only if the extra semicolon is there is quite weird indeed.

@Kobzol
Copy link
Contributor Author

Kobzol commented Aug 27, 2019

At my setup they trigger always (unless the compiler does not nothing and prints nothing out), however the combination async + macro + excess semicolon messes up the spans. I looked at the macro and tried to use quote_spanned, that didn't help.

Centril added a commit to Centril/rust that referenced this issue Sep 20, 2019
…rkor

Fix redundant semicolon lint interaction with proc macro attributes

Fixes rust-lang#63967 and fixes rust-lang#63947, both of which were caused by the lint's changes to the parser interacting poorly with proc macro attributes and causing span information to be lost

r? @varkor
tmandry added a commit to tmandry/rust that referenced this issue Sep 20, 2019
…rkor

Fix redundant semicolon lint interaction with proc macro attributes

Fixes rust-lang#63967 and fixes rust-lang#63947, both of which were caused by the lint's changes to the parser interacting poorly with proc macro attributes and causing span information to be lost

r? @varkor
tmandry added a commit to tmandry/rust that referenced this issue Sep 20, 2019
…rkor

Fix redundant semicolon lint interaction with proc macro attributes

Fixes rust-lang#63967 and fixes rust-lang#63947, both of which were caused by the lint's changes to the parser interacting poorly with proc macro attributes and causing span information to be lost

r? @varkor
tmandry added a commit to tmandry/rust that referenced this issue Sep 20, 2019
…rkor

Fix redundant semicolon lint interaction with proc macro attributes

Fixes rust-lang#63967 and fixes rust-lang#63947, both of which were caused by the lint's changes to the parser interacting poorly with proc macro attributes and causing span information to be lost

r? @varkor
tmandry added a commit to tmandry/rust that referenced this issue Sep 20, 2019
…rkor

Fix redundant semicolon lint interaction with proc macro attributes

Fixes rust-lang#63967 and fixes rust-lang#63947, both of which were caused by the lint's changes to the parser interacting poorly with proc macro attributes and causing span information to be lost

r? @varkor
@bors bors closed this as completed in 55a3ead Sep 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants