Skip to content
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

Prioritize items that return an enum when requesting completion in a pattern match #18712

Open
dev-ardi opened this issue Dec 18, 2024 · 3 comments
Labels
A-completion autocompletion C-feature Category: feature request

Comments

@dev-ardi
Copy link

dev-ardi commented Dec 18, 2024

    struct S {
        field1: u32,
        field2: Option<u32>,
        field3: Result<u32, u32>,
    }
    let my_s = S {
        field1: 42,
        field2: Some(42),
        field3: Ok(42),
    };
    match my_s. // When asked for completions in this position it should prioritize fields or methods that return options.

This should generalize to matches!. This already works well for let Some() and if let Some()

@dev-ardi dev-ardi added the C-feature Category: feature request label Dec 18, 2024
@Veykril
Copy link
Member

Veykril commented Dec 18, 2024

What is the rational behind this? One might as likely want to match on the u32 here

@Veykril Veykril added the A-completion autocompletion label Dec 18, 2024
@dev-ardi
Copy link
Author

I would say that by far it's not as common to match over integers as it is for enums.

@Giga-Bowser
Copy link
Contributor

What about something like this?

enum A {
    Foo,
    Bar,
    Baz,
}

struct B {
    field1: A,
}

struct C {
    field1: B,
    field2: A,
}

let my_c: C = /* ... */;

match my_c. // should we suggest field1 or field2?

I would say that the "matchability" of any given field depends so much on context we really do not have that we're probably best off just trying to behave predictably

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-completion autocompletion C-feature Category: feature request
Projects
None yet
Development

No branches or pull requests

3 participants