Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 6 pull requests #67310

Merged
merged 12 commits into from
Dec 15, 2019
17 changes: 16 additions & 1 deletion src/liballoc/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1079,7 +1079,22 @@ impl<T> Vec<T> {
pub fn retain<F>(&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
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/num/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.,
Expand Down
13 changes: 10 additions & 3 deletions src/librustc/hir/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Name> {
Some(match self.get(id) {
Node::Item(i) => i.ident.name,
Node::ForeignItem(fi) => fi.ident.name,
Node::ImplItem(ii) => ii.ident.name,
Expand All @@ -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)),
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/traits/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
23 changes: 0 additions & 23 deletions src/librustc_target/spec/i686_unknown_dragonfly.rs

This file was deleted.

1 change: 0 additions & 1 deletion src/librustc_target/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 21 additions & 14 deletions src/libstd/sys/wasi/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ impl OpenOptions {

impl File {
pub fn open(path: &Path, opts: &OpenOptions) -> io::Result<File> {
let (dir, file) = open_parent(path, wasi::RIGHTS_PATH_OPEN)?;
let (dir, file) = open_parent(path)?;
open_at(&dir, &file, opts)
}

Expand Down Expand Up @@ -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())?)
}
}
Expand All @@ -478,13 +478,13 @@ pub fn readdir(p: &Path) -> io::Result<ReadDir> {
}

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())?)
}

Expand All @@ -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<PathBuf> {
let (dir, file) = open_parent(p, wasi::RIGHTS_PATH_READLINK)?;
let (dir, file) = open_parent(p)?;
read_link(&dir, &file)
}

Expand Down Expand Up @@ -536,13 +536,13 @@ fn read_link(fd: &WasiFd, file: &Path) -> io::Result<PathBuf> {
}

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())?,
Expand All @@ -552,12 +552,12 @@ pub fn link(src: &Path, dst: &Path) -> io::Result<()> {
}

pub fn stat(p: &Path) -> io::Result<FileAttr> {
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<FileAttr> {
let (dir, file) = open_parent(p, wasi::RIGHTS_PATH_FILESTAT_GET)?;
let (dir, file) = open_parent(p)?;
metadata_at(&dir, 0, &file)
}

Expand Down Expand Up @@ -611,11 +611,11 @@ fn open_at(fd: &WasiFd, path: &Path, opts: &OpenOptions) -> io::Result<File> {
///
/// 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<WasiFd>, PathBuf)> {
fn open_parent(p: &Path) -> io::Result<(ManuallyDrop<WasiFd>, 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 \
Expand All @@ -635,6 +635,13 @@ fn open_parent(p: &Path, rights: wasi::Rights) -> io::Result<(ManuallyDrop<WasiF

return Ok((ManuallyDrop::new(WasiFd::from_raw(fd as u32)), path));
}

extern "C" {
pub fn __wasilibc_find_relpath(
path: *const libc::c_char,
relative_path: *mut *const libc::c_char,
) -> libc::c_int;
}
}

pub fn osstr2str(f: &OsStr) -> io::Result<&str> {
Expand Down
24 changes: 24 additions & 0 deletions src/test/ui/async-await/issue-67252-unnamed-future.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// edition:2018
use std::future::Future;
use std::pin::Pin;
use std::task::{Context, Poll};

fn spawn<T: Send>(_: 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() {}
22 changes: 22 additions & 0 deletions src/test/ui/async-await/issue-67252-unnamed-future.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
error: future cannot be sent between threads safely
--> $DIR/issue-67252-unnamed-future.rs:18:5
|
LL | fn spawn<T: Send>(_: 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