Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 0 additions & 1 deletion compiler/rustc_lint/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
}

fn visit_variant_data(&mut self, s: &'tcx hir::VariantData<'tcx>) {
lint_callback!(self, check_struct_def, s);
hir_visit::walk_struct_def(self, s);
}

Expand Down
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
1 change: 0 additions & 1 deletion compiler/rustc_lint/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ macro_rules! late_lint_methods {
fn check_trait_item(a: &'tcx rustc_hir::TraitItem<'tcx>);
fn check_impl_item(a: &'tcx rustc_hir::ImplItem<'tcx>);
fn check_impl_item_post(a: &'tcx rustc_hir::ImplItem<'tcx>);
fn check_struct_def(a: &'tcx rustc_hir::VariantData<'tcx>);
fn check_field_def(a: &'tcx rustc_hir::FieldDef<'tcx>);
fn check_variant(a: &'tcx rustc_hir::Variant<'tcx>);
fn check_path(a: &rustc_hir::Path<'tcx>, b: rustc_hir::HirId);
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