@@ -9,6 +9,7 @@ use rustc_middle::mir::interpret::{
99use rustc_middle:: mir:: * ;
1010use rustc_middle:: thir:: * ;
1111use rustc_middle:: ty:: { self , CanonicalUserTypeAnnotation , TyCtxt } ;
12+ use rustc_span:: DUMMY_SP ;
1213use rustc_target:: abi:: Size ;
1314
1415impl < ' a , ' tcx > Builder < ' a , ' tcx > {
@@ -26,7 +27,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
2627 let literal =
2728 match lit_to_mir_constant ( tcx, LitToConstInput { lit : & lit. node , ty, neg } ) {
2829 Ok ( c) => c,
29- Err ( LitToConstError :: Reported ) => ConstantKind :: Ty ( tcx. const_error ( ty) ) ,
30+ Err ( LitToConstError :: Reported ( guar) ) => {
31+ ConstantKind :: Ty ( tcx. const_error_with_guaranteed ( ty, guar) )
32+ }
3033 Err ( LitToConstError :: TypeError ) => {
3134 bug ! ( "encountered type error in `lit_to_mir_constant" )
3235 }
@@ -105,7 +108,15 @@ pub(crate) fn lit_to_mir_constant<'tcx>(
105108 let LitToConstInput { lit, ty, neg } = lit_input;
106109 let trunc = |n| {
107110 let param_ty = ty:: ParamEnv :: reveal_all ( ) . and ( ty) ;
108- let width = tcx. layout_of ( param_ty) . map_err ( |_| LitToConstError :: Reported ) ?. size ;
111+ let width = tcx
112+ . layout_of ( param_ty)
113+ . map_err ( |_| {
114+ LitToConstError :: Reported ( tcx. sess . delay_span_bug (
115+ DUMMY_SP ,
116+ format ! ( "couldn't compute width of literal: {:?}" , lit_input. lit) ,
117+ ) )
118+ } ) ?
119+ . size ;
109120 trace ! ( "trunc {} with size {} and shift {}" , n, width. bits( ) , 128 - width. bits( ) ) ;
110121 let result = width. truncate ( n) ;
111122 trace ! ( "trunc result: {}" , result) ;
@@ -136,12 +147,20 @@ pub(crate) fn lit_to_mir_constant<'tcx>(
136147 ( ast:: LitKind :: Int ( n, _) , ty:: Uint ( _) ) | ( ast:: LitKind :: Int ( n, _) , ty:: Int ( _) ) => {
137148 trunc ( if neg { ( * n as i128 ) . overflowing_neg ( ) . 0 as u128 } else { * n } ) ?
138149 }
139- ( ast:: LitKind :: Float ( n, _) , ty:: Float ( fty) ) => {
140- parse_float_into_constval ( * n, * fty, neg) . ok_or ( LitToConstError :: Reported ) ?
141- }
150+ ( ast:: LitKind :: Float ( n, _) , ty:: Float ( fty) ) => parse_float_into_constval ( * n, * fty, neg)
151+ . ok_or_else ( || {
152+ LitToConstError :: Reported ( tcx. sess . delay_span_bug (
153+ DUMMY_SP ,
154+ format ! ( "couldn't parse float literal: {:?}" , lit_input. lit) ,
155+ ) )
156+ } ) ?,
142157 ( ast:: LitKind :: Bool ( b) , ty:: Bool ) => ConstValue :: Scalar ( Scalar :: from_bool ( * b) ) ,
143158 ( ast:: LitKind :: Char ( c) , ty:: Char ) => ConstValue :: Scalar ( Scalar :: from_char ( * c) ) ,
144- ( ast:: LitKind :: Err , _) => return Err ( LitToConstError :: Reported ) ,
159+ ( ast:: LitKind :: Err , _) => {
160+ return Err ( LitToConstError :: Reported (
161+ tcx. sess . delay_span_bug ( DUMMY_SP , "encountered LitKind::Err during mir build" ) ,
162+ ) ) ;
163+ }
145164 _ => return Err ( LitToConstError :: TypeError ) ,
146165 } ;
147166
0 commit comments