Skip to content

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

Closed
@notgull

Description

@notgull

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-completionautocompletionA-macromacro expansionC-bugCategory: bugS-actionableSomeone could pick this issue up and work on it right now

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions