Skip to content

mismatched-arg-count lint on macro that impl same name methods #12308

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
EluvK opened this issue May 19, 2022 · 1 comment · Fixed by #13074
Closed

mismatched-arg-count lint on macro that impl same name methods #12308

EluvK opened this issue May 19, 2022 · 1 comment · Fixed by #13074
Labels
A-ty type system / type inference / traits / method resolution C-bug Category: bug

Comments

@EluvK
Copy link

EluvK commented May 19, 2022

rust-analyzer version:
rust-analyzer version: 7e95c14ea 2022-05-17 stable

rustc version:
rustc 1.63.0-nightly (cd282d7f7 2022-05-18)

relevant settings:
OS: Ubuntu 20.04.4 LTS

I was learning wasmer by its examples and came across this lint.
image

The origin macro is complicated so I extract the code and write a simple case to reproduce it :

#![allow(unused)]
use std::marker::PhantomData;

struct SomeFunc<Args = ()> {
    _phantom: PhantomData<Args>,
}

trait SomeTrait {}
impl SomeTrait for i32 {}
impl SomeTrait for f32 {}

impl<Args> SomeFunc<Args> {
    fn new() -> Self {
        Self {
            _phantom: PhantomData,
        }
    }
}

macro_rules! impl_call {
    (  $( $x:ident ),* ) => {
        #[allow(unused_parens, non_snake_case)]
        impl<$( $x , )*> SomeFunc<( $( $x ),* )>
        where
            $( $x: SomeTrait, )*
        {
            pub fn call(&self, $( $x: $x, )* ) {

            }
        }
    };
}

impl_call!(A1);
impl_call!(A1, A2);

fn main() {
    let f1 = SomeFunc::<i32>::new();
    f1.call(10);

    let f2 = SomeFunc::<(i32, f32)>::new();
    f2.call(10, 10.); // rust analyzer complains: expected 1 argument, found 2
}

cargo run works fine, but it seems rust-analyzer was confused at f2.call(...).

By chance, I tried to switch the order of impl_call! macros into:

impl_call!(A1, A2);
impl_call!(A1);

And the lint was gone! it's works just fine.
image

I suppose it might be a 🐞

BTW, I had search the existing issue, this is the closest one #9887 . but I'm not sure if it is the same reason.

@flodiebold
Copy link
Member

It's likely the same issue as #5441.

@flodiebold flodiebold added A-ty type system / type inference / traits / method resolution C-bug Category: bug labels May 19, 2022
@bors bors closed this as completed in a670ff8 Aug 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ty type system / type inference / traits / method resolution C-bug Category: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants