Skip to content

Commit

Permalink
Auto merge of rust-lang#127454 - matthiaskrgr:rollup-k3vfen2, r=matth…
Browse files Browse the repository at this point in the history
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#127179 (Print `TypeId` as hex for debugging)
 - rust-lang#127189 (LinkedList's Cursor: method to get a ref to the cursor's list)
 - rust-lang#127236 (doc: update config file path in platform-support/wasm32-wasip1-threads.md)
 - rust-lang#127297 (Improve std::Path's Hash quality by avoiding prefix collisions)
 - rust-lang#127308 (Attribute cleanups)
 - rust-lang#127354 (Describe Sized requirements for mem::offset_of)
 - rust-lang#127409 (Emit a wrap expr span_bug only if context is not tainted)
 - rust-lang#127447 (once_lock: make test not take as long in Miri)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Jul 7, 2024
2 parents a86fd0f + 35c5a45 commit c6b3f3d
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 11 deletions.
20 changes: 20 additions & 0 deletions alloc/src/collections/linked_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1495,6 +1495,14 @@ impl<'a, T, A: Allocator> Cursor<'a, T, A> {
pub fn back(&self) -> Option<&'a T> {
self.list.back()
}

/// Provides a reference to the cursor's parent list.
#[must_use]
#[inline(always)]
#[unstable(feature = "linked_list_cursors", issue = "58533")]
pub fn as_list(&self) -> &'a LinkedList<T, A> {
self.list
}
}

impl<'a, T, A: Allocator> CursorMut<'a, T, A> {
Expand Down Expand Up @@ -1605,6 +1613,18 @@ impl<'a, T, A: Allocator> CursorMut<'a, T, A> {
pub fn as_cursor(&self) -> Cursor<'_, T, A> {
Cursor { list: self.list, current: self.current, index: self.index }
}

/// Provides a read-only reference to the cursor's parent list.
///
/// The lifetime of the returned reference is bound to that of the
/// `CursorMut`, which means it cannot outlive the `CursorMut` and that the
/// `CursorMut` is frozen for the lifetime of the reference.
#[must_use]
#[inline(always)]
#[unstable(feature = "linked_list_cursors", issue = "58533")]
pub fn as_list(&self) -> &LinkedList<T, A> {
self.list
}
}

// Now the list editing operations
Expand Down
2 changes: 1 addition & 1 deletion core/src/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ impl hash::Hash for TypeId {
#[stable(feature = "rust1", since = "1.0.0")]
impl fmt::Debug for TypeId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
f.debug_tuple("TypeId").field(&self.as_u128()).finish()
write!(f, "TypeId({:#034x})", self.as_u128())
}
}

Expand Down
14 changes: 14 additions & 0 deletions core/src/mem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1266,6 +1266,20 @@ impl<T> SizedTypeProperties for T {}
/// // ^^^ error[E0616]: field `private` of struct `Struct` is private
/// ```
///
/// Only [`Sized`] fields are supported, but the container may be unsized:
/// ```
/// # use core::mem;
/// #[repr(C)]
/// pub struct Struct {
/// a: u8,
/// b: [u8],
/// }
///
/// assert_eq!(mem::offset_of!(Struct, a), 0); // OK
/// // assert_eq!(mem::offset_of!(Struct, b), 1);
/// // ^^^ error[E0277]: doesn't have a size known at compile-time
/// ```
///
/// Note that type layout is, in general, [subject to change and
/// platform-specific](https://doc.rust-lang.org/reference/type-layout.html). If
/// layout stability is required, consider using an [explicit `repr` attribute].
Expand Down
13 changes: 9 additions & 4 deletions std/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3192,15 +3192,19 @@ impl Hash for Path {
let bytes = &bytes[prefix_len..];

let mut component_start = 0;
let mut bytes_hashed = 0;
// track some extra state to avoid prefix collisions.
// ["foo", "bar"] and ["foobar"], will have the same payload bytes
// but result in different chunk_bits
let mut chunk_bits: usize = 0;

for i in 0..bytes.len() {
let is_sep = if verbatim { is_verbatim_sep(bytes[i]) } else { is_sep_byte(bytes[i]) };
if is_sep {
if i > component_start {
let to_hash = &bytes[component_start..i];
chunk_bits = chunk_bits.wrapping_add(to_hash.len());
chunk_bits = chunk_bits.rotate_right(2);
h.write(to_hash);
bytes_hashed += to_hash.len();
}

// skip over separator and optionally a following CurDir item
Expand All @@ -3221,11 +3225,12 @@ impl Hash for Path {

if component_start < bytes.len() {
let to_hash = &bytes[component_start..];
chunk_bits = chunk_bits.wrapping_add(to_hash.len());
chunk_bits = chunk_bits.rotate_right(2);
h.write(to_hash);
bytes_hashed += to_hash.len();
}

h.write_usize(bytes_hashed);
h.write_usize(chunk_bits);
}
}

Expand Down
35 changes: 35 additions & 0 deletions std/src/path/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1619,6 +1619,20 @@ pub fn test_compare() {
relative_from: Some("")
);

tc!("foo//", "foo",
eq: true,
starts_with: true,
ends_with: true,
relative_from: Some("")
);

tc!("foo///", "foo",
eq: true,
starts_with: true,
ends_with: true,
relative_from: Some("")
);

tc!("foo/.", "foo",
eq: true,
starts_with: true,
Expand All @@ -1633,13 +1647,34 @@ pub fn test_compare() {
relative_from: Some("")
);

tc!("foo/.//bar", "foo/bar",
eq: true,
starts_with: true,
ends_with: true,
relative_from: Some("")
);

tc!("foo//./bar", "foo/bar",
eq: true,
starts_with: true,
ends_with: true,
relative_from: Some("")
);

tc!("foo/bar", "foo",
eq: false,
starts_with: true,
ends_with: false,
relative_from: Some("bar")
);

tc!("foo/bar", "foobar",
eq: false,
starts_with: false,
ends_with: false,
relative_from: None
);

tc!("foo/bar/baz", "foo/bar",
eq: false,
starts_with: true,
Expand Down
19 changes: 13 additions & 6 deletions std/src/sync/once_lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,21 @@ use crate::sync::Once;
/// static LIST: OnceList<u32> = OnceList::new();
/// static COUNTER: AtomicU32 = AtomicU32::new(0);
///
/// let vec = (0..thread::available_parallelism().unwrap().get()).map(|_| thread::spawn(|| {
/// while let i @ 0..=1000 = COUNTER.fetch_add(1, Ordering::Relaxed) {
/// LIST.push(i);
/// # const LEN: u32 = if cfg!(miri) { 50 } else { 1000 };
/// # /*
/// const LEN: u32 = 1000;
/// # */
/// thread::scope(|s| {
/// for _ in 0..thread::available_parallelism().unwrap().get() {
/// s.spawn(|| {
/// while let i @ 0..LEN = COUNTER.fetch_add(1, Ordering::Relaxed) {
/// LIST.push(i);
/// }
/// });
/// }
/// })).collect::<Vec<thread::JoinHandle<_>>>();
/// vec.into_iter().for_each(|handle| handle.join().unwrap());
/// });
///
/// for i in 0..=1000 {
/// for i in 0..LEN {
/// assert!(LIST.contains(&i));
/// }
///
Expand Down

0 comments on commit c6b3f3d

Please sign in to comment.