@@ -2299,23 +2299,33 @@ impl<'tcx> Const<'tcx> {
22992299        assert_eq ! ( self . ty,  ty) ; 
23002300        // if `ty` does not depend on generic parameters, use an empty param_env 
23012301        let  size = tcx. layout_of ( param_env. with_reveal_all ( ) . and ( ty) ) . ok ( ) ?. size ; 
2302+         self . eval ( tcx,  param_env) . val . try_to_bits ( size) 
2303+     } 
2304+ 
2305+     #[ inline]  
2306+     pub  fn  eval ( 
2307+         & self , 
2308+         tcx :  TyCtxt < ' tcx > , 
2309+         param_env :  ParamEnv < ' tcx > , 
2310+     )  -> & Const < ' tcx >  { 
2311+         // FIXME(const_generics): this doesn't work right now, 
2312+         // because it tries to relate an `Infer` to a `Param`. 
23022313        match  self . val  { 
2303-             // FIXME(const_generics): this doesn't work right now, 
2304-             // because it tries to relate an `Infer` to a `Param`. 
23052314            ConstValue :: Unevaluated ( did,  substs)  => { 
23062315                // if `substs` has no unresolved components, use and empty param_env 
23072316                let  ( param_env,  substs)  = param_env. with_reveal_all ( ) . and ( substs) . into_parts ( ) ; 
23082317                // try to resolve e.g. associated constants to their definition on an impl 
2309-                 let  instance = ty:: Instance :: resolve ( tcx,  param_env,  did,  substs) ?; 
2318+                 let  instance = match  ty:: Instance :: resolve ( tcx,  param_env,  did,  substs)  { 
2319+                     Some ( instance)  => instance, 
2320+                     None  => return  self , 
2321+                 } ; 
23102322                let  gid = GlobalId  { 
23112323                    instance, 
23122324                    promoted :  None , 
23132325                } ; 
2314-                 let  evaluated = tcx. const_eval ( param_env. and ( gid) ) . ok ( ) ?; 
2315-                 evaluated. val . try_to_bits ( size) 
2326+                 tcx. const_eval ( param_env. and ( gid) ) . unwrap_or ( self ) 
23162327            } , 
2317-             // otherwise just extract a `ConstValue`'s bits if possible 
2318-             _ => self . val . try_to_bits ( size) , 
2328+             _ => self , 
23192329        } 
23202330    } 
23212331
0 commit comments