Skip to content

Commit b744e3d

Browse files
committed
[doc] note the special type inference handling for shifts
1 parent 6c53749 commit b744e3d

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/libcore/ops/bit.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,12 @@ macro_rules! bitxor_impl {
315315

316316
bitxor_impl! { bool usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
317317

318-
/// The left shift operator `<<`.
318+
/// The left shift operator `<<`. Note that because this trait is implemented
319+
/// for all integer types with multiple right-hand-side types, Rust's type
320+
/// checker has special handling for `_ << _`, setting the result type for
321+
/// integer operations to the type of the left-hand-side operand. This means
322+
/// that though `a << b` and `a.shl(b)` are one and the same from an evaluation
323+
/// standpoint, they are different when it comes to type inference.
319324
///
320325
/// # Examples
321326
///
@@ -417,7 +422,12 @@ macro_rules! shl_impl_all {
417422

418423
shl_impl_all! { u8 u16 u32 u64 u128 usize i8 i16 i32 i64 isize i128 }
419424

420-
/// The right shift operator `>>`.
425+
/// The right shift operator `>>`. Note that because this trait is implemented
426+
/// for all integer types with multiple right-hand-side types, Rust's type
427+
/// checker has special handling for `_ >> _`, setting the result type for
428+
/// integer operations to the type of the left-hand-side operand. This means
429+
/// that though `a >> b` and `a.shr(b)` are one and the same from an evaluation
430+
/// standpoint, they are different when it comes to type inference.
421431
///
422432
/// # Examples
423433
///

0 commit comments

Comments
 (0)