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 14 pull requests #82460

Closed
wants to merge 36 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
3ed189e
Cleanup `PpMode` and friends
LeSeulArtichaut Feb 18, 2021
dd3772e
A few more code cleanups
LeSeulArtichaut Feb 19, 2021
7ad4b7a
Replace normalize.css 3.0.0 with unminified version.
jsha Feb 20, 2021
9bbd482
Update normalize.css to 8.0.1
jsha Feb 20, 2021
7acb105
Re-minify normalize.css.
jsha Feb 20, 2021
10f2342
Remove some P-s
bugadani Feb 20, 2021
fece59b
Change `find_anon_type` method to function
0yoyoyo Feb 21, 2021
17176cc
Add indication of anonymous lifetime position
0yoyoyo Feb 21, 2021
ce1a521
Apply tidy check
0yoyoyo Feb 21, 2021
b9449a3
Add option enabling MIR inlining independently of mir-opt-level
tmiasko Feb 21, 2021
5c546be
Use optional values for inlining thresholds
tmiasko Feb 21, 2021
5f7d663
:arrow_up: rust-analyzer
lnicola Feb 22, 2021
75d1e30
Update test cases
0yoyoyo Feb 22, 2021
24c23f5
Test hexagon-enum only when llvm target is present
nagisa Feb 22, 2021
c02d210
Add tests
petrochenkov Feb 22, 2021
fc9d578
expand: Preserve order of inert attributes during expansion
petrochenkov Feb 22, 2021
e8dcc02
Add a `size()` function to WASI's `MetadataExt`.
sunfishcode Feb 22, 2021
fa74d48
Improve error msgs when found type is deref of expected
osa1 Feb 21, 2021
132ec26
Enable API documentation for `std::os::wasi`.
sunfishcode Feb 22, 2021
a6eb836
Use #[doc = include_str!()] in std
LeSeulArtichaut Dec 30, 2020
de6f1b8
Do not consider using a semicolon inside of a different-crate macro
notriddle Feb 14, 2021
df78eea
expand: Resolve and expand inner attributes on out-of-line modules
petrochenkov Feb 21, 2021
408ccd7
Rollup merge of #80534 - LeSeulArtichaut:doc-include, r=jyn514
Dylan-DPC Feb 24, 2021
d3e3d58
Rollup merge of #82090 - notriddle:consider-using-a-semicolon-here, r…
Dylan-DPC Feb 24, 2021
1975088
Rollup merge of #82269 - LeSeulArtichaut:cleanup-ppmode, r=spastorino
Dylan-DPC Feb 24, 2021
b98f608
Rollup merge of #82313 - jsha:update-normalize-css, r=GuillaumeGomez
Dylan-DPC Feb 24, 2021
2ffc621
Rollup merge of #82321 - bugadani:ast3, r=varkor
Dylan-DPC Feb 24, 2021
b0458bc
Rollup merge of #82364 - osa1:issue82361, r=estebank
Dylan-DPC Feb 24, 2021
5fdfc09
Rollup merge of #82370 - 0yoyoyo:update-issue-81650-point-anonymous-l…
Dylan-DPC Feb 24, 2021
936a488
Rollup merge of #82376 - tmiasko:inline-options, r=oli-obk
Dylan-DPC Feb 24, 2021
5878913
Rollup merge of #82394 - lnicola:rust-analyzer-2021-02-22, r=jonas-sc…
Dylan-DPC Feb 24, 2021
cc0c8f1
Rollup merge of #82399 - petrochenkov:modin2, r=Aaron1011
Dylan-DPC Feb 24, 2021
fb19700
Rollup merge of #82404 - nagisa:nagisa/hexagon-enums-llvm-comps, r=pe…
Dylan-DPC Feb 24, 2021
4f3203f
Rollup merge of #82419 - petrochenkov:inertord, r=Aaron1011
Dylan-DPC Feb 24, 2021
2d80e0b
Rollup merge of #82420 - sunfishcode:wasi-docs, r=alexcrichton
Dylan-DPC Feb 24, 2021
ec0e4c2
Rollup merge of #82421 - sunfishcode:wasi-metadata-size, r=alexcrichton
Dylan-DPC Feb 24, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Enable API documentation for std::os::wasi.
This adds API documentation support for `std::os::wasi` modeled after
how `std::os::unix` works, so that WASI can be documented [here] along
with the other platforms.

[here]: https://doc.rust-lang.org/stable/std/os/index.html

