Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions compiler/rustc_lint/src/nonstandard_style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ impl EarlyLintPass for NonCamelCaseTypes {

declare_lint! {
/// The `non_snake_case` lint detects variables, methods, functions,
/// lifetime parameters and modules that don't have snake case names.
/// lifetime parameters, named fields and modules that don't have snake case names.
///
/// ### Example
///
Expand Down Expand Up @@ -452,10 +452,8 @@ impl<'tcx> LateLintPass<'tcx> for NonSnakeCase {
}
}

fn check_struct_def(&mut self, cx: &LateContext<'_>, s: &hir::VariantData<'_>) {
Comment thread
chenyukang marked this conversation as resolved.
for sf in s.fields() {
self.check_snake_case(cx, "structure field", &sf.ident);
}
fn check_field_def(&mut self, cx: &LateContext<'_>, field: &hir::FieldDef<'_>) {
self.check_snake_case(cx, "structure field", &field.ident);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//@ check-pass

// Regression test for issue #159323
// Field-level lint attributes must control `non_snake_case` diagnostics for that field.

#![deny(non_snake_case, unfulfilled_lint_expectations)]

pub struct Struct {
#[expect(non_snake_case)]
pub expected_Field: bool,

#[allow(non_snake_case)]
pub allowed_Field: bool,
}

#[expect(non_snake_case)]
pub struct ParentExpectation {
pub expected_Field: bool,
}

pub enum Enum {
Variant {
#[expect(non_snake_case)]
expected_Field: bool,
},
}

pub union Union {
#[expect(non_snake_case)]
pub expected_Field: bool,
}

fn main() {}
Loading