make non_upper_case_globals
lint not report trait impls
This commit is contained in:
parent
c609da59d9
commit
625619551d
@ -494,6 +494,15 @@ fn check_item(&mut self, cx: &LateContext<'_>, it: &hir::Item<'_>) {
|
|||||||
hir::ItemKind::Const(..) => {
|
hir::ItemKind::Const(..) => {
|
||||||
NonUpperCaseGlobals::check_upper_case(cx, "constant", &it.ident);
|
NonUpperCaseGlobals::check_upper_case(cx, "constant", &it.ident);
|
||||||
}
|
}
|
||||||
|
// we only want to check inherent associated consts, trait consts
|
||||||
|
// are linted at def-site.
|
||||||
|
hir::ItemKind::Impl(hir::Impl { of_trait: None, items, .. }) => {
|
||||||
|
for it in *items {
|
||||||
|
if let hir::AssocItemKind::Const = it.kind {
|
||||||
|
NonUpperCaseGlobals::check_upper_case(cx, "associated constant", &it.ident);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -504,12 +513,6 @@ fn check_trait_item(&mut self, cx: &LateContext<'_>, ti: &hir::TraitItem<'_>) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_impl_item(&mut self, cx: &LateContext<'_>, ii: &hir::ImplItem<'_>) {
|
|
||||||
if let hir::ImplItemKind::Const(..) = ii.kind {
|
|
||||||
NonUpperCaseGlobals::check_upper_case(cx, "associated constant", &ii.ident);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn check_pat(&mut self, cx: &LateContext<'_>, p: &hir::Pat<'_>) {
|
fn check_pat(&mut self, cx: &LateContext<'_>, p: &hir::Pat<'_>) {
|
||||||
// Lint for constants that look like binding identifiers (#7526)
|
// Lint for constants that look like binding identifiers (#7526)
|
||||||
if let PatKind::Path(hir::QPath::Resolved(None, ref path)) = p.kind {
|
if let PatKind::Path(hir::QPath::Resolved(None, ref path)) = p.kind {
|
||||||
|
15
tests/ui/lint/lint-non-uppercase-trait-assoc-const.rs
Normal file
15
tests/ui/lint/lint-non-uppercase-trait-assoc-const.rs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#![deny(non_upper_case_globals)]
|
||||||
|
|
||||||
|
trait Trait {
|
||||||
|
const item: usize;
|
||||||
|
//~^ ERROR associated constant `item` should have an upper case name [non_upper_case_globals]
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Foo;
|
||||||
|
|
||||||
|
impl Trait for Foo {
|
||||||
|
const item: usize = 5;
|
||||||
|
// ^^^ there should be no error here (in the trait `impl`)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
14
tests/ui/lint/lint-non-uppercase-trait-assoc-const.stderr
Normal file
14
tests/ui/lint/lint-non-uppercase-trait-assoc-const.stderr
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
error: associated constant `item` should have an upper case name
|
||||||
|
--> $DIR/lint-non-uppercase-trait-assoc-const.rs:4:11
|
||||||
|
|
|
||||||
|
LL | const item: usize;
|
||||||
|
| ^^^^ help: convert the identifier to upper case: `ITEM`
|
||||||
|
|
|
||||||
|
note: the lint level is defined here
|
||||||
|
--> $DIR/lint-non-uppercase-trait-assoc-const.rs:1:9
|
||||||
|
|
|
||||||
|
LL | #![deny(non_upper_case_globals)]
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
Loading…
Reference in New Issue
Block a user