@@ -33,6 +33,11 @@ pub fn method_context(cx: &LateContext<'_>, id: LocalDefId) -> MethodLateContext
33
33
}
34
34
}
35
35
36
+ fn assoc_item_in_trait_impl ( cx : & LateContext < ' _ > , ii : & hir:: ImplItem < ' _ > ) -> bool {
37
+ let item = cx. tcx . associated_item ( ii. owner_id ) ;
38
+ item. trait_item_def_id . is_some ( )
39
+ }
40
+
36
41
declare_lint ! {
37
42
/// The `non_camel_case_types` lint detects types, variants, traits and
38
43
/// type parameters that don't have camel case names.
@@ -177,6 +182,7 @@ impl EarlyLintPass for NonCamelCaseTypes {
177
182
// trait impls where we should have warned for the trait definition already.
178
183
ast:: ItemKind :: Impl ( box ast:: Impl { of_trait : None , items, .. } ) => {
179
184
for it in items {
185
+ // FIXME: this doesn't respect `#[allow(..)]` on the item itself.
180
186
if let ast:: AssocItemKind :: Type ( ..) = it. kind {
181
187
self . check_case ( cx, "associated type" , & it. ident ) ;
182
188
}
@@ -494,15 +500,6 @@ impl<'tcx> LateLintPass<'tcx> for NonUpperCaseGlobals {
494
500
hir:: ItemKind :: Const ( ..) => {
495
501
NonUpperCaseGlobals :: check_upper_case ( cx, "constant" , & it. ident ) ;
496
502
}
497
- // we only want to check inherent associated consts, trait consts
498
- // are linted at def-site.
499
- hir:: ItemKind :: Impl ( hir:: Impl { of_trait : None , items, .. } ) => {
500
- for it in * items {
501
- if let hir:: AssocItemKind :: Const = it. kind {
502
- NonUpperCaseGlobals :: check_upper_case ( cx, "associated constant" , & it. ident ) ;
503
- }
504
- }
505
- }
506
503
_ => { }
507
504
}
508
505
}
@@ -513,6 +510,12 @@ impl<'tcx> LateLintPass<'tcx> for NonUpperCaseGlobals {
513
510
}
514
511
}
515
512
513
+ fn check_impl_item ( & mut self , cx : & LateContext < ' _ > , ii : & hir:: ImplItem < ' _ > ) {
514
+ if let hir:: ImplItemKind :: Const ( ..) = ii. kind && !assoc_item_in_trait_impl ( cx, ii) {
515
+ NonUpperCaseGlobals :: check_upper_case ( cx, "associated constant" , & ii. ident ) ;
516
+ }
517
+ }
518
+
516
519
fn check_pat ( & mut self , cx : & LateContext < ' _ > , p : & hir:: Pat < ' _ > ) {
517
520
// Lint for constants that look like binding identifiers (#7526)
518
521
if let PatKind :: Path ( hir:: QPath :: Resolved ( None , ref path) ) = p. kind {
0 commit comments