Skip to content

Commit

Permalink
Auto merge of #54101 - osa1:issue_54099, r=nikomatsakis
Browse files Browse the repository at this point in the history
Fix camel case type warning for types with trailing underscores

Fixes #54099
  • Loading branch information
bors committed Sep 19, 2018
2 parents 1e21c9a + 07646bb commit 4f3ff5a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/librustc_lint/nonstandard_style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 14 additions & 0 deletions src/test/ui/lint/issue-54099-camel-case-underscore-types.rs
Original file line number Diff line number Diff line change
@@ -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() { }
2 changes: 0 additions & 2 deletions src/test/ui/lint/lint-non-camel-case-types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
14 changes: 4 additions & 10 deletions src/test/ui/lint/lint-non-camel-case-types.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 4f3ff5a

Please sign in to comment.