Skip to content

Extra space before lifetime apostrophe in macro expansion #12260

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
tamaroning opened this issue May 15, 2022 · 7 comments · Fixed by #12262
Closed

Extra space before lifetime apostrophe in macro expansion #12260

tamaroning opened this issue May 15, 2022 · 7 comments · Fixed by #12262
Labels
A-macro macro expansion

Comments

@tamaroning
Copy link

tamaroning commented May 15, 2022

I try this code:

use std::marker::PhantomData;

struct Context<'cx> {
    phantom: PhantomData<&'cx ()>
}

macro_rules! trait_a {
    () => {
        trait A<'cx> {
            fn foo(&mut self, cx: &Context<'cx>);
        }       
    };
}

trait_a!();

struct S;

impl<'cx> A<'cx> for S {
    // Cursor is here
}

Rust analyzer completes the code as follow:

    fn foo(&mutself, cx: &Context< 'cx>) {
        
    }

I expected a completion like:

    fn foo(&mut self, cx: &Context<'cx>) {
        
    }

rust-analyzer version: (eg. output of "Rust Analyzer: Show RA Version" command)
rust-analyzer version: 5d5bbec 2022-05-09 stable

rustc version: (eg. output of rustc -V)
rustc 1.58.1 (db9d1b20b 2022-01-20)

relevant settings: (eg. client settings, or environment variables like CARGO, RUSTUP_HOME or CARGO_HOME)
none

If this is not a complex issue, I would like to tackle with this.

@tamaroning
Copy link
Author

@jhgg
There is also a needless whitespace prececding lifetime annotations.

@bors bors closed this as completed in 5ae9847 May 15, 2022
@lnicola
Copy link
Member

lnicola commented May 15, 2022

No, but we can't emit perfect code, and an extra space is harmless (it will get fixed on save/auto-format), as opposed to a missing one which causes rustfmt to fail.

After that PR, the completion is no longer "invalid".

@lnicola lnicola reopened this May 15, 2022
@tamaroning
Copy link
Author

@lnicola
I understand. thank you.

@jhgg
Copy link
Contributor

jhgg commented May 15, 2022

@lnicola did you mean to re open this?

@lnicola lnicola changed the title Invalid completion for fns in impl when trait is declared by macro expansions Extra space before lifetime apostrophe in macro expansion May 15, 2022
@lnicola
Copy link
Member

lnicola commented May 15, 2022

Yeah, and repurpose it for the space @tamaroning asked about. It might be an easy fix, we can close it if not.

@tamaroning
Copy link
Author

tamaroning commented May 16, 2022

@lnicola
Okey.
I found another invalid completion related to this issue. Is it better to fix them in one PR?
Anyway I would like to fix an extra space before lifetime apostrophe.

use std::marker::PhantomData;

struct Context<'cx> {
    phantom: PhantomData<&'cx ()>
}

macro_rules! trait_a {
    () => {
        trait A<'cx, 'a> {
            fn foo(&mut self, cx: &'a Context<'cx>);
        }       
    };
}

trait_a!();

struct S;

impl<'cx, 'a> A<'cx, 'a> for S {
    // invalid completion (space is needed before Context)
    fn foo(&mutself, cx: & 'aContext< 'cx>) {
        
    }
}

@Veykril Veykril added the A-macro macro expansion label May 20, 2022
bors added a commit that referenced this issue Aug 10, 2022
fix: Improve whitespace insertion in mbe

Related:  #12260 (comment)
@edwin0cheng
Copy link
Member

I just checked, #12990 fixed all the issues mentioned here. So we could close it.

@Veykril Veykril closed this as completed Aug 11, 2022
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-macro macro expansion
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants