From a5e8bbf32b32ed7d3b06149fdfa0977c0ec0a22e Mon Sep 17 00:00:00 2001 From: Charlie Fan Date: Fri, 10 Feb 2017 16:38:59 +0800 Subject: [PATCH 1/9] Add `swap` method for `Cell` --- src/libcore/cell.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index ab44342ebf02f..d130b0279a20d 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -186,6 +186,7 @@ use fmt::{self, Debug, Display}; use marker::Unsize; use mem; use ops::{Deref, DerefMut, CoerceUnsized}; +use ptr; /// A mutable memory location. /// @@ -387,6 +388,32 @@ impl Cell { drop(old); } + /// Swaps the values of two Cells. + /// Difference with `std::mem::swap` is that this function doesn't require `&mut` reference. + /// + /// # Examples + /// + /// ``` + /// #![feature(move_cell)] + /// use std::cell::Cell; + /// + /// let c1 = Cell::new(5i32); + /// let c2 = Cell::new(10i32); + /// c1.swap(&c2); + /// assert_eq!(10, c1.get()); + /// assert_eq!(5, c2.get()); + /// ``` + #[inline] + #[unstable(feature = "move_cell", issue = "39264")] + pub fn swap(&self, other: &Self) { + if ptr::eq(self, other) { + return; + } + unsafe { + ptr::swap(self.value.get(), other.value.get()); + } + } + /// Replaces the contained value. /// /// # Examples From ee54be3c9a8099d45d64764f0e50c315d5256a4c Mon Sep 17 00:00:00 2001 From: Shawn Walker-Salas Date: Sat, 11 Feb 2017 09:24:33 -0800 Subject: [PATCH 2/9] Add Solaris as recognized ostype Add cputype recognition for Solaris Fixes #39729 --- src/bootstrap/bootstrap.py | 15 +++++++++++++++ src/libstd/build.rs | 2 ++ src/libunwind/build.rs | 2 ++ 3 files changed, 19 insertions(+) diff --git a/src/bootstrap/bootstrap.py b/src/bootstrap/bootstrap.py index 27255b6910093..9593e3f0793b3 100644 --- a/src/bootstrap/bootstrap.py +++ b/src/bootstrap/bootstrap.py @@ -345,6 +345,21 @@ def build_triple(self): ostype = 'unknown-openbsd' elif ostype == 'NetBSD': ostype = 'unknown-netbsd' + elif ostype == 'SunOS': + ostype = 'sun-solaris' + # On Solaris, uname -m will return a machine classification instead + # of a cpu type, so uname -p is recommended instead. However, the + # output from that option is too generic for our purposes (it will + # always emit 'i386' on x86/amd64 systems). As such, isainfo -k + # must be used instead. + try: + cputype = subprocess.check_output(['isainfo', + '-k']).strip().decode(default_encoding) + except (subprocess.CalledProcessError, WindowsError): + err = "isainfo not found" + if self.verbose: + raise Exception(err) + sys.exit(err) elif ostype == 'Darwin': ostype = 'apple-darwin' elif ostype.startswith('MINGW'): diff --git a/src/libstd/build.rs b/src/libstd/build.rs index 0fca374f6e6d1..790cd5b65ba30 100644 --- a/src/libstd/build.rs +++ b/src/libstd/build.rs @@ -46,6 +46,8 @@ fn main() { } else if target.contains("dragonfly") || target.contains("bitrig") || target.contains("netbsd") || target.contains("openbsd") { println!("cargo:rustc-link-lib=pthread"); + } else if target.contains("solaris") { + println!("cargo:rustc-link-lib=gcc_s"); } else if target.contains("apple-darwin") { println!("cargo:rustc-link-lib=System"); } else if target.contains("apple-ios") { diff --git a/src/libunwind/build.rs b/src/libunwind/build.rs index f18b694d3d0c7..ea0d76978339d 100644 --- a/src/libunwind/build.rs +++ b/src/libunwind/build.rs @@ -27,6 +27,8 @@ fn main() { println!("cargo:rustc-link-lib=gcc_s"); } else if target.contains("openbsd") { println!("cargo:rustc-link-lib=gcc"); + } else if target.contains("solaris") { + println!("cargo:rustc-link-lib=gcc_s"); } else if target.contains("bitrig") { println!("cargo:rustc-link-lib=c++abi"); } else if target.contains("dragonfly") { From 33b655e6a8db00d099d1ef37c2f39f73b1248190 Mon Sep 17 00:00:00 2001 From: Shawn Walker-Salas Date: Sat, 11 Feb 2017 20:38:13 -0800 Subject: [PATCH 3/9] fix copy pasta Don't need to catch WindowsError. That was very silly of me. --- src/bootstrap/bootstrap.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bootstrap/bootstrap.py b/src/bootstrap/bootstrap.py index 9593e3f0793b3..7163a6f359cda 100644 --- a/src/bootstrap/bootstrap.py +++ b/src/bootstrap/bootstrap.py @@ -315,7 +315,7 @@ def build_triple(self): try: ostype = subprocess.check_output(['uname', '-s']).strip().decode(default_encoding) cputype = subprocess.check_output(['uname', '-m']).strip().decode(default_encoding) - except (subprocess.CalledProcessError, WindowsError): + except subprocess.CalledProcessError: if sys.platform == 'win32': return 'x86_64-pc-windows-msvc' err = "uname not found" From 4a618fee1efc279d8fe2386f3c74b7e3f3265aa8 Mon Sep 17 00:00:00 2001 From: Shawn Walker-Salas Date: Sat, 11 Feb 2017 22:55:25 -0800 Subject: [PATCH 4/9] fix exception handling for isainfo execution failure remove unnecessary gcc_s addition in libstd for Solaris --- src/bootstrap/bootstrap.py | 2 +- src/libstd/build.rs | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/bootstrap/bootstrap.py b/src/bootstrap/bootstrap.py index 7163a6f359cda..a632a82bf7d01 100644 --- a/src/bootstrap/bootstrap.py +++ b/src/bootstrap/bootstrap.py @@ -355,7 +355,7 @@ def build_triple(self): try: cputype = subprocess.check_output(['isainfo', '-k']).strip().decode(default_encoding) - except (subprocess.CalledProcessError, WindowsError): + except (subprocess.CalledProcessError, OSError): err = "isainfo not found" if self.verbose: raise Exception(err) diff --git a/src/libstd/build.rs b/src/libstd/build.rs index 790cd5b65ba30..0fca374f6e6d1 100644 --- a/src/libstd/build.rs +++ b/src/libstd/build.rs @@ -46,8 +46,6 @@ fn main() { } else if target.contains("dragonfly") || target.contains("bitrig") || target.contains("netbsd") || target.contains("openbsd") { println!("cargo:rustc-link-lib=pthread"); - } else if target.contains("solaris") { - println!("cargo:rustc-link-lib=gcc_s"); } else if target.contains("apple-darwin") { println!("cargo:rustc-link-lib=System"); } else if target.contains("apple-ios") { From 3807e1f393e3022dcf686e2109eda1fb34eb22c9 Mon Sep 17 00:00:00 2001 From: Shawn Walker-Salas Date: Sun, 12 Feb 2017 11:24:06 -0800 Subject: [PATCH 5/9] fix portability issue in error handling of build_triple --- src/bootstrap/bootstrap.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bootstrap/bootstrap.py b/src/bootstrap/bootstrap.py index a632a82bf7d01..caf2402f40c4b 100644 --- a/src/bootstrap/bootstrap.py +++ b/src/bootstrap/bootstrap.py @@ -315,7 +315,7 @@ def build_triple(self): try: ostype = subprocess.check_output(['uname', '-s']).strip().decode(default_encoding) cputype = subprocess.check_output(['uname', '-m']).strip().decode(default_encoding) - except subprocess.CalledProcessError: + except (subprocess.CalledProcessError, OSError): if sys.platform == 'win32': return 'x86_64-pc-windows-msvc' err = "uname not found" From 6194a7643c799c280c762917d8204275a2898f47 Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Sun, 12 Feb 2017 19:16:22 -0500 Subject: [PATCH 6/9] Remove '--disable-rustbuild' option from configure script. Fixes https://github.com/rust-lang/rust/issues/39762. --- configure | 1 - 1 file changed, 1 deletion(-) diff --git a/configure b/configure index c751ad9731a7d..d529375277bd9 100755 --- a/configure +++ b/configure @@ -644,7 +644,6 @@ opt stage0-landing-pads 1 "enable landing pads during bootstrap with stage0" opt dist-host-only 0 "only install bins for the host architecture" opt inject-std-version 1 "inject the current compiler version of libstd into programs" opt llvm-version-check 1 "check if the LLVM version is supported, build anyway" -opt rustbuild 1 "use the rust and cargo based build system" opt codegen-tests 1 "run the src/test/codegen tests" opt option-checking 1 "complain about unrecognized options in this configure script" opt ninja 0 "build LLVM using the Ninja generator (for MSVC, requires building in the correct environment)" From 8443c1e3b0676bc44f964275d19d15de5960c1a4 Mon Sep 17 00:00:00 2001 From: king6cong Date: Mon, 13 Feb 2017 18:41:45 +0800 Subject: [PATCH 7/9] typo fix --- src/libcollections/vec.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index 3873b3535a07b..9e3f117f9b20e 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -1213,7 +1213,7 @@ impl Vec { unsafe { let mut ptr = self.as_mut_ptr().offset(self.len() as isize); // Use SetLenOnDrop to work around bug where compiler - // may not realize the store through `ptr` trough self.set_len() + // may not realize the store through `ptr` through self.set_len() // don't alias. let mut local_len = SetLenOnDrop::new(&mut self.len); From 79d32e99481c1eb77f84edc21825aa608fa7ca8a Mon Sep 17 00:00:00 2001 From: Jake Goulding Date: Fri, 10 Feb 2017 21:09:54 -0500 Subject: [PATCH 8/9] Remove duplicated "parameter" in E0089 text Closes #39732 --- src/librustc_typeck/check/mod.rs | 7 ++----- src/test/compile-fail/E0089.rs | 5 ++--- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 8329d3eeed9e5..fd8bd37e4781c 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -4566,14 +4566,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { } else if !infer_types && types.len() < required_len { let adjust = |len| if len > 1 { "parameters" } else { "parameter" }; let required_param_str = adjust(required_len); - let actual_param_str = adjust(types.len()); struct_span_err!(self.tcx.sess, span, E0089, "too few type parameters provided: \ - expected {} {}, found {} {}", + expected {}, found {}", count(required_len), - required_param_str, - count(types.len()), - actual_param_str) + count(types.len())) .span_label(span, &format!("expected {} type {}", required_len, required_param_str)) .emit(); } diff --git a/src/test/compile-fail/E0089.rs b/src/test/compile-fail/E0089.rs index 9ce36523709e5..b767f129b727c 100644 --- a/src/test/compile-fail/E0089.rs +++ b/src/test/compile-fail/E0089.rs @@ -11,7 +11,6 @@ fn foo() {} fn main() { - foo::(); -//~^ ERROR E0089 -//~| NOTE expected 2 type parameters + foo::(); //~ ERROR expected 2 parameters, found 1 parameter [E0089] + //~| NOTE expected 2 type parameters } From 1c998416ee1eed8c7377c081668651b364cb738e Mon Sep 17 00:00:00 2001 From: Jake Goulding Date: Sun, 12 Feb 2017 20:29:51 -0500 Subject: [PATCH 9/9] Standardize lifetime and type parameter count mismatch errors They now always say how many lifetime / type parameters were expected and are explicit about stating "lifetime" or "type" instead of just "parameter". --- src/librustc_typeck/check/mod.rs | 43 +++++++++++-------- src/test/compile-fail/E0087.rs | 10 +++-- src/test/compile-fail/E0088.rs | 10 +++-- src/test/compile-fail/E0089.rs | 2 +- src/test/compile-fail/E0090.rs | 5 ++- .../compile-fail/ufcs-qpath-missing-params.rs | 2 +- 6 files changed, 42 insertions(+), 30 deletions(-) diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index fd8bd37e4781c..4b36e682f1e82 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -4510,28 +4510,32 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { } }; - let count = |n| { - format!("{} parameter{}", n, if n == 1 { "" } else { "s" }) + let count_lifetime_params = |n| { + format!("{} lifetime parameter{}", n, if n == 1 { "" } else { "s" }) + }; + let count_type_params = |n| { + format!("{} type parameter{}", n, if n == 1 { "" } else { "s" }) }; // Check provided lifetime parameters. let lifetime_defs = segment.map_or(&[][..], |(_, generics)| &generics.regions); if lifetimes.len() > lifetime_defs.len() { + let expected_text = count_lifetime_params(lifetime_defs.len()); + let actual_text = count_lifetime_params(lifetimes.len()); struct_span_err!(self.tcx.sess, span, E0088, "too many lifetime parameters provided: \ - expected {}, found {}", - count(lifetime_defs.len()), - count(lifetimes.len())) - .span_label(span, &format!("unexpected lifetime parameter{}", - match lifetimes.len() { 1 => "", _ => "s" })) + expected at most {}, found {}", + expected_text, actual_text) + .span_label(span, &format!("expected {}", expected_text)) .emit(); } else if lifetimes.len() > 0 && lifetimes.len() < lifetime_defs.len() { + let expected_text = count_lifetime_params(lifetime_defs.len()); + let actual_text = count_lifetime_params(lifetimes.len()); struct_span_err!(self.tcx.sess, span, E0090, "too few lifetime parameters provided: \ - expected {}, found {}", - count(lifetime_defs.len()), - count(lifetimes.len())) - .span_label(span, &format!("too few lifetime parameters")) + expected {}, found {}", + expected_text, actual_text) + .span_label(span, &format!("expected {}", expected_text)) .emit(); } @@ -4552,26 +4556,27 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { .count(); if types.len() > type_defs.len() { let span = types[type_defs.len()].span; + let expected_text = count_type_params(type_defs.len()); + let actual_text = count_type_params(types.len()); struct_span_err!(self.tcx.sess, span, E0087, "too many type parameters provided: \ expected at most {}, found {}", - count(type_defs.len()), - count(types.len())) - .span_label(span, &format!("too many type parameters")).emit(); + expected_text, actual_text) + .span_label(span, &format!("expected {}", expected_text)) + .emit(); // To prevent derived errors to accumulate due to extra // type parameters, we force instantiate_value_path to // use inference variables instead of the provided types. *segment = None; } else if !infer_types && types.len() < required_len { - let adjust = |len| if len > 1 { "parameters" } else { "parameter" }; - let required_param_str = adjust(required_len); + let expected_text = count_type_params(required_len); + let actual_text = count_type_params(types.len()); struct_span_err!(self.tcx.sess, span, E0089, "too few type parameters provided: \ expected {}, found {}", - count(required_len), - count(types.len())) - .span_label(span, &format!("expected {} type {}", required_len, required_param_str)) + expected_text, actual_text) + .span_label(span, &format!("expected {}", expected_text)) .emit(); } diff --git a/src/test/compile-fail/E0087.rs b/src/test/compile-fail/E0087.rs index 7c98de59e2797..0b8150affc0c0 100644 --- a/src/test/compile-fail/E0087.rs +++ b/src/test/compile-fail/E0087.rs @@ -8,9 +8,13 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn foo() {} +fn foo() {} +fn bar() {} fn main() { - foo::(); //~ ERROR E0087 - //~^ NOTE too many type parameters + foo::(); //~ ERROR expected at most 0 type parameters, found 1 type parameter [E0087] + //~^ NOTE expected 0 type parameters + + bar::(); //~ ERROR expected at most 1 type parameter, found 2 type parameters [E0087] + //~^ NOTE expected 1 type parameter } diff --git a/src/test/compile-fail/E0088.rs b/src/test/compile-fail/E0088.rs index 9ec0960322410..de188677a1121 100644 --- a/src/test/compile-fail/E0088.rs +++ b/src/test/compile-fail/E0088.rs @@ -12,9 +12,11 @@ fn f() {} fn g<'a>() {} fn main() { - f::<'static>(); //~ ERROR E0088 - //~^ unexpected lifetime parameter + f::<'static>(); + //~^ ERROR expected at most 0 lifetime parameters, found 1 lifetime parameter [E0088] + //~| NOTE expected 0 lifetime parameters - g::<'static, 'static>(); //~ ERROR E0088 - //~^ unexpected lifetime parameters + g::<'static, 'static>(); + //~^ ERROR expected at most 0 lifetime parameters, found 2 lifetime parameters [E0088] + //~| NOTE expected 0 lifetime parameters } diff --git a/src/test/compile-fail/E0089.rs b/src/test/compile-fail/E0089.rs index b767f129b727c..986630d818fff 100644 --- a/src/test/compile-fail/E0089.rs +++ b/src/test/compile-fail/E0089.rs @@ -11,6 +11,6 @@ fn foo() {} fn main() { - foo::(); //~ ERROR expected 2 parameters, found 1 parameter [E0089] + foo::(); //~ ERROR expected 2 type parameters, found 1 type parameter [E0089] //~| NOTE expected 2 type parameters } diff --git a/src/test/compile-fail/E0090.rs b/src/test/compile-fail/E0090.rs index 4600d2d63856a..c37f37031add6 100644 --- a/src/test/compile-fail/E0090.rs +++ b/src/test/compile-fail/E0090.rs @@ -9,7 +9,8 @@ // except according to those terms. fn foo<'a: 'b, 'b: 'a>() {} + fn main() { - foo::<'static>();//~ ERROR E0090 - //~^ too few lifetime parameters + foo::<'static>(); //~ ERROR expected 2 lifetime parameters, found 1 lifetime parameter [E0090] + //~^ NOTE expected 2 lifetime parameters } diff --git a/src/test/compile-fail/ufcs-qpath-missing-params.rs b/src/test/compile-fail/ufcs-qpath-missing-params.rs index a24515c516098..5c108e052160c 100644 --- a/src/test/compile-fail/ufcs-qpath-missing-params.rs +++ b/src/test/compile-fail/ufcs-qpath-missing-params.rs @@ -22,5 +22,5 @@ impl<'a> IntoCow<'a, str> for String { fn main() { ::into_cow("foo".to_string()); - //~^ ERROR too few type parameters provided: expected 1 parameter + //~^ ERROR too few type parameters provided: expected 1 type parameter }