Skip to content

"could not resolve macro $crate::format_args" when passing more than two arguments to assert_eq!(left, right, "there was an error {}, {}", x, y) #6791

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

Closed
jrop opened this issue Dec 9, 2020 · 3 comments

Comments

@jrop
Copy link

jrop commented Dec 9, 2020

Now, before I complain 😄 I want to give the obligatory resounding THANK YOU for creating such an amazing tool. I rely on rust-analyzer almost every day, and it is simply an invaluable aid to my job. Now for the bug:

The most recent version of rust-analyzer fails when passing messages + formatting args to assert_eq!(..):

❯ rust-analyzer --version
rust-analyzer a0fa522
// main.rs
fn main() {
    let x = 1;
    let y = 3;
    assert_eq!(1, 3, "The values are not equal: {} != {}", x, y);
}

The error message given is: [rust-analyzer macro-error] [E] could not resolve macro `$crate::format_args` . Now $crate::format_args is in the assert_eq! definition for more than two arguments:

macro_rules! assert_eq {
    ($left:expr, $right:expr) => ({
        // .. snip ..
    });
    ($left:expr, $right:expr,) => ({
        $crate::assert_eq!($left, $right)
    });
    ($left:expr, $right:expr, $($arg:tt)+) => ({
        match (&($left), &($right)) {
            (left_val, right_val) => {
                if !(*left_val == *right_val) {
                    // The reborrows below are intentional. Without them, the stack slot for the
                    // borrow is initialized even before the values are compared, leading to a
                    // noticeable slow down.
                    panic!(r#"assertion failed: `(left == right)`
  left: `{:?}`,
 right: `{:?}`: {}"#, &*left_val, &*right_val,
                           $crate::format_args!($($arg)+))
                }
            }
        }
    });
}

Here's a screenshot of the error message in context with the code (below). It seems that the spans for the error message are wonky as well:

image

@jrop jrop changed the title `could not resolve macro $crate::format_args when passing more than two arguments to assert_eq!(left, right, "there was an error {}, {}", x, y)` "could not resolve macro $crate::format_args" when passing more than two arguments to assert_eq!(left, right, "there was an error {}, {}", x, y) Dec 9, 2020
@jrop
Copy link
Author

jrop commented Dec 9, 2020

It's worth noting that when I upgrade rust-analyzer to the nightly (e4c6c70), I do not see this error. 👍

@jrop
Copy link
Author

jrop commented Dec 9, 2020

Possibly related #6788

@lnicola
Copy link
Member

lnicola commented Dec 9, 2020

Right, see #6716.

This should be fixed now, please reopen if it still happens on nightly, but #6788 should help with these.

@lnicola lnicola closed this as completed Dec 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants