Skip to content

Split up diagnostics in uncommon_codepoints (potentially splitting up the lint as well) #120228

Open
@Manishearth

Description

@Manishearth
Member

Currently we have the uncommon_codepoints lint, which lints on anything which is Identifier_Status=Restricted.

It may be worth improving the diagnostics there by splitting it into multiple different specialized diagnostics. In the long run, some of these might be something that should be promoted to a separate lint so that they can individually be allowed.

The diagnostics I can think of are:

  1. One that calls out confusables with operators and syntax. we already have this for parse errors but not for lints post-parse. Unicode does not provide this data directly but we can construct it from unicode data easily.
  2. One that talks about Technical in general
  3. One that talks about Exclusion in general (this is "scripts that are dead")
  4. One that talks about Limited_Use in general (this is "scripts that are alive but not in widespread digital use yet")
  5. One that talks about Not_NFKC in general.

The first one can be implemented by taking the set of Rust syntax characters, expanding that to their confusables set, and then winnowing it down to the set of characters that is allowed in an identifier. This could belong in a separate check in the unicode-security crate.

The others can be implemented by checking the identifier_type() of characters in the ident.

I might be able to mentor this, I can provide diagnostic text for these when needed.

Activity

added
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.
A-diagnosticsArea: Messages for errors, warnings, and lints
E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.
E-help-wantedCall for participation: Help is requested to fix this issue.
on Jan 22, 2024
HTGAzureX1212

HTGAzureX1212 commented on Jan 22, 2024

@HTGAzureX1212
Contributor

Hello, I'm interested in taking a go at this. Could anyone mentor me on this?

HTGAzureX1212

HTGAzureX1212 commented on Jan 22, 2024

@HTGAzureX1212
Contributor

@rustbot claim

Manishearth

Manishearth commented on Jan 22, 2024

@Manishearth
MemberAuthor

I'm too busy in the coming weeks to fully mentor but I can answer questions. Please make a thread in the diagnostics channel on rust-lang.zulipchat.org and ask questions there, ccing me ("Manish Goregaokar").

Manishearth

Manishearth commented on Jan 22, 2024

@Manishearth
MemberAuthor

I would start by implementing the checks for 2-5 using the existing APIs.

The relevant code is here:

cx.emit_spanned_lint(UNCOMMON_CODEPOINTS, sp, IdentifierUncommonCodepoints);

You'll want that to emit a different lint message based on context.

The lint messages are pulled from a diagnostics type https://github.com/rust-lang/rust/blob/master/compiler/rustc_lint/src/lints.rs#L1111

which links to

lint_identifier_uncommon_codepoints = identifier contains uncommon Unicode codepoints

I think the first change to make would actually be to make this diagnostic type contain a vector of characters, which it prints out as a list. Once we have that done, we should add more versions of it that have different messages, for Technical, Exclusion, etc.

added 2 commits that reference this issue on Jan 23, 2024

Rollup merge of rust-lang#120259 - HTGAzureX1212:HTGAzureX1212/split-…

ed207ae

Rollup merge of rust-lang#120259 - HTGAzureX1212:HTGAzureX1212/split-…

4d9b983

9 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-UnicodeArea: UnicodeA-diagnosticsArea: Messages for errors, warnings, and lintsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-cleanupCategory: PRs that clean code up or issues documenting cleanup.E-help-wantedCall for participation: Help is requested to fix this issue.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.L-uncommon_codepointsLint: uncommon_codepointsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @Manishearth@fmease@HTGAzureX1212@jieyouxu

      Issue actions

        Split up diagnostics in uncommon_codepoints (potentially splitting up the lint as well) · Issue #120228 · rust-lang/rust