1
Fork 0

Use &raw in the compiler

Like #130865 did for the standard library, we can use `&raw` in the
compiler now that stage0 supports it. Also like the other issue, I did
not make any doc or test changes at this time.
This commit is contained in:
Josh Stone 2024-09-26 20:33:26 -07:00
parent 58420a065b
commit 4160a54dc5
7 changed files with 13 additions and 13 deletions

View file

@ -123,7 +123,7 @@ fn get_llvm_object_symbols(
llvm::LLVMRustGetSymbols( llvm::LLVMRustGetSymbols(
buf.as_ptr(), buf.as_ptr(),
buf.len(), buf.len(),
std::ptr::addr_of_mut!(*state) as *mut c_void, (&raw mut *state) as *mut c_void,
callback, callback,
error_callback, error_callback,
) )

View file

@ -167,7 +167,7 @@ impl WriteBackendMethods for LlvmCodegenBackend {
fn print_pass_timings(&self) { fn print_pass_timings(&self) {
unsafe { unsafe {
let mut size = 0; let mut size = 0;
let cstr = llvm::LLVMRustPrintPassTimings(std::ptr::addr_of_mut!(size)); let cstr = llvm::LLVMRustPrintPassTimings(&raw mut size);
if cstr.is_null() { if cstr.is_null() {
println!("failed to get pass timings"); println!("failed to get pass timings");
} else { } else {
@ -180,7 +180,7 @@ impl WriteBackendMethods for LlvmCodegenBackend {
fn print_statistics(&self) { fn print_statistics(&self) {
unsafe { unsafe {
let mut size = 0; let mut size = 0;
let cstr = llvm::LLVMRustPrintStatistics(std::ptr::addr_of_mut!(size)); let cstr = llvm::LLVMRustPrintStatistics(&raw mut size);
if cstr.is_null() { if cstr.is_null() {
println!("failed to get pass stats"); println!("failed to get pass stats");
} else { } else {

View file

@ -478,7 +478,7 @@ pub(crate) fn print(req: &PrintRequest, mut out: &mut String, sess: &Session) {
&tm, &tm,
cpu_cstring.as_ptr(), cpu_cstring.as_ptr(),
callback, callback,
std::ptr::addr_of_mut!(out) as *mut c_void, (&raw mut out) as *mut c_void,
); );
} }
} }

View file

@ -437,7 +437,7 @@ impl<T> RwLock<T> {
#[inline(always)] #[inline(always)]
pub fn leak(&self) -> &T { pub fn leak(&self) -> &T {
let guard = self.read(); let guard = self.read();
let ret = unsafe { &*std::ptr::addr_of!(*guard) }; let ret = unsafe { &*(&raw const *guard) };
std::mem::forget(guard); std::mem::forget(guard);
ret ret
} }

View file

@ -233,7 +233,7 @@ impl<'sess> OnDiskCache<'sess> {
for (index, file) in files.iter().enumerate() { for (index, file) in files.iter().enumerate() {
let index = SourceFileIndex(index as u32); let index = SourceFileIndex(index as u32);
let file_ptr: *const SourceFile = std::ptr::addr_of!(**file); let file_ptr: *const SourceFile = &raw const **file;
file_to_file_index.insert(file_ptr, index); file_to_file_index.insert(file_ptr, index);
let source_file_id = EncodedSourceFileId::new(tcx, file); let source_file_id = EncodedSourceFileId::new(tcx, file);
file_index_to_stable_id.insert(index, source_file_id); file_index_to_stable_id.insert(index, source_file_id);
@ -827,7 +827,7 @@ pub struct CacheEncoder<'a, 'tcx> {
impl<'a, 'tcx> CacheEncoder<'a, 'tcx> { impl<'a, 'tcx> CacheEncoder<'a, 'tcx> {
#[inline] #[inline]
fn source_file_index(&mut self, source_file: Lrc<SourceFile>) -> SourceFileIndex { fn source_file_index(&mut self, source_file: Lrc<SourceFile>) -> SourceFileIndex {
self.file_to_file_index[&std::ptr::addr_of!(*source_file)] self.file_to_file_index[&(&raw const *source_file)]
} }
/// Encode something with additional information that allows to do some /// Encode something with additional information that allows to do some

View file

@ -103,13 +103,13 @@ impl<H, T> RawList<H, T> {
let mem = arena.dropless.alloc_raw(layout) as *mut RawList<H, T>; let mem = arena.dropless.alloc_raw(layout) as *mut RawList<H, T>;
unsafe { unsafe {
// Write the header // Write the header
ptr::addr_of_mut!((*mem).skel.header).write(header); (&raw mut (*mem).skel.header).write(header);
// Write the length // Write the length
ptr::addr_of_mut!((*mem).skel.len).write(slice.len()); (&raw mut (*mem).skel.len).write(slice.len());
// Write the elements // Write the elements
ptr::addr_of_mut!((*mem).skel.data) (&raw mut (*mem).skel.data)
.cast::<T>() .cast::<T>()
.copy_from_nonoverlapping(slice.as_ptr(), slice.len()); .copy_from_nonoverlapping(slice.as_ptr(), slice.len());
@ -160,7 +160,7 @@ macro_rules! impl_list_empty {
// SAFETY: `EMPTY` is sufficiently aligned to be an empty list for all // SAFETY: `EMPTY` is sufficiently aligned to be an empty list for all
// types with `align_of(T) <= align_of(MaxAlign)`, which we checked above. // types with `align_of(T) <= align_of(MaxAlign)`, which we checked above.
unsafe { &*(std::ptr::addr_of!(EMPTY) as *const RawList<$header_ty, T>) } unsafe { &*((&raw const EMPTY) as *const RawList<$header_ty, T>) }
} }
} }
}; };
@ -238,7 +238,7 @@ impl<H, T> Deref for RawList<H, T> {
impl<H, T> AsRef<[T]> for RawList<H, T> { impl<H, T> AsRef<[T]> for RawList<H, T> {
#[inline(always)] #[inline(always)]
fn as_ref(&self) -> &[T] { fn as_ref(&self) -> &[T] {
let data_ptr = ptr::addr_of!(self.skel.data).cast::<T>(); let data_ptr = (&raw const self.skel.data).cast::<T>();
// SAFETY: `data_ptr` has the same provenance as `self` and can therefore // SAFETY: `data_ptr` has the same provenance as `self` and can therefore
// access the `self.skel.len` elements stored at `self.skel.data`. // access the `self.skel.len` elements stored at `self.skel.data`.
// Note that we specifically don't reborrow `&self.skel.data`, because that // Note that we specifically don't reborrow `&self.skel.data`, because that

View file

@ -255,7 +255,7 @@ where
if TLV.is_set() { if TLV.is_set() {
Err(Error::from("StableMIR already running")) Err(Error::from("StableMIR already running"))
} else { } else {
let ptr: *const () = std::ptr::addr_of!(context) as _; let ptr: *const () = (&raw const context) as _;
TLV.set(&Cell::new(ptr), || Ok(f())) TLV.set(&Cell::new(ptr), || Ok(f()))
} }
} }