summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorxizheyin <xizheyin@smail.nju.edu.cn>2025-07-31 00:44:22 +0800
committerxizheyin <xizheyin@smail.nju.edu.cn>2025-07-31 13:55:59 +0800
commit7b667e7811f4a4b496f38d25c5e824f13638cdbb (patch)
tree9f83495f50b35a78912892b17202811cb032728e /tests
parent32e7a4b92b109c24e9822c862a7c74436b50e564 (diff)
downloadrust-7b667e7811f4a4b496f38d25c5e824f13638cdbb.tar.gz
rust-7b667e7811f4a4b496f38d25c5e824f13638cdbb.zip
Extend `is_case_difference` to handle digit-letter confusables
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/error-codes/E0423.stderr2
-rw-r--r--tests/ui/lint/lint-non-uppercase-usages.stderr2
-rw-r--r--tests/ui/parser/item-kw-case-mismatch.stderr6
-rw-r--r--tests/ui/parser/kw-in-trait-bounds.stderr8
-rw-r--r--tests/ui/parser/misspelled-keywords/hrdt.stderr2
-rw-r--r--tests/ui/parser/misspelled-keywords/impl-return.stderr2
-rw-r--r--tests/ui/parser/misspelled-keywords/static.stderr2
-rw-r--r--tests/ui/parser/misspelled-keywords/struct.stderr2
-rw-r--r--tests/ui/parser/recover/recover-fn-trait-from-fn-kw.stderr4
-rw-r--r--tests/ui/parser/typod-const-in-const-param-def.stderr8
-rw-r--r--tests/ui/suggestions/assoc-ct-for-assoc-method.stderr2
-rw-r--r--tests/ui/suggestions/bool_typo_err_suggest.stderr2
-rw-r--r--tests/ui/suggestions/case-difference-suggestions.rs57
-rw-r--r--tests/ui/suggestions/case-difference-suggestions.stderr99
-rw-r--r--tests/ui/suggestions/incorrect-variant-literal.svg2
15 files changed, 178 insertions, 22 deletions
diff --git a/tests/ui/error-codes/E0423.stderr b/tests/ui/error-codes/E0423.stderr
index e50b8bd820c..b699e53fb48 100644
--- a/tests/ui/error-codes/E0423.stderr
+++ b/tests/ui/error-codes/E0423.stderr
@@ -54,7 +54,7 @@ help: use struct literal syntax instead
 LL -     let f = Foo();
 LL +     let f = Foo { a: val };
    |
-help: a function with a similar name exists (notice the capitalization difference)
+help: a function with a similar name exists (notice the capitalization)
    |
 LL -     let f = Foo();
 LL +     let f = foo();
