Skip to content

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

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

Open
Veykril opened this issue Dec 19, 2021 · 0 comments
Open
Labels
A-completion autocompletion A-macro macro expansion C-Architecture Big architectural things which we need to figure up-front (or suggestions for rewrites :0) ) E-unknown It's unclear if the issue is E-hard or E-easy without digging in S-actionable Someone could pick this issue up and work on it right now

Comments

@Veykril
Copy link
Member

Veykril commented Dec 19, 2021

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

@Veykril Veykril added E-unknown It's unclear if the issue is E-hard or E-easy without digging in A-completion autocompletion A-macro macro expansion S-actionable Someone could pick this issue up and work on it right now labels Dec 19, 2021
@Veykril Veykril added the C-Architecture Big architectural things which we need to figure up-front (or suggestions for rewrites :0) ) label Dec 19, 2021
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-Architecture Big architectural things which we need to figure up-front (or suggestions for rewrites :0) ) E-unknown It's unclear if the issue is E-hard or E-easy without digging in S-actionable Someone could pick this issue up and work on it right now
Projects
None yet
Development

No branches or pull requests

1 participant