Skip to content

Commit

Permalink
Rollup merge of rust-lang#49915 - llogiq:doc-shift-types, r=joshtriplett
Browse files Browse the repository at this point in the history
[doc] note the special type inference handling for shift ops

This adds a note to the docs about the difference between the shift ops and the corresponding trait methods when it comes to type inference.
  • Loading branch information
kennytm committed Apr 14, 2018
2 parents 6f629d3 + b744e3d commit d21433e
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/libcore/ops/bit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,12 @@ macro_rules! bitxor_impl {

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

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

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

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

0 comments on commit d21433e

Please sign in to comment.