From edef5bc31bce648723ad0ddb2de4c0d1969fc8d0 Mon Sep 17 00:00:00 2001 From: Smitty Date: Wed, 26 May 2021 19:55:27 -0400 Subject: [PATCH] Lint against non-camelCase trait alias names Type aliases are linted as such, so (unstable) trait aliases should be treated the same way. --- compiler/rustc_lint/src/nonstandard_style.rs | 1 + src/test/ui/traits/alias/style_lint.rs | 8 ++++++++ src/test/ui/traits/alias/style_lint.stderr | 10 ++++++++++ 3 files changed, 19 insertions(+) create mode 100644 src/test/ui/traits/alias/style_lint.rs create mode 100644 src/test/ui/traits/alias/style_lint.stderr diff --git a/compiler/rustc_lint/src/nonstandard_style.rs b/compiler/rustc_lint/src/nonstandard_style.rs index be9c6eafb6fdb..7146dd51aa717 100644 --- a/compiler/rustc_lint/src/nonstandard_style.rs +++ b/compiler/rustc_lint/src/nonstandard_style.rs @@ -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), _ => (), } } diff --git a/src/test/ui/traits/alias/style_lint.rs b/src/test/ui/traits/alias/style_lint.rs new file mode 100644 index 0000000000000..33be20054b5d3 --- /dev/null +++ b/src/test/ui/traits/alias/style_lint.rs @@ -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() {} diff --git a/src/test/ui/traits/alias/style_lint.stderr b/src/test/ui/traits/alias/style_lint.stderr new file mode 100644 index 0000000000000..91e2ea90eb9e8 --- /dev/null +++ b/src/test/ui/traits/alias/style_lint.stderr @@ -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 +