File tree Expand file tree Collapse file tree 2 files changed +27
-6
lines changed Expand file tree Collapse file tree 2 files changed +27
-6
lines changed Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff line change 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 ( ) { }
You can’t perform that action at this time.
0 commit comments