@@ -12,6 +12,7 @@ use rustc_hir::pat_util::EnumerateAndAdjustIterator;
12
12
use rustc_hir:: { HirId , Pat , PatKind } ;
13
13
use rustc_infer:: infer;
14
14
use rustc_infer:: infer:: type_variable:: { TypeVariableOrigin , TypeVariableOriginKind } ;
15
+ use rustc_middle:: mir:: interpret:: ErrorHandled ;
15
16
use rustc_middle:: ty:: { self , Adt , BindingMode , Ty , TypeVisitableExt } ;
16
17
use rustc_session:: lint:: builtin:: NON_EXHAUSTIVE_OMITTED_PATTERNS ;
17
18
use rustc_span:: edit_distance:: find_best_match_for_name;
@@ -2164,7 +2165,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2164
2165
len : ty:: Const < ' tcx > ,
2165
2166
min_len : u64 ,
2166
2167
) -> ( Option < Ty < ' tcx > > , Ty < ' tcx > ) {
2167
- let guar = if let Some ( len) = len. try_eval_target_usize ( self . tcx , self . param_env ) {
2168
+ let len = match len. eval ( self . tcx , self . param_env , None ) {
2169
+ Ok ( val) => val
2170
+ . try_to_scalar ( )
2171
+ . and_then ( |scalar| scalar. try_to_int ( ) . ok ( ) )
2172
+ . and_then ( |int| int. try_to_target_usize ( self . tcx ) . ok ( ) ) ,
2173
+ Err ( ErrorHandled :: Reported ( ..) ) => {
2174
+ let guar = self . error_scrutinee_unfixed_length ( span) ;
2175
+ return ( Some ( Ty :: new_error ( self . tcx , guar) ) , arr_ty) ;
2176
+ }
2177
+ Err ( ErrorHandled :: TooGeneric ( ..) ) => None ,
2178
+ } ;
2179
+
2180
+ let guar = if let Some ( len) = len {
2168
2181
// Now we know the length...
2169
2182
if slice. is_none ( ) {
2170
2183
// ...and since there is no variable-length pattern,
0 commit comments