diff --git a/src/liballoc/vec.rs b/src/liballoc/vec.rs index 52b45b0b8fe07..2ad4e22884ea7 100644 --- a/src/liballoc/vec.rs +++ b/src/liballoc/vec.rs @@ -1079,7 +1079,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 diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index 88c14dfe7d1f8..33715418ffd73 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -144,7 +144,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., 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 da36b31038de7..701c19085bec5 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -2404,7 +2404,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/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), 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 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> { 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 +