From 07646bb387001b870d598d7e921fc480c789d337 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Sinan=20A=C4=9Facan?= Date: Mon, 10 Sep 2018 16:43:50 +0300 Subject: [PATCH] Fix camel case type warning for types with trailing underscores Fixes #54099 --- src/librustc_lint/nonstandard_style.rs | 2 +- .../issue-54099-camel-case-underscore-types.rs | 14 ++++++++++++++ src/test/ui/lint/lint-non-camel-case-types.rs | 2 -- src/test/ui/lint/lint-non-camel-case-types.stderr | 14 ++++---------- 4 files changed, 19 insertions(+), 13 deletions(-) create mode 100644 src/test/ui/lint/issue-54099-camel-case-underscore-types.rs diff --git a/src/librustc_lint/nonstandard_style.rs b/src/librustc_lint/nonstandard_style.rs index 09871c0e84049..56d204f15d935 100644 --- a/src/librustc_lint/nonstandard_style.rs +++ b/src/librustc_lint/nonstandard_style.rs @@ -59,10 +59,10 @@ impl NonCamelCaseTypes { fn is_camel_case(name: ast::Name) -> bool { let name = name.as_str(); + let name = name.trim_matches('_'); if name.is_empty() { return true; } - let name = name.trim_matches('_'); // start with a non-lowercase letter rather than non-uppercase // ones (some scripts don't have a concept of upper/lowercase) diff --git a/src/test/ui/lint/issue-54099-camel-case-underscore-types.rs b/src/test/ui/lint/issue-54099-camel-case-underscore-types.rs new file mode 100644 index 0000000000000..e4be1edc5d7b5 --- /dev/null +++ b/src/test/ui/lint/issue-54099-camel-case-underscore-types.rs @@ -0,0 +1,14 @@ +// compile-pass + +#![forbid(non_camel_case_types)] +#![allow(dead_code)] + +// None of the following types should generate a warning +struct _X {} +struct __X {} +struct __ {} +struct X_ {} +struct X__ {} +struct X___ {} + +fn main() { } 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 5dcdf3a863f87..2f0b6c57d55d0 100644 --- a/src/test/ui/lint/lint-non-camel-case-types.rs +++ b/src/test/ui/lint/lint-non-camel-case-types.rs @@ -43,8 +43,6 @@ struct foo7 { bar: isize, } -type __ = isize; //~ ERROR type `__` should have a camel case name such as `CamelCase` - struct X86_64; struct X86__64; //~ ERROR type `X86__64` should have a camel case name such as `X86_64` 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 85610dc7fa379..05834a66cd051 100644 --- a/src/test/ui/lint/lint-non-camel-case-types.stderr +++ b/src/test/ui/lint/lint-non-camel-case-types.stderr @@ -60,29 +60,23 @@ error: type parameter `ty` should have a camel case name such as `Ty` LL | fn f(_: ty) {} //~ ERROR type parameter `ty` should have a camel case name such as `Ty` | ^^ -error: type `__` should have a camel case name such as `CamelCase` - --> $DIR/lint-non-camel-case-types.rs:46:1 - | -LL | type __ = isize; //~ ERROR type `__` should have a camel case name such as `CamelCase` - | ^^^^^^^^^^^^^^^^ - error: type `X86__64` should have a camel case name such as `X86_64` - --> $DIR/lint-non-camel-case-types.rs:50:1 + --> $DIR/lint-non-camel-case-types.rs:48:1 | LL | struct X86__64; //~ ERROR type `X86__64` should have a camel case name such as `X86_64` | ^^^^^^^^^^^^^^^ error: type `Abc_123` should have a camel case name such as `Abc123` - --> $DIR/lint-non-camel-case-types.rs:52:1 + --> $DIR/lint-non-camel-case-types.rs:50:1 | LL | struct Abc_123; //~ ERROR type `Abc_123` should have a camel case name such as `Abc123` | ^^^^^^^^^^^^^^^ error: type `A1_b2_c3` should have a camel case name such as `A1B2C3` - --> $DIR/lint-non-camel-case-types.rs:54:1 + --> $DIR/lint-non-camel-case-types.rs:52:1 | LL | struct A1_b2_c3; //~ ERROR type `A1_b2_c3` should have a camel case name such as `A1B2C3` | ^^^^^^^^^^^^^^^^ -error: aborting due to 12 previous errors +error: aborting due to 11 previous errors