rust-lang / rust-lang/rust

Allow derives to `allow(non_ascii_idents)` at the non-crate level

Open
#151,025 5 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-diagnostics A-lints A-rust-for-linux I-lang-radar needs-triage T-compiler
Dominant language
Rust
Stars
119k
Forks
16.2k
PR merge metrics
PR metrics pending

Description

In https://github.com/google/zerocopy/issues/2880, a user reported that our use of non-ASCII identifiers in generated code triggers the non_ascii_idents lint in their codebase.

In https://github.com/google/zerocopy/pull/2882, we tried to solve this by emitting allow(non_ascii_idents) in derive-generated code, but this unfortunately has no effect, simply triggering this warning:

warning: allow(non_ascii_idents) is ignored unless specified at crate level
  --> zerocopy-derive/tests/issue_2880_expanded.rs:77:9
   |
77 |         non_ascii_idents,
   |         ^^^^^^^^^^^^^^^^
   |
   = note: `#[warn(unused_attributes)]` (part of `#[warn(unused)]`) on by default

This "crate-level only" behavior is also true of a number of other lints (for example). This restriction prevents us from using non-ASCII identifiers in generated code, which we intentionally do in order to minimize the likelihood of identifier conflicts with surrounding code. It would be good to support this in derive-generated code.

We propose one of the following:

  • Lift this restriction
  • Lift this restriction within code annotated with #[automatically_generated]
  • Implicitly suppress this lint within code annotated with #[automatically_generated]

cc @jswrenn

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with rustc_lint/src/non_ascii_idents.rs, which the issue identifies as an example of the crate-level restriction, and review the derive-generated-code and #[automatically_generated] cases described here. Done means one of the proposed behaviors is implemented so generated non-ASCII identifiers no longer produce the reported warning.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.