From 51a2e2fd826c82252d101ad1e1904319699e417e Mon Sep 17 00:00:00 2001
From: Ralf Jung <post@ralfj.de>
Date: Mon, 13 Feb 2017 19:50:54 +0100
Subject: [PATCH 01/13] Allow more Cell methods for non-Copy types

Contributes to #39264
---
 src/libcore/cell.rs | 120 ++++++++++++++++++++++----------------------
 1 file changed, 60 insertions(+), 60 deletions(-)

diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs
index ab44342ebf02f..1570428cf18b4 100644
--- a/src/libcore/cell.rs
+++ b/src/libcore/cell.rs
@@ -212,66 +212,6 @@ impl<T:Copy> Cell<T> {
     pub fn get(&self) -> T {
         unsafe{ *self.value.get() }
     }
-
-    /// Returns a reference to the underlying `UnsafeCell`.
-    ///
-    /// # Examples
-    ///
-    /// ```
-    /// #![feature(as_unsafe_cell)]
-    ///
-    /// use std::cell::Cell;
-    ///
-    /// let c = Cell::new(5);
-    ///
-    /// let uc = c.as_unsafe_cell();
-    /// ```
-    #[inline]
-    #[unstable(feature = "as_unsafe_cell", issue = "27708")]
-    #[rustc_deprecated(since = "1.12.0", reason = "renamed to as_ptr")]
-    pub fn as_unsafe_cell(&self) -> &UnsafeCell<T> {
-        &self.value
-    }
-
-    /// Returns a raw pointer to the underlying data in this cell.
-    ///
-    /// # Examples
-    ///
-    /// ```
-    /// use std::cell::Cell;
-    ///
-    /// let c = Cell::new(5);
-    ///
-    /// let ptr = c.as_ptr();
-    /// ```
-    #[inline]
-    #[stable(feature = "cell_as_ptr", since = "1.12.0")]
-    pub fn as_ptr(&self) -> *mut T {
-        self.value.get()
-    }
-
-    /// Returns a mutable reference to the underlying data.
-    ///
-    /// This call borrows `Cell` mutably (at compile-time) which guarantees
-    /// that we possess the only reference.
-    ///
-    /// # Examples
-    ///
-    /// ```
-    /// use std::cell::Cell;
-    ///
-    /// let mut c = Cell::new(5);
-    /// *c.get_mut() += 1;
-    ///
-    /// assert_eq!(c.get(), 6);
-    /// ```
-    #[inline]
-    #[stable(feature = "cell_get_mut", since = "1.11.0")]
-    pub fn get_mut(&mut self) -> &mut T {
-        unsafe {
-            &mut *self.value.get()
-        }
-    }
 }
 
 #[stable(feature = "rust1", since = "1.0.0")]
@@ -369,6 +309,66 @@ impl<T> Cell<T> {
         }
     }
 
+    /// Returns a reference to the underlying `UnsafeCell`.
+    ///
+    /// # Examples
+    ///
+    /// ```
+    /// #![feature(as_unsafe_cell)]
+    ///
+    /// use std::cell::Cell;
+    ///
+    /// let c = Cell::new(5);
+    ///
+    /// let uc = c.as_unsafe_cell();
+    /// ```
+    #[inline]
+    #[unstable(feature = "as_unsafe_cell", issue = "27708")]
+    #[rustc_deprecated(since = "1.12.0", reason = "renamed to as_ptr")]
+    pub fn as_unsafe_cell(&self) -> &UnsafeCell<T> {
+        &self.value
+    }
+
+    /// Returns a raw pointer to the underlying data in this cell.
+    ///
+    /// # Examples
+    ///
+    /// ```
+    /// use std::cell::Cell;
+    ///
+    /// let c = Cell::new(5);
+    ///
+    /// let ptr = c.as_ptr();
+    /// ```
+    #[inline]
+    #[stable(feature = "cell_as_ptr", since = "1.12.0")]
+    pub fn as_ptr(&self) -> *mut T {
+        self.value.get()
+    }
+
+    /// Returns a mutable reference to the underlying data.
+    ///
+    /// This call borrows `Cell` mutably (at compile-time) which guarantees
+    /// that we possess the only reference.
+    ///
+    /// # Examples
+    ///
+    /// ```
+    /// use std::cell::Cell;
+    ///
+    /// let mut c = Cell::new(5);
+    /// *c.get_mut() += 1;
+    ///
+    /// assert_eq!(c.get(), 6);
+    /// ```
+    #[inline]
+    #[stable(feature = "cell_get_mut", since = "1.11.0")]
+    pub fn get_mut(&mut self) -> &mut T {
+        unsafe {
+            &mut *self.value.get()
+        }
+    }
+
     /// Sets the contained value.
     ///
     /// # Examples

