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

[Rust] Add + use<> syntax #4139

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

[Rust] Add + use<> syntax #4139

wants to merge 2 commits into from

Conversation

ehuss
Copy link
Contributor

@ehuss ehuss commented Jan 25, 2025

This adds support for the + use<> precise capture syntax to Rust which was introduced in Rust 1.82.
Documentation

- match: '<'
scope: punctuation.definition.generic.begin.rust
set:
- match: '>'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest to add a meta scope to generics.

Suggested change
- match: '>'
- match: '>'
- meta_scope: meta.generic.rust

Comment on lines +813 to +815
- match: \b(Self)\b
scope: keyword.other.rust
- match: '{{identifier}}'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Self is already defined as storage type in no-path-type-names context and identifiers should also receive valuable scope names. Types are currently unscoped as other identifiers are.

I'd therefore suggest to include ordinary identifiers context, which would also - even if maybe not required - handle fully qualified identifiers.

Suggested change
- match: \b(Self)\b
scope: keyword.other.rust
- match: '{{identifier}}'
- include: identifiers

Copy link
Collaborator

@FichteFoll FichteFoll Jan 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While it's not be 100% accurate either, I'd rather include types here since that is meant to be used in situations where types are expected. It matches lifetimes as well as stray identifiers and commonly known stdlib types. Alternatively, you could refactor the types context a bit and only include the relevant things for UseBoundGenericArg here, which are lifetimes and (pathed) identifiers (with a type scope).

Commas still need to be matched separately, though.

Copy link
Collaborator

@FichteFoll FichteFoll Jan 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, reading the spec properly, pathed identifiers aren't supported and it is also unlikely for built-in names to be used since this is supposed to refer to generics and a generic with a built-in name would shadow it.

In that case, please instead simply include all-generic-type-names.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants