diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
commit | 698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch) | |
tree | 173a775858bd501c378080a10dca74132f05bc50 /src/test/ui/lint/rfc-2457-non-ascii-idents | |
parent | Initial commit. (diff) | |
download | rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip |
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/ui/lint/rfc-2457-non-ascii-idents')
9 files changed, 194 insertions, 0 deletions
diff --git a/src/test/ui/lint/rfc-2457-non-ascii-idents/lint-confusable-idents.rs b/src/test/ui/lint/rfc-2457-non-ascii-idents/lint-confusable-idents.rs new file mode 100644 index 000000000..e7da825ae --- /dev/null +++ b/src/test/ui/lint/rfc-2457-non-ascii-idents/lint-confusable-idents.rs @@ -0,0 +1,16 @@ +#![deny(confusable_idents)] +#![allow(uncommon_codepoints, non_upper_case_globals)] + +const s: usize = 42; +const s_s: usize = 42; + +fn main() { + let s = "rust"; //~ ERROR identifier pair considered confusable + let s_s = "rust2"; //~ ERROR identifier pair considered confusable + not_affected(); +} + +fn not_affected() { + let s1 = 1; + let sl = 'l'; +} diff --git a/src/test/ui/lint/rfc-2457-non-ascii-idents/lint-confusable-idents.stderr b/src/test/ui/lint/rfc-2457-non-ascii-idents/lint-confusable-idents.stderr new file mode 100644 index 000000000..e9906c83d --- /dev/null +++ b/src/test/ui/lint/rfc-2457-non-ascii-idents/lint-confusable-idents.stderr @@ -0,0 +1,26 @@ +error: identifier pair considered confusable between `s` and `s` + --> $DIR/lint-confusable-idents.rs:8:9 + | +LL | const s: usize = 42; + | -- this is where the previous identifier occurred +... +LL | let s = "rust"; + | ^ + | +note: the lint level is defined here + --> $DIR/lint-confusable-idents.rs:1:9 + | +LL | #![deny(confusable_idents)] + | ^^^^^^^^^^^^^^^^^ + +error: identifier pair considered confusable between `s_s` and `s_s` + --> $DIR/lint-confusable-idents.rs:9:9 + | +LL | const s_s: usize = 42; + | --- this is where the previous identifier occurred +... +LL | let s_s = "rust2"; + | ^^^^^ + +error: aborting due to 2 previous errors + diff --git a/src/test/ui/lint/rfc-2457-non-ascii-idents/lint-mixed-script-confusables-2.rs b/src/test/ui/lint/rfc-2457-non-ascii-idents/lint-mixed-script-confusables-2.rs new file mode 100644 index 000000000..f62c8a190 --- /dev/null +++ b/src/test/ui/lint/rfc-2457-non-ascii-idents/lint-mixed-script-confusables-2.rs @@ -0,0 +1,19 @@ +// check-pass +#![deny(mixed_script_confusables)] + +struct ΑctuallyNotLatin; + +fn main() { + let λ = 42; // this usage of Greek confirms that Greek is used intentionally. +} + +mod роре { + const エ: &'static str = "アイウ"; + + // this usage of Katakana confirms that Katakana is used intentionally. + fn ニャン() { + let д: usize = 100; // this usage of Cyrillic confirms that Cyrillic is used intentionally. + + println!("meow!"); + } +} diff --git a/src/test/ui/lint/rfc-2457-non-ascii-idents/lint-mixed-script-confusables.rs b/src/test/ui/lint/rfc-2457-non-ascii-idents/lint-mixed-script-confusables.rs new file mode 100644 index 000000000..9d837d41f --- /dev/null +++ b/src/test/ui/lint/rfc-2457-non-ascii-idents/lint-mixed-script-confusables.rs @@ -0,0 +1,14 @@ +#![deny(mixed_script_confusables)] + +struct ΑctuallyNotLatin; +//~^ ERROR the usage of Script Group `Greek` in this crate consists solely of + +fn main() { + let v = ΑctuallyNotLatin; +} + +mod роре { +//~^ ERROR the usage of Script Group `Cyrillic` in this crate consists solely of + const エ: &'static str = "アイウ"; + //~^ ERROR the usage of Script Group `Japanese, Katakana` in this crate consists solely of +} diff --git a/src/test/ui/lint/rfc-2457-non-ascii-idents/lint-mixed-script-confusables.stderr b/src/test/ui/lint/rfc-2457-non-ascii-idents/lint-mixed-script-confusables.stderr new file mode 100644 index 000000000..9ca034b71 --- /dev/null +++ b/src/test/ui/lint/rfc-2457-non-ascii-idents/lint-mixed-script-confusables.stderr @@ -0,0 +1,34 @@ +error: the usage of Script Group `Greek` in this crate consists solely of mixed script confusables + --> $DIR/lint-mixed-script-confusables.rs:3:8 + | +LL | struct ΑctuallyNotLatin; + | ^^^^^^^^^^^^^^^^ + | +note: the lint level is defined here + --> $DIR/lint-mixed-script-confusables.rs:1:9 + | +LL | #![deny(mixed_script_confusables)] + | ^^^^^^^^^^^^^^^^^^^^^^^^ + = note: the usage includes 'Α' (U+0391) + = note: please recheck to make sure their usages are indeed what you want + +error: the usage of Script Group `Cyrillic` in this crate consists solely of mixed script confusables + --> $DIR/lint-mixed-script-confusables.rs:10:5 + | +LL | mod роре { + | ^^^^ + | + = note: the usage includes 'е' (U+0435), 'о' (U+043E), 'р' (U+0440) + = note: please recheck to make sure their usages are indeed what you want + +error: the usage of Script Group `Japanese, Katakana` in this crate consists solely of mixed script confusables + --> $DIR/lint-mixed-script-confusables.rs:12:11 + | +LL | const エ: &'static str = "アイウ"; + | ^^ + | + = note: the usage includes 'エ' (U+30A8) + = note: please recheck to make sure their usages are indeed what you want + +error: aborting due to 3 previous errors + diff --git a/src/test/ui/lint/rfc-2457-non-ascii-idents/lint-non-ascii-idents.rs b/src/test/ui/lint/rfc-2457-non-ascii-idents/lint-non-ascii-idents.rs new file mode 100644 index 000000000..8ae174409 --- /dev/null +++ b/src/test/ui/lint/rfc-2457-non-ascii-idents/lint-non-ascii-idents.rs @@ -0,0 +1,12 @@ +#![deny(non_ascii_idents)] + +const חלודה: usize = 2; //~ ERROR identifier contains non-ASCII characters + +fn coöperation() {} //~ ERROR identifier contains non-ASCII characters + +fn main() { + let naïveté = 2; //~ ERROR identifier contains non-ASCII characters + + // using the same identifier the second time won't trigger the lint. + println!("{}", naïveté); +} diff --git a/src/test/ui/lint/rfc-2457-non-ascii-idents/lint-non-ascii-idents.stderr b/src/test/ui/lint/rfc-2457-non-ascii-idents/lint-non-ascii-idents.stderr new file mode 100644 index 000000000..8ed7f093c --- /dev/null +++ b/src/test/ui/lint/rfc-2457-non-ascii-idents/lint-non-ascii-idents.stderr @@ -0,0 +1,26 @@ +error: identifier contains non-ASCII characters + --> $DIR/lint-non-ascii-idents.rs:3:7 + | +LL | const חלודה: usize = 2; + | ^^^^^ + | +note: the lint level is defined here + --> $DIR/lint-non-ascii-idents.rs:1:9 + | +LL | #![deny(non_ascii_idents)] + | ^^^^^^^^^^^^^^^^ + +error: identifier contains non-ASCII characters + --> $DIR/lint-non-ascii-idents.rs:5:4 + | +LL | fn coöperation() {} + | ^^^^^^^^^^^ + +error: identifier contains non-ASCII characters + --> $DIR/lint-non-ascii-idents.rs:8:9 + | +LL | let naïveté = 2; + | ^^^^^^^ + +error: aborting due to 3 previous errors + diff --git a/src/test/ui/lint/rfc-2457-non-ascii-idents/lint-uncommon-codepoints.rs b/src/test/ui/lint/rfc-2457-non-ascii-idents/lint-uncommon-codepoints.rs new file mode 100644 index 000000000..ed8e7dddd --- /dev/null +++ b/src/test/ui/lint/rfc-2457-non-ascii-idents/lint-uncommon-codepoints.rs @@ -0,0 +1,13 @@ +#![deny(uncommon_codepoints)] + +const µ: f64 = 0.000001; //~ ERROR identifier contains uncommon Unicode codepoints +//~| WARNING should have an upper case name + +fn dijkstra() {} //~ ERROR identifier contains uncommon Unicode codepoints + +fn main() { + let ㇻㇲㇳ = "rust"; //~ ERROR identifier contains uncommon Unicode codepoints + + // using the same identifier the second time won't trigger the lint. + println!("{}", ㇻㇲㇳ); +} diff --git a/src/test/ui/lint/rfc-2457-non-ascii-idents/lint-uncommon-codepoints.stderr b/src/test/ui/lint/rfc-2457-non-ascii-idents/lint-uncommon-codepoints.stderr new file mode 100644 index 000000000..0533da030 --- /dev/null +++ b/src/test/ui/lint/rfc-2457-non-ascii-idents/lint-uncommon-codepoints.stderr @@ -0,0 +1,34 @@ +error: identifier contains uncommon Unicode codepoints + --> $DIR/lint-uncommon-codepoints.rs:3:7 + | +LL | const µ: f64 = 0.000001; + | ^ + | +note: the lint level is defined here + --> $DIR/lint-uncommon-codepoints.rs:1:9 + | +LL | #![deny(uncommon_codepoints)] + | ^^^^^^^^^^^^^^^^^^^ + +error: identifier contains uncommon Unicode codepoints + --> $DIR/lint-uncommon-codepoints.rs:6:4 + | +LL | fn dijkstra() {} + | ^^^^^^^ + +error: identifier contains uncommon Unicode codepoints + --> $DIR/lint-uncommon-codepoints.rs:9:9 + | +LL | let ㇻㇲㇳ = "rust"; + | ^^^^^^ + +warning: constant `µ` should have an upper case name + --> $DIR/lint-uncommon-codepoints.rs:3:7 + | +LL | const µ: f64 = 0.000001; + | ^ help: convert the identifier to upper case: `Μ` + | + = note: `#[warn(non_upper_case_globals)]` on by default + +error: aborting due to 3 previous errors; 1 warning emitted + |