How to have VScode + Rust analyzer show match type identifier?

Sorry if this was a dup topic. I do not know what is the official name of <> around a type.

My problem is that, my vscode + rust ayalyzer env, show matching symbol of {}, [] and (). By which I meant, when I place the cursor on one of the matching symbols, the other one shows in special color or something to let me know where it is. But with <> (typically used like collect::<Vec<_>>(), vscode does not do anything.

How can I make it work like the others?

The less than and greather than symbols (<>) in Rust are used for generics (both for setting generic type parameters and for providing such generic type arguments).

When you use the underscore as an argument for a generic type parameter, you're telling the compiler to infer it.

As a workaround for getting the type information in such cases, you can bind the expression to a variable:

let what_vec = my_iteration.collect::<Vec<_>>();

I think the OP is just asking about matching bracket functionality. Because <> are overloaded to signify both comparison operators and angle brackets, VSCode doesn’t by default consider them brackets. Figuring out whether a < or > is used as a bracket or operator requires more involved parsing than with other bracket types; it’s notoriously difficult in C++’s case, somewhat easier with Rust but still requires quite deep understanding of the language grammar. I don’t know whether VSCode exposes any way to customize matching bracket highlighting, but I wouldn’t be surprised if it doesn’t.

1 Like

Ah, gotcha! Yes, indeed that functionality doesn't work in VSCode, but I just tested in Zed and it works as expected.

Works in Helix also.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.