diff options
| author | bors <bors@rust-lang.org> | 2018-09-19 09:20:36 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-09-19 09:20:36 +0000 |
| commit | 4f3ff5a97bcd2d05ee0c768122752dc74f96ccc3 (patch) | |
| tree | 474427685bd959478cb7902d3f6b2f22d7e6b686 | |
| parent | 1e21c9a297a9fe668d62887a3a6a4add8e717b17 (diff) | |
| parent | 07646bb387001b870d598d7e921fc480c789d337 (diff) | |
| download | rust-4f3ff5a97bcd2d05ee0c768122752dc74f96ccc3.tar.gz rust-4f3ff5a97bcd2d05ee0c768122752dc74f96ccc3.zip | |
Auto merge of #54101 - osa1:issue_54099, r=nikomatsakis
Fix camel case type warning for types with trailing underscores Fixes #54099
| -rw-r--r-- | src/librustc_lint/nonstandard_style.rs | 2 | ||||
| -rw-r--r-- | src/test/ui/lint/issue-54099-camel-case-underscore-types.rs | 14 | ||||
| -rw-r--r-- | src/test/ui/lint/lint-non-camel-case-types.rs | 2 | ||||
| -rw-r--r-- | src/test/ui/lint/lint-non-camel-case-types.stderr | 14 |
4 files changed, 19 insertions, 13 deletions
diff --git a/src/librustc_lint/nonstandard_style.rs b/src/librustc_lint/nonstandard_style.rs index 09871c0e840..56d204f15d9 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 00000000000..e4be1edc5d7 --- /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 5dcdf3a863f..2f0b6c57d55 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 85610dc7fa3..05834a66cd0 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>(_: 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 |
