about summary refs log tree commit diff
path: root/compiler/rustc_trait_selection/src
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2024-04-14 09:21:38 -0400
committerMichael Goulet <michael@errs.io>2024-04-14 09:42:53 -0400
commite4c71f1fd8caf703dde7edb75b3cd33585aadddc (patch)
tree88bda8ad0bc9c2b4f3498d2de89e4a519e8e06cf /compiler/rustc_trait_selection/src
parentd6ac50e54722efc02cec9d06037e004d14881e64 (diff)
downloadrust-e4c71f1fd8caf703dde7edb75b3cd33585aadddc.tar.gz
rust-e4c71f1fd8caf703dde7edb75b3cd33585aadddc.zip
Fix value suggestion for array in generic context
Diffstat (limited to 'compiler/rustc_trait_selection/src')
-rw-r--r--compiler/rustc_trait_selection/src/lib.rs1
-rw-r--r--compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs8
2 files changed, 4 insertions, 5 deletions
diff --git a/compiler/rustc_trait_selection/src/lib.rs b/compiler/rustc_trait_selection/src/lib.rs
index b5fb710e4cc..057d00aeae8 100644
--- a/compiler/rustc_trait_selection/src/lib.rs
+++ b/compiler/rustc_trait_selection/src/lib.rs
@@ -22,6 +22,7 @@
 #![feature(box_patterns)]
 #![feature(control_flow_enum)]
 #![feature(extract_if)]
+#![feature(if_let_guard)]
 #![feature(let_chains)]
 #![feature(option_take_if)]
 #![feature(never_type)]
diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs
index 6ae7cbf717b..36fb5c8a6f7 100644
--- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs
+++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs
@@ -4583,11 +4583,9 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
                     format!("&{}{ty}", mutability.prefix_str())
                 }
             }
-            ty::Array(ty, len) => format!(
-                "[{}; {}]",
-                self.ty_kind_suggestion(param_env, *ty)?,
-                len.eval_target_usize(tcx, ty::ParamEnv::reveal_all()),
-            ),
+            ty::Array(ty, len) if let Some(len) = len.try_eval_target_usize(tcx, param_env) => {
+                format!("[{}; {}]", self.ty_kind_suggestion(param_env, *ty)?, len)
+            }
             ty::Tuple(tys) => format!(
                 "({})",
                 tys.iter()