Two changes of particular interest:

 - This changes the `AsRawFd` for `io::Stdin` for WASI to return
   `libc::STDIN_FILENO` instead of `sys::stdio::Stdin.as_raw_fd()` (and
   similar for `Stdout` and `Stderr`), which matches how the `unix`
   version works. `STDIN_FILENO` etc. may not always be explicitly
   reserved at the WASI level, but as long as we have Rust's `std` and
   `libc`, I think it's reasonable to guarantee that we'll always use
   `libc::STDIN_FILENO` for stdin.

 - This duplicates the `osstr2str` utility function, rather than
   trying to share it across all the configurations that need it.
  • Loading branch information
sunfishcode committed Feb 23, 2021
commit 132ec261b0d215f77b71eeee3d814cd304fc1a29
3 changes: 3 additions & 0 deletions library/std/src/os/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ pub use crate::sys::windows_ext as windows;
#[doc(cfg(target_os = "linux"))]
pub mod linux;

#[cfg(doc)]
pub use crate::sys::wasi_ext as wasi;

// If we're not documenting libstd then we just expose the main modules as we otherwise would.

#[cfg(not(doc))]
Expand Down
30 changes: 26 additions & 4 deletions library/std/src/sys/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ cfg_if::cfg_if! {
#[stable(feature = "rust1", since = "1.0.0")]
pub use self::ext as unix_ext;
} else if #[cfg(any(target_os = "hermit",
target_arch = "wasm32",
all(target_arch = "wasm32", not(target_os = "wasi")),
all(target_vendor = "fortanix", target_env = "sgx")))] {
// On wasm right now the module below doesn't compile
// On non-WASI wasm right now the module below doesn't compile
// (missing things in `libc` which is empty) so just omit everything
// with an empty module
#[unstable(issue = "none", feature = "std_internals")]
Expand All @@ -85,9 +85,9 @@ cfg_if::cfg_if! {
#[stable(feature = "rust1", since = "1.0.0")]
pub use self::ext as windows_ext;
} else if #[cfg(any(target_os = "hermit",
target_arch = "wasm32",
all(target_arch = "wasm32", not(target_os = "wasi")),
all(target_vendor = "fortanix", target_env = "sgx")))] {
// On wasm right now the shim below doesn't compile, so
// On non-WASI wasm right now the shim below doesn't compile, so
// just omit it
#[unstable(issue = "none", feature = "std_internals")]
#[allow(missing_docs)]
Expand All @@ -106,3 +106,25 @@ cfg_if::cfg_if! {
pub mod windows_ext;
}
}

#[cfg(doc)]
cfg_if::cfg_if! {
if #[cfg(target_os = "wasi")] {
// On WASI we'll document what's already available
#[stable(feature = "rust1", since = "1.0.0")]
pub use self::ext as wasi_ext;
} else if #[cfg(any(target_os = "hermit",
target_arch = "wasm32",
all(target_vendor = "fortanix", target_env = "sgx")))] {
// On non-WASI wasm right now the module below doesn't compile
// (missing things in `libc` which is empty) so just omit everything
// with an empty module
#[unstable(issue = "none", feature = "std_internals")]
#[allow(missing_docs)]
pub mod wasi_ext {}
} else {
// On other platforms like Windows document the bare bones of WASI
#[path = "wasi/ext/mod.rs"]
pub mod wasi_ext;
}
}
25 changes: 16 additions & 9 deletions library/std/src/sys/wasi/ext/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
#![deny(unsafe_op_in_unsafe_fn)]
#![unstable(feature = "wasi_ext", issue = "none")]

use crate::ffi::OsStr;
use crate::fs::{self, File, Metadata, OpenOptions};
use crate::io::{self, IoSlice, IoSliceMut};
use crate::path::{Path, PathBuf};
use crate::sys::fs::osstr2str;
use crate::sys_common::{AsInner, AsInnerMut, FromInner};
// Used for `File::read` on intra-doc links
#[allow(unused_imports)]
use io::{Read, Write};

