odd span with unused import generated by macro

59f8bda
Opened by Alex Burka at 2020-06-13 04:49:47

I noticed this in a much more complex macro (it was recursive), but I minimized it:

macro_rules! m { ($($i:ident)*) => { use $($i)::*; } }

m!(std cmp);
warning: unused import, #[warn(unused_imports)] on by default
 --> /Users/alex/.multirust/toolchains/beta/cargo/.cargo/script-cache/expr-8aedeaeb93034069/expr.rs:5:64
  |
5 | {macro_rules! m { ($($i:ident)*) => { use $($i)::*; } } m!(std cmp);}
  |                                                                ^^^

I can't say the span is wrong... but it also doesn't seem right. cc @jonathandturner

  1. I see something a little different, granted I tweaked your example to be:

    macro_rules! m { ($($i:ident)*) => { use $($i)::*; } }
    fn main() {
      m!(std cmp);
    }
    

    But I get...

    warning: unused import, #[warn(unused_imports)] on by default
     --> durka.rs:3:10
      |
    3 |   m!(std cmp);
      |   -------^^^--
      |   |
      |   in this macro invocation
    

    That's not great either (primary span needs a label), but it's different

    Sophia J. Turner at 2016-08-29 15:24:15

  2. Yeah, it is only pointing to part of the path for some reason, but I don't know where it should point -- it might not even be a contiguous span since the path is being assembled by a macro.

    Alex Burka at 2016-08-29 17:34:20

  3. In the future, ideally, we'll have a macro debugger that should be a much better experience than debugging macros like this with the compiler errors.

    cc @nrc - who might have some ideas.

    Sophia J. Turner at 2016-08-29 17:36:18

  4. Triage: now is

    warning: unused import: `$i`
     --> src/lib.rs:1:44
      |
    1 | macro_rules! m { ($($i:ident)*) => { use $($i)::*; } }
      |                                            ^^
    2 | 
    3 | m!(std cmp);
      | ------------ in this macro invocation
      |
      = note: `#[warn(unused_imports)]` on by default
      = note: this warning originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
    
    

    Steve Klabnik at 2020-06-13 04:49:47