diff --git a/tests/ui/lint/lint-non-uppercase-usages.stderr b/tests/ui/lint/lint-non-uppercase-usages.stderr
index 7c7e573a88e..b34be31216d 100644
--- a/tests/ui/lint/lint-non-uppercase-usages.stderr
+++ b/tests/ui/lint/lint-non-uppercase-usages.stderr
@@ -29,7 +29,7 @@ warning: const parameter `foo` should have an upper case name
 LL | fn foo<const foo: u32>() {
    |              ^^^
    |
-help: convert the identifier to upper case (notice the capitalization difference)
+help: convert the identifier to upper case (notice the capitalization)
    |
 LL - fn foo<const foo: u32>() {
 LL + fn foo<const FOO: u32>() {
diff --git a/tests/ui/parser/item-kw-case-mismatch.stderr b/tests/ui/parser/item-kw-case-mismatch.stderr
index df39eb10fdb..d2a1eb7f2f5 100644
--- a/tests/ui/parser/item-kw-case-mismatch.stderr
+++ b/tests/ui/parser/item-kw-case-mismatch.stderr
@@ -4,7 +4,7 @@ error: keyword `use` is written in the wrong case
 LL | Use std::ptr::read;
    | ^^^
    |
-help: write it in the correct case (notice the capitalization difference)
+help: write it in the correct case (notice the capitalization)
    |
 LL - Use std::ptr::read;
 LL + use std::ptr::read;
@@ -28,7 +28,7 @@ error: keyword `fn` is written in the wrong case
 LL | async Fn _a() {}
    |       ^^
    |
-help: write it in the correct case (notice the capitalization difference)
+help: write it in the correct case (notice the capitalization)
    |
 LL - async Fn _a() {}
 LL + async fn _a() {}
@@ -40,7 +40,7 @@ error: keyword `fn` is written in the wrong case
 LL | Fn _b() {}
    | ^^
    |
-help: write it in the correct case (notice the capitalization difference)
+help: write it in the correct case (notice the capitalization)
    |
 LL - Fn _b() {}
 LL + fn _b() {}
diff --git a/tests/ui/parser/kw-in-trait-bounds.stderr b/tests/ui/parser/kw-in-trait-bounds.stderr
index 1892d0b6226..5a4adf3e37b 100644
--- a/tests/ui/parser/kw-in-trait-bounds.stderr
+++ b/tests/ui/parser/kw-in-trait-bounds.stderr
@@ -4,7 +4,7 @@ error: expected identifier, found keyword `fn`
 LL | fn _f<F: fn(), G>(_: impl fn(), _: &dyn fn())
    |          ^^
    |
-help: use `Fn` to refer to the trait (notice the capitalization difference)
+help: use `Fn` to refer to the trait (notice the capitalization)
    |
 LL - fn _f<F: fn(), G>(_: impl fn(), _: &dyn fn())
 LL + fn _f<F: Fn(), G>(_: impl fn(), _: &dyn fn())
@@ -16,7 +16,7 @@ error: expected identifier, found keyword `fn`
 LL | fn _f<F: fn(), G>(_: impl fn(), _: &dyn fn())
    |                           ^^
    |
-help: use `Fn` to refer to the trait (notice the capitalization difference)
+help: use `Fn` to refer to the trait (notice the capitalization)
    |
 LL - fn _f<F: fn(), G>(_: impl fn(), _: &dyn fn())
 LL + fn _f<F: fn(), G>(_: impl Fn(), _: &dyn fn())
@@ -28,7 +28,7 @@ error: expected identifier, found keyword `fn`
 LL | fn _f<F: fn(), G>(_: impl fn(), _: &dyn fn())
    |                                         ^^
    |
-help: use `Fn` to refer to the trait (notice the capitalization difference)
+help: use `Fn` to refer to the trait (notice the capitalization)
    |
 LL - fn _f<F: fn(), G>(_: impl fn(), _: &dyn fn())
 LL + fn _f<F: fn(), G>(_: impl fn(), _: &dyn Fn())
@@ -40,7 +40,7 @@ error: expected identifier, found keyword `fn`
 LL | G: fn(),
    |    ^^
    |
-help: use `Fn` to refer to the trait (notice the capitalization difference)
+help: use `Fn` to refer to the trait (notice the capitalization)
    |
 LL - G: fn(),
 LL + G: Fn(),
diff --git a/tests/ui/parser/misspelled-keywords/hrdt.stderr b/tests/ui/parser/misspelled-keywords/hrdt.stderr
index e5fc1a50382..497bd613bf4 100644
--- a/tests/ui/parser/misspelled-keywords/hrdt.stderr
+++ b/tests/ui/parser/misspelled-keywords/hrdt.stderr
@@ -4,7 +4,7 @@ error: expected one of `!`, `(`, `+`, `::`, `<`, `where`, or `{`, found keyword
 LL |     Where for<'a> F: Fn(&'a (u8, u16)) -> &'a u8,
    |           ^^^ expected one of 7 possible tokens
    |
-help: write keyword `where` in lowercase (notice the capitalization difference)
+help: write keyword `where` in lowercase (notice the capitalization)
    |
 LL -     Where for<'a> F: Fn(&'a (u8, u16)) -> &'a u8,
 LL +     where for<'a> F: Fn(&'a (u8, u16)) -> &'a u8,
