parent
b70baa4f92
commit
08a0e71ec9
3 changed files with 37 additions and 1 deletions
|
@ -175,13 +175,23 @@ impl EarlyLintPass for NonCamelCaseTypes {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
match it.kind {
|
match &it.kind {
|
||||||
ast::ItemKind::TyAlias(..)
|
ast::ItemKind::TyAlias(..)
|
||||||
| ast::ItemKind::Enum(..)
|
| ast::ItemKind::Enum(..)
|
||||||
| ast::ItemKind::Struct(..)
|
| ast::ItemKind::Struct(..)
|
||||||
| ast::ItemKind::Union(..) => self.check_case(cx, "type", &it.ident),
|
| ast::ItemKind::Union(..) => self.check_case(cx, "type", &it.ident),
|
||||||
ast::ItemKind::Trait(..) => self.check_case(cx, "trait", &it.ident),
|
ast::ItemKind::Trait(..) => self.check_case(cx, "trait", &it.ident),
|
||||||
ast::ItemKind::TraitAlias(..) => self.check_case(cx, "trait alias", &it.ident),
|
ast::ItemKind::TraitAlias(..) => self.check_case(cx, "trait alias", &it.ident),
|
||||||
|
|
||||||
|
// N.B. This check is only for inherent associated types, so that we don't lint against
|
||||||
|
// trait impls where we should have warned for the trait definition already.
|
||||||
|
ast::ItemKind::Impl(box ast::Impl { of_trait: None, items, .. }) => {
|
||||||
|
for it in items {
|
||||||
|
if let ast::AssocItemKind::Type(..) = it.kind {
|
||||||
|
self.check_case(cx, "associated type", &it.ident);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
12
src/test/ui/associated-inherent-types/style.rs
Normal file
12
src/test/ui/associated-inherent-types/style.rs
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
#![feature(inherent_associated_types)]
|
||||||
|
#![allow(incomplete_features, dead_code)]
|
||||||
|
#![deny(non_camel_case_types)]
|
||||||
|
|
||||||
|
struct S;
|
||||||
|
|
||||||
|
impl S {
|
||||||
|
type typ = ();
|
||||||
|
//~^ ERROR associated type `typ` should have an upper camel case name
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
14
src/test/ui/associated-inherent-types/style.stderr
Normal file
14
src/test/ui/associated-inherent-types/style.stderr
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
error: associated type `typ` should have an upper camel case name
|
||||||
|
--> $DIR/style.rs:8:10
|
||||||
|
|
|
||||||
|
LL | type typ = ();
|
||||||
|
| ^^^ help: convert the identifier to upper camel case: `Typ`
|
||||||
|
|
|
||||||
|
note: the lint level is defined here
|
||||||
|
--> $DIR/style.rs:3:9
|
||||||
|
|
|
||||||
|
LL | #![deny(non_camel_case_types)]
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue