Skip to content

Commit

Permalink
Auto merge of #85732 - Smittyvb:trait-alias-camelcase-lint, r=varkor
Browse files Browse the repository at this point in the history
Lint against non-CamelCase trait alias names

Type aliases are linted as such, so (unstable) trait aliases should be treated the same way.
  • Loading branch information
bors committed May 27, 2021
2 parents 9814e83 + edef5bc commit 8d1e3d3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions compiler/rustc_lint/src/nonstandard_style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ impl EarlyLintPass for NonCamelCaseTypes {
| ast::ItemKind::Struct(..)
| ast::ItemKind::Union(..) => self.check_case(cx, "type", &it.ident),
ast::ItemKind::Trait(..) => self.check_case(cx, "trait", &it.ident),
ast::ItemKind::TraitAlias(..) => self.check_case(cx, "trait alias", &it.ident),
_ => (),
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/test/ui/traits/alias/style_lint.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// check-pass

#![feature(trait_alias)]

trait Foo = std::fmt::Display + std::fmt::Debug;
trait bar = std::fmt::Display + std::fmt::Debug; //~WARN trait alias `bar` should have an upper camel case name

fn main() {}
10 changes: 10 additions & 0 deletions src/test/ui/traits/alias/style_lint.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
warning: trait alias `bar` should have an upper camel case name
--> $DIR/style_lint.rs:6:7
|
LL | trait bar = std::fmt::Display + std::fmt::Debug;
| ^^^ help: convert the identifier to upper camel case: `Bar`
|
= note: `#[warn(non_camel_case_types)]` on by default

warning: 1 warning emitted

0 comments on commit 8d1e3d3

Please sign in to comment.