mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-30 18:53:39 +00:00
Auto merge of #67310 - Centril:rollup-22jiyow, r=Centril
Rollup of 6 pull requests Successful merges: - #67255 (Remove i686-unknown-dragonfly target) - #67267 (Fix signature of `__wasilibc_find_relpath`) - #67282 (Fix example code of OpenOptions::open) - #67289 (Do not ICE on unnamed future) - #67300 (Restore original implementation of Vec::retain) - #67305 (Doc typo) Failed merges: r? @ghost
This commit is contained in:
commit
a605441e04
@ -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
|
||||
|
@ -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.,
|
||||
|
@ -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,
|
||||
@ -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)),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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,
|
||||
})
|
||||
}
|
@ -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),
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
@ -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<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())?)
|
||||
}
|
||||
|
||||
@ -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)
|
||||
}
|
||||
|
||||
@ -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())?,
|
||||
@ -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)
|
||||
}
|
||||
|
||||
@ -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 \
|
||||
@ -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> {
|
||||
|
24
src/test/ui/async-await/issue-67252-unnamed-future.rs
Normal file
24
src/test/ui/async-await/issue-67252-unnamed-future.rs
Normal file
@ -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
src/test/ui/async-await/issue-67252-unnamed-future.stderr
Normal file
22
src/test/ui/async-await/issue-67252-unnamed-future.stderr
Normal file
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user