Skip to content

Commit a2826dc

Browse files
authored
Rollup merge of #110575 - Ezrashaw:fix-regression-110573, r=compiler-errors
fix lint regression in `non_upper_case_globals` Fixes #110573 The issue also exists for inherent associated types (where I copied my impl from). `EarlyContext` is more involved to fix in this way, so I'll leave it be for now (note it's unstable so that's not urgent). r? `@compiler-errors`
2 parents a496ae6 + 8cad917 commit a2826dc

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

compiler/rustc_lint/src/nonstandard_style.rs

+12-9
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ pub fn method_context(cx: &LateContext<'_>, id: LocalDefId) -> MethodLateContext
3333
}
3434
}
3535

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+
3641
declare_lint! {
3742
/// The `non_camel_case_types` lint detects types, variants, traits and
3843
/// type parameters that don't have camel case names.
@@ -177,6 +182,7 @@ impl EarlyLintPass for NonCamelCaseTypes {
177182
// trait impls where we should have warned for the trait definition already.
178183
ast::ItemKind::Impl(box ast::Impl { of_trait: None, items, .. }) => {
179184
for it in items {
185+
// FIXME: this doesn't respect `#[allow(..)]` on the item itself.
180186
if let ast::AssocItemKind::Type(..) = it.kind {
181187
self.check_case(cx, "associated type", &it.ident);
182188
}
@@ -494,15 +500,6 @@ impl<'tcx> LateLintPass<'tcx> for NonUpperCaseGlobals {
494500
hir::ItemKind::Const(..) => {
495501
NonUpperCaseGlobals::check_upper_case(cx, "constant", &it.ident);
496502
}
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-
}
506503
_ => {}
507504
}
508505
}
@@ -513,6 +510,12 @@ impl<'tcx> LateLintPass<'tcx> for NonUpperCaseGlobals {
513510
}
514511
}
515512

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+
516519
fn check_pat(&mut self, cx: &LateContext<'_>, p: &hir::Pat<'_>) {
517520
// Lint for constants that look like binding identifiers (#7526)
518521
if let PatKind::Path(hir::QPath::Resolved(None, ref path)) = p.kind {

tests/ui/lint/issue-110573.rs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// check-pass
2+
3+
#![deny(warnings)]
4+
5+
pub struct Struct;
6+
7+
impl Struct {
8+
#[allow(non_upper_case_globals)]
9+
pub const Const: () = ();
10+
}
11+
12+
fn main() {}

0 commit comments

Comments
 (0)