Skip to content

Autocompleting a trait that is defined in a macro omits spaces between tokens #12278

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
notgull opened this issue May 16, 2022 · 3 comments · Fixed by #12376
Closed

Autocompleting a trait that is defined in a macro omits spaces between tokens #12278

notgull opened this issue May 16, 2022 · 3 comments · Fixed by #12376
Labels
A-completion autocompletion A-macro macro expansion C-bug Category: bug S-actionable Someone could pick this issue up and work on it right now

Comments

@notgull
Copy link

notgull commented May 16, 2022

rust-analyzer version: 94fa8a653 2022-05-12 nightly

rustc version: rustc 1.62.0-nightly (de1bc0008 2022-04-21)

relevant settings: Rustup on Ubuntu 22.04, with VS Code 1.67.1

In VSCode, I typed in the following code:

macro_rules! noop {
    ($($item: item)*) => {
        $($item)*
    }
}

noop! {
    trait Foo {
        fn foo(&mut self, bar: i64, baz: &mut u32) -> Result<(), u32>;
    }
}

struct Test;

impl Foo for Test {
    f // my cursor is right here, and the autocomplete "fn foo(..)" option appears
}

When I press "enter" to autocomplete the method, the following is generated:

impl Foo for Test {
    fn foo(&mutself, bar:i64, baz: &mutu32) ->Result<(),u32> {
        
    }
}

Note the lack of space between &mut and self, as well as &mut and u32. This leads to a compile error when I try to compile or even rustfmt this code. Removing the trait from the macro prevents this from happening.

@Veykril
Copy link
Member

Veykril commented May 20, 2022

This has been partially addresed in #12262 for mut self, but not for mut ident

@lnicola
Copy link
Member

lnicola commented May 24, 2022

Not really. This works fine with Expand macro recursively (even for mut ident), but not with the completion.

EDIT: oh, are we running rustfmt on that?

@lnicola lnicola added A-completion autocompletion S-actionable Someone could pick this issue up and work on it right now C-bug Category: bug labels May 24, 2022
@Veykril
Copy link
Member

Veykril commented May 24, 2022

Ah, we don't insert whitespace for the completions. (We are running rustfmt on Expand macro recursively nowadays, but that is not what fixes it here, rustfmt would just fail on this invalid input)

bors added a commit that referenced this issue May 24, 2022
fix: Insert whitespace into trait-impl completions when coming from macros

Fixes #12278
@bors bors closed this as completed in 161ab76 May 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-completion autocompletion A-macro macro expansion C-bug Category: bug S-actionable Someone could pick this issue up and work on it right now
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants