@@ -313,15 +313,17 @@ pub(crate) trait HInt: Int {
313
313
/// Integer that is double the bit width of the integer this trait is implemented for
314
314
type D : DInt <H = Self > + MinInt ;
315
315
316
+ // NB: some of the below methods could have default implementations (e.g. `widen_hi`), but for
317
+ // unknown reasons this can cause infinite recursion when optimizations are disabled. See
318
+ // <https://github.com/rust-lang/compiler-builtins/pull/707> for context.
319
+
316
320
/// Widens (using default extension) the integer to have double bit width
317
321
fn widen( self ) -> Self :: D ;
318
322
/// Widens (zero extension only) the integer to have double bit width. This is needed to get
319
323
/// around problems with associated type bounds (such as `Int<Othersign: DInt>`) being unstable
320
324
fn zero_widen( self ) -> Self :: D ;
321
325
/// Widens the integer to have double bit width and shifts the integer into the higher bits
322
- fn widen_hi( self ) -> Self :: D {
323
- self . widen( ) << <Self as MinInt >:: BITS
324
- }
326
+ fn widen_hi( self ) -> Self :: D ;
325
327
/// Widening multiplication with zero widening. This cannot overflow.
326
328
fn zero_widen_mul( self , rhs: Self ) -> Self :: D ;
327
329
/// Widening multiplication. This cannot overflow.
@@ -364,6 +366,9 @@ macro_rules! impl_h_int {
364
366
fn widen_mul( self , rhs: Self ) -> Self :: D {
365
367
self . widen( ) . wrapping_mul( rhs. widen( ) )
366
368
}
369
+ fn widen_hi( self ) -> Self :: D {
370
+ ( self as $X) << <Self as MinInt >:: BITS
371
+ }
367
372
}
368
373
) *
369
374
} ;
0 commit comments