about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorkennytm <kennytm@gmail.com>2018-04-14 15:23:08 +0800
committerkennytm <kennytm@gmail.com>2018-04-14 15:23:08 +0800
commitd21433eeae00b566f144d1dd67eed0c7cdb40a93 (patch)
treec2fb279d57ed762cb361382916a675bdbf163678 /src
parent6f629d365407cac1de372a64abec046dce6d9bb1 (diff)
parentb744e3d7f516f1c679a4f6315110e856b9731de4 (diff)
downloadrust-d21433eeae00b566f144d1dd67eed0c7cdb40a93.tar.gz
rust-d21433eeae00b566f144d1dd67eed0c7cdb40a93.zip
Rollup merge of #49915 - llogiq:doc-shift-types, r=joshtriplett
[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.
Diffstat (limited to 'src')
-rw-r--r--src/libcore/ops/bit.rs14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/libcore/ops/bit.rs b/src/libcore/ops/bit.rs
index a0ecd6cf75c..ec1e65be774 100644
--- a/src/libcore/ops/bit.rs
+++ b/src/libcore/ops/bit.rs
@@ -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
 ///
@@ -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
 ///