From 0660732988ad0324ebf4437eb53f82f599c3ccfd Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Wed, 8 Dec 2021 18:48:17 +0000 Subject: [PATCH 01/17] `std::path::absolute` --- library/std/src/lib.rs | 1 + library/std/src/path.rs | 80 ++++++++++++++++++++++++++++- library/std/src/path/tests.rs | 58 +++++++++++++++++++++ library/std/src/sys/sgx/path.rs | 7 ++- library/std/src/sys/solid/path.rs | 7 ++- library/std/src/sys/unix/path.rs | 45 +++++++++++++++- library/std/src/sys/windows/path.rs | 16 ++++++ 7 files changed, 210 insertions(+), 4 deletions(-) diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index 67846e7883570..25183984a3faf 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -225,6 +225,7 @@ // std is implemented with unstable features, many of which are internal // compiler details that will never be stable // NB: the following list is sorted to minimize merge conflicts. +#![feature(absolute_path)] #![feature(alloc_error_handler)] #![feature(alloc_layout_extra)] #![feature(allocator_api)] diff --git a/library/std/src/path.rs b/library/std/src/path.rs index 9ade2847e8ea9..d2e11467ea384 100644 --- a/library/std/src/path.rs +++ b/library/std/src/path.rs @@ -84,7 +84,7 @@ use crate::str::FromStr; use crate::sync::Arc; use crate::ffi::{OsStr, OsString}; - +use crate::sys; use crate::sys::path::{is_sep_byte, is_verbatim_sep, parse_prefix, MAIN_SEP_STR}; //////////////////////////////////////////////////////////////////////////////// @@ -3141,3 +3141,81 @@ impl Error for StripPrefixError { "prefix not found" } } + +/// Makes the path absolute without accessing the filesystem. +/// +/// If the path is relative, the current directory is used as the base directory. +/// All intermediate components will be resolved according to platforms-specific +/// rules but unlike [`canonicalize`][crate::fs::canonicalize] this does not +/// resolve symlinks and may succeed even if the path does not exist. +/// +/// If the `path` is empty or getting the +/// [current directory][crate::env::current_dir] fails then an error will be +/// returned. +/// +/// # Examples +/// +/// ## Posix paths +/// +/// ``` +/// #![feature(absolute_path)] +/// # #[cfg(unix)] +/// fn main() -> std::io::Result<()> { +/// use std::path::{self, Path}; +/// +/// // Relative to absolute +/// let absolute = path::absolute("foo/./bar")?; +/// assert!(absolute.ends_with("foo/bar")); +/// +/// // Absolute to absolute +/// let absolute = path::absolute("/foo//test/.././bar.rs")?; +/// assert_eq!(absolute, Path::new("/foo/test/../bar.rs")); +/// Ok(()) +/// } +/// # #[cfg(not(unix))] +/// # fn main() {} +/// ``` +/// +/// The paths is resolved using [POSIX semantics][posix-semantics] except that +/// it stops short of resolving symlinks. This means it will keep `..` +/// components and trailing slashes. +/// +/// ## Windows paths +/// +/// ``` +/// #![feature(absolute_path)] +/// # #[cfg(windows)] +/// fn main() -> std::io::Result<()> { +/// use std::path::{self, Path}; +/// +/// // Relative to absolute +/// let absolute = path::absolute("foo/./bar")?; +/// assert!(absolute.ends_with(r"foo\bar")); +/// +/// // Absolute to absolute +/// let absolute = path::absolute(r"C:\foo//test\..\./bar.rs")?; +/// +/// assert_eq!(absolute, Path::new(r"C:\foo\bar.rs")); +/// Ok(()) +/// } +/// # #[cfg(not(windows))] +/// # fn main() {} +/// ``` +/// +/// For verbatim paths this will simply return the path as given. For other +/// paths this is currently equivalent to calling [`GetFullPathNameW`][windows-path] +/// This may change in the future. +/// +/// [posix-semantics]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_13 +/// [windows-path]: https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getfullpathnamew +#[unstable(feature = "absolute_path", issue = "none")] +pub fn absolute>(path: P) -> io::Result { + let path = path.as_ref(); + if path.as_os_str().is_empty() { + return Err(io::Error::new_const( + io::ErrorKind::InvalidInput, + &"cannot make an empty path absolute", + )); + } + sys::path::absolute(path) +} diff --git a/library/std/src/path/tests.rs b/library/std/src/path/tests.rs index 2bf499e1ab823..cf35254a2e365 100644 --- a/library/std/src/path/tests.rs +++ b/library/std/src/path/tests.rs @@ -1665,6 +1665,64 @@ fn test_ord() { ord!(Equal, "foo/bar", "foo/bar//"); } +#[test] +#[cfg(unix)] +fn test_unix_absolute() { + use crate::path::absolute; + + assert!(absolute("").is_err()); + + let relative = "a/b"; + let mut expected = crate::env::current_dir().unwrap(); + expected.push(relative); + assert_eq!(absolute(relative).unwrap(), expected); + + // Test how components are collected. + assert_eq!(absolute("/a/b/c").unwrap(), Path::new("/a/b/c")); + assert_eq!(absolute("/a//b/c").unwrap(), Path::new("/a/b/c")); + assert_eq!(absolute("//a/b/c").unwrap(), Path::new("//a/b/c")); + assert_eq!(absolute("///a/b/c").unwrap(), Path::new("/a/b/c")); + assert_eq!(absolute("/a/b/c/").unwrap(), Path::new("/a/b/c/")); + assert_eq!(absolute("/a/./b/../c/.././..").unwrap(), Path::new("/a/b/../c/../..")); +} + +#[test] +#[cfg(windows)] +fn test_windows_absolute() { + use crate::path::absolute; + // An empty path is an error. + assert!(absolute("").is_err()); + + let relative = r"a\b"; + let mut expected = crate::env::current_dir().unwrap(); + expected.push(relative); + assert_eq!(absolute(relative).unwrap(), expected); + + macro_rules! unchanged( + ($path:expr) => { + assert_eq!(absolute($path).unwrap(), Path::new($path)); + } + ); + + unchanged!(r"C:\path\to\file"); + unchanged!(r"C:\path\to\file\"); + unchanged!(r"\\server\share\to\file"); + unchanged!(r"\\server.\share.\to\file"); + unchanged!(r"\\.\PIPE\name"); + unchanged!(r"\\.\C:\path\to\COM1"); + unchanged!(r"\\?\C:\path\to\file"); + unchanged!(r"\\?\UNC\server\share\to\file"); + unchanged!(r"\\?\PIPE\name"); + // Verbatim paths are always unchanged, no matter what. + unchanged!(r"\\?\path.\to/file.."); + + assert_eq!(absolute(r"C:\path..\to.\file.").unwrap(), Path::new(r"C:\path..\to\file")); + assert_eq!(absolute(r"C:\path\to\COM1").unwrap(), Path::new(r"\\.\COM1")); + assert_eq!(absolute(r"C:\path\to\COM1.txt").unwrap(), Path::new(r"\\.\COM1")); + assert_eq!(absolute(r"C:\path\to\COM1 .txt").unwrap(), Path::new(r"\\.\COM1")); + assert_eq!(absolute(r"C:\path\to\cOnOuT$").unwrap(), Path::new(r"\\.\cOnOuT$")); +} + #[bench] fn bench_path_cmp_fast_path_buf_sort(b: &mut test::Bencher) { let prefix = "my/home"; diff --git a/library/std/src/sys/sgx/path.rs b/library/std/src/sys/sgx/path.rs index 840a7ae042625..9cfc61bf174fa 100644 --- a/library/std/src/sys/sgx/path.rs +++ b/library/std/src/sys/sgx/path.rs @@ -1,5 +1,6 @@ use crate::ffi::OsStr; -use crate::path::Prefix; +use crate::path::{Path, PathBuf, Prefix}; +use crate::sys::unsupported; #[inline] pub fn is_sep_byte(b: u8) -> bool { @@ -17,3 +18,7 @@ pub fn parse_prefix(_: &OsStr) -> Option> { pub const MAIN_SEP_STR: &str = "/"; pub const MAIN_SEP: char = '/'; + +pub(crate) fn absolute(_path: &Path) -> io::Result { + unsupported() +} diff --git a/library/std/src/sys/solid/path.rs b/library/std/src/sys/solid/path.rs index 4a14332d4999c..ed532dc989b1f 100644 --- a/library/std/src/sys/solid/path.rs +++ b/library/std/src/sys/solid/path.rs @@ -1,5 +1,6 @@ use crate::ffi::OsStr; -use crate::path::Prefix; +use crate::path::{Path, PathBuf, Prefix}; +use crate::sys::unsupported; #[inline] pub fn is_sep_byte(b: u8) -> bool { @@ -17,3 +18,7 @@ pub fn parse_prefix(_: &OsStr) -> Option> { pub const MAIN_SEP_STR: &str = "\\"; pub const MAIN_SEP: char = '\\'; + +pub(crate) fn absolute(_path: &Path) -> io::Result { + unsupported() +} diff --git a/library/std/src/sys/unix/path.rs b/library/std/src/sys/unix/path.rs index 717add9ec48db..1fdabab4598a7 100644 --- a/library/std/src/sys/unix/path.rs +++ b/library/std/src/sys/unix/path.rs @@ -1,5 +1,8 @@ +use crate::env; use crate::ffi::OsStr; -use crate::path::Prefix; +use crate::io; +use crate::os::unix::ffi::OsStrExt; +use crate::path::{Path, PathBuf, Prefix}; #[inline] pub fn is_sep_byte(b: u8) -> bool { @@ -18,3 +21,43 @@ pub fn parse_prefix(_: &OsStr) -> Option> { pub const MAIN_SEP_STR: &str = "/"; pub const MAIN_SEP: char = '/'; + +/// Make a POSIX path absolute without changing its semantics. +pub(crate) fn absolute(path: &Path) -> io::Result { + // This is mostly a wrapper around collecting `Path::components`, with + // exceptions made where this conflicts with the POSIX specification. + // See 4.13 Pathname Resolution, IEEE Std 1003.1-2017 + // https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_13 + + let mut components = path.components(); + let path_os = path.as_os_str().as_bytes(); + + let mut normalized = if path.is_absolute() { + // "If a pathname begins with two successive characters, the + // first component following the leading characters may be + // interpreted in an implementation-defined manner, although more than + // two leading characters shall be treated as a single + // character." + if path_os.starts_with(b"//") && !path_os.starts_with(b"///") { + components.next(); + PathBuf::from("//") + } else { + PathBuf::new() + } + } else { + env::current_dir()? + }; + normalized.extend(components); + + // "Interfaces using pathname resolution may specify additional constraints + // when a pathname that does not name an existing directory contains at + // least one non- character and contains one or more trailing + // characters". + // A trailing is also meaningful if "a symbolic link is + // encountered during pathname resolution". + if path_os.ends_with(b"/") { + normalized.push(""); + } + + Ok(normalized) +} diff --git a/library/std/src/sys/windows/path.rs b/library/std/src/sys/windows/path.rs index 79e0eaf6c34c6..e54fcaed4957d 100644 --- a/library/std/src/sys/windows/path.rs +++ b/library/std/src/sys/windows/path.rs @@ -260,3 +260,19 @@ pub(crate) fn maybe_verbatim(path: &Path) -> io::Result> { )?; Ok(path) } + +/// Make a Windows path absolute. +pub(crate) fn absolute(path: &Path) -> io::Result { + if path.as_os_str().bytes().starts_with(br"\\?\") { + return Ok(path.into()); + } + let path = to_u16s(path)?; + let lpfilename = path.as_ptr(); + fill_utf16_buf( + // SAFETY: `fill_utf16_buf` ensures the `buffer` and `size` are valid. + // `lpfilename` is a pointer to a null terminated string that is not + // invalidated until after `GetFullPathNameW` returns successfully. + |buffer, size| unsafe { c::GetFullPathNameW(lpfilename, size, buffer, ptr::null_mut()) }, + super::os2path, + ) +} From 60ec6a0e38dcac5ee47b138fda678ab816151ab6 Mon Sep 17 00:00:00 2001 From: Noah Lev Date: Mon, 27 Dec 2021 11:40:17 -0800 Subject: [PATCH 02/17] Tweak sentence in `transmute` docs --- library/core/src/intrinsics.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/core/src/intrinsics.rs b/library/core/src/intrinsics.rs index 4ecc3b0c7f8e1..acbb612352b36 100644 --- a/library/core/src/intrinsics.rs +++ b/library/core/src/intrinsics.rs @@ -961,7 +961,7 @@ extern "rust-intrinsic" { /// Below are common applications of `transmute` which can be replaced with safer /// constructs. /// - /// Turning raw bytes(`&[u8]`) to `u32`, `f64`, etc.: + /// Turning raw bytes (`&[u8]`) into `u32`, `f64`, etc.: /// /// ``` /// let raw_bytes = [0x78, 0x56, 0x34, 0x12]; From 7fd6ddfba2da259cd5c4232ff32e4c14a54a0e60 Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Thu, 30 Dec 2021 19:45:20 +0800 Subject: [PATCH 03/17] Error when selected impl is not const in constck --- .../rustc_const_eval/src/transform/check_consts/check.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_const_eval/src/transform/check_consts/check.rs b/compiler/rustc_const_eval/src/transform/check_consts/check.rs index 1d5f463015294..f3e9f4bfc9752 100644 --- a/compiler/rustc_const_eval/src/transform/check_consts/check.rs +++ b/compiler/rustc_const_eval/src/transform/check_consts/check.rs @@ -811,7 +811,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> { param_env, Binder::dummy(TraitPredicate { trait_ref, - constness: ty::BoundConstness::ConstIfConst, + constness: ty::BoundConstness::NotConst, polarity: ty::ImplPolarity::Positive, }), ); @@ -830,6 +830,10 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> { return; } Ok(Some(ImplSource::UserDefined(data))) => { + if let hir::Constness::NotConst = tcx.impl_constness(data.impl_def_id) { + self.check_op(ops::FnCallNonConst(None)); + return; + } let callee_name = tcx.item_name(callee); if let Some(&did) = tcx .associated_item_def_ids(data.impl_def_id) From 2b70a3df7a73b283e7f19439a98c81bb66f6a852 Mon Sep 17 00:00:00 2001 From: Noah Lev Date: Sun, 9 Jan 2022 12:41:13 -0800 Subject: [PATCH 04/17] Display "private fields" instead of "fields omitted" Also: * Always use `/* */` block comments * Use the same message everywhere, rather than sometimes prefixing with "some" When I first read rustdoc docs, I was confused why the fields were being omitted. It was only later that I realized it was because they were private. It's also always bothered me that rustdoc sometimes uses `//` and sometimes uses `/*` comments for these messages, so this change makes them all use `/*`. Technically, I think fields can be omitted if they are public but `doc(hidden)` too, but `doc(hidden)` is analogous to privacy. It's really just used to emulate "doc privacy" when -- because of technical limitations -- an item has to be public. So I think it's fine to include this under the category of "private fields". --- src/librustdoc/html/render/print_item.rs | 8 +++----- src/test/rustdoc/structfields.rs | 8 ++++---- src/test/rustdoc/toggle-item-contents.rs | 2 +- src/test/rustdoc/union.rs | 2 +- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index 44a9ec5ea4210..fb24f3286d713 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -1557,7 +1557,7 @@ fn render_union( } if it.has_stripped_fields().unwrap() { - write!(w, " // some fields omitted\n{}", tab); + write!(w, " /* private fields */\n{}", tab); } if toggle { toggle_close(w); @@ -1613,13 +1613,11 @@ fn render_struct( if has_visible_fields { if it.has_stripped_fields().unwrap() { - write!(w, "\n{} // some fields omitted", tab); + write!(w, "\n{} /* private fields */", tab); } write!(w, "\n{}", tab); } else if it.has_stripped_fields().unwrap() { - // If there are no visible fields we can just display - // `{ /* fields omitted */ }` to save space. - write!(w, " /* fields omitted */ "); + write!(w, " /* private fields */ "); } if toggle { toggle_close(w); diff --git a/src/test/rustdoc/structfields.rs b/src/test/rustdoc/structfields.rs index 6de198453cd27..7e1cada4b9828 100644 --- a/src/test/rustdoc/structfields.rs +++ b/src/test/rustdoc/structfields.rs @@ -2,7 +2,7 @@ pub struct Foo { // @has - //pre "pub a: ()" pub a: (), - // @has - //pre "// some fields omitted" + // @has - //pre "/* private fields */" // @!has - //pre "b: ()" b: (), // @!has - //pre "c: usize" @@ -16,7 +16,7 @@ pub struct Foo { pub struct Bar { // @has - //pre "pub a: ()" pub a: (), - // @!has - //pre "// some fields omitted" + // @!has - //pre "/* private fields */" } // @has structfields/enum.Qux.html @@ -29,11 +29,11 @@ pub enum Qux { b: (), // @has - //pre "c: usize" c: usize, - // @has - //pre "// some fields omitted" + // @has - //pre "/* private fields */" }, } -// @has structfields/struct.Baz.html //pre "pub struct Baz { /* fields omitted */ }" +// @has structfields/struct.Baz.html //pre "pub struct Baz { /* private fields */ }" pub struct Baz { x: u8, #[doc(hidden)] diff --git a/src/test/rustdoc/toggle-item-contents.rs b/src/test/rustdoc/toggle-item-contents.rs index 937646987dd4f..c1df4613e3562 100644 --- a/src/test/rustdoc/toggle-item-contents.rs +++ b/src/test/rustdoc/toggle-item-contents.rs @@ -55,7 +55,7 @@ pub union Union { // @has 'toggle_item_contents/struct.PrivStruct.html' // @count - '//details[@class="rustdoc-toggle type-contents-toggle"]' 0 -// @has - '//div[@class="docblock item-decl"]' 'fields omitted' +// @has - '//div[@class="docblock item-decl"]' '/* private fields */' pub struct PrivStruct { a: usize, b: usize, diff --git a/src/test/rustdoc/union.rs b/src/test/rustdoc/union.rs index 8918622773205..5a788eb1b1cae 100644 --- a/src/test/rustdoc/union.rs +++ b/src/test/rustdoc/union.rs @@ -2,7 +2,7 @@ pub union U { // @has - //pre "pub a: u8" pub a: u8, - // @has - //pre "// some fields omitted" + // @has - //pre "/* private fields */" // @!has - //pre "b: u16" b: u16, } From 8fd8db5c2955dd715cf7ee59205a733abcdd34fc Mon Sep 17 00:00:00 2001 From: Dmitrii - Demenev Date: Sun, 9 Jan 2022 19:17:15 -0500 Subject: [PATCH 05/17] Extended the note on the use of `no_run` attribute --- src/doc/rustdoc/src/documentation-tests.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/doc/rustdoc/src/documentation-tests.md b/src/doc/rustdoc/src/documentation-tests.md index aea55d4f4b69c..534fd19b52eb2 100644 --- a/src/doc/rustdoc/src/documentation-tests.md +++ b/src/doc/rustdoc/src/documentation-tests.md @@ -335,7 +335,8 @@ panic during execution. If the code doesn't panic, the test will fail. The `no_run` attribute will compile your code but not run it. This is important for examples such as "Here's how to retrieve a web page," which you would want to ensure compiles, but might be run in a test -environment that has no network access. +environment that has no network access. This attribute can also be +used to demonstrate code snippets that can cause Undefined Behavior. ```rust /// ```no_run From 680ebeaa792a6446b0096492b286a748f79dd933 Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Sun, 9 Jan 2022 13:47:50 -0800 Subject: [PATCH 06/17] RELEASES.md: Add 1.58 release note for `File::options` stabilization --- RELEASES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/RELEASES.md b/RELEASES.md index d6f5909a2ebc0..6356ddb2da727 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -42,6 +42,7 @@ Stabilized APIs - [`{integer}::saturating_div`] - [`Option::unwrap_unchecked`] - [`NonZero{unsigned}::is_power_of_two`] +- [`File::options`] These APIs are now usable in const contexts: @@ -137,6 +138,7 @@ and related tools. [`{integer}::saturating_div`]: https://doc.rust-lang.org/stable/std/primitive.i8.html#method.saturating_div [`Option::unwrap_unchecked`]: https://doc.rust-lang.org/stable/std/option/enum.Option.html#method.unwrap_unchecked [`NonZero{unsigned}::is_power_of_two`]: https://doc.rust-lang.org/stable/std/num/struct.NonZeroU8.html#method.is_power_of_two +[`File::options`]: https://doc.rust-lang.org/stable/std/fs/struct.File.html#method.options [`unix::process::ExitStatusExt::core_dumped`]: https://doc.rust-lang.org/stable/std/os/unix/process/trait.ExitStatusExt.html#tymethod.core_dumped [`unix::process::ExitStatusExt::stopped_signal`]: https://doc.rust-lang.org/stable/std/os/unix/process/trait.ExitStatusExt.html#tymethod.stopped_signal [`unix::process::ExitStatusExt::continued`]: https://doc.rust-lang.org/stable/std/os/unix/process/trait.ExitStatusExt.html#tymethod.continued From 2ae616af302d6022fbc3234122bc3bb71915c073 Mon Sep 17 00:00:00 2001 From: Yaroslav Dynnikov Date: Mon, 10 Jan 2022 14:22:45 +0300 Subject: [PATCH 07/17] Fix doc formatting for time.rs The doc states that instants are not steady, but the word "not" wasn't highlighted in bold. --- library/std/src/time.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/std/src/time.rs b/library/std/src/time.rs index 86cc93c445376..b6867e68df745 100644 --- a/library/std/src/time.rs +++ b/library/std/src/time.rs @@ -54,7 +54,7 @@ pub use core::time::FromSecsError; /// instant when created, and are often useful for tasks such as measuring /// benchmarks or timing how long an operation takes. /// -/// Note, however, that instants are not guaranteed to be **steady**. In other +/// Note, however, that instants are **not** guaranteed to be **steady**. In other /// words, each tick of the underlying clock might not be the same length (e.g. /// some seconds may be longer than others). An instant may jump forwards or /// experience time dilation (slow down or speed up), but it will never go From 55abf38bf2d7a8c38dd15440cf7bb1a13b04bcb8 Mon Sep 17 00:00:00 2001 From: Wesley Wiser Date: Mon, 10 Jan 2022 10:41:31 -0500 Subject: [PATCH 08/17] Add note about upstream commit musl-patch-configure.diff is derived from --- src/ci/docker/scripts/musl-toolchain.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ci/docker/scripts/musl-toolchain.sh b/src/ci/docker/scripts/musl-toolchain.sh index 3c17f316d1fe8..e358b8139d7d0 100644 --- a/src/ci/docker/scripts/musl-toolchain.sh +++ b/src/ci/docker/scripts/musl-toolchain.sh @@ -48,7 +48,9 @@ cd musl-cross-make git checkout a54eb56f33f255dfca60be045f12a5cfaf5a72a9 # Fix the cfi detection script in musl's configure so cfi is generated -# when debug info is asked for. +# when debug info is asked for. This patch is derived from +# https://git.musl-libc.org/cgit/musl/commit/?id=c4d4028dde90562f631edf559fbc42d8ec1b29de. +# When we upgrade to a version that includes this commit, we can remove the patch. mkdir patches/musl-1.1.24 cp ../musl-patch-configure.diff patches/musl-1.1.24/0001-fix-cfi-detection.diff From 881b427fa3cd53097d05b68079f435949d94e51f Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 10 Jan 2022 21:01:09 +0100 Subject: [PATCH 09/17] Add missing suffix for sidebar-items script path --- src/librustdoc/html/render/context.rs | 2 +- src/librustdoc/html/render/mod.rs | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/librustdoc/html/render/context.rs b/src/librustdoc/html/render/context.rs index 534a542d58ed0..0e661228bedfa 100644 --- a/src/librustdoc/html/render/context.rs +++ b/src/librustdoc/html/render/context.rs @@ -665,7 +665,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> { _ => unreachable!(), }; let items = self.build_sidebar_items(module); - let js_dst = self.dst.join("sidebar-items.js"); + let js_dst = self.dst.join(&format!("sidebar-items{}.js", self.shared.resource_suffix)); let v = format!("initSidebarItems({});", serde_json::to_string(&items).unwrap()); scx.fs.write(js_dst, v)?; } diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 7adf63f26f602..76840d9fe7c5b 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -1823,7 +1823,11 @@ fn print_sidebar(cx: &Context<'_>, it: &clean::Item, buffer: &mut Buffer) { ty = it.type_(), path = relpath ); - write!(buffer, "", relpath); + write!( + buffer, + "", + relpath, cx.shared.resource_suffix + ); // Closes sidebar-elems div. buffer.write_str(""); } From 5786bbddc670597af286381b27fbb9f563cf7dc7 Mon Sep 17 00:00:00 2001 From: david-perez Date: Mon, 10 Jan 2022 23:18:34 +0100 Subject: [PATCH 10/17] Eliminate "boxed" wording in `std::error::Error` documentation In commit 29403ee, documentation for the methods on `std::any::Any` was modified so that they referred to the concrete value behind the trait object as the "inner" value. This is a more accurate wording than "boxed": while putting trait objects inside boxes is arguably the most common use, they can also be placed behind other pointer types like `&mut` or `std::sync::Arc`. This commit does the same documentation changes for `std::error::Error`. --- library/std/src/error.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/library/std/src/error.rs b/library/std/src/error.rs index ea0c230fa42db..526a1b92b19e2 100644 --- a/library/std/src/error.rs +++ b/library/std/src/error.rs @@ -606,21 +606,21 @@ impl Error for time::FromSecsError {} // Copied from `any.rs`. impl dyn Error + 'static { - /// Returns `true` if the boxed type is the same as `T` + /// Returns `true` if the inner type is the same as `T`. #[stable(feature = "error_downcast", since = "1.3.0")] #[inline] pub fn is(&self) -> bool { // Get `TypeId` of the type this function is instantiated with. let t = TypeId::of::(); - // Get `TypeId` of the type in the trait object. - let boxed = self.type_id(private::Internal); + // Get `TypeId` of the type in the trait object (`self`). + let concrete = self.type_id(private::Internal); // Compare both `TypeId`s on equality. - t == boxed + t == concrete } - /// Returns some reference to the boxed value if it is of type `T`, or + /// Returns some reference to the inner value if it is of type `T`, or /// `None` if it isn't. #[stable(feature = "error_downcast", since = "1.3.0")] #[inline] @@ -632,7 +632,7 @@ impl dyn Error + 'static { } } - /// Returns some mutable reference to the boxed value if it is of type `T`, or + /// Returns some mutable reference to the inner value if it is of type `T`, or /// `None` if it isn't. #[stable(feature = "error_downcast", since = "1.3.0")] #[inline] From fc8af986fd9a102cb14b15ce22f8e58b52aaef52 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 3 Jan 2022 01:39:43 -0300 Subject: [PATCH 11/17] Document Box FFI guarantee in 1.41.0 release notes Fixes #68676 --- RELEASES.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/RELEASES.md b/RELEASES.md index 59d04d4ba769b..c19b8c01ce91a 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -2588,6 +2588,11 @@ Language - [Visibility modifiers (e.g. `pub`) are now syntactically allowed on trait items and enum variants.][66183] These are still rejected semantically, but can be seen and parsed by procedural macros and conditional compilation. +- [You can now define a Rust `extern "C"` function with `Box` and use `T*` as the corresponding + type on the C side.][62514] Please see [the documentation][box-memory-layout] for more information, + including the important caveat about preferring to avoid `Box` in Rust signatures for functions defined in C. + +[box-memory-layout]: https://doc.rust-lang.org/std/boxed/index.html#memory-layout Compiler -------- @@ -2662,6 +2667,7 @@ Compatibility Notes [54733]: https://github.com/rust-lang/rust/pull/54733/ [61351]: https://github.com/rust-lang/rust/pull/61351/ +[62514]: https://github.com/rust-lang/rust/pull/62514/ [67255]: https://github.com/rust-lang/rust/pull/67255/ [66661]: https://github.com/rust-lang/rust/pull/66661/ [66771]: https://github.com/rust-lang/rust/pull/66771/ From c91ad5d0f251eb412e4db89fd929117ee970ea89 Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Sun, 9 Jan 2022 14:08:08 -0800 Subject: [PATCH 12/17] Improve documentation for File::options to give a more likely example `File::options().read(true).open(...)` is equivalent to just `File::open`. Change the example to set the `append` flag instead, and then change the filename to something more likely to be written in append mode. --- library/std/src/fs.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/library/std/src/fs.rs b/library/std/src/fs.rs index dae85027b6c29..a00b5e1232369 100644 --- a/library/std/src/fs.rs +++ b/library/std/src/fs.rs @@ -356,9 +356,10 @@ impl File { /// open or create a file with specific options if `open()` or `create()` /// are not appropriate. /// - /// It is equivalent to `OpenOptions::new()` but allows you to write more - /// readable code. Instead of `OpenOptions::new().read(true).open("foo.txt")` - /// you can write `File::options().read(true).open("foo.txt")`. This + /// It is equivalent to `OpenOptions::new()`, but allows you to write more + /// readable code. Instead of + /// `OpenOptions::new().append(true).open("example.log")`, + /// you can write `File::options().append(true).open("example.log")`. This /// also avoids the need to import `OpenOptions`. /// /// See the [`OpenOptions::new`] function for more details. @@ -369,7 +370,7 @@ impl File { /// use std::fs::File; /// /// fn main() -> std::io::Result<()> { - /// let mut f = File::options().read(true).open("foo.txt")?; + /// let mut f = File::options().append(true).open("example.log")?; /// Ok(()) /// } /// ``` From 11bea2681cc1a191879ea6f93c8fe433a262503b Mon Sep 17 00:00:00 2001 From: Yacin Tmimi Date: Mon, 10 Jan 2022 21:48:22 -0500 Subject: [PATCH 13/17] Update AsmArgs field visibility for rustfmt To more easily allow rustfmt to format the asm! macro as specified in rust-dev-tools/fmt-rfcs#152 certain fields are made public. --- compiler/rustc_builtin_macros/src/asm.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/compiler/rustc_builtin_macros/src/asm.rs b/compiler/rustc_builtin_macros/src/asm.rs index 1a93b9be99ead..caf8ac77df187 100644 --- a/compiler/rustc_builtin_macros/src/asm.rs +++ b/compiler/rustc_builtin_macros/src/asm.rs @@ -16,13 +16,13 @@ use rustc_target::asm::InlineAsmArch; use smallvec::smallvec; pub struct AsmArgs { - templates: Vec>, - operands: Vec<(ast::InlineAsmOperand, Span)>, + pub templates: Vec>, + pub operands: Vec<(ast::InlineAsmOperand, Span)>, named_args: FxHashMap, reg_args: FxHashSet, - clobber_abis: Vec<(Symbol, Span)>, + pub clobber_abis: Vec<(Symbol, Span)>, options: ast::InlineAsmOptions, - options_spans: Vec, + pub options_spans: Vec, } fn parse_args<'a>( From 22d4e97d6d9c038635f39c5f874a45ee33c1e9cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Tue, 11 Jan 2022 07:20:40 +0200 Subject: [PATCH 14/17] :arrow_up: rust-analyzer --- src/tools/rust-analyzer | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/rust-analyzer b/src/tools/rust-analyzer index 8e9ccbf97a702..0f8c96c92689a 160000 --- a/src/tools/rust-analyzer +++ b/src/tools/rust-analyzer @@ -1 +1 @@ -Subproject commit 8e9ccbf97a70259b6c6576e8fd7d77d28238737e +Subproject commit 0f8c96c92689af8378dbe9f466c6bf15a3a27458 From 9234c0fd5203f551e60ba9dfe54179aec501c986 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 11 Jan 2022 13:42:20 +0100 Subject: [PATCH 15/17] Fix style for rust logo --- src/librustdoc/html/static/css/themes/ayu.css | 2 +- src/librustdoc/html/static/css/themes/dark.css | 2 +- src/librustdoc/html/static/css/themes/light.css | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/librustdoc/html/static/css/themes/ayu.css b/src/librustdoc/html/static/css/themes/ayu.css index 6ed7845e83a35..13b07eb7995b8 100644 --- a/src/librustdoc/html/static/css/themes/ayu.css +++ b/src/librustdoc/html/static/css/themes/ayu.css @@ -61,7 +61,7 @@ pre, .rustdoc.source .example-wrap { background-color: #14191f; } -.rust-logo > img { +.rust-logo { filter: drop-shadow(1px 0 0px #fff) drop-shadow(0 1px 0 #fff) drop-shadow(-1px 0 0 #fff) diff --git a/src/librustdoc/html/static/css/themes/dark.css b/src/librustdoc/html/static/css/themes/dark.css index 64b6eb6696b83..f1ea2d7dd69a6 100644 --- a/src/librustdoc/html/static/css/themes/dark.css +++ b/src/librustdoc/html/static/css/themes/dark.css @@ -32,7 +32,7 @@ pre, .rustdoc.source .example-wrap { background-color: #505050; } -.rust-logo > img { +.rust-logo { filter: drop-shadow(1px 0 0px #fff) drop-shadow(0 1px 0 #fff) drop-shadow(-1px 0 0 #fff) diff --git a/src/librustdoc/html/static/css/themes/light.css b/src/librustdoc/html/static/css/themes/light.css index dbacc9f30735b..cb4ceddd1f7ae 100644 --- a/src/librustdoc/html/static/css/themes/light.css +++ b/src/librustdoc/html/static/css/themes/light.css @@ -43,7 +43,7 @@ pre, .rustdoc.source .example-wrap { scrollbar-color: rgba(36, 37, 39, 0.6) #d9d9d9; } -.rust-logo > img { +.rust-logo { /* No need for a border in here! */ } From 24c6e963d038c586458dac287b143ac29c1b6053 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 11 Jan 2022 13:57:17 +0100 Subject: [PATCH 16/17] Add GUI test for rust logo style in the sidebars --- src/test/rustdoc-gui/rust-logo.goml | 78 +++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 src/test/rustdoc-gui/rust-logo.goml diff --git a/src/test/rustdoc-gui/rust-logo.goml b/src/test/rustdoc-gui/rust-logo.goml new file mode 100644 index 0000000000000..4a9dcf735065f --- /dev/null +++ b/src/test/rustdoc-gui/rust-logo.goml @@ -0,0 +1,78 @@ +// This test ensures that the correct style is applied to the rust logo in the sidebar. +goto: file://|DOC_PATH|/test_docs/index.html + +// First we start with the dark theme. +local-storage: { + "rustdoc-theme": "dark", + "rustdoc-preferred-dark-theme": "dark", + "rustdoc-use-system-theme": "false", +} +reload: + +assert-css: ( + ".rust-logo", + {"filter": "drop-shadow(rgb(255, 255, 255) 1px 0px 0px) drop-shadow(rgb(255, 255, 255) 0px 1px 0px) drop-shadow(rgb(255, 255, 255) -1px 0px 0px) drop-shadow(rgb(255, 255, 255) 0px -1px 0px)"}, +) + +// In the source view page now. +goto: file://|DOC_PATH|/src/test_docs/lib.rs.html + +local-storage: { + "rustdoc-theme": "dark", + "rustdoc-preferred-dark-theme": "dark", + "rustdoc-use-system-theme": "false", +} +reload: + +assert-css: ( + ".rust-logo", + {"filter": "drop-shadow(rgb(255, 255, 255) 1px 0px 0px) drop-shadow(rgb(255, 255, 255) 0px 1px 0px) drop-shadow(rgb(255, 255, 255) -1px 0px 0px) drop-shadow(rgb(255, 255, 255) 0px -1px 0px)"}, +) + +// Then with the ayu theme. +local-storage: { + "rustdoc-theme": "ayu", + "rustdoc-preferred-dark-theme": "ayu", + "rustdoc-use-system-theme": "false", +} +reload: + +assert-css: ( + ".rust-logo", + {"filter": "drop-shadow(rgb(255, 255, 255) 1px 0px 0px) drop-shadow(rgb(255, 255, 255) 0px 1px 0px) drop-shadow(rgb(255, 255, 255) -1px 0px 0px) drop-shadow(rgb(255, 255, 255) 0px -1px 0px)"}, +) + +// In the source view page now. +goto: file://|DOC_PATH|/src/test_docs/lib.rs.html + +local-storage: { + "rustdoc-theme": "ayu", + "rustdoc-preferred-dark-theme": "ayu", + "rustdoc-use-system-theme": "false", +} +reload: + +assert-css: ( + ".rust-logo", + {"filter": "drop-shadow(rgb(255, 255, 255) 1px 0px 0px) drop-shadow(rgb(255, 255, 255) 0px 1px 0px) drop-shadow(rgb(255, 255, 255) -1px 0px 0px) drop-shadow(rgb(255, 255, 255) 0px -1px 0px)"}, +) + +// And finally with the light theme. +local-storage: {"rustdoc-theme": "light", "rustdoc-use-system-theme": "false"} +reload: + +assert-css: ( + ".rust-logo", + {"filter": "none"}, +) + +// In the source view page now. +goto: file://|DOC_PATH|/src/test_docs/lib.rs.html + +local-storage: {"rustdoc-theme": "light", "rustdoc-use-system-theme": "false"} +reload: + +assert-css: ( + ".rust-logo", + {"filter": "none"}, +) From bf5130b502d3d1c61465c8deded65a1cb3929fbd Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Tue, 11 Jan 2022 23:52:24 +0800 Subject: [PATCH 17/17] Add test --- ...efault-method-body-is-const-same-trait-ck.rs | 17 +++++++++++++++++ ...lt-method-body-is-const-same-trait-ck.stderr | 9 +++++++++ 2 files changed, 26 insertions(+) create mode 100644 src/test/ui/rfc-2632-const-trait-impl/default-method-body-is-const-same-trait-ck.rs create mode 100644 src/test/ui/rfc-2632-const-trait-impl/default-method-body-is-const-same-trait-ck.stderr diff --git a/src/test/ui/rfc-2632-const-trait-impl/default-method-body-is-const-same-trait-ck.rs b/src/test/ui/rfc-2632-const-trait-impl/default-method-body-is-const-same-trait-ck.rs new file mode 100644 index 0000000000000..cccb856c2f675 --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/default-method-body-is-const-same-trait-ck.rs @@ -0,0 +1,17 @@ +#![feature(const_fn_trait_bound)] +#![feature(const_trait_impl)] + +pub trait Tr { + #[default_method_body_is_const] + fn a(&self) {} + + #[default_method_body_is_const] + fn b(&self) { + ().a() + //~^ ERROR calls in constant functions are limited + } +} + +impl Tr for () {} + +fn main() {} diff --git a/src/test/ui/rfc-2632-const-trait-impl/default-method-body-is-const-same-trait-ck.stderr b/src/test/ui/rfc-2632-const-trait-impl/default-method-body-is-const-same-trait-ck.stderr new file mode 100644 index 0000000000000..91f4d2fd4b0e8 --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/default-method-body-is-const-same-trait-ck.stderr @@ -0,0 +1,9 @@ +error[E0015]: calls in constant functions are limited to constant functions, tuple structs and tuple variants + --> $DIR/default-method-body-is-const-same-trait-ck.rs:10:9 + | +LL | ().a() + | ^^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0015`.