/// WASI-specific extensions to [`File`].
pub trait FileExt {
Expand Down Expand Up @@ -54,11 +57,11 @@ pub trait FileExt {
/// # Errors
///
/// If this function encounters an error of the kind
/// [`ErrorKind::Interrupted`] then the error is ignored and the operation
/// [`io::ErrorKind::Interrupted`] then the error is ignored and the operation
/// will continue.
///
/// If this function encounters an "end of file" before completely filling
/// the buffer, it returns an error of the kind [`ErrorKind::UnexpectedEof`].
/// the buffer, it returns an error of the kind [`io::ErrorKind::UnexpectedEof`].
/// The contents of `buf` are unspecified in this case.
///
/// If any other read error is encountered then this function immediately
Expand Down Expand Up @@ -131,16 +134,16 @@ pub trait FileExt {
/// The current file cursor is not affected by this function.
///
/// This method will continuously call [`write_at`] until there is no more data
/// to be written or an error of non-[`ErrorKind::Interrupted`] kind is
/// to be written or an error of non-[`io::ErrorKind::Interrupted`] kind is
/// returned. This method will not return until the entire buffer has been
/// successfully written or such an error occurs. The first error that is
/// not of [`ErrorKind::Interrupted`] kind generated from this method will be
/// not of [`io::ErrorKind::Interrupted`] kind generated from this method will be
/// returned.
///
/// # Errors
///
/// This function will return the first error of
/// non-[`ErrorKind::Interrupted`] kind that [`write_at`] returns.
/// non-[`io::ErrorKind::Interrupted`] kind that [`write_at`] returns.
///
/// [`write_at`]: FileExt::write_at
#[stable(feature = "rw_exact_all_at", since = "1.33.0")]
Expand Down Expand Up @@ -426,7 +429,7 @@ impl MetadataExt for fs::Metadata {
}
}

/// WASI-specific extensions for [`FileType`].
/// WASI-specific extensions for [`fs::FileType`].
///
/// Adds support for special WASI file types such as block/character devices,
/// pipes, and sockets.
Expand Down Expand Up @@ -517,8 +520,12 @@ pub fn symlink<P: AsRef<Path>, U: AsRef<Path>>(

/// Create a symbolic link.
///
/// This is a convenience API similar to [`std::os::unix::fs::symlink`] and
/// [`std::os::windows::fs::symlink_file`] and [`symlink_dir`](std::os::windows::fs::symlink_dir).
/// This is a convenience API similar to `std::os::unix::fs::symlink` and
/// `std::os::windows::fs::symlink_file` and `std::os::windows::fs::symlink_dir`.
pub fn symlink_path<P: AsRef<Path>, U: AsRef<Path>>(old_path: P, new_path: U) -> io::Result<()> {
crate::sys::fs::symlink(old_path.as_ref(), new_path.as_ref())
}

fn osstr2str(f: &OsStr) -> io::Result<&str> {
f.to_str().ok_or_else(|| io::Error::new(io::ErrorKind::Other, "input must be utf-8"))
}
12 changes: 6 additions & 6 deletions library/std/src/sys/wasi/ext/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,36 +145,36 @@ impl IntoRawFd for fs::File {

impl AsRawFd for io::Stdin {
fn as_raw_fd(&self) -> RawFd {
sys::stdio::Stdin.as_raw_fd()
libc::STDIN_FILENO
}
}

impl AsRawFd for io::Stdout {
fn as_raw_fd(&self) -> RawFd {
sys::stdio::Stdout.as_raw_fd()
libc::STDOUT_FILENO
}
}

impl AsRawFd for io::Stderr {
fn as_raw_fd(&self) -> RawFd {
sys::stdio::Stderr.as_raw_fd()
libc::STDERR_FILENO
}
}

impl<'a> AsRawFd for io::StdinLock<'a> {
fn as_raw_fd(&self) -> RawFd {
sys::stdio::Stdin.as_raw_fd()
libc::STDIN_FILENO
}
}

impl<'a> AsRawFd for io::StdoutLock<'a> {
fn as_raw_fd(&self) -> RawFd {
sys::stdio::Stdout.as_raw_fd()
libc::STDOUT_FILENO
}
}

impl<'a> AsRawFd for io::StderrLock<'a> {
fn as_raw_fd(&self) -> RawFd {
sys::stdio::Stderr.as_raw_fd()
libc::STDERR_FILENO
}
}
28 changes: 28 additions & 0 deletions library/std/src/sys/wasi/ext/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,32 @@
//! Platform-specific extensions to `std` for WASI.
//!
//! Provides access to platform-level information on WASI, and exposes
//! WASI-specific functions that would otherwise be inappropriate as
//! part of the core `std` library.
//!
//! It exposes more ways to deal with platform-specific strings (`OsStr`,
//! `OsString`), allows to set permissions more granularly, extract low-level
//! file descriptors from files and sockets, and has platform-specific helpers
//! for spawning processes.
//!
//! # Examples
//!
//! ```no_run
//! use std::fs::File;
//! use std::os::wasi::prelude::*;
//!
//! fn main() -> std::io::Result<()> {
//! let f = File::create("foo.txt")?;
//! let fd = f.as_raw_fd();
//!
//! // use fd with native WASI bindings
//!
//! Ok(())
//! }
//! ```

#![deny(unsafe_op_in_unsafe_fn)]
#![doc(cfg(target_os = "wasi"))]

pub mod ffi;
pub mod fs;
Expand Down