From 0f47327a697b2c70353073083a20a9bd5b0e4360 Mon Sep 17 00:00:00 2001 From: Antonio Huete Jimenez Date: Thu, 12 Dec 2019 16:19:37 +0100 Subject: [PATCH 1/6] Remove i686-unknown-dragonfly target --- .../spec/i686_unknown_dragonfly.rs | 23 ------------------- src/librustc_target/spec/mod.rs | 1 - 2 files changed, 24 deletions(-) delete mode 100644 src/librustc_target/spec/i686_unknown_dragonfly.rs diff --git a/src/librustc_target/spec/i686_unknown_dragonfly.rs b/src/librustc_target/spec/i686_unknown_dragonfly.rs deleted file mode 100644 index 20315e7145c73..0000000000000 --- a/src/librustc_target/spec/i686_unknown_dragonfly.rs +++ /dev/null @@ -1,23 +0,0 @@ -use crate::spec::{LinkerFlavor, Target, TargetResult}; - -pub fn target() -> TargetResult { - let mut base = super::dragonfly_base::opts(); - base.cpu = "pentium4".to_string(); - base.max_atomic_width = Some(64); - base.pre_link_args.get_mut(&LinkerFlavor::Gcc).unwrap().push("-m32".to_string()); - base.stack_probes = true; - - Ok(Target { - llvm_target: "i686-unknown-dragonfly".to_string(), - target_endian: "little".to_string(), - target_pointer_width: "32".to_string(), - target_c_int_width: "32".to_string(), - data_layout: "e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128".to_string(), - arch: "x86".to_string(), - target_os: "dragonfly".to_string(), - target_env: String::new(), - target_vendor: "unknown".to_string(), - linker_flavor: LinkerFlavor::Gcc, - options: base, - }) -} diff --git a/src/librustc_target/spec/mod.rs b/src/librustc_target/spec/mod.rs index 693cf75e8fd64..34b321d38f0f6 100644 --- a/src/librustc_target/spec/mod.rs +++ b/src/librustc_target/spec/mod.rs @@ -398,7 +398,6 @@ supported_targets! { ("powerpc64-unknown-freebsd", powerpc64_unknown_freebsd), ("x86_64-unknown-freebsd", x86_64_unknown_freebsd), - ("i686-unknown-dragonfly", i686_unknown_dragonfly), ("x86_64-unknown-dragonfly", x86_64_unknown_dragonfly), ("aarch64-unknown-openbsd", aarch64_unknown_openbsd), From 641ccd58c168a296f5c36a191660ef63a32a98b9 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 12 Dec 2019 14:48:47 -0800 Subject: [PATCH 2/6] Fix signature of `__wasilibc_find_relpath` Looks like this function changed upstream, so it needs to be adjusted for when used by libstd. --- src/libstd/sys/wasi/fs.rs | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/src/libstd/sys/wasi/fs.rs b/src/libstd/sys/wasi/fs.rs index fad092e35c3e6..04bfdf67e12d2 100644 --- a/src/libstd/sys/wasi/fs.rs +++ b/src/libstd/sys/wasi/fs.rs @@ -364,7 +364,7 @@ impl OpenOptions { impl File { pub fn open(path: &Path, opts: &OpenOptions) -> io::Result { - let (dir, file) = open_parent(path, wasi::RIGHTS_PATH_OPEN)?; + let (dir, file) = open_parent(path)?; open_at(&dir, &file, opts) } @@ -452,7 +452,7 @@ impl DirBuilder { } pub fn mkdir(&self, p: &Path) -> io::Result<()> { - let (dir, file) = open_parent(p, wasi::RIGHTS_PATH_CREATE_DIRECTORY)?; + let (dir, file) = open_parent(p)?; dir.create_directory(osstr2str(file.as_ref())?) } } @@ -478,13 +478,13 @@ pub fn readdir(p: &Path) -> io::Result { } pub fn unlink(p: &Path) -> io::Result<()> { - let (dir, file) = open_parent(p, wasi::RIGHTS_PATH_UNLINK_FILE)?; + let (dir, file) = open_parent(p)?; dir.unlink_file(osstr2str(file.as_ref())?) } pub fn rename(old: &Path, new: &Path) -> io::Result<()> { - let (old, old_file) = open_parent(old, wasi::RIGHTS_PATH_RENAME_SOURCE)?; - let (new, new_file) = open_parent(new, wasi::RIGHTS_PATH_RENAME_TARGET)?; + let (old, old_file) = open_parent(old)?; + let (new, new_file) = open_parent(new)?; old.rename(osstr2str(old_file.as_ref())?, &new, osstr2str(new_file.as_ref())?) } @@ -495,12 +495,12 @@ pub fn set_perm(_p: &Path, _perm: FilePermissions) -> io::Result<()> { } pub fn rmdir(p: &Path) -> io::Result<()> { - let (dir, file) = open_parent(p, wasi::RIGHTS_PATH_REMOVE_DIRECTORY)?; + let (dir, file) = open_parent(p)?; dir.remove_directory(osstr2str(file.as_ref())?) } pub fn readlink(p: &Path) -> io::Result { - let (dir, file) = open_parent(p, wasi::RIGHTS_PATH_READLINK)?; + let (dir, file) = open_parent(p)?; read_link(&dir, &file) } @@ -536,13 +536,13 @@ fn read_link(fd: &WasiFd, file: &Path) -> io::Result { } pub fn symlink(src: &Path, dst: &Path) -> io::Result<()> { - let (dst, dst_file) = open_parent(dst, wasi::RIGHTS_PATH_SYMLINK)?; + let (dst, dst_file) = open_parent(dst)?; dst.symlink(osstr2str(src.as_ref())?, osstr2str(dst_file.as_ref())?) } pub fn link(src: &Path, dst: &Path) -> io::Result<()> { - let (src, src_file) = open_parent(src, wasi::RIGHTS_PATH_LINK_SOURCE)?; - let (dst, dst_file) = open_parent(dst, wasi::RIGHTS_PATH_LINK_TARGET)?; + let (src, src_file) = open_parent(src)?; + let (dst, dst_file) = open_parent(dst)?; src.link( wasi::LOOKUPFLAGS_SYMLINK_FOLLOW, osstr2str(src_file.as_ref())?, @@ -552,12 +552,12 @@ pub fn link(src: &Path, dst: &Path) -> io::Result<()> { } pub fn stat(p: &Path) -> io::Result { - let (dir, file) = open_parent(p, wasi::RIGHTS_PATH_FILESTAT_GET)?; + let (dir, file) = open_parent(p)?; metadata_at(&dir, wasi::LOOKUPFLAGS_SYMLINK_FOLLOW, &file) } pub fn lstat(p: &Path) -> io::Result { - let (dir, file) = open_parent(p, wasi::RIGHTS_PATH_FILESTAT_GET)?; + let (dir, file) = open_parent(p)?; metadata_at(&dir, 0, &file) } @@ -611,11 +611,11 @@ fn open_at(fd: &WasiFd, path: &Path, opts: &OpenOptions) -> io::Result { /// /// Note that this can fail if `p` doesn't look like it can be opened relative /// to any preopened file descriptor. -fn open_parent(p: &Path, rights: wasi::Rights) -> io::Result<(ManuallyDrop, PathBuf)> { +fn open_parent(p: &Path) -> io::Result<(ManuallyDrop, PathBuf)> { let p = CString::new(p.as_os_str().as_bytes())?; unsafe { let mut ret = ptr::null(); - let fd = libc::__wasilibc_find_relpath(p.as_ptr(), rights, 0, &mut ret); + let fd = __wasilibc_find_relpath(p.as_ptr(), &mut ret); if fd == -1 { let msg = format!( "failed to find a preopened file descriptor \ @@ -635,6 +635,13 @@ fn open_parent(p: &Path, rights: wasi::Rights) -> io::Result<(ManuallyDrop libc::c_int; + } } pub fn osstr2str(f: &OsStr) -> io::Result<&str> { From b65c6ec10fe2b80e22706f5b3245cc5f6f372edf Mon Sep 17 00:00:00 2001 From: Patrick Wang Date: Sat, 14 Dec 2019 03:12:50 +0800 Subject: [PATCH 3/6] Fix incorrect example code of OpenOptions::open --- src/libstd/fs.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libstd/fs.rs b/src/libstd/fs.rs index a109e38e1e3bc..01e57ec0ab941 100644 --- a/src/libstd/fs.rs +++ b/src/libstd/fs.rs @@ -936,7 +936,7 @@ impl OpenOptions { /// ```no_run /// use std::fs::OpenOptions; /// - /// let file = OpenOptions::new().open("foo.txt"); + /// let file = OpenOptions::new().read(true).open("foo.txt"); /// ``` /// /// [`ErrorKind`]: ../io/enum.ErrorKind.html From 7ea6c46a6d70506e92630f0186f2c6b0386147a0 Mon Sep 17 00:00:00 2001 From: Aaron Loucks Date: Sat, 14 Dec 2019 12:38:45 -0500 Subject: [PATCH 4/6] Restore original implementation of Vec::retain This PR reverts #48065, which aimed to optimize `Vec::retain` by making use of `Vec::drain_filter`. Unfortunately at that time, `drain_filter` was unsound. The soundness hole in `Vec::drain_filter` was fixed in #61224 by guaranteeing that cleanup logic runs via a nested `Drop`, even in the event of a panic. Implementing this nested drop affects codegen (apparently?) and results in slower code. Fixes #65970 --- src/liballoc/vec.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/liballoc/vec.rs b/src/liballoc/vec.rs index 6e165ccb91998..e5abfdd52022a 100644 --- a/src/liballoc/vec.rs +++ b/src/liballoc/vec.rs @@ -1075,7 +1075,22 @@ impl Vec { pub fn retain(&mut self, mut f: F) where F: FnMut(&T) -> bool { - self.drain_filter(|x| !f(x)); + let len = self.len(); + let mut del = 0; + { + let v = &mut **self; + + for i in 0..len { + if !f(&v[i]) { + del += 1; + } else if del > 0 { + v.swap(i - del, i); + } + } + } + if del > 0 { + self.truncate(len - del); + } } /// Removes all but the first of consecutive elements in the vector that resolve to the same From e08944fdafac547aecc1a94e44cc978a202eec86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Fri, 13 Dec 2019 15:27:55 -0800 Subject: [PATCH 5/6] Do not ICE on unnamed future --- src/librustc/hir/map/mod.rs | 13 +++++++--- src/librustc/traits/error_reporting.rs | 2 +- .../async-await/issue-67252-unnamed-future.rs | 24 +++++++++++++++++++ .../issue-67252-unnamed-future.stderr | 22 +++++++++++++++++ 4 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 src/test/ui/async-await/issue-67252-unnamed-future.rs create mode 100644 src/test/ui/async-await/issue-67252-unnamed-future.stderr diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index 5bf5a93ad0102..69e772697f846 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -1016,8 +1016,8 @@ impl<'hir> Map<'hir> { } } - pub fn name(&self, id: HirId) -> Name { - match self.get(id) { + pub fn opt_name(&self, id: HirId) -> Option { + Some(match self.get(id) { Node::Item(i) => i.ident.name, Node::ForeignItem(fi) => fi.ident.name, Node::ImplItem(ii) => ii.ident.name, @@ -1028,7 +1028,14 @@ impl<'hir> Map<'hir> { Node::GenericParam(param) => param.name.ident().name, Node::Binding(&Pat { kind: PatKind::Binding(_, _, l, _), .. }) => l.name, Node::Ctor(..) => self.name(self.get_parent_item(id)), - _ => bug!("no name for {}", self.node_to_string(id)) + _ => return None, + }) + } + + pub fn name(&self, id: HirId) -> Name { + match self.opt_name(id) { + Some(name) => name, + None => bug!("no name for {}", self.node_to_string(id)), } } diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index 6a111895b5637..1a92d1eb8c5d3 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -2353,7 +2353,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { let message = if let Some(name) = last_generator .and_then(|generator_did| self.tcx.parent(generator_did)) .and_then(|parent_did| self.tcx.hir().as_local_hir_id(parent_did)) - .map(|parent_hir_id| self.tcx.hir().name(parent_hir_id)) + .and_then(|parent_hir_id| self.tcx.hir().opt_name(parent_hir_id)) { format!("future returned by `{}` is not {}", name, trait_name) } else { diff --git a/src/test/ui/async-await/issue-67252-unnamed-future.rs b/src/test/ui/async-await/issue-67252-unnamed-future.rs new file mode 100644 index 0000000000000..1a7ff613341ec --- /dev/null +++ b/src/test/ui/async-await/issue-67252-unnamed-future.rs @@ -0,0 +1,24 @@ +// edition:2018 +use std::future::Future; +use std::pin::Pin; +use std::task::{Context, Poll}; + +fn spawn(_: T) {} + +pub struct AFuture; +impl Future for AFuture{ + type Output = (); + + fn poll(mut self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<()> { + unimplemented!() + } +} + +async fn foo() { + spawn(async { //~ ERROR future cannot be sent between threads safely + let _a = std::ptr::null_mut::<()>(); // `*mut ()` is not `Send` + AFuture.await; + }); +} + +fn main() {} diff --git a/src/test/ui/async-await/issue-67252-unnamed-future.stderr b/src/test/ui/async-await/issue-67252-unnamed-future.stderr new file mode 100644 index 0000000000000..24aedeb96597a --- /dev/null +++ b/src/test/ui/async-await/issue-67252-unnamed-future.stderr @@ -0,0 +1,22 @@ +error: future cannot be sent between threads safely + --> $DIR/issue-67252-unnamed-future.rs:18:5 + | +LL | fn spawn(_: T) {} + | ----- ---- required by this bound in `spawn` +... +LL | spawn(async { + | ^^^^^ future is not `Send` + | + = help: within `impl std::future::Future`, the trait `std::marker::Send` is not implemented for `*mut ()` +note: future is not `Send` as this value is used across an await + --> $DIR/issue-67252-unnamed-future.rs:20:9 + | +LL | let _a = std::ptr::null_mut::<()>(); // `*mut ()` is not `Send` + | -- has type `*mut ()` +LL | AFuture.await; + | ^^^^^^^^^^^^^ await occurs here, with `_a` maybe used later +LL | }); + | - `_a` is later dropped here + +error: aborting due to previous error + From d0008baebd9d2cb98cfe852a6e2ce9b7cd7ca78a Mon Sep 17 00:00:00 2001 From: Alex Kapranoff Date: Sat, 14 Dec 2019 17:12:40 -0800 Subject: [PATCH 6/6] Doc typo --- src/libcore/num/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index 5a97aa4acfa4c..d752284541285 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -143,7 +143,7 @@ NonZeroI8 NonZeroI16 NonZeroI32 NonZeroI64 NonZeroI128 NonZeroIsize } /// Provides intentionally-wrapped arithmetic on `T`. /// -/// Operations like `+` on `u32` values is intended to never overflow, +/// Operations like `+` on `u32` values are intended to never overflow, /// and in some debug configurations overflow is detected and results /// in a panic. While most arithmetic falls into this category, some /// code explicitly expects and relies upon modular arithmetic (e.g.,