From ff0ce4f5fa83a03082ed6efb3f0088dcd935be92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Sat, 14 Mar 2026 20:12:18 +0000 Subject: [PATCH] Make some suggestions verbose --- compiler/rustc_trait_selection/src/errors.rs | 9 ++++++--- .../consts/array-literal-len-mismatch.stderr | 9 +++++++-- tests/ui/consts/const-array-oob-arith.stderr | 18 ++++++++++++++---- tests/ui/inference/array-len-mismatch.stderr | 18 ++++++++++++++---- 4 files changed, 41 insertions(+), 13 deletions(-) diff --git a/compiler/rustc_trait_selection/src/errors.rs b/compiler/rustc_trait_selection/src/errors.rs index 6f63c1d663f1..34b9c9988f35 100644 --- a/compiler/rustc_trait_selection/src/errors.rs +++ b/compiler/rustc_trait_selection/src/errors.rs @@ -1707,7 +1707,8 @@ pub enum TypeErrorAdditionalDiags { #[suggestion( "if you meant to write a byte literal, prefix with `b`", code = "b'{code}'", - applicability = "machine-applicable" + applicability = "machine-applicable", + style = "verbose" )] MeantByteLiteral { #[primary_span] @@ -1717,7 +1718,8 @@ pub enum TypeErrorAdditionalDiags { #[suggestion( "if you meant to write a `char` literal, use single quotes", code = "'{code}'", - applicability = "machine-applicable" + applicability = "machine-applicable", + style = "verbose" )] MeantCharLiteral { #[primary_span] @@ -1737,7 +1739,8 @@ pub enum TypeErrorAdditionalDiags { #[suggestion( "consider specifying the actual array length", code = "{length}", - applicability = "maybe-incorrect" + applicability = "maybe-incorrect", + style = "verbose" )] ConsiderSpecifyingLength { #[primary_span] diff --git a/tests/ui/consts/array-literal-len-mismatch.stderr b/tests/ui/consts/array-literal-len-mismatch.stderr index 782d059a294c..bf828ff5acf5 100644 --- a/tests/ui/consts/array-literal-len-mismatch.stderr +++ b/tests/ui/consts/array-literal-len-mismatch.stderr @@ -3,9 +3,14 @@ error[E0308]: mismatched types | LL | const NUMBERS: [u8; 3] = [10, 20]; | ------- ^^^^^^^^ expected an array with a size of 3, found one with a size of 2 - | | | - | | help: consider specifying the actual array length: `2` + | | | expected because of the type of the constant + | +help: consider specifying the actual array length + | +LL - const NUMBERS: [u8; 3] = [10, 20]; +LL + const NUMBERS: [u8; 2] = [10, 20]; + | error: aborting due to 1 previous error diff --git a/tests/ui/consts/const-array-oob-arith.stderr b/tests/ui/consts/const-array-oob-arith.stderr index d37ae5e4a7b3..0cb654237ab5 100644 --- a/tests/ui/consts/const-array-oob-arith.stderr +++ b/tests/ui/consts/const-array-oob-arith.stderr @@ -3,18 +3,28 @@ error[E0308]: mismatched types | LL | const BLUB: [i32; (ARR[0] - 40) as usize] = [5]; | ----------------------------- ^^^ expected an array with a size of 2, found one with a size of 1 - | | | - | | help: consider specifying the actual array length: `1` + | | | expected because of the type of the constant + | +help: consider specifying the actual array length + | +LL - const BLUB: [i32; (ARR[0] - 40) as usize] = [5]; +LL + const BLUB: [i32; 1] = [5]; + | error[E0308]: mismatched types --> $DIR/const-array-oob-arith.rs:9:44 | LL | const BOO: [i32; (ARR[0] - 41) as usize] = [5, 99]; | ----------------------------- ^^^^^^^ expected an array with a size of 1, found one with a size of 2 - | | | - | | help: consider specifying the actual array length: `2` + | | | expected because of the type of the constant + | +help: consider specifying the actual array length + | +LL - const BOO: [i32; (ARR[0] - 41) as usize] = [5, 99]; +LL + const BOO: [i32; 2] = [5, 99]; + | error: aborting due to 2 previous errors diff --git a/tests/ui/inference/array-len-mismatch.stderr b/tests/ui/inference/array-len-mismatch.stderr index 7146e3803d53..94813d404b2b 100644 --- a/tests/ui/inference/array-len-mismatch.stderr +++ b/tests/ui/inference/array-len-mismatch.stderr @@ -3,18 +3,28 @@ error[E0308]: mismatched types | LL | let wrong: [u8; 3] = [10, 20]; | ------- ^^^^^^^^ expected an array with a size of 3, found one with a size of 2 - | | | - | | help: consider specifying the actual array length: `2` + | | | expected due to this + | +help: consider specifying the actual array length + | +LL - let wrong: [u8; 3] = [10, 20]; +LL + let wrong: [u8; 2] = [10, 20]; + | error[E0308]: mismatched types --> $DIR/array-len-mismatch.rs:9:26 | LL | let wrong: [u8; 3] = returns_arr(); | ------- ^^^^^^^^^^^^^ expected an array with a size of 3, found one with a size of 2 - | | | - | | help: consider specifying the actual array length: `2` + | | | expected due to this + | +help: consider specifying the actual array length + | +LL - let wrong: [u8; 3] = returns_arr(); +LL + let wrong: [u8; 2] = returns_arr(); + | error: aborting due to 2 previous errors