fire "non_camel_case_types" for associated types

This commit is contained in:
Andy Russell 2020-01-06 09:51:23 -05:00
parent a80e63f3fa
commit a7727c59ac
No known key found for this signature in database
GPG key ID: BE2221033EDBC374
5 changed files with 18 additions and 2 deletions

View file

@ -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);
}

View file

@ -1,5 +1,6 @@
// check-pass
#![allow(dead_code)]
#![allow(non_camel_case_types)]
// pretty-expanded FIXME #23616
trait Person {

View file

@ -1,5 +1,7 @@
// run-pass
#![allow(non_camel_case_types)]
#![allow(unused_variables)]
trait Foo {
type bar;
fn bar();

View file

@ -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) { }
}

View file

@ -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>(_: ty) {}
| ^^ help: convert the identifier to upper camel case: `Ty`
error: aborting due to 8 previous errors
error: aborting due to 9 previous errors