From a7727c59ac0b80fbbd7b3ab045260727ab64ce21 Mon Sep 17 00:00:00 2001 From: Andy Russell Date: Mon, 6 Jan 2020 09:51:23 -0500 Subject: [PATCH] fire "non_camel_case_types" for associated types --- src/librustc_lint/nonstandard_style.rs | 6 ++++++ src/test/ui/issues/issue-17732.rs | 1 + src/test/ui/issues/issue-35600.rs | 2 ++ src/test/ui/lint/lint-non-camel-case-types.rs | 1 + src/test/ui/lint/lint-non-camel-case-types.stderr | 10 ++++++++-- 5 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/librustc_lint/nonstandard_style.rs b/src/librustc_lint/nonstandard_style.rs index a97061c50ae45..524de2cf40a83 100644 --- a/src/librustc_lint/nonstandard_style.rs +++ b/src/librustc_lint/nonstandard_style.rs @@ -142,6 +142,12 @@ impl EarlyLintPass for NonCamelCaseTypes { } } + fn check_trait_item(&mut self, cx: &EarlyContext<'_>, it: &ast::AssocItem) { + if let ast::AssocItemKind::TyAlias(..) = it.kind { + self.check_case(cx, "associated type", &it.ident); + } + } + fn check_variant(&mut self, cx: &EarlyContext<'_>, v: &ast::Variant) { self.check_case(cx, "variant", &v.ident); } diff --git a/src/test/ui/issues/issue-17732.rs b/src/test/ui/issues/issue-17732.rs index 5e11fc4fcfb58..8f63d5baef875 100644 --- a/src/test/ui/issues/issue-17732.rs +++ b/src/test/ui/issues/issue-17732.rs @@ -1,5 +1,6 @@ // check-pass #![allow(dead_code)] +#![allow(non_camel_case_types)] // pretty-expanded FIXME #23616 trait Person { diff --git a/src/test/ui/issues/issue-35600.rs b/src/test/ui/issues/issue-35600.rs index 9d74726d279e5..f0bab6010d724 100644 --- a/src/test/ui/issues/issue-35600.rs +++ b/src/test/ui/issues/issue-35600.rs @@ -1,5 +1,7 @@ // run-pass +#![allow(non_camel_case_types)] #![allow(unused_variables)] + trait Foo { type bar; fn bar(); diff --git a/src/test/ui/lint/lint-non-camel-case-types.rs b/src/test/ui/lint/lint-non-camel-case-types.rs index d3b119a944109..acd5c5df9e8f6 100644 --- a/src/test/ui/lint/lint-non-camel-case-types.rs +++ b/src/test/ui/lint/lint-non-camel-case-types.rs @@ -23,6 +23,7 @@ enum Foo5 { } trait foo6 { //~ ERROR trait `foo6` should have an upper camel case name + type foo7; //~ ERROR associated type `foo7` should have an upper camel case name fn dummy(&self) { } } diff --git a/src/test/ui/lint/lint-non-camel-case-types.stderr b/src/test/ui/lint/lint-non-camel-case-types.stderr index 177f8c8fe9b63..f82eefed4368a 100644 --- a/src/test/ui/lint/lint-non-camel-case-types.stderr +++ b/src/test/ui/lint/lint-non-camel-case-types.stderr @@ -46,11 +46,17 @@ error: trait `foo6` should have an upper camel case name LL | trait foo6 { | ^^^^ help: convert the identifier to upper camel case (notice the capitalization): `Foo6` +error: associated type `foo7` should have an upper camel case name + --> $DIR/lint-non-camel-case-types.rs:26:10 + | +LL | type foo7; + | ^^^^ help: convert the identifier to upper camel case (notice the capitalization): `Foo7` + error: type parameter `ty` should have an upper camel case name - --> $DIR/lint-non-camel-case-types.rs:29:6 + --> $DIR/lint-non-camel-case-types.rs:30:6 | LL | fn f(_: ty) {} | ^^ help: convert the identifier to upper camel case: `Ty` -error: aborting due to 8 previous errors +error: aborting due to 9 previous errors