From 044ed10fee3351da2315d5d8e26949929ad918ce Mon Sep 17 00:00:00 2001
From: Ralf Jung <post@ralfj.de>
Date: Tue, 14 Feb 2017 09:46:03 +0100
Subject: [PATCH 02/13] Remove Copy bound from some Cell trait impls

Contributes to #39264
---
 src/libcore/cell.rs | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs
index 1570428cf18b4..2b4ce3a35fcca 100644
--- a/src/libcore/cell.rs
+++ b/src/libcore/cell.rs
@@ -229,7 +229,7 @@ impl<T:Copy> Clone for Cell<T> {
 }
 
 #[stable(feature = "rust1", since = "1.0.0")]
-impl<T:Default + Copy> Default for Cell<T> {
+impl<T:Default> Default for Cell<T> {
     /// Creates a `Cell<T>`, with the `Default` value for T.
     #[inline]
     fn default() -> Cell<T> {
@@ -285,7 +285,7 @@ impl<T:Ord + Copy> Ord for Cell<T> {
 }
 
 #[stable(feature = "cell_from", since = "1.12.0")]
-impl<T: Copy> From<T> for Cell<T> {
+impl<T> From<T> for Cell<T> {
     fn from(t: T) -> Cell<T> {
         Cell::new(t)
     }

From ca54fc76ae3045917273c5c102f5d9e0e99deb7e Mon Sep 17 00:00:00 2001
From: Sebastian Waisbrot <seppo0010@gmail.com>
Date: Tue, 14 Feb 2017 01:32:05 -0300
Subject: [PATCH 03/13] Show five traits implementation in help when there are
 exactly five

---
 src/librustc/traits/error_reporting.rs        |  9 ++--
 .../issue-39802-show-5-trait-impls.rs         | 37 ++++++++++++++++
 .../issue-39802-show-5-trait-impls.stderr     | 43 +++++++++++++++++++
 3 files changed, 86 insertions(+), 3 deletions(-)
 create mode 100644 src/test/ui/did_you_mean/issue-39802-show-5-trait-impls.rs
 create mode 100644 src/test/ui/did_you_mean/issue-39802-show-5-trait-impls.stderr

diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs
index 024c14ce9d922..70ca5fe83a932 100644
--- a/src/librustc/traits/error_reporting.rs
+++ b/src/librustc/traits/error_reporting.rs
@@ -36,7 +36,6 @@ use ty::fold::TypeFolder;
 use ty::subst::Subst;
 use util::nodemap::{FxHashMap, FxHashSet};
 
-use std::cmp;
 use std::fmt;
 use syntax::ast;
 use hir::{intravisit, Local, Pat};
@@ -392,12 +391,16 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
             return;
         }
 
-        let end = cmp::min(4, impl_candidates.len());
+        let end = if impl_candidates.len() <= 5 {
+            impl_candidates.len()
+        } else {
+            4
+        };
         err.help(&format!("the following implementations were found:{}{}",
                           &impl_candidates[0..end].iter().map(|candidate| {
                               format!("\n  {:?}", candidate)
                           }).collect::<String>(),
-                          if impl_candidates.len() > 4 {
+                          if impl_candidates.len() > 5 {
                               format!("\nand {} others", impl_candidates.len() - 4)
                           } else {
                               "".to_owned()
diff --git a/src/test/ui/did_you_mean/issue-39802-show-5-trait-impls.rs b/src/test/ui/did_you_mean/issue-39802-show-5-trait-impls.rs
new file mode 100644
index 0000000000000..68b1f79c89bbe
--- /dev/null
+++ b/src/test/ui/did_you_mean/issue-39802-show-5-trait-impls.rs
@@ -0,0 +1,37 @@
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+trait Foo<B> {
+    fn bar(&self){}
+}
+
+impl Foo<u8> for i8 {}
+impl Foo<u16> for i8 {}
+impl Foo<u32> for i8 {}
+impl Foo<u64> for i8 {}
+impl Foo<bool> for i8 {}
+
+impl Foo<u16> for u8 {}
+impl Foo<u32> for u8 {}
+impl Foo<u64> for u8 {}
+impl Foo<bool> for u8 {}
+
+impl Foo<u8> for bool {}
+impl Foo<u16> for bool {}
+impl Foo<u32> for bool {}
+impl Foo<u64> for bool {}
+impl Foo<bool> for bool {}
+impl Foo<i8> for bool {}
+
+fn main() {
+    Foo::<i32>::bar(&1i8);
+    Foo::<i32>::bar(&1u8);
+    Foo::<i32>::bar(&true);
+}
diff --git a/src/test/ui/did_you_mean/issue-39802-show-5-trait-impls.stderr b/src/test/ui/did_you_mean/issue-39802-show-5-trait-impls.stderr
new file mode 100644
index 0000000000000..4ea4adfcfe0fc
--- /dev/null
+++ b/src/test/ui/did_you_mean/issue-39802-show-5-trait-impls.stderr
@@ -0,0 +1,43 @@
+error[E0277]: the trait bound `i8: Foo<i32>` is not satisfied
+  --> $DIR/issue-39802-show-5-trait-impls.rs:34:5
+   |
+34 |     Foo::<i32>::bar(&1i8);
+   |     ^^^^^^^^^^^^^^^ the trait `Foo<i32>` is not implemented for `i8`
+   |
+   = help: the following implementations were found:
+             <i8 as Foo<u8>>
+             <i8 as Foo<u16>>
+             <i8 as Foo<u32>>
+             <i8 as Foo<u64>>
+             <i8 as Foo<bool>>
+   = note: required by `Foo::bar`
+
+error[E0277]: the trait bound `u8: Foo<i32>` is not satisfied
+  --> $DIR/issue-39802-show-5-trait-impls.rs:35:5
+   |
+35 |     Foo::<i32>::bar(&1u8);
+   |     ^^^^^^^^^^^^^^^ the trait `Foo<i32>` is not implemented for `u8`
+   |
+   = help: the following implementations were found:
+             <u8 as Foo<u16>>
+             <u8 as Foo<u32>>
+             <u8 as Foo<u64>>
+             <u8 as Foo<bool>>
+   = note: required by `Foo::bar`
+
+error[E0277]: the trait bound `bool: Foo<i32>` is not satisfied
+  --> $DIR/issue-39802-show-5-trait-impls.rs:36:5
+   |
+36 |     Foo::<i32>::bar(&true);
+   |     ^^^^^^^^^^^^^^^ the trait `Foo<i32>` is not implemented for `bool`
+   |
+   = help: the following implementations were found:
+             <bool as Foo<u8>>
+             <bool as Foo<u16>>
+             <bool as Foo<u32>>
+             <bool as Foo<u64>>
+           and 2 others
+   = note: required by `Foo::bar`
+
+error: aborting due to 3 previous errors
+

From b2c4e74edbbbf9d1c5a43b634aef0b31fb8f94a7 Mon Sep 17 00:00:00 2001
From: Alex Crichton <alex@alexcrichton.com>
Date: Tue, 14 Feb 2017 14:30:39 -0800
Subject: [PATCH 04/13] rustc: Link statically to the MSVCRT

This commit changes all MSVC rustc binaries to be compiled with
`-C target-feature=+crt-static` to link statically against the MSVCRT instead of
dynamically (as it does today). This also necessitates compiling LLVM in a
different fashion, ensuring it's compiled with `/MT` instead of `/MD`.

cc #37406
---
 src/bootstrap/bin/rustc.rs | 5 +++++
 src/bootstrap/native.rs    | 6 ++++++
 2 files changed, 11 insertions(+)

diff --git a/src/bootstrap/bin/rustc.rs b/src/bootstrap/bin/rustc.rs
index 90fd31ecbdd73..62e476bd737d3 100644
--- a/src/bootstrap/bin/rustc.rs
+++ b/src/bootstrap/bin/rustc.rs
@@ -205,6 +205,11 @@ fn main() {
                 }
             }
         }
+
+        if target.contains("pc-windows-msvc") {
+            cmd.arg("-Z").arg("unstable-options");
+            cmd.arg("-C").arg("target-feature=+crt-static");
+        }
     }
 
     if verbose > 1 {
diff --git a/src/bootstrap/native.rs b/src/bootstrap/native.rs
index 21fc61cc81484..f16fc2092f616 100644
--- a/src/bootstrap/native.rs
+++ b/src/bootstrap/native.rs
@@ -99,6 +99,12 @@ pub fn llvm(build: &Build, target: &str) {
        .define("LLVM_TARGET_ARCH", target.split('-').next().unwrap())
        .define("LLVM_DEFAULT_TARGET_TRIPLE", target);
 
+    if target.contains("msvc") {
+        cfg.define("LLVM_USE_CRT_DEBUG", "MT");
+        cfg.define("LLVM_USE_CRT_RELEASE", "MT");
+        cfg.define("LLVM_USE_CRT_RELWITHDEBINFO", "MT");
+    }
+
     if target.starts_with("i686") {
         cfg.define("LLVM_BUILD_32_BITS", "ON");
     }

From aebd94fd3c151212723906fb0445f0153917abac Mon Sep 17 00:00:00 2001
From: est31 <MTest31@outlook.com>
Date: Sun, 12 Feb 2017 06:49:15 +0100
Subject: [PATCH 05/13] Stabilize field init shorthand

Closes #37340.
---
 src/doc/book/src/structs.md                   |  2 --
 src/doc/reference.md                          |  1 -
 src/librustc/lib.rs                           |  2 +-
 src/librustc_incremental/lib.rs               |  2 +-
 src/librustc_typeck/lib.rs                    |  2 +-
 src/libsyntax/feature_gate.rs                 |  9 ++-----
 .../feature-gate-field-init-shorthand.rs      | 24 -------------------
 .../struct-fields-shorthand-unresolved.rs     |  2 --
 .../compile-fail/struct-fields-shorthand.rs   |  2 --
 .../struct-field-numeric-shorthand.rs         |  2 --
 src/test/run-pass/struct-field-shorthand.rs   |  2 --
 11 files changed, 5 insertions(+), 45 deletions(-)
 delete mode 100644 src/test/compile-fail/feature-gate-field-init-shorthand.rs

diff --git a/src/doc/book/src/structs.md b/src/doc/book/src/structs.md
index 51af343c13012..6423147e66e09 100644
--- a/src/doc/book/src/structs.md
+++ b/src/doc/book/src/structs.md
@@ -122,8 +122,6 @@ fields of the data structure are initialized with variables of the same
 names as the fields.
 
 ```
-#![feature(field_init_shorthand)]
-
 #[derive(Debug)]
 struct Person<'a> {
     name: &'a str,
diff --git a/src/doc/reference.md b/src/doc/reference.md
index 7155641e2c28a..f2be20d4a7516 100644
--- a/src/doc/reference.md
+++ b/src/doc/reference.md
@@ -2825,7 +2825,6 @@ This allows a compact syntax with less duplication.
 Example:
 
 ```
-# #![feature(field_init_shorthand)]
 # struct Point3d { x: i32, y: i32, z: i32 }
 # let x = 0;
 # let y_value = 0;
diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs
index 5c0ec8de7ecd2..d144f7575a2e2 100644
--- a/src/librustc/lib.rs
+++ b/src/librustc/lib.rs
@@ -29,7 +29,7 @@
 #![feature(conservative_impl_trait)]
 #![feature(const_fn)]
 #![feature(core_intrinsics)]
-#![feature(field_init_shorthand)]
+#![cfg_attr(stage0,feature(field_init_shorthand))]
 #![feature(i128_type)]
 #![feature(libc)]
 #![feature(loop_break_value)]
diff --git a/src/librustc_incremental/lib.rs b/src/librustc_incremental/lib.rs
index e3c339829f6a4..906c4b7256fdc 100644
--- a/src/librustc_incremental/lib.rs
+++ b/src/librustc_incremental/lib.rs
@@ -24,7 +24,7 @@
 #![feature(rand)]
 #![feature(core_intrinsics)]
 #![feature(conservative_impl_trait)]
-#![feature(field_init_shorthand)]
+#![cfg_attr(stage0,feature(field_init_shorthand))]
 #![feature(pub_restricted)]
 
 extern crate graphviz;
diff --git a/src/librustc_typeck/lib.rs b/src/librustc_typeck/lib.rs
index f19a59a5d38ae..0bcf8ab7d6c20 100644
--- a/src/librustc_typeck/lib.rs
+++ b/src/librustc_typeck/lib.rs
@@ -77,7 +77,7 @@ This API is completely unstable and subject to change.
 #![feature(box_patterns)]
 #![feature(box_syntax)]
 #![feature(conservative_impl_trait)]
-#![feature(field_init_shorthand)]
+#![cfg_attr(stage0,feature(field_init_shorthand))]
 #![feature(loop_break_value)]
 #![feature(quote)]
 #![feature(rustc_diagnostic_macros)]
diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs
index a7c86bf8e06ba..1bed3e2784773 100644
--- a/src/libsyntax/feature_gate.rs
+++ b/src/libsyntax/feature_gate.rs
@@ -288,9 +288,6 @@ declare_features! (
     // Allows attributes on lifetime/type formal parameters in generics (RFC 1327)
     (active, generic_param_attrs, "1.11.0", Some(34761)),
 
-    // Allows field shorthands (`x` meaning `x: x`) in struct literal expressions.
-    (active, field_init_shorthand, "1.14.0", Some(37340)),
-
     // The #![windows_subsystem] attribute
     (active, windows_subsystem, "1.14.0", Some(37499)),
 
@@ -385,6 +382,8 @@ declare_features! (
     (accepted, more_struct_aliases, "1.16.0", Some(37544)),
     // elide `'static` lifetimes in `static`s and `const`s
     (accepted, static_in_const, "1.17.0", Some(35897)),
+    // Allows field shorthands (`x` meaning `x: x`) in struct literal expressions.
+    (accepted, field_init_shorthand, "1.17.0", Some(37340)),
 );
 // (changing above list without updating src/doc/reference.md makes @cmr sad)
 
@@ -1233,10 +1232,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
             }
             ast::ExprKind::Struct(_, ref fields, _) => {
                 for field in fields {
-                    if field.is_shorthand {
-                        gate_feature_post!(&self, field_init_shorthand, field.span,
-                                           "struct field shorthands are unstable");
-                    }
                     if starts_with_digit(&field.ident.node.name.as_str()) {
                         gate_feature_post!(&self, relaxed_adts,
                                           field.span,
diff --git a/src/test/compile-fail/feature-gate-field-init-shorthand.rs b/src/test/compile-fail/feature-gate-field-init-shorthand.rs
deleted file mode 100644
index cd2dae7f461ab..0000000000000
--- a/src/test/compile-fail/feature-gate-field-init-shorthand.rs
+++ /dev/null
@@ -1,24 +0,0 @@
-// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-struct Foo {
-    x: i32,
-    y: bool,
-    z: i32
-}
-
-fn main() {
-    let (x, y, z) = (1, true, 2);
-    let _ = Foo {
-        x, //~ ERROR struct field shorthands are unstable
-        y: y,
-        z //~ ERROR struct field shorthands are unstable
-    };
-}
diff --git a/src/test/compile-fail/struct-fields-shorthand-unresolved.rs b/src/test/compile-fail/struct-fields-shorthand-unresolved.rs
index 02372a3919da5..984f337fb3d14 100644
--- a/src/test/compile-fail/struct-fields-shorthand-unresolved.rs
+++ b/src/test/compile-fail/struct-fields-shorthand-unresolved.rs
@@ -8,8 +8,6 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-#![feature(field_init_shorthand)]
-
 struct Foo {
     x: i32,
     y: i32
diff --git a/src/test/compile-fail/struct-fields-shorthand.rs b/src/test/compile-fail/struct-fields-shorthand.rs
index f764322cadbbb..e46ae73f1a1d4 100644
--- a/src/test/compile-fail/struct-fields-shorthand.rs
+++ b/src/test/compile-fail/struct-fields-shorthand.rs
@@ -8,8 +8,6 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-#![feature(field_init_shorthand)]
-
 struct Foo {
     x: i32,
     y: i32
diff --git a/src/test/parse-fail/struct-field-numeric-shorthand.rs b/src/test/parse-fail/struct-field-numeric-shorthand.rs
index 2a5c25d1868f5..49ba0d8bde625 100644
--- a/src/test/parse-fail/struct-field-numeric-shorthand.rs
+++ b/src/test/parse-fail/struct-field-numeric-shorthand.rs
@@ -10,8 +10,6 @@
 
 // compile-flags: -Z parse-only
 
-#![feature(field_init_shorthand)]
-
 struct Rgb(u8, u8, u8);
 
 fn main() {
diff --git a/src/test/run-pass/struct-field-shorthand.rs b/src/test/run-pass/struct-field-shorthand.rs
index fe91db572d20e..b61e232200c9a 100644
--- a/src/test/run-pass/struct-field-shorthand.rs
+++ b/src/test/run-pass/struct-field-shorthand.rs
@@ -8,8 +8,6 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-#![feature(field_init_shorthand)]
-
 struct Foo {
     x: i32,
     y: bool,

From 5156dedec88a94191eec9e629c93c8e58b71f44f Mon Sep 17 00:00:00 2001
From: king6cong <king6cong@gmail.com>
Date: Wed, 15 Feb 2017 14:52:13 +0800
Subject: [PATCH 06/13] make doc consistent with var name

---
 src/libstd/collections/hash/map.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs
index ffb7a1a1fc15f..e67b6060b9a3b 100644
--- a/src/libstd/collections/hash/map.rs
+++ b/src/libstd/collections/hash/map.rs
@@ -437,7 +437,7 @@ fn pop_internal<K, V>(starting_bucket: FullBucketMut<K, V>) -> (K, V) {
 /// Perform robin hood bucket stealing at the given `bucket`. You must
 /// also pass that bucket's displacement so we don't have to recalculate it.
 ///
-/// `hash`, `k`, and `v` are the elements to "robin hood" into the hashtable.
+/// `hash`, `key`, and `val` are the elements to "robin hood" into the hashtable.
 fn robin_hood<'a, K: 'a, V: 'a>(bucket: FullBucketMut<'a, K, V>,
                                 mut displacement: usize,
                                 mut hash: SafeHash,

From 938fed7f0f28b68a16d8938221d1bc59e697ffa1 Mon Sep 17 00:00:00 2001
From: Luxko <liarluxlux@gmail.com>
Date: Wed, 15 Feb 2017 03:53:27 -0600
Subject: [PATCH 07/13] Update procedural-macros.md

Fix typo
---
 src/doc/book/src/procedural-macros.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/doc/book/src/procedural-macros.md b/src/doc/book/src/procedural-macros.md
index d286c3b7bdc63..6c4700f9305ca 100644
--- a/src/doc/book/src/procedural-macros.md
+++ b/src/doc/book/src/procedural-macros.md
@@ -99,7 +99,7 @@ created, we'll add it to our toml:
 hello-world-derive = { path = "hello-world-derive" }
 ```
 
-As for our the source of our `hello-world-derive` crate, here's an example:
+As for the source of our `hello-world-derive` crate, here's an example:
 
 ```rust,ignore
 extern crate proc_macro;

From b82131332706e5b39cb12186ce7ff6c682281464 Mon Sep 17 00:00:00 2001
From: king6cong <king6cong@gmail.com>
Date: Wed, 15 Feb 2017 18:38:34 +0800
Subject: [PATCH 08/13] sys/mod doc update and mod import order adjust

---
 src/libstd/sys/mod.rs | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/src/libstd/sys/mod.rs b/src/libstd/sys/mod.rs
index 14da376efa998..ef4dc365dbef8 100644
--- a/src/libstd/sys/mod.rs
+++ b/src/libstd/sys/mod.rs
@@ -13,11 +13,11 @@
 //! The `std::sys` module is the abstracted interface through which
 //! `std` talks to the underlying operating system. It has different
 //! implementations for different operating system families, today
-//! just Unix and Windows.
+//! just Unix and Windows, and initial support for Redox.
 //!
 //! The centralization of platform-specific code in this module is
 //! enforced by the "platform abstraction layer" tidy script in
-//! `tools/tidy/pal.rs`.
+//! `tools/tidy/src/pal.rs`.
 //!
 //! This module is closely related to the platform-independent system
 //! integration code in `std::sys_common`. See that module's
@@ -34,10 +34,6 @@
 
 pub use self::imp::*;
 
-#[cfg(target_os = "redox")]
-#[path = "redox/mod.rs"]
-mod imp;
-
 #[cfg(unix)]
 #[path = "unix/mod.rs"]
 mod imp;
@@ -45,3 +41,7 @@ mod imp;
 #[cfg(windows)]
 #[path = "windows/mod.rs"]
 mod imp;
+
+#[cfg(target_os = "redox")]
+#[path = "redox/mod.rs"]
+mod imp;

From 577497b541110f814c8385eff86a2d2e4b935585 Mon Sep 17 00:00:00 2001
From: Dmitry Guzeev <dmitry.guzeev@yahoo.com>
Date: Wed, 15 Feb 2017 15:13:31 +0300
Subject: [PATCH 09/13] Fix typo

---
 src/grammar/README.md | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/grammar/README.md b/src/grammar/README.md
index cd2dd38de36aa..83808108ff832 100644
--- a/src/grammar/README.md
+++ b/src/grammar/README.md
@@ -8,7 +8,7 @@ The build of the rust part is included with `make tidy` and can be run with `mak
 
 # Manual build
 
-To use manually, assuming antlr4 ist installed at `/usr/share/java/antlr-complete.jar`:
+To use manually, assuming antlr4 is installed at `/usr/share/java/antlr-complete.jar`:
 
 ```
 antlr4 RustLexer.g4
@@ -20,8 +20,8 @@ for file in ../*/**.rs; do
 done
 ```
 
-Note That the `../*/**.rs` glob will match every `*.rs` file in the above
-directory and all of its recursive children. This is a zsh extension.
+Note that the `../*/**.rs` glob will match every `*.rs` file in the above
+directory and all of its recursive children. This is a Zsh extension.
 
 
 ## Cleanup

From b6a161833289d402986164912aeb9d005857675d Mon Sep 17 00:00:00 2001
From: Michal Nazarewicz <mina86@mina86.com>
Date: Mon, 13 Feb 2017 02:09:24 +0100
Subject: [PATCH 10/13] =?UTF-8?q?book:=20don=E2=80=99t=20use=20GNU=20exten?=
 =?UTF-8?q?sions=20in=20the=20example=20unnecessarily?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The use of a GNU C extension for bloc expressions is immaterial to the
actual problem with C macros that the section tries to show so don’t
use it and instead use a plain C way of writing the macro.
---
 src/doc/book/src/macros.md | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/src/doc/book/src/macros.md b/src/doc/book/src/macros.md
index 3ccbeb05f01db..ae1e1c65dd225 100644
--- a/src/doc/book/src/macros.md
+++ b/src/doc/book/src/macros.md
@@ -261,36 +261,34 @@ The metavariable `$x` is parsed as a single expression node, and keeps its
 place in the syntax tree even after substitution.
 
 Another common problem in macro systems is ‘variable capture’. Here’s a C
-macro, using [a GNU C extension] to emulate Rust’s expression blocks.
-
-[a GNU C extension]: https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html
+macro using a block with multiple statements.
 
 ```text
-#define LOG(msg) ({ \
+#define LOG(msg) do { \
     int state = get_log_state(); \
     if (state > 0) { \
         printf("log(%d): %s\n", state, msg); \
     } \
-})
+} while (0)
 ```
 
 Here’s a simple use case that goes terribly wrong:
 
 ```text
 const char *state = "reticulating splines";
-LOG(state)
+LOG(state);
 ```
 
 This expands to
 
 ```text
 const char *state = "reticulating splines";
-{
+do {
     int state = get_log_state();
     if (state > 0) {
         printf("log(%d): %s\n", state, state);
     }
-}
+} while (0);
 ```
 
 The second variable named `state` shadows the first one.  This is a problem

From cf20d8e23cb590ab405476ce0ad184d9856be9cd Mon Sep 17 00:00:00 2001
From: Colm Seale <colm.seale@gmail.com>
Date: Wed, 15 Feb 2017 01:18:11 +0000
Subject: [PATCH 11/13] static recursion test added to compile-fail test suite

    Issue #39059
    r? @est31
---
 .../feature-gate-static_recursion.rs          | 49 +++++++++++++++++++
 src/tools/tidy/src/features.rs                |  2 +-
 2 files changed, 50 insertions(+), 1 deletion(-)
 create mode 100644 src/test/compile-fail/feature-gate-static_recursion.rs

diff --git a/src/test/compile-fail/feature-gate-static_recursion.rs b/src/test/compile-fail/feature-gate-static_recursion.rs
new file mode 100644
index 0000000000000..bd20c891d8ed3
--- /dev/null
+++ b/src/test/compile-fail/feature-gate-static_recursion.rs
@@ -0,0 +1,49 @@
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+static mut S: *const u8 = unsafe { &S as *const *const u8 as *const u8 };
+//~^ ERROR recursive static (see issue #29719)
+
+struct StaticDoubleLinked {
+    prev: &'static StaticDoubleLinked,
+    next: &'static StaticDoubleLinked,
+    data: i32,
+    head: bool,
+}
+
+static L1: StaticDoubleLinked = StaticDoubleLinked{prev: &L3, next: &L2, data: 1, head: true};
+//~^ ERROR recursive static (see issue #29719)
+//~^^ ERROR recursive static (see issue #29719)
+//~^^^ ERROR recursive static (see issue #29719)
+static L2: StaticDoubleLinked = StaticDoubleLinked{prev: &L1, next: &L3, data: 2, head: false};
+static L3: StaticDoubleLinked = StaticDoubleLinked{prev: &L2, next: &L1, data: 3, head: false};
+
+
+pub fn main() {
+    unsafe { assert_eq!(S, *(S as *const *const u8)); }
+
+    let mut test_vec = Vec::new();
+    let mut cur = &L1;
+    loop {
+        test_vec.push(cur.data);
+        cur = cur.next;
+        if cur.head { break }
+    }
+    assert_eq!(&test_vec, &[1,2,3]);
+
+    let mut test_vec = Vec::new();
+    let mut cur = &L1;
+    loop {
+        cur = cur.prev;
+        test_vec.push(cur.data);
+        if cur.head { break }
+    }
+    assert_eq!(&test_vec, &[3,2,1]);
+}
diff --git a/src/tools/tidy/src/features.rs b/src/tools/tidy/src/features.rs
index cb6e73237d5eb..13f272517b1fd 100644
--- a/src/tools/tidy/src/features.rs
+++ b/src/tools/tidy/src/features.rs
@@ -166,7 +166,7 @@ pub fn check(path: &Path, bad: &mut bool) {
 
     // FIXME get this whitelist empty.
     let whitelist = vec![
-        "abi_ptx", "simd", "static_recursion",
+        "abi_ptx", "simd",
         "cfg_target_has_atomic",
         "unboxed_closures", "stmt_expr_attributes",
         "cfg_target_thread_local", "unwind_attributes",

From d5a4db3c16c5fa203f03b7f0b9c7f85d17e8b8ad Mon Sep 17 00:00:00 2001
From: Peter Atashian <retep998@gmail.com>
Date: Wed, 15 Feb 2017 17:31:51 -0500
Subject: [PATCH 12/13] Fix parameter to GetUserProfileDirectoryW

---
 src/libstd/sys/windows/c.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/libstd/sys/windows/c.rs b/src/libstd/sys/windows/c.rs
index e5010ca356449..4daab31c28f49 100644
--- a/src/libstd/sys/windows/c.rs
+++ b/src/libstd/sys/windows/c.rs
@@ -912,7 +912,7 @@ extern "system" {
     pub fn Sleep(dwMilliseconds: DWORD);
     pub fn GetProcessId(handle: HANDLE) -> DWORD;
     pub fn GetUserProfileDirectoryW(hToken: HANDLE,
-                                    lpProfileDir: LPCWSTR,
+                                    lpProfileDir: LPWSTR,
                                     lpcchSize: *mut DWORD) -> BOOL;
     pub fn SetHandleInformation(hObject: HANDLE,
                                 dwMask: DWORD,

From e77f8568f67b6dc265a620f7506a6f931c3a002e Mon Sep 17 00:00:00 2001
From: Brian Anderson <banderson@mozilla.com>
Date: Tue, 14 Feb 2017 04:10:52 +0000
Subject: [PATCH 13/13] Add a test that -fPIC is applied

---
 src/test/run-make/fpic/Makefile |  9 +++++++++
 src/test/run-make/fpic/hello.rs | 11 +++++++++++
 2 files changed, 20 insertions(+)
 create mode 100644 src/test/run-make/fpic/Makefile
 create mode 100644 src/test/run-make/fpic/hello.rs

diff --git a/src/test/run-make/fpic/Makefile b/src/test/run-make/fpic/Makefile
new file mode 100644
index 0000000000000..da69c83eb3713
--- /dev/null
+++ b/src/test/run-make/fpic/Makefile
@@ -0,0 +1,9 @@
+-include ../tools.mk
+
+# Test for #39529. 
+# `-z text` causes ld to error if there are any non-PIC sections
+
+all:
+ifndef IS_WINDOWS
+	$(RUSTC) hello.rs -C link-args=-Wl,-z,text
+endif
diff --git a/src/test/run-make/fpic/hello.rs b/src/test/run-make/fpic/hello.rs
new file mode 100644
index 0000000000000..a9e231b0ea839
--- /dev/null
+++ b/src/test/run-make/fpic/hello.rs
@@ -0,0 +1,11 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+fn main() { }