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

Backward spans are displayed strangely #42104

Closed
dtolnay opened this issue May 19, 2017 · 7 comments
Closed

Backward spans are displayed strangely #42104

dtolnay opened this issue May 19, 2017 · 7 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints E-help-wanted Call for participation: Help is requested to fix this issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. P-low Low priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@dtolnay
Copy link
Member

dtolnay commented May 19, 2017

macro_rules! m {
    ($a:tt $b:tt) => {
        $b $a;
    }
}

fn main() {
    m!(S struct);
}

This is a regression in 1.18.0-beta but unclear whether it affects anything in practice. We encountered this in #rust-libs discussing #40939.

$ rustc +stable --version
rustc 1.17.0 (56124baa9 2017-04-24)
$ cargo +stable build
   Compiling testing v0.1.0
warning: struct is never used: `S`
 --> src/main.rs:8:10
  |
8 |     m!(S struct);
  |     -----^------- in this macro invocation
  |
  = note: #[warn(dead_code)] on by default

    Finished dev [unoptimized + debuginfo] target(s) in 0.34 secs
$ rustc +beta --version
rustc 1.18.0-beta.2 (f4e8e81c3 2017-05-11)
$ cargo +beta build
   Compiling testing v0.1.0
warning: struct is never used: `S`
 --> src/main.rs:8:10
  |
3 | |         $b $a;
  | |______________^
...
8 |       m!(S struct);
  |  _____-----^-------
  | |     |
  | |     in this macro invocation
  |
  = note: #[warn(dead_code)] on by default

    Finished dev [unoptimized + debuginfo] target(s) in 0.45 secs
@dtolnay
Copy link
Member Author

dtolnay commented May 19, 2017

cc @estebank who touched this code recently.

@estebank
Copy link
Contributor

Oh, beautiful... I'm seeing many problems with this output, beyond the obvious. I feel the proper output should either be:

warning: struct is never used: `S`
 --> src/main.rs:8:10
  |
3 |         $b $a;
  |         ^^^^^^ unused struct
...
8 |     m!(S struct);
  |     ------------- in this macro invocation
  |
  = note: #[warn(dead_code)] on by default

or

warning: struct is never used: `S`
 --> src/main.rs:8:10
  |
8 |     m!(S struct);
  |     ---^^^^^^^^-- in this macro invocation
  |        |
  |        unused struct
  = note: #[warn(dead_code)] on by default

I can make (or mentor) a small patch to either swap end and start if they are reversed or only point at the last end for that case, but I'd prefer to properly fix the spans generated in macro invocations in a better way regardless.

@dtolnay
Copy link
Member Author

dtolnay commented Jun 17, 2017

This made it into 1.18.0.

@Mark-Simulacrum Mark-Simulacrum added regression-from-stable-to-beta Performance or correctness regression from stable to beta. regression-from-stable-to-stable Performance or correctness regression from one stable version to another. and removed regression-from-stable-to-beta Performance or correctness regression from stable to beta. labels Jun 17, 2017
@brson brson added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-diagnostics Area: Messages for errors, warnings, and lints E-help-wanted Call for participation: Help is requested to fix this issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. labels Jul 13, 2017
@Mark-Simulacrum Mark-Simulacrum added the P-low Low priority label Jul 13, 2017
@brson
Copy link
Contributor

brson commented Jul 13, 2017

Help wanted. @estebank can mentor.

bors added a commit that referenced this issue Jul 22, 2017
Use the macro structure spans instead of the invocation

Fix #42104, CC #2887.
@estebank
Copy link
Contributor

@brson should this be backported to 1.19? I don't feel there's a need to rush it.

@Mark-Simulacrum
Copy link
Member

I'm going to suggest that we don't backport this; it's not high-impact enough.

@estebank
Copy link
Contributor

That's my thinking as well.

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 E-help-wanted Call for participation: Help is requested to fix this issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. P-low Low priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. 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

4 participants