Skip to content

Commit 9626f2b

Browse files
committed
Fix extra non_snake_case warning for shorthand field bindings
1 parent edebf77 commit 9626f2b

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

compiler/rustc_lint/src/nonstandard_style.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -437,12 +437,13 @@ impl<'tcx> LateLintPass<'tcx> for NonSnakeCase {
437437
if let hir::Node::Pat(parent_pat) = cx.tcx.hir().get(cx.tcx.hir().get_parent_node(hid))
438438
{
439439
if let PatKind::Struct(_, field_pats, _) = &parent_pat.kind {
440-
for field in field_pats.iter() {
441-
if field.ident != ident {
442-
// Only check if a new name has been introduced, to avoid warning
443-
// on both the struct definition and this pattern.
444-
self.check_snake_case(cx, "variable", &ident);
445-
}
440+
if field_pats
441+
.iter()
442+
.any(|field| !field.is_shorthand && field.pat.hir_id == p.hir_id)
443+
{
444+
// Only check if a new name has been introduced, to avoid warning
445+
// on both the struct definition and this pattern.
446+
self.check_snake_case(cx, "variable", &ident);
446447
}
447448
return;
448449
}

src/test/ui/lint/issue-89469.rs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Regression test for #89469, where an extra non_snake_case warning was
2+
// reported for a shorthand field binding.
3+
4+
// check-pass
5+
#![deny(non_snake_case)]
6+
7+
#[allow(non_snake_case)]
8+
struct Entry {
9+
A: u16,
10+
a: u16
11+
}
12+
13+
fn foo() -> Entry {todo!()}
14+
15+
pub fn f() {
16+
let Entry { A, a } = foo();
17+
let _ = (A, a);
18+
}
19+
20+
fn main() {}

0 commit comments

Comments
 (0)