Skip to content

Fix camel case type warning for types with trailing underscores #54101

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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___ {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking around, I couldn't find many tests for this lint really...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

e.g., to see whether X_X would fail

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I actually don't know the answer to that myself -- that is whether X_X is camel case or not. Btw there are a few more tests about this in lint-non-camel-case-types.rs.


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`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well... The former message was not wrong per se. But pretty much useless

We should probably just add underscore-only identifiers to the https://rust-lang-nursery.github.io/rust-clippy/master/index.html#just_underscores_and_digits lint in clippy


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