Skip to content

Commit 4f3ff5a

Browse files
committed
Auto merge of #54101 - osa1:issue_54099, r=nikomatsakis
Fix camel case type warning for types with trailing underscores Fixes #54099
2 parents 1e21c9a + 07646bb commit 4f3ff5a

File tree

4 files changed

+19
-13
lines changed

4 files changed

+19
-13
lines changed

src/librustc_lint/nonstandard_style.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ impl NonCamelCaseTypes {
5959

6060
fn is_camel_case(name: ast::Name) -> bool {
6161
let name = name.as_str();
62+
let name = name.trim_matches('_');
6263
if name.is_empty() {
6364
return true;
6465
}
65-
let name = name.trim_matches('_');
6666

6767
// start with a non-lowercase letter rather than non-uppercase
6868
// ones (some scripts don't have a concept of upper/lowercase)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// compile-pass
2+
3+
#![forbid(non_camel_case_types)]
4+
#![allow(dead_code)]
5+
6+
// None of the following types should generate a warning
7+
struct _X {}
8+
struct __X {}
9+
struct __ {}
10+
struct X_ {}
11+
struct X__ {}
12+
struct X___ {}
13+
14+
fn main() { }

src/test/ui/lint/lint-non-camel-case-types.rs

-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ struct foo7 {
4343
bar: isize,
4444
}
4545

46-
type __ = isize; //~ ERROR type `__` should have a camel case name such as `CamelCase`
47-
4846
struct X86_64;
4947

5048
struct X86__64; //~ ERROR type `X86__64` should have a camel case name such as `X86_64`

src/test/ui/lint/lint-non-camel-case-types.stderr

+4-10
Original file line numberDiff line numberDiff line change
@@ -60,29 +60,23 @@ error: type parameter `ty` should have a camel case name such as `Ty`
6060
LL | fn f<ty>(_: ty) {} //~ ERROR type parameter `ty` should have a camel case name such as `Ty`
6161
| ^^
6262

63-
error: type `__` should have a camel case name such as `CamelCase`
64-
--> $DIR/lint-non-camel-case-types.rs:46:1
65-
|
66-
LL | type __ = isize; //~ ERROR type `__` should have a camel case name such as `CamelCase`
67-
| ^^^^^^^^^^^^^^^^
68-
6963
error: type `X86__64` should have a camel case name such as `X86_64`
70-
--> $DIR/lint-non-camel-case-types.rs:50:1
64+
--> $DIR/lint-non-camel-case-types.rs:48:1
7165
|
7266
LL | struct X86__64; //~ ERROR type `X86__64` should have a camel case name such as `X86_64`
7367
| ^^^^^^^^^^^^^^^
7468

7569
error: type `Abc_123` should have a camel case name such as `Abc123`
76-
--> $DIR/lint-non-camel-case-types.rs:52:1
70+
--> $DIR/lint-non-camel-case-types.rs:50:1
7771
|
7872
LL | struct Abc_123; //~ ERROR type `Abc_123` should have a camel case name such as `Abc123`
7973
| ^^^^^^^^^^^^^^^
8074

8175
error: type `A1_b2_c3` should have a camel case name such as `A1B2C3`
82-
--> $DIR/lint-non-camel-case-types.rs:54:1
76+
--> $DIR/lint-non-camel-case-types.rs:52:1
8377
|
8478
LL | struct A1_b2_c3; //~ ERROR type `A1_b2_c3` should have a camel case name such as `A1B2C3`
8579
| ^^^^^^^^^^^^^^^^
8680

87-
error: aborting due to 12 previous errors
81+
error: aborting due to 11 previous errors
8882

0 commit comments

Comments
 (0)