Skip to content

Error location incorrectly extracted inside macros. #2569

Closed
@omerbenamram

Description

@omerbenamram

It seems that rust-analyzer can sometimes incorrectly resolve location of an error, to a non-existing location such as <::alloc::macros::vec macros>.

image

The compiler resolves those spans nicely:

error[E0308]: mismatched types
   --> intcode-computer\./src/lib.rs:438:36
    |
438 |         test_memory!("1,0,0,0,99", vec![], "2,0,0,0,99");
    |                                    ^^^^^^ expected &[i64], found struct `std::vec::Vec`
    |
    = note: expected type `&[i64]`
               found type `std::vec::Vec<_>`
    = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) 

I tried to minimize it very crudely, but it didn't seem to always occur, at least not in this example:

macro_rules! my_macro {
    ($t: expr) => {
        a($t);
    };
}

fn a(v: &[i64]) {
    unimplemented!()
}

fn main() {
    let x = 0_i64;
    my_macro!(vec![1])
}

which seems to resolve fine to main.rs:

image

This reproduces on my advent of code repo https://github.com/omerbenamram/AOC2019/.

I'm not sure which part of rust-analyzer is responsible for this behavior, but I could take a look in a general direction if it's not too complex.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions