@@ -313,15 +313,17 @@ pub(crate) trait HInt: Int {
313313 /// Integer that is double the bit width of the integer this trait is implemented for
314314 type D : DInt <H = Self > + MinInt ;
315315
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+
316320 /// Widens (using default extension) the integer to have double bit width
317321 fn widen( self ) -> Self :: D ;
318322 /// Widens (zero extension only) the integer to have double bit width. This is needed to get
319323 /// around problems with associated type bounds (such as `Int<Othersign: DInt>`) being unstable
320324 fn zero_widen( self ) -> Self :: D ;
321325 /// 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 ;
325327 /// Widening multiplication with zero widening. This cannot overflow.
326328 fn zero_widen_mul( self , rhs: Self ) -> Self :: D ;
327329 /// Widening multiplication. This cannot overflow.
@@ -364,6 +366,9 @@ macro_rules! impl_h_int {
364366 fn widen_mul( self , rhs: Self ) -> Self :: D {
365367 self . widen( ) . wrapping_mul( rhs. widen( ) )
366368 }
369+ fn widen_hi( self ) -> Self :: D {
370+ ( self as $X) << <Self as MinInt >:: BITS
371+ }
367372 }
368373 ) *
369374 } ;
0 commit comments