Skip to content

Commit 05d4c81

Browse files
authored
Rollup merge of rust-lang#73839 - crlf0710:snapshot_the_reality, r=Manishearth
Split and expand nonstandard-style lints unicode unit test. RFC 2457 requested that the `nonstandard_style` series of linted be adjusted to cover the non_ascii_identifier case. However when i read the code of those implementations, it seems they're already supporting non_ascii_identifiers. But the exact rules is a little different than what's proposed in RFC 2457. So I splitted and expanded the existing test case to try to exercise every branch in the code. I think it'll also be easier to examine the cases in these unit tests to see whether it's ok to just leave them as is, or some adjustments are needed. r? @Manishearth
2 parents a6ca459 + e8f5785 commit 05d4c81

7 files changed

+189
-16
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#![allow(dead_code)]
2+
3+
#![forbid(non_camel_case_types)]
4+
#![feature(non_ascii_idents)]
5+
6+
// Some scripts (e.g., hiragana) don't have a concept of
7+
// upper/lowercase
8+
9+
// 1. non_camel_case_types
10+
11+
// Can start with non-lowercase letter
12+
struct Θχ;
13+
struct ヒa;
14+
15+
struct χa;
16+
//~^ ERROR type `χa` should have an upper camel case name
17+
18+
// If there's already leading or trailing underscores, they get trimmed before checking.
19+
// This is fine:
20+
struct _ヒb;
21+
22+
// This is not:
23+
struct __χa;
24+
//~^ ERROR type `__χa` should have an upper camel case name
25+
26+
// Besides this, we cannot have two continous underscores in the middle.
27+
28+
struct 对__否;
29+
//~^ ERROR type `对__否` should have an upper camel case name
30+
31+
struct ヒ__χ;
32+
//~^ ERROR type `ヒ__χ` should have an upper camel case name
33+
34+
// also cannot have lowercase letter next to a underscore.
35+
// so this triggers the lint:
36+
37+
struct Hello_你好;
38+
//~^ ERROR type `Hello_你好` should have an upper camel case name
39+
40+
struct Hello_World;
41+
//~^ ERROR type `Hello_World` should have an upper camel case name
42+
43+
struct 你_ӟ;
44+
//~^ ERROR type `你_ӟ` should have an upper camel case name
45+
46+
// and this is ok:
47+
48+
struct 你_好;
49+
50+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
error: type `χa` should have an upper camel case name
2+
--> $DIR/lint-nonstandard-style-unicode-1.rs:15:8
3+
|
4+
LL | struct χa;
5+
| ^^ help: convert the identifier to upper camel case: `Χa`
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/lint-nonstandard-style-unicode-1.rs:3:11
9+
|
10+
LL | #![forbid(non_camel_case_types)]
11+
| ^^^^^^^^^^^^^^^^^^^^
12+
13+
error: type `__χa` should have an upper camel case name
14+
--> $DIR/lint-nonstandard-style-unicode-1.rs:23:8
15+
|
16+
LL | struct __χa;
17+
| ^^^^ help: convert the identifier to upper camel case: `Χa`
18+
19+
error: type `对__否` should have an upper camel case name
20+
--> $DIR/lint-nonstandard-style-unicode-1.rs:28:8
21+
|
22+
LL | struct 对__否;
23+
| ^^^^^^ help: convert the identifier to upper camel case: `对_否`
24+
25+
error: type `ヒ__χ` should have an upper camel case name
26+
--> $DIR/lint-nonstandard-style-unicode-1.rs:31:8
27+
|
28+
LL | struct ヒ__χ;
29+
| ^^^^^ help: convert the identifier to upper camel case: `ヒΧ`
30+
31+
error: type `Hello_你好` should have an upper camel case name
32+
--> $DIR/lint-nonstandard-style-unicode-1.rs:37:8
33+
|
34+
LL | struct Hello_你好;
35+
| ^^^^^^^^^^ help: convert the identifier to upper camel case: `Hello你好`
36+
37+
error: type `Hello_World` should have an upper camel case name
38+
--> $DIR/lint-nonstandard-style-unicode-1.rs:40:8
39+
|
40+
LL | struct Hello_World;
41+
| ^^^^^^^^^^^ help: convert the identifier to upper camel case: `HelloWorld`
42+
43+
error: type `你_ӟ` should have an upper camel case name
44+
--> $DIR/lint-nonstandard-style-unicode-1.rs:43:8
45+
|
46+
LL | struct 你_ӟ;
47+
| ^^^^ help: convert the identifier to upper camel case: `你Ӟ`
48+
49+
error: aborting due to 7 previous errors
50+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#![allow(dead_code)]
2+
3+
#![forbid(non_snake_case)]
4+
#![feature(non_ascii_idents)]
5+
6+
// Some scripts (e.g., hiragana) don't have a concept of
7+
// upper/lowercase
8+
9+
// 2. non_snake_case
10+
11+
// Can only use non-uppercase letters.
12+
// So this works:
13+
14+
fn 编程() {}
15+
16+
// but this doesn't:
17+
18+
fn Ц() {}
19+
//~^ ERROR function `Ц` should have a snake case name
20+
21+
// besides this, you cannot use continous underscores in the middle
22+
23+
fn 分__隔() {}
24+
//~^ ERROR function `分__隔` should have a snake case name
25+
26+
// but you can use them both at the beginning and at the end.
27+
28+
fn _______不_连_续_的_存_在_______() {}
29+
30+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error: function `Ц` should have a snake case name
2+
--> $DIR/lint-nonstandard-style-unicode-2.rs:18:4
3+
|
4+
LL | fn Ц() {}
5+
| ^ help: convert the identifier to snake case: `ц`
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/lint-nonstandard-style-unicode-2.rs:3:11
9+
|
10+
LL | #![forbid(non_snake_case)]
11+
| ^^^^^^^^^^^^^^
12+
13+
error: function `分__隔` should have a snake case name
14+
--> $DIR/lint-nonstandard-style-unicode-2.rs:23:4
15+
|
16+
LL | fn 分__隔() {}
17+
| ^^^^^^ help: convert the identifier to snake case: `分_隔`
18+
19+
error: aborting due to 2 previous errors
20+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#![allow(dead_code)]
2+
3+
#![forbid(non_upper_case_globals)]
4+
#![feature(non_ascii_idents)]
5+
6+
// Some scripts (e.g., hiragana) don't have a concept of
7+
// upper/lowercase
8+
9+
// 3. non_upper_case_globals
10+
11+
// Can only use non-lowercase letters.
12+
// So this works:
13+
14+
static: usize = 0;
15+
16+
// but this doesn't:
17+
18+
static τεχ: f32 = 3.14159265;
19+
//~^ ERROR static variable `τεχ` should have an upper case name
20+
21+
// This has no limit at all on underscore usages.
22+
23+
static __密__封__线__内__禁__止__答__题__: bool = true;
24+
25+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error: static variable `τεχ` should have an upper case name
2+
--> $DIR/lint-nonstandard-style-unicode-3.rs:18:8
3+
|
4+
LL | static τεχ: f32 = 3.14159265;
5+
| ^^^ help: convert the identifier to upper case: `ΤΕΧ`
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/lint-nonstandard-style-unicode-3.rs:3:11
9+
|
10+
LL | #![forbid(non_upper_case_globals)]
11+
| ^^^^^^^^^^^^^^^^^^^^^^
12+
13+
error: aborting due to previous error
14+

src/test/ui/lint/lint-nonstandard-style-unicode.rs

-16
This file was deleted.

0 commit comments

Comments
 (0)