@@ -9,6 +9,7 @@ use rustc_middle::mir::interpret::{
9
9
use rustc_middle:: mir:: * ;
10
10
use rustc_middle:: thir:: * ;
11
11
use rustc_middle:: ty:: { self , CanonicalUserTypeAnnotation , TyCtxt } ;
12
+ use rustc_span:: DUMMY_SP ;
12
13
use rustc_target:: abi:: Size ;
13
14
14
15
impl < ' a , ' tcx > Builder < ' a , ' tcx > {
@@ -26,7 +27,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
26
27
let literal =
27
28
match lit_to_mir_constant ( tcx, LitToConstInput { lit : & lit. node , ty, neg } ) {
28
29
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
+ }
30
33
Err ( LitToConstError :: TypeError ) => {
31
34
bug ! ( "encountered type error in `lit_to_mir_constant" )
32
35
}
@@ -105,7 +108,15 @@ pub(crate) fn lit_to_mir_constant<'tcx>(
105
108
let LitToConstInput { lit, ty, neg } = lit_input;
106
109
let trunc = |n| {
107
110
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 ;
109
120
trace ! ( "trunc {} with size {} and shift {}" , n, width. bits( ) , 128 - width. bits( ) ) ;
110
121
let result = width. truncate ( n) ;
111
122
trace ! ( "trunc result: {}" , result) ;
@@ -136,12 +147,20 @@ pub(crate) fn lit_to_mir_constant<'tcx>(
136
147
( ast:: LitKind :: Int ( n, _) , ty:: Uint ( _) ) | ( ast:: LitKind :: Int ( n, _) , ty:: Int ( _) ) => {
137
148
trunc ( if neg { ( * n as i128 ) . overflowing_neg ( ) . 0 as u128 } else { * n } ) ?
138
149
}
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
+ } ) ?,
142
157
( ast:: LitKind :: Bool ( b) , ty:: Bool ) => ConstValue :: Scalar ( Scalar :: from_bool ( * b) ) ,
143
158
( 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
+ }
145
164
_ => return Err ( LitToConstError :: TypeError ) ,
146
165
} ;
147
166
0 commit comments