From 415aff0516fd90fb11fc7f01743480f22460a3f7 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Mon, 30 Mar 2020 06:43:49 +0200 Subject: [PATCH 01/13] move OS constants to platform crate --- Cargo.lock | 4 ++-- src/libstd/Cargo.toml | 2 +- src/libstd/sys/hermit/fs.rs | 10 ++-------- 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fdc84e53d121d..a0233124b84ac 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1372,9 +1372,9 @@ dependencies = [ [[package]] name = "hermit-abi" -version = "0.1.1" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f22b8f315b98f415780ddbe9163c7dbbc5a07225b6d102ace1d8aeef85775140" +checksum = "0ebe6e23502442c4c9cd80fcb8bdf867dc5f4a9e9f1d882499fa49c5ed83e559" dependencies = [ "compiler_builtins", "libc", diff --git a/src/libstd/Cargo.toml b/src/libstd/Cargo.toml index 0dd2f79d066e4..1bb764897ea54 100644 --- a/src/libstd/Cargo.toml +++ b/src/libstd/Cargo.toml @@ -41,7 +41,7 @@ dlmalloc = { version = "0.1", features = ['rustc-dep-of-std'] } fortanix-sgx-abi = { version = "0.3.2", features = ['rustc-dep-of-std'] } [target.'cfg(all(any(target_arch = "x86_64", target_arch = "aarch64"), target_os = "hermit"))'.dependencies] -hermit-abi = { version = "0.1", features = ['rustc-dep-of-std'] } +hermit-abi = { version = "0.1.9", features = ['rustc-dep-of-std'] } [target.wasm32-wasi.dependencies] wasi = { version = "0.9.0", features = ['rustc-dep-of-std'], default-features = false } diff --git a/src/libstd/sys/hermit/fs.rs b/src/libstd/sys/hermit/fs.rs index 37ac5984eeeaf..9d2fe5e1f606a 100644 --- a/src/libstd/sys/hermit/fs.rs +++ b/src/libstd/sys/hermit/fs.rs @@ -6,6 +6,8 @@ use crate::io::{IoSlice, IoSliceMut, SeekFrom}; use crate::path::{Path, PathBuf}; use crate::sys::cvt; use crate::sys::hermit::abi; +use crate::sys::hermit::abi::{O_RDONLY, O_WRONLY, O_RDWR,O_CREAT, + O_EXCL, O_TRUNC, O_APPEND}; use crate::sys::hermit::fd::FileDesc; use crate::sys::time::SystemTime; use crate::sys::{unsupported, Void}; @@ -17,14 +19,6 @@ pub use crate::sys_common::fs::copy; fn cstr(path: &Path) -> io::Result { Ok(CString::new(path.as_os_str().as_bytes())?) } -//const O_ACCMODE: i32 = 00000003; -const O_RDONLY: i32 = 00000000; -const O_WRONLY: i32 = 00000001; -const O_RDWR: i32 = 00000002; -const O_CREAT: i32 = 00000100; -const O_EXCL: i32 = 00000200; -const O_TRUNC: i32 = 00001000; -const O_APPEND: i32 = 00002000; #[derive(Debug)] pub struct File(FileDesc); From 412083469e717bb45299570841194bc45b019792 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Mon, 30 Mar 2020 07:05:35 +0200 Subject: [PATCH 02/13] minor changes to pass the format check --- src/libstd/sys/hermit/fs.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/libstd/sys/hermit/fs.rs b/src/libstd/sys/hermit/fs.rs index 9d2fe5e1f606a..973ee768d7b00 100644 --- a/src/libstd/sys/hermit/fs.rs +++ b/src/libstd/sys/hermit/fs.rs @@ -6,8 +6,7 @@ use crate::io::{IoSlice, IoSliceMut, SeekFrom}; use crate::path::{Path, PathBuf}; use crate::sys::cvt; use crate::sys::hermit::abi; -use crate::sys::hermit::abi::{O_RDONLY, O_WRONLY, O_RDWR,O_CREAT, - O_EXCL, O_TRUNC, O_APPEND}; +use crate::sys::hermit::abi::{O_RDONLY, O_WRONLY, O_RDWR,O_CREAT, O_EXCL, O_TRUNC, O_APPEND}; use crate::sys::hermit::fd::FileDesc; use crate::sys::time::SystemTime; use crate::sys::{unsupported, Void}; From 6c80bdb388618eb574149a18e2ae7d1c34f6f762 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Mon, 30 Mar 2020 07:17:00 +0200 Subject: [PATCH 03/13] reorder imports to pass the format check --- src/libstd/sys/hermit/fs.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libstd/sys/hermit/fs.rs b/src/libstd/sys/hermit/fs.rs index 973ee768d7b00..287a039066780 100644 --- a/src/libstd/sys/hermit/fs.rs +++ b/src/libstd/sys/hermit/fs.rs @@ -6,7 +6,7 @@ use crate::io::{IoSlice, IoSliceMut, SeekFrom}; use crate::path::{Path, PathBuf}; use crate::sys::cvt; use crate::sys::hermit::abi; -use crate::sys::hermit::abi::{O_RDONLY, O_WRONLY, O_RDWR,O_CREAT, O_EXCL, O_TRUNC, O_APPEND}; +use crate::sys::hermit::abi::{O_APPEND, O_CREAT, O_EXCL, O_RDONLY, O_RDWR, O_TRUNC, O_WRONLY}; use crate::sys::hermit::fd::FileDesc; use crate::sys::time::SystemTime; use crate::sys::{unsupported, Void}; From 9f6b96e461003853bf36052cfaf79b12e1c35413 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Mon, 30 Mar 2020 07:37:52 +0200 Subject: [PATCH 04/13] move the definition of thread priorities to hermit-abi --- Cargo.lock | 4 ++-- src/libstd/Cargo.toml | 2 +- src/libstd/sys/hermit/thread.rs | 25 +------------------------ 3 files changed, 4 insertions(+), 27 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a0233124b84ac..e51eded2200de 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1372,9 +1372,9 @@ dependencies = [ [[package]] name = "hermit-abi" -version = "0.1.9" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ebe6e23502442c4c9cd80fcb8bdf867dc5f4a9e9f1d882499fa49c5ed83e559" +checksum = "725cf19794cf90aa94e65050cb4191ff5d8fa87a498383774c47b332e3af952e" dependencies = [ "compiler_builtins", "libc", diff --git a/src/libstd/Cargo.toml b/src/libstd/Cargo.toml index 1bb764897ea54..3a83f3f569a26 100644 --- a/src/libstd/Cargo.toml +++ b/src/libstd/Cargo.toml @@ -41,7 +41,7 @@ dlmalloc = { version = "0.1", features = ['rustc-dep-of-std'] } fortanix-sgx-abi = { version = "0.3.2", features = ['rustc-dep-of-std'] } [target.'cfg(all(any(target_arch = "x86_64", target_arch = "aarch64"), target_os = "hermit"))'.dependencies] -hermit-abi = { version = "0.1.9", features = ['rustc-dep-of-std'] } +hermit-abi = { version = "0.1.10", features = ['rustc-dep-of-std'] } [target.wasm32-wasi.dependencies] wasi = { version = "0.9.0", features = ['rustc-dep-of-std'], default-features = false } diff --git a/src/libstd/sys/hermit/thread.rs b/src/libstd/sys/hermit/thread.rs index c3c29c93826de..00d760d02e877 100644 --- a/src/libstd/sys/hermit/thread.rs +++ b/src/libstd/sys/hermit/thread.rs @@ -1,7 +1,6 @@ #![allow(dead_code)] use crate::ffi::CStr; -use crate::fmt; use crate::io; use crate::mem; use crate::sys::hermit::abi; @@ -12,28 +11,6 @@ use crate::sys_common::thread::*; pub type Tid = abi::Tid; -/// Priority of a task -#[derive(PartialEq, Eq, PartialOrd, Ord, Debug, Clone, Copy)] -pub struct Priority(u8); - -impl Priority { - pub const fn into(self) -> u8 { - self.0 - } - - pub const fn from(x: u8) -> Self { - Priority(x) - } -} - -impl fmt::Display for Priority { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "{}", self.0) - } -} - -pub const NORMAL_PRIO: Priority = Priority::from(2); - pub struct Thread { tid: Tid, } @@ -55,7 +32,7 @@ impl Thread { &mut tid as *mut Tid, thread_start, &*p as *const _ as *const u8 as usize, - Priority::into(NORMAL_PRIO), + abi::Priority::into(abi::NORMAL_PRIO), core_id, ); From f8d6fc1d106a6b3fa2dbd4085b69e56d64cfd941 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Fri, 3 Apr 2020 13:21:12 -0700 Subject: [PATCH 05/13] Open-code Fuse's Option matches --- src/libcore/iter/adapters/fuse.rs | 77 +++++++++++++++++-------------- 1 file changed, 42 insertions(+), 35 deletions(-) diff --git a/src/libcore/iter/adapters/fuse.rs b/src/libcore/iter/adapters/fuse.rs index a60ca64ec87c8..bdfeb75a868c8 100644 --- a/src/libcore/iter/adapters/fuse.rs +++ b/src/libcore/iter/adapters/fuse.rs @@ -28,6 +28,22 @@ impl Fuse { #[stable(feature = "fused", since = "1.26.0")] impl FusedIterator for Fuse where I: Iterator {} +/// Fuse the iterator if the expression is `None`. +macro_rules! fuse { + ($self:ident . iter . $($call:tt)+) => { + match $self.iter { + Some(ref mut iter) => match iter.$($call)+ { + None => { + $self.iter = None; + None + } + item => item, + }, + None => None, + } + }; +} + #[stable(feature = "rust1", since = "1.0.0")] impl Iterator for Fuse where @@ -37,35 +53,36 @@ where #[inline] default fn next(&mut self) -> Option<::Item> { - let next = self.iter.as_mut()?.next(); - if next.is_none() { - self.iter = None; - } - next + fuse!(self.iter.next()) } #[inline] default fn nth(&mut self, n: usize) -> Option { - let nth = self.iter.as_mut()?.nth(n); - if nth.is_none() { - self.iter = None; - } - nth + fuse!(self.iter.nth(n)) } #[inline] default fn last(self) -> Option { - self.iter?.last() + match self.iter { + Some(iter) => iter.last(), + None => None, + } } #[inline] default fn count(self) -> usize { - self.iter.map_or(0, I::count) + match self.iter { + Some(iter) => iter.count(), + None => 0, + } } #[inline] default fn size_hint(&self) -> (usize, Option) { - self.iter.as_ref().map_or((0, Some(0)), I::size_hint) + match self.iter { + Some(ref iter) => iter.size_hint(), + None => (0, Some(0)), + } } #[inline] @@ -98,11 +115,7 @@ where where P: FnMut(&Self::Item) -> bool, { - let found = self.iter.as_mut()?.find(predicate); - if found.is_none() { - self.iter = None; - } - found + fuse!(self.iter.find(predicate)) } } @@ -113,20 +126,12 @@ where { #[inline] default fn next_back(&mut self) -> Option<::Item> { - let next = self.iter.as_mut()?.next_back(); - if next.is_none() { - self.iter = None; - } - next + fuse!(self.iter.next_back()) } #[inline] default fn nth_back(&mut self, n: usize) -> Option<::Item> { - let nth = self.iter.as_mut()?.nth_back(n); - if nth.is_none() { - self.iter = None; - } - nth + fuse!(self.iter.nth_back(n)) } #[inline] @@ -159,11 +164,7 @@ where where P: FnMut(&Self::Item) -> bool, { - let found = self.iter.as_mut()?.rfind(predicate); - if found.is_none() { - self.iter = None; - } - found + fuse!(self.iter.rfind(predicate)) } } @@ -173,11 +174,17 @@ where I: ExactSizeIterator, { default fn len(&self) -> usize { - self.iter.as_ref().map_or(0, I::len) + match self.iter { + Some(ref iter) => iter.len(), + None => 0, + } } default fn is_empty(&self) -> bool { - self.iter.as_ref().map_or(true, I::is_empty) + match self.iter { + Some(ref iter) => iter.is_empty(), + None => true, + } } } From 6fdd4f37b7eb68a4a44d97db70ee6b805255f0e6 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Fri, 3 Apr 2020 13:30:21 -0700 Subject: [PATCH 06/13] Use a macro to expand the specialized Fuse --- src/libcore/iter/adapters/fuse.rs | 64 +++++++++++-------------------- 1 file changed, 23 insertions(+), 41 deletions(-) diff --git a/src/libcore/iter/adapters/fuse.rs b/src/libcore/iter/adapters/fuse.rs index bdfeb75a868c8..23bc215aa779d 100644 --- a/src/libcore/iter/adapters/fuse.rs +++ b/src/libcore/iter/adapters/fuse.rs @@ -188,34 +188,16 @@ where } } -// NOTE: for `I: FusedIterator`, we assume that the iterator is always `Some` -impl Fuse { - #[inline(always)] - fn as_inner(&self) -> &I { - match self.iter { - Some(ref iter) => iter, +// NOTE: for `I: FusedIterator`, we assume that the iterator is always `Some`. +// Implementing this as a directly-expanded macro helps codegen performance. +macro_rules! unchecked { + ($self:ident) => { + match $self { + Fuse { iter: Some(iter) } => iter, // SAFETY: the specialized iterator never sets `None` - None => unsafe { intrinsics::unreachable() }, + Fuse { iter: None } => unsafe { intrinsics::unreachable() }, } - } - - #[inline(always)] - fn as_inner_mut(&mut self) -> &mut I { - match self.iter { - Some(ref mut iter) => iter, - // SAFETY: the specialized iterator never sets `None` - None => unsafe { intrinsics::unreachable() }, - } - } - - #[inline(always)] - fn into_inner(self) -> I { - match self.iter { - Some(iter) => iter, - // SAFETY: the specialized iterator never sets `None` - None => unsafe { intrinsics::unreachable() }, - } - } + }; } #[stable(feature = "fused", since = "1.26.0")] @@ -225,27 +207,27 @@ where { #[inline] fn next(&mut self) -> Option<::Item> { - self.as_inner_mut().next() + unchecked!(self).next() } #[inline] fn nth(&mut self, n: usize) -> Option { - self.as_inner_mut().nth(n) + unchecked!(self).nth(n) } #[inline] fn last(self) -> Option { - self.into_inner().last() + unchecked!(self).last() } #[inline] fn count(self) -> usize { - self.into_inner().count() + unchecked!(self).count() } #[inline] fn size_hint(&self) -> (usize, Option) { - self.as_inner().size_hint() + unchecked!(self).size_hint() } #[inline] @@ -255,7 +237,7 @@ where Fold: FnMut(Acc, Self::Item) -> R, R: Try, { - self.as_inner_mut().try_fold(init, fold) + unchecked!(self).try_fold(init, fold) } #[inline] @@ -263,7 +245,7 @@ where where Fold: FnMut(Acc, Self::Item) -> Acc, { - self.into_inner().fold(init, fold) + unchecked!(self).fold(init, fold) } #[inline] @@ -271,7 +253,7 @@ where where P: FnMut(&Self::Item) -> bool, { - self.as_inner_mut().find(predicate) + unchecked!(self).find(predicate) } } @@ -282,12 +264,12 @@ where { #[inline] fn next_back(&mut self) -> Option<::Item> { - self.as_inner_mut().next_back() + unchecked!(self).next_back() } #[inline] fn nth_back(&mut self, n: usize) -> Option<::Item> { - self.as_inner_mut().nth_back(n) + unchecked!(self).nth_back(n) } #[inline] @@ -297,7 +279,7 @@ where Fold: FnMut(Acc, Self::Item) -> R, R: Try, { - self.as_inner_mut().try_rfold(init, fold) + unchecked!(self).try_rfold(init, fold) } #[inline] @@ -305,7 +287,7 @@ where where Fold: FnMut(Acc, Self::Item) -> Acc, { - self.into_inner().rfold(init, fold) + unchecked!(self).rfold(init, fold) } #[inline] @@ -313,7 +295,7 @@ where where P: FnMut(&Self::Item) -> bool, { - self.as_inner_mut().rfind(predicate) + unchecked!(self).rfind(predicate) } } @@ -323,11 +305,11 @@ where I: ExactSizeIterator + FusedIterator, { fn len(&self) -> usize { - self.as_inner().len() + unchecked!(self).len() } fn is_empty(&self) -> bool { - self.as_inner().is_empty() + unchecked!(self).is_empty() } } From 13bd25e4722a02f7b38797c7d116bfb9d1667e72 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Wed, 1 Apr 2020 19:17:08 +0300 Subject: [PATCH 07/13] Do not lose or reorder user-provided linker arguments --- src/librustc_codegen_ssa/back/link.rs | 24 +++++++------------ src/librustc_interface/tests.rs | 2 +- src/librustc_session/options.rs | 18 ++++++++++---- .../link-args-order/Makefile | 10 ++++++++ .../link-args-order/empty.rs | 6 +++++ 5 files changed, 38 insertions(+), 22 deletions(-) create mode 100644 src/test/run-make-fulldeps/link-args-order/Makefile create mode 100644 src/test/run-make-fulldeps/link-args-order/empty.rs diff --git a/src/librustc_codegen_ssa/back/link.rs b/src/librustc_codegen_ssa/back/link.rs index 1e780c5f86771..49786bc3b068d 100644 --- a/src/librustc_codegen_ssa/back/link.rs +++ b/src/librustc_codegen_ssa/back/link.rs @@ -505,10 +505,7 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>( cmd.args(args); } } - if let Some(ref args) = sess.opts.debugging_opts.pre_link_args { - cmd.args(args); - } - cmd.args(&sess.opts.debugging_opts.pre_link_arg); + cmd.args(&sess.opts.debugging_opts.pre_link_args); if sess.target.target.options.is_like_fuchsia { let prefix = match sess.opts.debugging_opts.sanitizer { @@ -1302,18 +1299,17 @@ fn link_args<'a, B: ArchiveBuilder<'a>>( cmd.gc_sections(keep_metadata); } - let used_link_args = &codegen_results.crate_info.link_args; + let attr_link_args = codegen_results.crate_info.link_args.iter(); + let user_link_args: Vec<_> = + sess.opts.cg.link_args.iter().chain(attr_link_args).cloned().collect(); if crate_type == config::CrateType::Executable { let mut position_independent_executable = false; if t.options.position_independent_executables { - let empty_vec = Vec::new(); - let args = sess.opts.cg.link_args.as_ref().unwrap_or(&empty_vec); - let more_args = &sess.opts.cg.link_arg; - let mut args = args.iter().chain(more_args.iter()).chain(used_link_args.iter()); - - if is_pic(sess) && !sess.crt_static(Some(crate_type)) && !args.any(|x| *x == "-static") + if is_pic(sess) + && !sess.crt_static(Some(crate_type)) + && !user_link_args.iter().any(|x| x == "-static") { position_independent_executable = true; } @@ -1444,11 +1440,7 @@ fn link_args<'a, B: ArchiveBuilder<'a>>( // Finally add all the linker arguments provided on the command line along // with any #[link_args] attributes found inside the crate - if let Some(ref args) = sess.opts.cg.link_args { - cmd.args(args); - } - cmd.args(&sess.opts.cg.link_arg); - cmd.args(&used_link_args); + cmd.args(&user_link_args); } // # Native library linking diff --git a/src/librustc_interface/tests.rs b/src/librustc_interface/tests.rs index f58c5cc8eeb8a..b452ccfe33a52 100644 --- a/src/librustc_interface/tests.rs +++ b/src/librustc_interface/tests.rs @@ -382,7 +382,7 @@ fn test_codegen_options_tracking_hash() { opts.cg.linker = Some(PathBuf::from("linker")); assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash()); - opts.cg.link_args = Some(vec![String::from("abc"), String::from("def")]); + opts.cg.link_args = vec![String::from("abc"), String::from("def")]; assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash()); opts.cg.link_dead_code = true; diff --git a/src/librustc_session/options.rs b/src/librustc_session/options.rs index 3962e30335db2..8cd6ca86f4689 100644 --- a/src/librustc_session/options.rs +++ b/src/librustc_session/options.rs @@ -296,9 +296,17 @@ macro_rules! options { use std::path::PathBuf; use std::str::FromStr; + // Sometimes different options need to build a common structure. + // That structure can kept in one of the options' fields, the others become dummy. + macro_rules! redirect_field { + ($cg:ident.link_arg) => { $cg.link_args }; + ($cg:ident.pre_link_arg) => { $cg.pre_link_args }; + ($cg:ident.$field:ident) => { $cg.$field }; + } + $( pub fn $opt(cg: &mut $struct_name, v: Option<&str>) -> bool { - $parse(&mut cg.$opt, v) + $parse(&mut redirect_field!(cg.$opt), v) } )* @@ -643,9 +651,9 @@ options! {CodegenOptions, CodegenSetter, basic_codegen_options, "this option is deprecated and does nothing"), linker: Option = (None, parse_opt_pathbuf, [UNTRACKED], "system linker to link outputs with"), - link_arg: Vec = (vec![], parse_string_push, [UNTRACKED], + link_arg: (/* redirected to link_args */) = ((), parse_string_push, [UNTRACKED], "a single extra argument to append to the linker invocation (can be used several times)"), - link_args: Option> = (None, parse_opt_list, [UNTRACKED], + link_args: Vec = (Vec::new(), parse_list, [UNTRACKED], "extra arguments to append to the linker invocation (space separated)"), link_dead_code: bool = (false, parse_bool, [UNTRACKED], "don't let linker strip dead code (turning it on can be used for code coverage)"), @@ -876,9 +884,9 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options, "make rustc print the total optimization fuel used by a crate"), force_unstable_if_unmarked: bool = (false, parse_bool, [TRACKED], "force all crates to be `rustc_private` unstable"), - pre_link_arg: Vec = (vec![], parse_string_push, [UNTRACKED], + pre_link_arg: (/* redirected to pre_link_args */) = ((), parse_string_push, [UNTRACKED], "a single extra argument to prepend the linker invocation (can be used several times)"), - pre_link_args: Option> = (None, parse_opt_list, [UNTRACKED], + pre_link_args: Vec = (Vec::new(), parse_list, [UNTRACKED], "extra arguments to prepend to the linker invocation (space separated)"), profile: bool = (false, parse_bool, [TRACKED], "insert profiling code"), diff --git a/src/test/run-make-fulldeps/link-args-order/Makefile b/src/test/run-make-fulldeps/link-args-order/Makefile new file mode 100644 index 0000000000000..98c1e0eac3b0e --- /dev/null +++ b/src/test/run-make-fulldeps/link-args-order/Makefile @@ -0,0 +1,10 @@ +# ignore-msvc + +-include ../tools.mk + +RUSTC_FLAGS = -C linker-flavor=ld -C link-arg=a -C link-args="b c" -C link-args="d e" -C link-arg=f +RUSTC_FLAGS_PRE = -C linker-flavor=ld -Z pre-link-arg=a -Z pre-link-args="b c" -Z pre-link-args="d e" -Z pre-link-arg=f + +all: + $(RUSTC) $(RUSTC_FLAGS) empty.rs 2>&1 | $(CGREP) '"a" "b" "c" "d" "e" "f" "g"' + $(RUSTC) $(RUSTC_FLAGS_PRE) empty.rs 2>&1 | $(CGREP) '"a" "b" "c" "d" "e" "f"' diff --git a/src/test/run-make-fulldeps/link-args-order/empty.rs b/src/test/run-make-fulldeps/link-args-order/empty.rs new file mode 100644 index 0000000000000..2439171004b5f --- /dev/null +++ b/src/test/run-make-fulldeps/link-args-order/empty.rs @@ -0,0 +1,6 @@ +#![feature(link_args)] + +#[link_args = "g"] +extern "C" {} + +fn main() {} From d06b26fb6c70e1d019951041f3cc535eae4afc40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Linus=20F=C3=A4rnstrand?= Date: Sun, 5 Apr 2020 11:30:25 +0200 Subject: [PATCH 08/13] Stop importing the float modules. Use assoc consts --- src/libcore/ops/range.rs | 12 ------------ src/libstd/f32.rs | 42 ---------------------------------------- src/libstd/f64.rs | 6 ------ 3 files changed, 60 deletions(-) diff --git a/src/libcore/ops/range.rs b/src/libcore/ops/range.rs index 946a765e18f3b..d4e6048579a56 100644 --- a/src/libcore/ops/range.rs +++ b/src/libcore/ops/range.rs @@ -98,8 +98,6 @@ impl> Range { /// # Examples /// /// ``` - /// use std::f32; - /// /// assert!(!(3..5).contains(&2)); /// assert!( (3..5).contains(&3)); /// assert!( (3..5).contains(&4)); @@ -198,8 +196,6 @@ impl> RangeFrom { /// # Examples /// /// ``` - /// use std::f32; - /// /// assert!(!(3..).contains(&2)); /// assert!( (3..).contains(&3)); /// assert!( (3..).contains(&1_000_000_000)); @@ -282,8 +278,6 @@ impl> RangeTo { /// # Examples /// /// ``` - /// use std::f32; - /// /// assert!( (..5).contains(&-1_000_000_000)); /// assert!( (..5).contains(&4)); /// assert!(!(..5).contains(&5)); @@ -453,8 +447,6 @@ impl> RangeInclusive { /// # Examples /// /// ``` - /// use std::f32; - /// /// assert!(!(3..=5).contains(&2)); /// assert!( (3..=5).contains(&3)); /// assert!( (3..=5).contains(&4)); @@ -581,8 +573,6 @@ impl> RangeToInclusive { /// # Examples /// /// ``` - /// use std::f32; - /// /// assert!( (..=5).contains(&-1_000_000_000)); /// assert!( (..=5).contains(&5)); /// assert!(!(..=5).contains(&6)); @@ -721,8 +711,6 @@ pub trait RangeBounds { /// # Examples /// /// ``` - /// use std::f32; - /// /// assert!( (3..5).contains(&4)); /// assert!(!(3..5).contains(&2)); /// diff --git a/src/libstd/f32.rs b/src/libstd/f32.rs index ac8f305ae9127..c33c8f270783d 100644 --- a/src/libstd/f32.rs +++ b/src/libstd/f32.rs @@ -112,8 +112,6 @@ impl f32 { /// # Examples /// /// ``` - /// use std::f32; - /// /// let x = 3.6_f32; /// let y = -3.6_f32; /// let abs_difference_x = (x.fract() - 0.6).abs(); @@ -135,8 +133,6 @@ impl f32 { /// # Examples /// /// ``` - /// use std::f32; - /// /// let x = 3.5_f32; /// let y = -3.5_f32; /// @@ -164,8 +160,6 @@ impl f32 { /// # Examples /// /// ``` - /// use std::f32; - /// /// let f = 3.5_f32; /// /// assert_eq!(f.signum(), 1.0); @@ -190,8 +184,6 @@ impl f32 { /// # Examples /// /// ``` - /// use std::f32; - /// /// let f = 3.5_f32; /// /// assert_eq!(f.copysign(0.42), 3.5_f32); @@ -217,8 +209,6 @@ impl f32 { /// # Examples /// /// ``` - /// use std::f32; - /// /// let m = 10.0_f32; /// let x = 4.0_f32; /// let b = 60.0_f32; @@ -301,8 +291,6 @@ impl f32 { /// # Examples /// /// ``` - /// use std::f32; - /// /// let x = 2.0_f32; /// let abs_difference = (x.powi(2) - (x * x)).abs(); /// @@ -320,8 +308,6 @@ impl f32 { /// # Examples /// /// ``` - /// use std::f32; - /// /// let x = 2.0_f32; /// let abs_difference = (x.powf(2.0) - (x * x)).abs(); /// @@ -341,8 +327,6 @@ impl f32 { /// # Examples /// /// ``` - /// use std::f32; - /// /// let positive = 4.0_f32; /// let negative = -4.0_f32; /// @@ -363,8 +347,6 @@ impl f32 { /// # Examples /// /// ``` - /// use std::f32; - /// /// let one = 1.0f32; /// // e^1 /// let e = one.exp(); @@ -386,8 +368,6 @@ impl f32 { /// # Examples /// /// ``` - /// use std::f32; - /// /// let f = 2.0f32; /// /// // 2^2 - 4 == 0 @@ -407,8 +387,6 @@ impl f32 { /// # Examples /// /// ``` - /// use std::f32; - /// /// let one = 1.0f32; /// // e^1 /// let e = one.exp(); @@ -434,8 +412,6 @@ impl f32 { /// # Examples /// /// ``` - /// use std::f32; - /// /// let five = 5.0f32; /// /// // log5(5) - 1 == 0 @@ -455,8 +431,6 @@ impl f32 { /// # Examples /// /// ``` - /// use std::f32; - /// /// let two = 2.0f32; /// /// // log2(2) - 1 == 0 @@ -479,8 +453,6 @@ impl f32 { /// # Examples /// /// ``` - /// use std::f32; - /// /// let ten = 10.0f32; /// /// // log10(10) - 1 == 0 @@ -503,8 +475,6 @@ impl f32 { /// # Examples /// /// ``` - /// use std::f32; - /// /// let x = 3.0f32; /// let y = -3.0f32; /// @@ -536,8 +506,6 @@ impl f32 { /// # Examples /// /// ``` - /// use std::f32; - /// /// let x = 8.0f32; /// /// // x^(1/3) - 2 == 0 @@ -558,8 +526,6 @@ impl f32 { /// # Examples /// /// ``` - /// use std::f32; - /// /// let x = 2.0f32; /// let y = 3.0f32; /// @@ -686,8 +652,6 @@ impl f32 { /// # Examples /// /// ``` - /// use std::f32; - /// /// let f = 1.0f32; /// /// // atan(tan(1)) @@ -766,8 +730,6 @@ impl f32 { /// # Examples /// /// ``` - /// use std::f32; - /// /// let x = 6.0f32; /// /// // e^(ln(6)) - 1 @@ -881,8 +843,6 @@ impl f32 { /// # Examples /// /// ``` - /// use std::f32; - /// /// let x = 1.0f32; /// let f = x.sinh().asinh(); /// @@ -906,8 +866,6 @@ impl f32 { /// # Examples /// /// ``` - /// use std::f32; - /// /// let x = 1.0f32; /// let f = x.cosh().acosh(); /// diff --git a/src/libstd/f64.rs b/src/libstd/f64.rs index 798738e50a754..8d6d619219b50 100644 --- a/src/libstd/f64.rs +++ b/src/libstd/f64.rs @@ -133,8 +133,6 @@ impl f64 { /// # Examples /// /// ``` - /// use std::f64; - /// /// let x = 3.5_f64; /// let y = -3.5_f64; /// @@ -162,8 +160,6 @@ impl f64 { /// # Examples /// /// ``` - /// use std::f64; - /// /// let f = 3.5_f64; /// /// assert_eq!(f.signum(), 1.0); @@ -188,8 +184,6 @@ impl f64 { /// # Examples /// /// ``` - /// use std::f64; - /// /// let f = 3.5_f64; /// /// assert_eq!(f.copysign(0.42), 3.5_f64); From daf8afdc85017795e049fe1cf7c7dc47cbccef9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Linus=20F=C3=A4rnstrand?= Date: Sun, 5 Apr 2020 11:36:44 +0200 Subject: [PATCH 09/13] Remove more std::f32 imports in libstd --- src/libstd/f32.rs | 54 +++++++++++++---------------------------------- src/libstd/f64.rs | 54 +++++++++++++---------------------------------- 2 files changed, 30 insertions(+), 78 deletions(-) diff --git a/src/libstd/f32.rs b/src/libstd/f32.rs index c33c8f270783d..65273275a4006 100644 --- a/src/libstd/f32.rs +++ b/src/libstd/f32.rs @@ -546,9 +546,7 @@ impl f32 { /// # Examples /// /// ``` - /// use std::f32; - /// - /// let x = f32::consts::FRAC_PI_2; + /// let x = std::f32::consts::FRAC_PI_2; /// /// let abs_difference = (x.sin() - 1.0).abs(); /// @@ -566,9 +564,7 @@ impl f32 { /// # Examples /// /// ``` - /// use std::f32; - /// - /// let x = 2.0 * f32::consts::PI; + /// let x = 2.0 * std::f32::consts::PI; /// /// let abs_difference = (x.cos() - 1.0).abs(); /// @@ -586,9 +582,7 @@ impl f32 { /// # Examples /// /// ``` - /// use std::f32; - /// - /// let x = f32::consts::FRAC_PI_4; + /// let x = std::f32::consts::FRAC_PI_4; /// let abs_difference = (x.tan() - 1.0).abs(); /// /// assert!(abs_difference <= f32::EPSILON); @@ -607,12 +601,10 @@ impl f32 { /// # Examples /// /// ``` - /// use std::f32; - /// - /// let f = f32::consts::FRAC_PI_2; + /// let f = std::f32::consts::FRAC_PI_2; /// /// // asin(sin(pi/2)) - /// let abs_difference = (f.sin().asin() - f32::consts::FRAC_PI_2).abs(); + /// let abs_difference = (f.sin().asin() - std::f32::consts::FRAC_PI_2).abs(); /// /// assert!(abs_difference <= f32::EPSILON); /// ``` @@ -630,12 +622,10 @@ impl f32 { /// # Examples /// /// ``` - /// use std::f32; - /// - /// let f = f32::consts::FRAC_PI_4; + /// let f = std::f32::consts::FRAC_PI_4; /// /// // acos(cos(pi/4)) - /// let abs_difference = (f.cos().acos() - f32::consts::FRAC_PI_4).abs(); + /// let abs_difference = (f.cos().acos() - std::f32::consts::FRAC_PI_4).abs(); /// /// assert!(abs_difference <= f32::EPSILON); /// ``` @@ -676,8 +666,6 @@ impl f32 { /// # Examples /// /// ``` - /// use std::f32; - /// /// // Positive angles measured counter-clockwise /// // from positive x axis /// // -pi/4 radians (45 deg clockwise) @@ -688,8 +676,8 @@ impl f32 { /// let x2 = -3.0f32; /// let y2 = 3.0f32; /// - /// let abs_difference_1 = (y1.atan2(x1) - (-f32::consts::FRAC_PI_4)).abs(); - /// let abs_difference_2 = (y2.atan2(x2) - (3.0 * f32::consts::FRAC_PI_4)).abs(); + /// let abs_difference_1 = (y1.atan2(x1) - (-std::f32::consts::FRAC_PI_4)).abs(); + /// let abs_difference_2 = (y2.atan2(x2) - (3.0 * std::f32::consts::FRAC_PI_4)).abs(); /// /// assert!(abs_difference_1 <= f32::EPSILON); /// assert!(abs_difference_2 <= f32::EPSILON); @@ -707,9 +695,7 @@ impl f32 { /// # Examples /// /// ``` - /// use std::f32; - /// - /// let x = f32::consts::FRAC_PI_4; + /// let x = std::f32::consts::FRAC_PI_4; /// let f = x.sin_cos(); /// /// let abs_difference_0 = (f.0 - x.sin()).abs(); @@ -750,9 +736,7 @@ impl f32 { /// # Examples /// /// ``` - /// use std::f32; - /// - /// let x = f32::consts::E - 1.0; + /// let x = std::f32::consts::E - 1.0; /// /// // ln(1 + (e - 1)) == ln(e) == 1 /// let abs_difference = (x.ln_1p() - 1.0).abs(); @@ -771,9 +755,7 @@ impl f32 { /// # Examples /// /// ``` - /// use std::f32; - /// - /// let e = f32::consts::E; + /// let e = std::f32::consts::E; /// let x = 1.0f32; /// /// let f = x.sinh(); @@ -795,9 +777,7 @@ impl f32 { /// # Examples /// /// ``` - /// use std::f32; - /// - /// let e = f32::consts::E; + /// let e = std::f32::consts::E; /// let x = 1.0f32; /// let f = x.cosh(); /// // Solving cosh() at 1 gives this result @@ -819,9 +799,7 @@ impl f32 { /// # Examples /// /// ``` - /// use std::f32; - /// - /// let e = f32::consts::E; + /// let e = std::f32::consts::E; /// let x = 1.0f32; /// /// let f = x.tanh(); @@ -885,9 +863,7 @@ impl f32 { /// # Examples /// /// ``` - /// use std::f32; - /// - /// let e = f32::consts::E; + /// let e = std::f32::consts::E; /// let f = e.tanh().atanh(); /// /// let abs_difference = (f - e).abs(); diff --git a/src/libstd/f64.rs b/src/libstd/f64.rs index 8d6d619219b50..ff222fc8539d0 100644 --- a/src/libstd/f64.rs +++ b/src/libstd/f64.rs @@ -548,9 +548,7 @@ impl f64 { /// # Examples /// /// ``` - /// use std::f64; - /// - /// let x = f64::consts::FRAC_PI_2; + /// let x = std::f64::consts::FRAC_PI_2; /// /// let abs_difference = (x.sin() - 1.0).abs(); /// @@ -568,9 +566,7 @@ impl f64 { /// # Examples /// /// ``` - /// use std::f64; - /// - /// let x = 2.0 * f64::consts::PI; + /// let x = 2.0 * std::f64::consts::PI; /// /// let abs_difference = (x.cos() - 1.0).abs(); /// @@ -588,9 +584,7 @@ impl f64 { /// # Examples /// /// ``` - /// use std::f64; - /// - /// let x = f64::consts::FRAC_PI_4; + /// let x = std::f64::consts::FRAC_PI_4; /// let abs_difference = (x.tan() - 1.0).abs(); /// /// assert!(abs_difference < 1e-14); @@ -609,12 +603,10 @@ impl f64 { /// # Examples /// /// ``` - /// use std::f64; - /// - /// let f = f64::consts::FRAC_PI_2; + /// let f = std::f64::consts::FRAC_PI_2; /// /// // asin(sin(pi/2)) - /// let abs_difference = (f.sin().asin() - f64::consts::FRAC_PI_2).abs(); + /// let abs_difference = (f.sin().asin() - std::f64::consts::FRAC_PI_2).abs(); /// /// assert!(abs_difference < 1e-10); /// ``` @@ -632,12 +624,10 @@ impl f64 { /// # Examples /// /// ``` - /// use std::f64; - /// - /// let f = f64::consts::FRAC_PI_4; + /// let f = std::f64::consts::FRAC_PI_4; /// /// // acos(cos(pi/4)) - /// let abs_difference = (f.cos().acos() - f64::consts::FRAC_PI_4).abs(); + /// let abs_difference = (f.cos().acos() - std::f64::consts::FRAC_PI_4).abs(); /// /// assert!(abs_difference < 1e-10); /// ``` @@ -678,8 +668,6 @@ impl f64 { /// # Examples /// /// ``` - /// use std::f64; - /// /// // Positive angles measured counter-clockwise /// // from positive x axis /// // -pi/4 radians (45 deg clockwise) @@ -690,8 +678,8 @@ impl f64 { /// let x2 = -3.0_f64; /// let y2 = 3.0_f64; /// - /// let abs_difference_1 = (y1.atan2(x1) - (-f64::consts::FRAC_PI_4)).abs(); - /// let abs_difference_2 = (y2.atan2(x2) - (3.0 * f64::consts::FRAC_PI_4)).abs(); + /// let abs_difference_1 = (y1.atan2(x1) - (-std::f64::consts::FRAC_PI_4)).abs(); + /// let abs_difference_2 = (y2.atan2(x2) - (3.0 * std::f64::consts::FRAC_PI_4)).abs(); /// /// assert!(abs_difference_1 < 1e-10); /// assert!(abs_difference_2 < 1e-10); @@ -709,9 +697,7 @@ impl f64 { /// # Examples /// /// ``` - /// use std::f64; - /// - /// let x = f64::consts::FRAC_PI_4; + /// let x = std::f64::consts::FRAC_PI_4; /// let f = x.sin_cos(); /// /// let abs_difference_0 = (f.0 - x.sin()).abs(); @@ -752,9 +738,7 @@ impl f64 { /// # Examples /// /// ``` - /// use std::f64; - /// - /// let x = f64::consts::E - 1.0; + /// let x = std::f64::consts::E - 1.0; /// /// // ln(1 + (e - 1)) == ln(e) == 1 /// let abs_difference = (x.ln_1p() - 1.0).abs(); @@ -773,9 +757,7 @@ impl f64 { /// # Examples /// /// ``` - /// use std::f64; - /// - /// let e = f64::consts::E; + /// let e = std::f64::consts::E; /// let x = 1.0_f64; /// /// let f = x.sinh(); @@ -797,9 +779,7 @@ impl f64 { /// # Examples /// /// ``` - /// use std::f64; - /// - /// let e = f64::consts::E; + /// let e = std::f64::consts::E; /// let x = 1.0_f64; /// let f = x.cosh(); /// // Solving cosh() at 1 gives this result @@ -821,9 +801,7 @@ impl f64 { /// # Examples /// /// ``` - /// use std::f64; - /// - /// let e = f64::consts::E; + /// let e = std::f64::consts::E; /// let x = 1.0_f64; /// /// let f = x.tanh(); @@ -887,9 +865,7 @@ impl f64 { /// # Examples /// /// ``` - /// use std::f64; - /// - /// let e = f64::consts::E; + /// let e = std::f64::consts::E; /// let f = e.tanh().atanh(); /// /// let abs_difference = (f - e).abs(); From 28c9231a91b9c4708be2c0ff89204d707b53cc06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Linus=20F=C3=A4rnstrand?= Date: Sun, 5 Apr 2020 11:44:25 +0200 Subject: [PATCH 10/13] Make libcore float constant examples similar to libstd --- src/libcore/num/f32.rs | 8 ++------ src/libcore/num/f64.rs | 8 ++------ 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/src/libcore/num/f32.rs b/src/libcore/num/f32.rs index 4ab82add32b53..6be108f280eda 100644 --- a/src/libcore/num/f32.rs +++ b/src/libcore/num/f32.rs @@ -394,9 +394,7 @@ impl f32 { /// Converts radians to degrees. /// /// ``` - /// use std::f32::consts; - /// - /// let angle = consts::PI; + /// let angle = std::f32::consts::PI; /// /// let abs_difference = (angle.to_degrees() - 180.0).abs(); /// @@ -413,11 +411,9 @@ impl f32 { /// Converts degrees to radians. /// /// ``` - /// use std::f32::consts; - /// /// let angle = 180.0f32; /// - /// let abs_difference = (angle.to_radians() - consts::PI).abs(); + /// let abs_difference = (angle.to_radians() - std::f32::consts::PI).abs(); /// /// assert!(abs_difference <= f32::EPSILON); /// ``` diff --git a/src/libcore/num/f64.rs b/src/libcore/num/f64.rs index 20818a9b750f4..da22ba8d3c9d2 100644 --- a/src/libcore/num/f64.rs +++ b/src/libcore/num/f64.rs @@ -407,9 +407,7 @@ impl f64 { /// Converts radians to degrees. /// /// ``` - /// use std::f64::consts; - /// - /// let angle = consts::PI; + /// let angle = std::f64::consts::PI; /// /// let abs_difference = (angle.to_degrees() - 180.0).abs(); /// @@ -427,11 +425,9 @@ impl f64 { /// Converts degrees to radians. /// /// ``` - /// use std::f64::consts; - /// /// let angle = 180.0_f64; /// - /// let abs_difference = (angle.to_radians() - consts::PI).abs(); + /// let abs_difference = (angle.to_radians() - std::f64::consts::PI).abs(); /// /// assert!(abs_difference < 1e-10); /// ``` From 935683bd9cf668a0f616a336528c768115847aad Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Sun, 5 Apr 2020 13:37:04 +0200 Subject: [PATCH 11/13] Simplify dtor registration for HermitCore by using a list of destructors The implementation is similiar to macOS solution doesn't depend on additional OS support --- src/libstd/sys/hermit/fast_thread_local.rs | 34 +++++++++++++- src/libstd/sys/hermit/mod.rs | 2 + src/libstd/sys/hermit/thread.rs | 4 ++ src/libstd/sys/hermit/thread_local.rs | 52 ++++------------------ 4 files changed, 48 insertions(+), 44 deletions(-) diff --git a/src/libstd/sys/hermit/fast_thread_local.rs b/src/libstd/sys/hermit/fast_thread_local.rs index 1108e2545bdeb..9b683fce15748 100644 --- a/src/libstd/sys/hermit/fast_thread_local.rs +++ b/src/libstd/sys/hermit/fast_thread_local.rs @@ -1,4 +1,36 @@ #![cfg(target_thread_local)] #![unstable(feature = "thread_local_internals", issue = "none")] -pub use crate::sys_common::thread_local::register_dtor_fallback as register_dtor; +// Simplify dtor registration by using a list of destructors. +// The this solution works like the implementation of macOS and +// doesn't additional OS support + +use crate::cell::Cell; +use crate::ptr; + +#[thread_local] +static DTORS: Cell<*mut List> = Cell::new(ptr::null_mut()); + +type List = Vec<(*mut u8, unsafe extern "C" fn(*mut u8))>; + +pub unsafe fn register_dtor(t: *mut u8, dtor: unsafe extern "C" fn(*mut u8)) { + if DTORS.get().is_null() { + let v: Box = box Vec::new(); + DTORS.set(Box::into_raw(v)); + } + + let list: &mut List = &mut *DTORS.get(); + list.push((t, dtor)); +} + +// every thread call this function to run through all possible destructors +pub unsafe fn run_dtors() { + let mut ptr = DTORS.replace(ptr::null_mut()); + while !ptr.is_null() { + let list = Box::from_raw(ptr); + for (ptr, dtor) in list.into_iter() { + dtor(ptr); + } + ptr = DTORS.replace(ptr::null_mut()); + } +} diff --git a/src/libstd/sys/hermit/mod.rs b/src/libstd/sys/hermit/mod.rs index 958532b8fc4b2..6736d964e521b 100644 --- a/src/libstd/sys/hermit/mod.rs +++ b/src/libstd/sys/hermit/mod.rs @@ -103,6 +103,7 @@ pub unsafe extern "C" fn runtime_entry( argv: *const *const c_char, env: *const *const c_char, ) -> ! { + use crate::sys::hermit::fast_thread_local::run_dtors; extern "C" { fn main(argc: isize, argv: *const *const c_char) -> i32; } @@ -112,6 +113,7 @@ pub unsafe extern "C" fn runtime_entry( let result = main(argc as isize, argv); + run_dtors(); abi::exit(result); } diff --git a/src/libstd/sys/hermit/thread.rs b/src/libstd/sys/hermit/thread.rs index c7bea168f34d8..c0ee2829f09af 100644 --- a/src/libstd/sys/hermit/thread.rs +++ b/src/libstd/sys/hermit/thread.rs @@ -5,6 +5,7 @@ use crate::fmt; use crate::io; use crate::mem; use crate::sys::hermit::abi; +use crate::sys::hermit::fast_thread_local::run_dtors; use crate::time::Duration; use core::u32; @@ -70,6 +71,9 @@ impl Thread { unsafe { // Finally, let's run some code. Box::from_raw(main as *mut Box)(); + + // run all destructors + run_dtors(); } } } diff --git a/src/libstd/sys/hermit/thread_local.rs b/src/libstd/sys/hermit/thread_local.rs index c6f8adb21623a..f8be9863ed56f 100644 --- a/src/libstd/sys/hermit/thread_local.rs +++ b/src/libstd/sys/hermit/thread_local.rs @@ -1,60 +1,26 @@ -#![allow(dead_code)] // not used on all platforms - -use crate::collections::BTreeMap; -use crate::ptr; -use crate::sync::atomic::{AtomicUsize, Ordering}; -use crate::sys_common::mutex::Mutex; - pub type Key = usize; -type Dtor = unsafe extern "C" fn(*mut u8); - -static NEXT_KEY: AtomicUsize = AtomicUsize::new(0); - -static mut KEYS: *mut BTreeMap> = ptr::null_mut(); -static KEYS_LOCK: Mutex = Mutex::new(); - -#[thread_local] -static mut LOCALS: *mut BTreeMap = ptr::null_mut(); - -unsafe fn keys() -> &'static mut BTreeMap> { - if KEYS.is_null() { - KEYS = Box::into_raw(Box::new(BTreeMap::new())); - } - &mut *KEYS -} - -unsafe fn locals() -> &'static mut BTreeMap { - if LOCALS.is_null() { - LOCALS = Box::into_raw(Box::new(BTreeMap::new())); - } - &mut *LOCALS -} - #[inline] -pub unsafe fn create(dtor: Option) -> Key { - let key = NEXT_KEY.fetch_add(1, Ordering::SeqCst); - let _guard = KEYS_LOCK.lock(); - keys().insert(key, dtor); - key +pub unsafe fn create(_dtor: Option) -> Key { + panic!("should not be used on the wasm target"); } #[inline] -pub unsafe fn get(key: Key) -> *mut u8 { - if let Some(&entry) = locals().get(&key) { entry } else { ptr::null_mut() } +pub unsafe fn set(_key: Key, _value: *mut u8) { + panic!("should not be used on the wasm target"); } #[inline] -pub unsafe fn set(key: Key, value: *mut u8) { - locals().insert(key, value); +pub unsafe fn get(_key: Key) -> *mut u8 { + panic!("should not be used on the wasm target"); } #[inline] -pub unsafe fn destroy(key: Key) { - keys().remove(&key); +pub unsafe fn destroy(_key: Key) { + panic!("should not be used on the wasm target"); } #[inline] pub fn requires_synchronized_create() -> bool { - false + panic!("should not be used on the wasm target"); } From 0cd4c8936682896fa321746f7d1993cc4120a264 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Sat, 4 Apr 2020 19:47:50 -0700 Subject: [PATCH 12/13] =?UTF-8?q?"cannot=20resolve"=20=E2=86=92=20"cannot?= =?UTF-8?q?=20satisfy"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../traits/error_reporting/mod.rs | 10 +++++----- src/test/ui/associated-const/issue-63496.stderr | 4 ++-- src/test/ui/associated-item/issue-48027.stderr | 2 +- .../associated-types-overridden-binding.stderr | 4 ++-- .../associated-types-unconstrained.stderr | 2 +- src/test/ui/error-codes/E0283.stderr | 2 +- src/test/ui/issues/issue-12028.stderr | 2 +- src/test/ui/issues/issue-21974.stderr | 2 +- src/test/ui/issues/issue-24424.stderr | 2 +- src/test/ui/issues/issue-29147.stderr | 2 +- src/test/ui/issues/issue-54954.stderr | 2 +- src/test/ui/issues/issue-58022.stderr | 2 +- src/test/ui/question-mark-type-infer.stderr | 2 +- .../trait-static-method-generic-inference.stderr | 2 +- src/test/ui/type/type-annotation-needed.rs | 2 +- src/test/ui/type/type-annotation-needed.stderr | 2 +- src/test/ui/type/type-check/issue-40294.stderr | 2 +- 17 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/librustc_trait_selection/traits/error_reporting/mod.rs b/src/librustc_trait_selection/traits/error_reporting/mod.rs index 5a9a96887f66a..f0a157b377076 100644 --- a/src/librustc_trait_selection/traits/error_reporting/mod.rs +++ b/src/librustc_trait_selection/traits/error_reporting/mod.rs @@ -1377,7 +1377,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> { return; } let mut err = self.need_type_info_err(body_id, span, self_ty, ErrorCode::E0283); - err.note(&format!("cannot resolve `{}`", predicate)); + err.note(&format!("cannot satisfy `{}`", predicate)); if let ObligationCauseCode::ItemObligation(def_id) = obligation.cause.code { self.suggest_fully_qualified_path(&mut err, def_id, span, trait_ref.def_id()); } else if let ( @@ -1407,7 +1407,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> { // LL | const fn const_val() -> usize { // | --------- - required by this bound in `Tt::const_val` // | - // = note: cannot resolve `_: Tt` + // = note: cannot satisfy `_: Tt` err.span_suggestion_verbose( span.shrink_to_hi(), @@ -1457,7 +1457,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> { return; } let mut err = self.need_type_info_err(body_id, span, self_ty, ErrorCode::E0284); - err.note(&format!("cannot resolve `{}`", predicate)); + err.note(&format!("cannot satisfy `{}`", predicate)); err } @@ -1469,10 +1469,10 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> { self.tcx.sess, span, E0284, - "type annotations needed: cannot resolve `{}`", + "type annotations needed: cannot satisfy `{}`", predicate, ); - err.span_label(span, &format!("cannot resolve `{}`", predicate)); + err.span_label(span, &format!("cannot satisfy `{}`", predicate)); err } }; diff --git a/src/test/ui/associated-const/issue-63496.stderr b/src/test/ui/associated-const/issue-63496.stderr index 3a70e7d43c25e..34e947030a072 100644 --- a/src/test/ui/associated-const/issue-63496.stderr +++ b/src/test/ui/associated-const/issue-63496.stderr @@ -10,7 +10,7 @@ LL | fn f() -> ([u8; A::C], [u8; A::C]); | cannot infer type | help: use the fully qualified path to an implementation: `::C` | - = note: cannot resolve `_: A` + = note: cannot satisfy `_: A` = note: associated constants cannot be accessed directly on a `trait`, they can only be accessed through a specific `impl` error[E0283]: type annotations needed @@ -25,7 +25,7 @@ LL | fn f() -> ([u8; A::C], [u8; A::C]); | cannot infer type | help: use the fully qualified path to an implementation: `::C` | - = note: cannot resolve `_: A` + = note: cannot satisfy `_: A` = note: associated constants cannot be accessed directly on a `trait`, they can only be accessed through a specific `impl` error: aborting due to 2 previous errors diff --git a/src/test/ui/associated-item/issue-48027.stderr b/src/test/ui/associated-item/issue-48027.stderr index 62a380732a8bb..98b545c6e0e78 100644 --- a/src/test/ui/associated-item/issue-48027.stderr +++ b/src/test/ui/associated-item/issue-48027.stderr @@ -22,7 +22,7 @@ LL | fn return_n(&self) -> [u8; Bar::X]; | cannot infer type | help: use the fully qualified path to an implementation: `::X` | - = note: cannot resolve `_: Bar` + = note: cannot satisfy `_: Bar` = note: associated constants cannot be accessed directly on a `trait`, they can only be accessed through a specific `impl` error: aborting due to 2 previous errors diff --git a/src/test/ui/associated-types/associated-types-overridden-binding.stderr b/src/test/ui/associated-types/associated-types-overridden-binding.stderr index 9e10ed7b72952..683a2ab21d9c8 100644 --- a/src/test/ui/associated-types/associated-types-overridden-binding.stderr +++ b/src/test/ui/associated-types/associated-types-overridden-binding.stderr @@ -6,7 +6,7 @@ LL | trait Foo: Iterator {} LL | trait Bar: Foo {} | ^^^^^^^^^^^^^^^ cannot infer type for type parameter `Self` | - = note: cannot resolve `::Item == i32` + = note: cannot satisfy `::Item == i32` error[E0284]: type annotations needed --> $DIR/associated-types-overridden-binding.rs:7:21 @@ -16,7 +16,7 @@ LL | trait I32Iterator = Iterator; LL | trait U32Iterator = I32Iterator; | ^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type for type parameter `Self` | - = note: cannot resolve `::Item == i32` + = note: cannot satisfy `::Item == i32` error: aborting due to 2 previous errors diff --git a/src/test/ui/associated-types/associated-types-unconstrained.stderr b/src/test/ui/associated-types/associated-types-unconstrained.stderr index 14ce4836f97f8..2914a7f868b2b 100644 --- a/src/test/ui/associated-types/associated-types-unconstrained.stderr +++ b/src/test/ui/associated-types/associated-types-unconstrained.stderr @@ -4,7 +4,7 @@ error[E0284]: type annotations needed LL | let x: isize = Foo::bar(); | ^^^^^^^^ cannot infer type | - = note: cannot resolve `<_ as Foo>::A == _` + = note: cannot satisfy `<_ as Foo>::A == _` error: aborting due to previous error diff --git a/src/test/ui/error-codes/E0283.stderr b/src/test/ui/error-codes/E0283.stderr index ae5b7c3ae8f67..e95583c91a72f 100644 --- a/src/test/ui/error-codes/E0283.stderr +++ b/src/test/ui/error-codes/E0283.stderr @@ -7,7 +7,7 @@ LL | fn create() -> u32; LL | let cont: u32 = Generator::create(); | ^^^^^^^^^^^^^^^^^ cannot infer type | - = note: cannot resolve `_: Generator` + = note: cannot satisfy `_: Generator` error: aborting due to previous error diff --git a/src/test/ui/issues/issue-12028.stderr b/src/test/ui/issues/issue-12028.stderr index fe7e8f89f7f1a..434c5de2874e0 100644 --- a/src/test/ui/issues/issue-12028.stderr +++ b/src/test/ui/issues/issue-12028.stderr @@ -4,7 +4,7 @@ error[E0284]: type annotations needed LL | self.input_stream(&mut stream); | ^^^^^^^^^^^^ cannot infer type for type parameter `H` declared on the trait `StreamHash` | - = note: cannot resolve `<_ as StreamHasher>::S == ::S` + = note: cannot satisfy `<_ as StreamHasher>::S == ::S` error: aborting due to previous error diff --git a/src/test/ui/issues/issue-21974.stderr b/src/test/ui/issues/issue-21974.stderr index 19823499066eb..d36d0dad4a196 100644 --- a/src/test/ui/issues/issue-21974.stderr +++ b/src/test/ui/issues/issue-21974.stderr @@ -7,7 +7,7 @@ LL | trait Foo { LL | where &'a T : Foo, | ^^^ cannot infer type for reference `&'a T` | - = note: cannot resolve `&'a T: Foo` + = note: cannot satisfy `&'a T: Foo` error: aborting due to previous error diff --git a/src/test/ui/issues/issue-24424.stderr b/src/test/ui/issues/issue-24424.stderr index 538d44c3b2ef3..f9338981408b7 100644 --- a/src/test/ui/issues/issue-24424.stderr +++ b/src/test/ui/issues/issue-24424.stderr @@ -7,7 +7,7 @@ LL | LL | impl <'l0, 'l1, T0> Trait1<'l0, T0> for bool where T0 : Trait0<'l0>, T0 : Trait0<'l1> {} | ^^^^^^^^^^^ cannot infer type for type parameter `T0` | - = note: cannot resolve `T0: Trait0<'l0>` + = note: cannot satisfy `T0: Trait0<'l0>` error: aborting due to previous error diff --git a/src/test/ui/issues/issue-29147.stderr b/src/test/ui/issues/issue-29147.stderr index 1efedb45cace7..94aff5963544c 100644 --- a/src/test/ui/issues/issue-29147.stderr +++ b/src/test/ui/issues/issue-29147.stderr @@ -7,7 +7,7 @@ LL | trait Foo { fn xxx(&self); } LL | let _ = >::xxx; | ^^^^^^^^^^^^ cannot infer type for struct `S5<_>` | - = note: cannot resolve `S5<_>: Foo` + = note: cannot satisfy `S5<_>: Foo` error: aborting due to previous error diff --git a/src/test/ui/issues/issue-54954.stderr b/src/test/ui/issues/issue-54954.stderr index 4967b82216e46..ca5439e290b75 100644 --- a/src/test/ui/issues/issue-54954.stderr +++ b/src/test/ui/issues/issue-54954.stderr @@ -13,7 +13,7 @@ LL | const ARR_LEN: usize = Tt::const_val::<[i8; 123]>(); LL | const fn const_val() -> usize { | --------- - required by this bound in `Tt::const_val` | - = note: cannot resolve `_: Tt` + = note: cannot satisfy `_: Tt` error[E0080]: evaluation of constant value failed --> $DIR/issue-54954.rs:13:15 diff --git a/src/test/ui/issues/issue-58022.stderr b/src/test/ui/issues/issue-58022.stderr index 70a7c38b83425..fb31467ec47fa 100644 --- a/src/test/ui/issues/issue-58022.stderr +++ b/src/test/ui/issues/issue-58022.stderr @@ -16,7 +16,7 @@ LL | fn new(slice: &[u8; Foo::SIZE]) -> Self; | cannot infer type | help: use the fully qualified path to an implementation: `::SIZE` | - = note: cannot resolve `_: Foo` + = note: cannot satisfy `_: Foo` = note: associated constants cannot be accessed directly on a `trait`, they can only be accessed through a specific `impl` error: aborting due to 2 previous errors diff --git a/src/test/ui/question-mark-type-infer.stderr b/src/test/ui/question-mark-type-infer.stderr index 262344fba5999..64d8f685637fb 100644 --- a/src/test/ui/question-mark-type-infer.stderr +++ b/src/test/ui/question-mark-type-infer.stderr @@ -4,7 +4,7 @@ error[E0284]: type annotations needed LL | l.iter().map(f).collect()? | ^^^^^^^ cannot infer type | - = note: cannot resolve `<_ as std::ops::Try>::Ok == _` + = note: cannot satisfy `<_ as std::ops::Try>::Ok == _` help: consider specifying the type argument in the method call | LL | l.iter().map(f).collect::()? diff --git a/src/test/ui/traits/trait-static-method-generic-inference.stderr b/src/test/ui/traits/trait-static-method-generic-inference.stderr index f9718dac3547d..8f20cc5093e11 100644 --- a/src/test/ui/traits/trait-static-method-generic-inference.stderr +++ b/src/test/ui/traits/trait-static-method-generic-inference.stderr @@ -7,7 +7,7 @@ LL | fn new() -> T; LL | let _f: base::Foo = base::HasNew::new(); | ^^^^^^^^^^^^^^^^^ cannot infer type | - = note: cannot resolve `_: base::HasNew` + = note: cannot satisfy `_: base::HasNew` error: aborting due to previous error diff --git a/src/test/ui/type/type-annotation-needed.rs b/src/test/ui/type/type-annotation-needed.rs index a420515be496d..b9bf6d79b1c89 100644 --- a/src/test/ui/type/type-annotation-needed.rs +++ b/src/test/ui/type/type-annotation-needed.rs @@ -6,5 +6,5 @@ fn main() { foo(42); //~^ ERROR type annotations needed //~| NOTE cannot infer type - //~| NOTE cannot resolve + //~| NOTE cannot satisfy } diff --git a/src/test/ui/type/type-annotation-needed.stderr b/src/test/ui/type/type-annotation-needed.stderr index df7d73d7a7c1d..e6cd7ac388091 100644 --- a/src/test/ui/type/type-annotation-needed.stderr +++ b/src/test/ui/type/type-annotation-needed.stderr @@ -7,7 +7,7 @@ LL | fn foo>(x: i32) {} LL | foo(42); | ^^^ cannot infer type for type parameter `T` declared on the function `foo` | - = note: cannot resolve `_: std::convert::Into` + = note: cannot satisfy `_: std::convert::Into` help: consider specifying the type argument in the function call | LL | foo::(42); diff --git a/src/test/ui/type/type-check/issue-40294.stderr b/src/test/ui/type/type-check/issue-40294.stderr index 2c889b6c2ca0a..7d81e0ce10c70 100644 --- a/src/test/ui/type/type-check/issue-40294.stderr +++ b/src/test/ui/type/type-check/issue-40294.stderr @@ -7,7 +7,7 @@ LL | trait Foo: Sized { LL | where &'a T : Foo, | ^^^ cannot infer type for reference `&'a T` | - = note: cannot resolve `&'a T: Foo` + = note: cannot satisfy `&'a T: Foo` error: aborting due to previous error From 004ce25ec0ddb198bb63e14a41aaeb29f7d53bc0 Mon Sep 17 00:00:00 2001 From: Yoshua Wuyts Date: Sun, 5 Apr 2020 20:59:10 +0200 Subject: [PATCH 13/13] Remove labels in libstd/lib.rs macro imports These labels were probably moved around when rustfmt was introduced. --- src/libstd/lib.rs | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index ff8f6731724d0..a9a519f0a3a71 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -517,20 +517,8 @@ pub use std_detect::detect; #[stable(feature = "rust1", since = "1.0.0")] #[allow(deprecated, deprecated_in_future)] pub use core::{ - // Stable - assert_eq, - assert_ne, - debug_assert, - debug_assert_eq, - debug_assert_ne, - // Unstable - matches, - r#try, - todo, - unimplemented, - unreachable, - write, - writeln, + assert_eq, assert_ne, debug_assert, debug_assert_eq, debug_assert_ne, matches, r#try, todo, + unimplemented, unreachable, write, writeln, }; // Re-export built-in macros defined through libcore.