non-camel-case-types lint does not flag `repr(C)` types
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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