From 9835e2ae736235810b4ea1c162ca5e65c547e770 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 18 May 2024 04:49:50 +0200 Subject: Merging upstream version 1.71.1+dfsg1. Signed-off-by: Daniel Baumann --- compiler/rustc_middle/src/ty/list.rs | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) (limited to 'compiler/rustc_middle/src/ty/list.rs') diff --git a/compiler/rustc_middle/src/ty/list.rs b/compiler/rustc_middle/src/ty/list.rs index 79365ef28..71911a5a6 100644 --- a/compiler/rustc_middle/src/ty/list.rs +++ b/compiler/rustc_middle/src/ty/list.rs @@ -1,4 +1,5 @@ use crate::arena::Arena; +use rustc_data_structures::aligned::{align_of, Aligned}; use rustc_serialize::{Encodable, Encoder}; use std::alloc::Layout; use std::cmp::Ordering; @@ -198,22 +199,23 @@ impl<'a, T: Copy> IntoIterator for &'a List { unsafe impl Sync for List {} -unsafe impl<'a, T: 'a> rustc_data_structures::tagged_ptr::Pointer for &'a List { - const BITS: usize = std::mem::align_of::().trailing_zeros() as usize; - - #[inline] - fn into_usize(self) -> usize { - self as *const List as usize - } - - #[inline] - unsafe fn from_usize(ptr: usize) -> &'a List { - &*(ptr as *const List) - } +// We need this since `List` uses extern type `OpaqueListContents`. +#[cfg(parallel_compiler)] +use rustc_data_structures::sync::DynSync; +#[cfg(parallel_compiler)] +unsafe impl DynSync for List {} + +// Safety: +// Layouts of `Equivalent` and `List` are the same, modulo opaque tail, +// thus aligns of `Equivalent` and `List` must be the same. +unsafe impl Aligned for List { + const ALIGN: ptr::Alignment = { + #[repr(C)] + struct Equivalent { + _len: usize, + _data: [T; 0], + } - unsafe fn with_ref R>(ptr: usize, f: F) -> R { - // `Self` is `&'a List` which impls `Copy`, so this is fine. - let ptr = Self::from_usize(ptr); - f(&ptr) - } + align_of::>() + }; } -- cgit v1.2.3