Skip to content

Completions in macros should consider the fragment type they are part of #11059

Open
@Veykril

Description

macro_rules! tuple_to_record_closure {
    ($ident:ident { $( $field:ident ),+ $(,)? }) => {
        |($( $field ),+)| $ident { $( $field ),+ }
    };
}
struct Foo { foo: () }
fn main() {
    tuple_to_record_closure! {
        Foo {
            f$0
        }
    }
}

Typing at the cursor position gives us various completions, one of which is the Foo { foo }: Foo pattern completion as the identifier is used in a pattern position in the expansion. This completion is wrong though, as applying it will lead to syntax errors. In this case we need to consider that the identifier we are completing is being captures as an $ident fragment, as such only stupid identifier completions should be allowed. OTOH if it was a $pat fragment capture, this completion would be fine.

We currently lack the ability of figuring out what kind of fragment type a token got captured by, so that needs to be done first. #11183

cc #11058

Metadata

Assignees

No one assigned

    Labels

    A-completionautocompletionA-macromacro expansionC-ArchitectureBig architectural things which we need to figure up-front (or suggestions for rewrites :0) )E-unknownIt's unclear if the issue is E-hard or E-easy without digging inS-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