Skip to content

Commit 613cb32

Browse files
committed
compiler: use addr_of!
1 parent ff187a9 commit 613cb32

File tree

7 files changed

+9
-9
lines changed

7 files changed

+9
-9
lines changed

compiler/rustc_codegen_llvm/src/back/archive.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ fn get_llvm_object_symbols(
313313
llvm::LLVMRustGetSymbols(
314314
buf.as_ptr(),
315315
buf.len(),
316-
&mut *state as *mut &mut _ as *mut c_void,
316+
std::ptr::addr_of_mut!(*state) as *mut c_void,
317317
callback,
318318
error_callback,
319319
)

compiler/rustc_codegen_llvm/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ impl WriteBackendMethods for LlvmCodegenBackend {
169169
fn print_pass_timings(&self) {
170170
unsafe {
171171
let mut size = 0;
172-
let cstr = llvm::LLVMRustPrintPassTimings(&mut size as *mut usize);
172+
let cstr = llvm::LLVMRustPrintPassTimings(std::ptr::addr_of_mut!(size));
173173
if cstr.is_null() {
174174
println!("failed to get pass timings");
175175
} else {
@@ -182,7 +182,7 @@ impl WriteBackendMethods for LlvmCodegenBackend {
182182
fn print_statistics(&self) {
183183
unsafe {
184184
let mut size = 0;
185-
let cstr = llvm::LLVMRustPrintStatistics(&mut size as *mut usize);
185+
let cstr = llvm::LLVMRustPrintStatistics(std::ptr::addr_of_mut!(size));
186186
if cstr.is_null() {
187187
println!("failed to get pass stats");
188188
} else {

compiler/rustc_codegen_llvm/src/llvm_util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ pub(crate) fn print(req: &PrintRequest, mut out: &mut dyn PrintBackendInfo, sess
435435
&tm,
436436
cpu_cstring.as_ptr(),
437437
callback,
438-
&mut out as *mut &mut dyn PrintBackendInfo as *mut c_void,
438+
std::ptr::addr_of_mut!(out) as *mut c_void,
439439
);
440440
}
441441
}

compiler/rustc_data_structures/src/sync.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ impl<T> RwLock<T> {
429429
#[inline(always)]
430430
pub fn leak(&self) -> &T {
431431
let guard = self.read();
432-
let ret = unsafe { &*(&*guard as *const T) };
432+
let ret = unsafe { &*std::ptr::addr_of!(*guard) };
433433
std::mem::forget(guard);
434434
ret
435435
}

compiler/rustc_middle/src/query/on_disk_cache.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ impl<'sess> OnDiskCache<'sess> {
233233

234234
for (index, file) in files.iter().enumerate() {
235235
let index = SourceFileIndex(index as u32);
236-
let file_ptr: *const SourceFile = &**file as *const _;
236+
let file_ptr: *const SourceFile = std::ptr::addr_of!(**file);
237237
file_to_file_index.insert(file_ptr, index);
238238
let source_file_id = EncodedSourceFileId::new(tcx, file);
239239
file_index_to_stable_id.insert(index, source_file_id);
@@ -835,7 +835,7 @@ pub struct CacheEncoder<'a, 'tcx> {
835835
impl<'a, 'tcx> CacheEncoder<'a, 'tcx> {
836836
#[inline]
837837
fn source_file_index(&mut self, source_file: Lrc<SourceFile>) -> SourceFileIndex {
838-
self.file_to_file_index[&(&*source_file as *const SourceFile)]
838+
self.file_to_file_index[&std::ptr::addr_of!(*source_file)]
839839
}
840840

841841
/// Encode something with additional information that allows to do some

compiler/rustc_middle/src/ty/list.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ impl<T> List<T> {
6161
// length) that is 64-byte aligned, thus featuring the necessary
6262
// trailing padding for elements with up to 64-byte alignment.
6363
static EMPTY_SLICE: InOrder<usize, MaxAlign> = InOrder(0, MaxAlign);
64-
unsafe { &*(&EMPTY_SLICE as *const _ as *const List<T>) }
64+
unsafe { &*(std::ptr::addr_of!(EMPTY_SLICE) as *const List<T>) }
6565
}
6666

6767
pub fn len(&self) -> usize {

compiler/stable_mir/src/compiler_interface.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ where
208208
if TLV.is_set() {
209209
Err(Error::from("StableMIR already running"))
210210
} else {
211-
let ptr: *const () = &context as *const &_ as _;
211+
let ptr: *const () = std::ptr::addr_of!(context) as _;
212212
TLV.set(&Cell::new(ptr), || Ok(f()))
213213
}
214214
}

0 commit comments

Comments
 (0)