11use  rustc_abi:: { BackendRepr ,  VariantIdx } ; 
22use  rustc_data_structures:: stack:: ensure_sufficient_stack; 
3- use  rustc_middle:: mir:: interpret:: { EvalToValTreeResult ,  GlobalId ,  ReportedErrorInfo } ; 
3+ use  rustc_middle:: mir:: interpret:: { EvalToValTreeResult ,  GlobalId ,  ValTreeCreationError } ; 
44use  rustc_middle:: ty:: layout:: { LayoutCx ,  LayoutOf ,  TyAndLayout } ; 
55use  rustc_middle:: ty:: { self ,  Ty ,  TyCtxt } ; 
66use  rustc_middle:: { bug,  mir} ; 
77use  rustc_span:: DUMMY_SP ; 
88use  tracing:: { debug,  instrument,  trace} ; 
99
10+ use  super :: VALTREE_MAX_NODES ; 
1011use  super :: eval_queries:: { mk_eval_cx_to_read_const_val,  op_to_const} ; 
1112use  super :: machine:: CompileTimeInterpCx ; 
12- use  super :: { VALTREE_MAX_NODES ,  ValTreeCreationError ,  ValTreeCreationResult } ; 
1313use  crate :: const_eval:: CanAccessMutGlobal ; 
14- use  crate :: errors:: MaxNumNodesInConstErr ; 
1514use  crate :: interpret:: { 
1615    ImmTy ,  Immediate ,  InternKind ,  MPlaceTy ,  MemPlaceMeta ,  MemoryKind ,  PlaceTy ,  Projectable ,  Scalar , 
1716    intern_const_alloc_recursive, 
@@ -24,7 +23,7 @@ fn branches<'tcx>(
2423    field_count :  usize , 
2524    variant :  Option < VariantIdx > , 
2625    num_nodes :  & mut  usize , 
27- )  -> ValTreeCreationResult < ' tcx >  { 
26+ )  -> EvalToValTreeResult < ' tcx >  { 
2827    let  place = match  variant { 
2928        Some ( variant)  => ecx. project_downcast ( place,  variant) . unwrap ( ) , 
3029        None  => place. clone ( ) , 
@@ -58,7 +57,7 @@ fn slice_branches<'tcx>(
5857    ecx :  & CompileTimeInterpCx < ' tcx > , 
5958    place :  & MPlaceTy < ' tcx > , 
6059    num_nodes :  & mut  usize , 
61- )  -> ValTreeCreationResult < ' tcx >  { 
60+ )  -> EvalToValTreeResult < ' tcx >  { 
6261    let  n = place. len ( ecx) . unwrap_or_else ( |_| panic ! ( "expected to use len of place {place:?}" ) ) ; 
6362
6463    let  mut  elems = Vec :: with_capacity ( n as  usize ) ; 
@@ -76,7 +75,7 @@ fn const_to_valtree_inner<'tcx>(
7675    ecx :  & CompileTimeInterpCx < ' tcx > , 
7776    place :  & MPlaceTy < ' tcx > , 
7877    num_nodes :  & mut  usize , 
79- )  -> ValTreeCreationResult < ' tcx >  { 
78+ )  -> EvalToValTreeResult < ' tcx >  { 
8079    let  tcx = * ecx. tcx ; 
8180    let  ty = place. layout . ty ; 
8281    debug ! ( "ty kind: {:?}" ,  ty. kind( ) ) ; 
@@ -91,7 +90,7 @@ fn const_to_valtree_inner<'tcx>(
9190            Ok ( ty:: ValTree :: zst ( tcx) ) 
9291        } 
9392        ty:: Bool  | ty:: Int ( _)  | ty:: Uint ( _)  | ty:: Float ( _)  | ty:: Char  => { 
94-             let  val = ecx. read_immediate ( place) . unwrap ( ) ; 
93+             let  val = ecx. read_immediate ( place) . report_err ( ) ? ; 
9594            let  val = val. to_scalar_int ( ) . unwrap ( ) ; 
9695            * num_nodes += 1 ; 
9796
@@ -113,7 +112,7 @@ fn const_to_valtree_inner<'tcx>(
113112            // equality at compile-time (see `ptr_guaranteed_cmp`). 
114113            // However we allow those that are just integers in disguise. 
115114            // First, get the pointer. Remember it might be wide! 
116-             let  val = ecx. read_immediate ( place) . unwrap ( ) ; 
115+             let  val = ecx. read_immediate ( place) . report_err ( ) ? ; 
117116            // We could allow wide raw pointers where both sides are integers in the future, 
118117            // but for now we reject them. 
119118            if  matches ! ( val. layout. backend_repr,  BackendRepr :: ScalarPair ( ..) )  { 
@@ -134,7 +133,7 @@ fn const_to_valtree_inner<'tcx>(
134133        ty:: FnPtr ( ..)  => Err ( ValTreeCreationError :: NonSupportedType ( ty) ) , 
135134
136135        ty:: Ref ( _,  _,  _)   => { 
137-             let  derefd_place = ecx. deref_pointer ( place) . unwrap ( ) ; 
136+             let  derefd_place = ecx. deref_pointer ( place) . report_err ( ) ? ; 
138137            const_to_valtree_inner ( ecx,  & derefd_place,  num_nodes) 
139138        } 
140139
@@ -158,7 +157,7 @@ fn const_to_valtree_inner<'tcx>(
158157                bug ! ( "uninhabited types should have errored and never gotten converted to valtree" ) 
159158            } 
160159
161-             let  variant = ecx. read_discriminant ( place) . unwrap ( ) ; 
160+             let  variant = ecx. read_discriminant ( place) . report_err ( ) ? ; 
162161            branches ( ecx,  place,  def. variant ( variant) . fields . len ( ) ,  def. is_enum ( ) . then_some ( variant) ,  num_nodes) 
163162        } 
164163
@@ -249,24 +248,7 @@ pub(crate) fn eval_to_valtree<'tcx>(
249248    debug ! ( ?place) ; 
250249
251250    let  mut  num_nodes = 0 ; 
252-     let  valtree_result = const_to_valtree_inner ( & ecx,  & place,  & mut  num_nodes) ; 
253- 
254-     match  valtree_result { 
255-         Ok ( valtree)  => Ok ( Ok ( valtree) ) , 
256-         Err ( err)  => { 
257-             let  did = cid. instance . def_id ( ) ; 
258-             let  global_const_id = cid. display ( tcx) ; 
259-             let  span = tcx. hir_span_if_local ( did) ; 
260-             match  err { 
261-                 ValTreeCreationError :: NodesOverflow  => { 
262-                     let  handled =
263-                         tcx. dcx ( ) . emit_err ( MaxNumNodesInConstErr  {  span,  global_const_id } ) ; 
264-                     Err ( ReportedErrorInfo :: allowed_in_infallible ( handled) . into ( ) ) 
265-                 } 
266-                 ValTreeCreationError :: NonSupportedType ( ty)  => Ok ( Err ( ty) ) , 
267-             } 
268-         } 
269-     } 
251+     const_to_valtree_inner ( & ecx,  & place,  & mut  num_nodes) 
270252} 
271253
272254/// Converts a `ValTree` to a `ConstValue`, which is needed after mir 
0 commit comments