Skip to content

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

Description

@joshlf

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

In google/zerocopy#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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.A-rust-for-linuxRelevant for the Rust-for-Linux projectI-lang-radarItems that are on lang's radar and will need eventual work or consideration.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions