From f3f6891be2cc84d0ca15ba02a3d564b9d53805cc Mon Sep 17 00:00:00 2001 From: avborhanian Date: Fri, 7 Jan 2022 01:29:20 -0800 Subject: [PATCH 1/5] Update location from a relative path to absolute --- src/doc/not_found.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/not_found.md b/src/doc/not_found.md index d26fcfc0168d7..f0794fc0be378 100644 --- a/src/doc/not_found.md +++ b/src/doc/not_found.md @@ -84,7 +84,7 @@ function on_submit(event) { if (form['from'].value === 'duckduckgo') { document.location.href = form.action + '?q=' + encodeURIComponent(q + ' site:doc.rust-lang.org'); } else if (form['from'].value === 'library') { - document.location.href = 'std/index.html?search=' + encodeURIComponent(q); + document.location.href = '/std/index.html?search=' + encodeURIComponent(q); } } From 51dacc572fb4da8ed48c3d8e145f99a5202c16e3 Mon Sep 17 00:00:00 2001 From: Leo Simons Date: Fri, 28 Jan 2022 09:08:12 +0100 Subject: [PATCH 2/5] Fix broken link from rustdoc docs to ayu theme --- src/doc/rustdoc/src/what-to-include.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/rustdoc/src/what-to-include.md b/src/doc/rustdoc/src/what-to-include.md index 9683f519be121..2a6b62ebfd552 100644 --- a/src/doc/rustdoc/src/what-to-include.md +++ b/src/doc/rustdoc/src/what-to-include.md @@ -118,7 +118,7 @@ rustdoc --theme awesome.css src/lib.rs Here is an example of a new theme, [Ayu]. -[Ayu]: https://github.com/rust-lang/rust/blob/master/src/librustdoc/html/static/themes/ayu.css +[Ayu]: https://github.com/rust-lang/rust/blob/master/src/librustdoc/html/static/css/themes/ayu.css [API Guidelines]: https://rust-lang.github.io/api-guidelines/documentation.html#rustdoc-does-not-show-unhelpful-implementation-details-c-hidden [Documentation tests]: documentation-tests.md [on this blog]: https://blog.guillaume-gomez.fr/articles/2016-09-16+Generating+doc+with+rustdoc+and+a+custom+theme From 91183933340a7ba87267ff97e291950fe77c39a1 Mon Sep 17 00:00:00 2001 From: cameron Date: Mon, 31 Jan 2022 16:56:10 +0000 Subject: [PATCH 3/5] regression test for issue 90847 --- .../ui/const-generics/generic_const_exprs/issue-90847.rs | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 src/test/ui/const-generics/generic_const_exprs/issue-90847.rs diff --git a/src/test/ui/const-generics/generic_const_exprs/issue-90847.rs b/src/test/ui/const-generics/generic_const_exprs/issue-90847.rs new file mode 100644 index 0000000000000..ebc6fe1412320 --- /dev/null +++ b/src/test/ui/const-generics/generic_const_exprs/issue-90847.rs @@ -0,0 +1,9 @@ +// check-pass + +#![allow(incomplete_features)] +#![feature(generic_const_exprs)] +#![feature(adt_const_params)] + +struct Foo where [(); 0 + 0]: Sized; + +fn main() {} From c35a1d40286ea806fb2225e3a6db852ba8dd71e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Miku=C5=82a?= Date: Fri, 25 Feb 2022 17:41:00 +0100 Subject: [PATCH 4/5] Fix MinGW target detection in raw-dylib LLVM target doesn't have to be the same as Rust target so relying on it is wrong. --- compiler/rustc_codegen_llvm/src/back/archive.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_codegen_llvm/src/back/archive.rs b/compiler/rustc_codegen_llvm/src/back/archive.rs index 1a2cec2a0d97f..f814cc9304331 100644 --- a/compiler/rustc_codegen_llvm/src/back/archive.rs +++ b/compiler/rustc_codegen_llvm/src/back/archive.rs @@ -151,7 +151,9 @@ impl<'a> ArchiveBuilder<'a> for LlvmArchiveBuilder<'a> { output_path.with_extension("lib") }; - let mingw_gnu_toolchain = self.config.sess.target.llvm_target.ends_with("pc-windows-gnu"); + let target = &self.config.sess.target; + let mingw_gnu_toolchain = + target.vendor == "pc" && target.os == "windows" && target.env == "gnu"; let import_name_and_ordinal_vector: Vec<(String, Option)> = dll_imports .iter() From aac0281d30e3bf276422d215237c243047e5998b Mon Sep 17 00:00:00 2001 From: Ibraheem Ahmed Date: Mon, 11 Oct 2021 17:41:25 -0400 Subject: [PATCH 5/5] add `slice::{from_ptr_range, from_mut_ptr_range}` --- library/core/src/slice/mod.rs | 3 + library/core/src/slice/raw.rs | 111 ++++++++++++++++++++++++++++++++++ library/core/tests/lib.rs | 1 + library/core/tests/slice.rs | 22 +++++++ 4 files changed, 137 insertions(+) diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs index cd38c3a75473d..7d64a88cec67a 100644 --- a/library/core/src/slice/mod.rs +++ b/library/core/src/slice/mod.rs @@ -71,6 +71,9 @@ pub use raw::{from_raw_parts, from_raw_parts_mut}; #[stable(feature = "from_ref", since = "1.28.0")] pub use raw::{from_mut, from_ref}; +#[unstable(feature = "slice_from_ptr_range", issue = "89792")] +pub use raw::{from_mut_ptr_range, from_ptr_range}; + // This function is public only because there is no other way to unit test heapsort. #[unstable(feature = "sort_internals", reason = "internal to sort module", issue = "none")] pub use sort::heapsort; diff --git a/library/core/src/slice/raw.rs b/library/core/src/slice/raw.rs index e797283818481..39c8d68e4bf34 100644 --- a/library/core/src/slice/raw.rs +++ b/library/core/src/slice/raw.rs @@ -1,6 +1,7 @@ //! Free functions to create `&[T]` and `&mut [T]`. use crate::array; +use crate::ops::Range; use crate::ptr; /// Forms a slice from a pointer and a length. @@ -177,3 +178,113 @@ pub const fn from_ref(s: &T) -> &[T] { pub const fn from_mut(s: &mut T) -> &mut [T] { array::from_mut(s) } + +/// Forms a slice from a pointer range. +/// +/// This function is useful for interacting with foreign interfaces which +/// use two pointers to refer to a range of elements in memory, as is +/// common in C++. +/// +/// # Safety +/// +/// Behavior is undefined if any of the following conditions are violated: +/// +/// * The `start` pointer of the range must be a [valid] and properly aligned pointer +/// to the first element of a slice. +/// +/// * The `end` pointer must be a [valid] and properly aligned pointer to *one past* +/// the last element, such that the offset from the end to the start pointer is +/// the length of the slice. +/// +/// * The range must contain `N` consecutive properly initialized values of type `T`: +/// +/// * The entire memory range of this slice must be contained within a single allocated object! +/// Slices can never span across multiple allocated objects. +/// +/// * The memory referenced by the returned slice must not be mutated for the duration +/// of lifetime `'a`, except inside an `UnsafeCell`. +/// +/// * The total length of the range must be no larger than `isize::MAX`. +/// See the safety documentation of [`pointer::offset`]. +/// +/// Note that a range created from [`slice::as_ptr_range`] fulfills these requirements. +/// +/// # Caveat +/// +/// The lifetime for the returned slice is inferred from its usage. To +/// prevent accidental misuse, it's suggested to tie the lifetime to whichever +/// source lifetime is safe in the context, such as by providing a helper +/// function taking the lifetime of a host value for the slice, or by explicit +/// annotation. +/// +/// # Examples +/// +/// ``` +/// #![feature(slice_from_ptr_range)] +/// +/// use core::slice; +/// +/// let x = [1, 2, 3]; +/// let range = x.as_ptr_range(); +/// +/// unsafe { +/// assert_eq!(slice::from_ptr_range(range), &x); +/// } +/// ``` +/// +/// [valid]: ptr#safety +#[unstable(feature = "slice_from_ptr_range", issue = "89792")] +pub unsafe fn from_ptr_range<'a, T>(range: Range<*const T>) -> &'a [T] { + // SAFETY: the caller must uphold the safety contract for `from_ptr_range`. + unsafe { from_raw_parts(range.start, range.end.offset_from(range.start) as usize) } +} + +/// Performs the same functionality as [`from_ptr_range`], except that a +/// mutable slice is returned. +/// +/// # Safety +/// +/// Behavior is undefined if any of the following conditions are violated: +/// +/// * The `start` pointer of the range must be a [valid] and properly aligned pointer +/// to the first element of a slice. +/// +/// * The `end` pointer must be a [valid] and properly aligned pointer to *one past* +/// the last element, such that the offset from the end to the start pointer is +/// the length of the slice. +/// +/// * The range must contain `N` consecutive properly initialized values of type `T`: +/// +/// * The entire memory range of this slice must be contained within a single allocated object! +/// Slices can never span across multiple allocated objects. +/// +/// * The memory referenced by the returned slice must not be accessed through any other pointer +/// (not derived from the return value) for the duration of lifetime `'a`. +/// Both read and write accesses are forbidden. +/// +/// * The total length of the range must be no larger than `isize::MAX`. +/// See the safety documentation of [`pointer::offset`]. +/// +/// Note that a range created from [`slice::as_mut_ptr_range`] fulfills these requirements. +/// +/// # Examples +/// +/// ``` +/// #![feature(slice_from_ptr_range)] +/// +/// use core::slice; +/// +/// let mut x = [1, 2, 3]; +/// let range = x.as_mut_ptr_range(); +/// +/// unsafe { +/// assert_eq!(slice::from_mut_ptr_range(range), &mut [1, 2, 3]); +/// } +/// ``` +/// +/// [valid]: ptr#safety +#[unstable(feature = "slice_from_ptr_range", issue = "89792")] +pub unsafe fn from_mut_ptr_range<'a, T>(range: Range<*mut T>) -> &'a mut [T] { + // SAFETY: the caller must uphold the safety contract for `from_mut_ptr_range`. + unsafe { from_raw_parts_mut(range.start, range.end.offset_from(range.start) as usize) } +} diff --git a/library/core/tests/lib.rs b/library/core/tests/lib.rs index 06c7be054a038..fb59bc2596f76 100644 --- a/library/core/tests/lib.rs +++ b/library/core/tests/lib.rs @@ -48,6 +48,7 @@ #![feature(pin_macro)] #![feature(sort_internals)] #![feature(slice_take)] +#![feature(slice_from_ptr_range)] #![feature(maybe_uninit_uninit_array)] #![feature(maybe_uninit_array_assume_init)] #![feature(maybe_uninit_write_slice)] diff --git a/library/core/tests/slice.rs b/library/core/tests/slice.rs index 88cbd7352a214..06a30d7096c77 100644 --- a/library/core/tests/slice.rs +++ b/library/core/tests/slice.rs @@ -2,6 +2,7 @@ use core::cell::Cell; use core::cmp::Ordering; use core::mem::MaybeUninit; use core::result::Result::{Err, Ok}; +use core::slice; #[test] fn test_position() { @@ -2480,3 +2481,24 @@ take_tests! { (take_mut_oob_max_range_to_inclusive, (..=usize::MAX), None, empty_max_mut!()), (take_mut_in_bounds_max_range_from, (usize::MAX..), Some(&mut [] as _), empty_max_mut!()), } + +#[test] +fn test_slice_from_ptr_range() { + let arr = ["foo".to_owned(), "bar".to_owned()]; + let range = arr.as_ptr_range(); + unsafe { + assert_eq!(slice::from_ptr_range(range), &arr); + } + + let mut arr = [1, 2, 3]; + let range = arr.as_mut_ptr_range(); + unsafe { + assert_eq!(slice::from_mut_ptr_range(range), &mut [1, 2, 3]); + } + + let arr: [Vec; 0] = []; + let range = arr.as_ptr_range(); + unsafe { + assert_eq!(slice::from_ptr_range(range), &arr); + } +}