diff --git a/tests/ui/parser/misspelled-keywords/impl-return.stderr b/tests/ui/parser/misspelled-keywords/impl-return.stderr
index ff5391461a9..d49d962d7e9 100644
--- a/tests/ui/parser/misspelled-keywords/impl-return.stderr
+++ b/tests/ui/parser/misspelled-keywords/impl-return.stderr
@@ -4,7 +4,7 @@ error: expected one of `!`, `(`, `+`, `::`, `<`, `where`, or `{`, found `Display
 LL | fn code() -> Impl Display {}
    |                   ^^^^^^^ expected one of 7 possible tokens
    |
-help: write keyword `impl` in lowercase (notice the capitalization difference)
+help: write keyword `impl` in lowercase (notice the capitalization)
    |
 LL - fn code() -> Impl Display {}
 LL + fn code() -> impl Display {}
diff --git a/tests/ui/parser/misspelled-keywords/static.stderr b/tests/ui/parser/misspelled-keywords/static.stderr
index e559f2be109..0df40bcdc33 100644
--- a/tests/ui/parser/misspelled-keywords/static.stderr
+++ b/tests/ui/parser/misspelled-keywords/static.stderr
@@ -4,7 +4,7 @@ error: expected one of `!` or `::`, found `a`
 LL | Static a = 0;
    |        ^ expected one of `!` or `::`
    |
-help: write keyword `static` in lowercase (notice the capitalization difference)
+help: write keyword `static` in lowercase (notice the capitalization)
    |
 LL - Static a = 0;
 LL + static a = 0;
diff --git a/tests/ui/parser/misspelled-keywords/struct.stderr b/tests/ui/parser/misspelled-keywords/struct.stderr
index edbec3b9456..af8614ef14b 100644
--- a/tests/ui/parser/misspelled-keywords/struct.stderr
+++ b/tests/ui/parser/misspelled-keywords/struct.stderr
@@ -4,7 +4,7 @@ error: expected one of `!` or `::`, found `Foor`
 LL | Struct Foor {
    |        ^^^^ expected one of `!` or `::`
    |
-help: write keyword `struct` in lowercase (notice the capitalization difference)
+help: write keyword `struct` in lowercase (notice the capitalization)
    |
 LL - Struct Foor {
 LL + struct Foor {
diff --git a/tests/ui/parser/recover/recover-fn-trait-from-fn-kw.stderr b/tests/ui/parser/recover/recover-fn-trait-from-fn-kw.stderr
index 4e1fcaf4936..bd809e77a8f 100644
--- a/tests/ui/parser/recover/recover-fn-trait-from-fn-kw.stderr
+++ b/tests/ui/parser/recover/recover-fn-trait-from-fn-kw.stderr
@@ -4,7 +4,7 @@ error: expected identifier, found keyword `fn`
 LL | fn foo(_: impl fn() -> i32) {}
    |                ^^
    |
-help: use `Fn` to refer to the trait (notice the capitalization difference)
+help: use `Fn` to refer to the trait (notice the capitalization)
    |
 LL - fn foo(_: impl fn() -> i32) {}
 LL + fn foo(_: impl Fn() -> i32) {}
@@ -16,7 +16,7 @@ error: expected identifier, found keyword `fn`
 LL | fn foo2<T: fn(i32)>(_: T) {}
    |            ^^
    |
-help: use `Fn` to refer to the trait (notice the capitalization difference)
+help: use `Fn` to refer to the trait (notice the capitalization)
    |
 LL - fn foo2<T: fn(i32)>(_: T) {}
 LL + fn foo2<T: Fn(i32)>(_: T) {}
diff --git a/tests/ui/parser/typod-const-in-const-param-def.stderr b/tests/ui/parser/typod-const-in-const-param-def.stderr
index bf7168a0157..cc1600fe5cb 100644
--- a/tests/ui/parser/typod-const-in-const-param-def.stderr
+++ b/tests/ui/parser/typod-const-in-const-param-def.stderr
@@ -4,7 +4,7 @@ error: `const` keyword was mistyped as `Const`
 LL | pub fn foo<Const N: u8>() {}
    |            ^^^^^
    |
-help: use the `const` keyword (notice the capitalization difference)
+help: use the `const` keyword (notice the capitalization)
    |
 LL - pub fn foo<Const N: u8>() {}
 LL + pub fn foo<const N: u8>() {}
@@ -16,7 +16,7 @@ error: `const` keyword was mistyped as `Const`
 LL | pub fn baz<Const N: u8, T>() {}
    |            ^^^^^
    |
-help: use the `const` keyword (notice the capitalization difference)
+help: use the `const` keyword (notice the capitalization)
    |
 LL - pub fn baz<Const N: u8, T>() {}
 LL + pub fn baz<const N: u8, T>() {}
@@ -28,7 +28,7 @@ error: `const` keyword was mistyped as `Const`
 LL | pub fn qux<T, Const N: u8>() {}
    |               ^^^^^
    |
-help: use the `const` keyword (notice the capitalization difference)
+help: use the `const` keyword (notice the capitalization)
    |
 LL - pub fn qux<T, Const N: u8>() {}
 LL + pub fn qux<T, const N: u8>() {}
@@ -40,7 +40,7 @@ error: `const` keyword was mistyped as `Const`
 LL | pub fn quux<T, Const N: u8, U>() {}
    |                ^^^^^
    |
-help: use the `const` keyword (notice the capitalization difference)
+help: use the `const` keyword (notice the capitalization)
    |
 LL - pub fn quux<T, Const N: u8, U>() {}
 LL + pub fn quux<T, const N: u8, U>() {}
diff --git a/tests/ui/suggestions/assoc-ct-for-assoc-method.stderr b/tests/ui/suggestions/assoc-ct-for-assoc-method.stderr
index 6d6fd983038..47efe69cfc2 100644
--- a/tests/ui/suggestions/assoc-ct-for-assoc-method.stderr
+++ b/tests/ui/suggestions/assoc-ct-for-assoc-method.stderr
@@ -8,7 +8,7 @@ LL |     let x: i32 = MyS::foo;
    |
    = note: expected type `i32`
            found fn item `fn() -> MyS {MyS::foo}`
-help: try referring to the associated const `FOO` instead (notice the capitalization difference)
+help: try referring to the associated const `FOO` instead (notice the capitalization)
    |
 LL -     let x: i32 = MyS::foo;
 LL +     let x: i32 = MyS::FOO;
diff --git a/tests/ui/suggestions/bool_typo_err_suggest.stderr b/tests/ui/suggestions/bool_typo_err_suggest.stderr
index faf799d0fda..d46ce1ad8a9 100644
--- a/tests/ui/suggestions/bool_typo_err_suggest.stderr
+++ b/tests/ui/suggestions/bool_typo_err_suggest.stderr
@@ -16,7 +16,7 @@ error[E0425]: cannot find value `False` in this scope
 LL |     let y = False;
    |             ^^^^^ not found in this scope
    |
-help: you may want to use a bool value instead (notice the capitalization difference)
+help: you may want to use a bool value instead (notice the capitalization)
    |
 LL -     let y = False;
 LL +     let y = false;
diff --git a/tests/ui/suggestions/case-difference-suggestions.rs b/tests/ui/suggestions/case-difference-suggestions.rs
new file mode 100644
index 00000000000..d554b6e9367
--- /dev/null
+++ b/tests/ui/suggestions/case-difference-suggestions.rs
@@ -0,0 +1,57 @@
+fn main() {
+
+    // Simple case difference, no hit
+    let hello = "hello";
+    println!("{}", Hello); //~ ERROR cannot find value `Hello` in this scope
+
+    // Multiple case differences, hit
+    let myVariable = 10;
+    println!("{}", myvariable); //~ ERROR cannot find value `myvariable` in this scope
+
+    // Case difference with special characters, hit
+    let user_name = "john";
+    println!("{}", User_Name); //~ ERROR cannot find value `User_Name` in this scope
+
+    // All uppercase vs all lowercase, hit
+    let FOO = 42;
+    println!("{}", foo); //~ ERROR cannot find value `foo` in this scope
+
+
+    // 0 vs O
+    let FFO0 = 100;
+    println!("{}", FFOO); //~ ERROR cannot find value `FFOO` in this scope
+
+    let l1st = vec![1, 2, 3];
+    println!("{}", list); //~ ERROR cannot find value `list` in this scope
+
+    let S5 = "test";
+    println!("{}", SS); //~ ERROR cannot find value `SS` in this scope
+
+    let aS5 = "test";
+    println!("{}", a55); //~ ERROR cannot find value `a55` in this scope
+
+    let B8 = 8;
+    println!("{}", BB); //~ ERROR cannot find value `BB` in this scope
+
+    let g9 = 9;
+    println!("{}", gg); //~ ERROR cannot find value `gg` in this scope
+
+    let o1d = "old";
+    println!("{}", old); //~ ERROR cannot find value `old` in this scope
+
+    let new1 = "new";
+    println!("{}", newl); //~ ERROR cannot find value `newl` in this scope
+
+    let apple = "apple";
+    println!("{}", app1e); //~ ERROR cannot find value `app1e` in this scope
+
+    let a = 1;
+    println!("{}", A); //~ ERROR cannot find value `A` in this scope
+
+    let worldlu = "world";
+    println!("{}", world1U); //~ ERROR cannot find value `world1U` in this scope
+
+    let myV4rlable = 42;
+    println!("{}", myv4r1able); //~ ERROR cannot find value `myv4r1able` in this scope
+
+}
diff --git a/tests/ui/suggestions/case-difference-suggestions.stderr b/tests/ui/suggestions/case-difference-suggestions.stderr
new file mode 100644
index 00000000000..c3d2410a6eb
--- /dev/null
+++ b/tests/ui/suggestions/case-difference-suggestions.stderr
@@ -0,0 +1,99 @@
+error[E0425]: cannot find value `Hello` in this scope
+  --> $DIR/case-difference-suggestions.rs:5:20
+   |
+LL |     println!("{}", Hello);
+   |                    ^^^^^ help: a local variable with a similar name exists: `hello`
+
+error[E0425]: cannot find value `myvariable` in this scope
+  --> $DIR/case-difference-suggestions.rs:9:20
+   |
+LL |     println!("{}", myvariable);
+   |                    ^^^^^^^^^^ help: a local variable with a similar name exists (notice the capitalization): `myVariable`
+
+error[E0425]: cannot find value `User_Name` in this scope
+  --> $DIR/case-difference-suggestions.rs:13:20
+   |
+LL |     println!("{}", User_Name);
+   |                    ^^^^^^^^^ help: a local variable with a similar name exists: `user_name`
+
+error[E0425]: cannot find value `foo` in this scope
+  --> $DIR/case-difference-suggestions.rs:17:20
+   |
+LL |     println!("{}", foo);
+   |                    ^^^ help: a local variable with a similar name exists (notice the capitalization): `FOO`
+
+error[E0425]: cannot find value `FFOO` in this scope
+  --> $DIR/case-difference-suggestions.rs:22:20
+   |
+LL |     println!("{}", FFOO);
+   |                    ^^^^ help: a local variable with a similar name exists (notice the digit/letter confusion): `FFO0`
+
+error[E0425]: cannot find value `list` in this scope
+  --> $DIR/case-difference-suggestions.rs:25:20
+   |
+LL |     println!("{}", list);
+   |                    ^^^^ help: a local variable with a similar name exists: `l1st`
+
+error[E0425]: cannot find value `SS` in this scope
+  --> $DIR/case-difference-suggestions.rs:28:20
+   |
+LL |     println!("{}", SS);
+   |                    ^^ help: a local variable with a similar name exists (notice the digit/letter confusion): `S5`
+
+error[E0425]: cannot find value `a55` in this scope
+  --> $DIR/case-difference-suggestions.rs:31:20
+   |
+LL |     println!("{}", a55);
+   |                    ^^^ help: a local variable with a similar name exists (notice the digit/letter confusion): `aS5`
+
+error[E0425]: cannot find value `BB` in this scope
+  --> $DIR/case-difference-suggestions.rs:34:20
+   |
+LL |     println!("{}", BB);
+   |                    ^^ help: a local variable with a similar name exists (notice the digit/letter confusion): `B8`
+
+error[E0425]: cannot find value `gg` in this scope
+  --> $DIR/case-difference-suggestions.rs:37:20
+   |
+LL |     println!("{}", gg);
+   |                    ^^ help: a local variable with a similar name exists (notice the digit/letter confusion): `g9`
+
+error[E0425]: cannot find value `old` in this scope
+  --> $DIR/case-difference-suggestions.rs:40:20
+   |
+LL |     println!("{}", old);
+   |                    ^^^ help: a local variable with a similar name exists (notice the digit/letter confusion): `o1d`
+
+error[E0425]: cannot find value `newl` in this scope
+  --> $DIR/case-difference-suggestions.rs:43:20
+   |
+LL |     println!("{}", newl);
+   |                    ^^^^ help: a local variable with a similar name exists (notice the digit/letter confusion): `new1`
+
+error[E0425]: cannot find value `app1e` in this scope
+  --> $DIR/case-difference-suggestions.rs:46:20
+   |
+LL |     println!("{}", app1e);
+   |                    ^^^^^ help: a local variable with a similar name exists (notice the digit/letter confusion): `apple`
+
+error[E0425]: cannot find value `A` in this scope
+  --> $DIR/case-difference-suggestions.rs:49:20
+   |
+LL |     println!("{}", A);
+   |                    ^ help: a local variable with a similar name exists: `a`
+
+error[E0425]: cannot find value `world1U` in this scope
+  --> $DIR/case-difference-suggestions.rs:52:20
+   |
+LL |     println!("{}", world1U);
+   |                    ^^^^^^^ help: a local variable with a similar name exists (notice the capitalization and digit/letter confusion): `worldlu`
+
+error[E0425]: cannot find value `myv4r1able` in this scope
+  --> $DIR/case-difference-suggestions.rs:55:20
+   |
+LL |     println!("{}", myv4r1able);
+   |                    ^^^^^^^^^^ help: a local variable with a similar name exists (notice the capitalization and digit/letter confusion): `myV4rlable`
+
+error: aborting due to 16 previous errors
+
+For more information about this error, try `rustc --explain E0425`.
diff --git a/tests/ui/suggestions/incorrect-variant-literal.svg b/tests/ui/suggestions/incorrect-variant-literal.svg
index 279fd30f216..2cab1f4b60f 100644
--- a/tests/ui/suggestions/incorrect-variant-literal.svg
+++ b/tests/ui/suggestions/incorrect-variant-literal.svg
@@ -455,7 +455,7 @@
 </tspan>
     <tspan x="10px" y="3916px"><tspan>   </tspan><tspan class="fg-ansi256-012 bold">|</tspan>
 </tspan>
-    <tspan x="10px" y="3934px"><tspan class="fg-ansi256-014 bold">help</tspan><tspan>: there is a variant with a similar name (notice the capitalization difference)</tspan>
+    <tspan x="10px" y="3934px"><tspan class="fg-ansi256-014 bold">help</tspan><tspan>: there is a variant with a similar name (notice the capitalization)</tspan>
 </tspan>
     <tspan x="10px" y="3952px"><tspan>   </tspan><tspan class="fg-ansi256-012 bold">|</tspan>
 </tspan>