rust-lang / rust-lang/rust

non-camel-case-types lint does not flag `repr(C)` types

Open
#132,925 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-lints A-repr C-discussion L-non_camel_case_types T-compiler T-lang
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Code
#![forbid(non_camel_case_types)]

#[repr(C)]
pub struct foo_bar {}
Current output
<no error>
Desired output
Compiling playground v0.0.1 (/playground)
error: type `foo_bar` should have an upper camel case name
 --> src/lib.rs:4:12
  |
4 | pub struct foo_bar {}
  |            ^^^^^^^ help: convert the identifier to upper camel case: `FooBar`
  |
note: the lint level is defined here
 --> src/lib.rs:1:11
  |
1 | #![forbid(non_camel_case_types)]
  |           ^^^^^^^^^^^^^^^^^^^^

error: could not compile `playground` (lib) due to 1 previous error
Rationale and extra context

This was clearly an explicit design choice at one point: https://github.com/rust-lang/rust/blob/81eef2d362a6f03db6f8928f82d94298d31eb81b/compiler/rustc_lint/src/nonstandard_style.rs#L170

Presumably, the idea was that you'd have a bunch of FFI types with their native C names, and that's what repr(C) is for. You wouldn't want this lint firing for such types.

But I don't think it's one that makes sense today. repr(C) is used any time you want a stable layout, not just when you're defining a C type for FFI. The lint should fire in all cases, and crates that define a bunch of C types should silence the lint where appropriate.

Other cases

Rust Version
> rustc --version --verbose
rustc 1.82.0 (f6e511eec 2024-10-15)
binary: rustc
commit-hash: f6e511eec7342f59a25f7c0534f1dbea00d01b14
commit-date: 2024-10-15
host: x86_64-unknown-linux-gnu
release: 1.82.0
LLVM version: 19.1.1
Anything else?

No response

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 compiler/rustc_lint/src/nonstandard_style.rs, especially the lint handling linked in the issue, and reproduce the provided repr(C) example. Trace why the non_camel_case_types lint skips repr(C) types. Done means the example emits the expected upper-camel-case error while preserving the intended lint behavior elsewhere.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.