Skip to content

Commit 4160a54

Browse files
committed
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.
1 parent 58420a0 commit 4160a54

7 files changed

Lines changed: 13 additions & 13 deletions

File tree

‎compiler/rustc_codegen_llvm/src/back/archive.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ fn get_llvm_object_symbols(
123123
llvm::LLVMRustGetSymbols(
124124
buf.as_ptr(),
125125
buf.len(),
126-
std::ptr::addr_of_mut!(*state)as*mutc_void,
126+
(&rawmut*state)as*mutc_void,
127127
callback,
128128
error_callback,
129129
)

‎compiler/rustc_codegen_llvm/src/lib.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ impl WriteBackendMethods for LlvmCodegenBackend {
167167
fnprint_pass_timings(&self){
168168
unsafe{
169169
letmut size = 0;
170-
let cstr = llvm::LLVMRustPrintPassTimings(std::ptr::addr_of_mut!(size));
170+
let cstr = llvm::LLVMRustPrintPassTimings(&rawmutsize);
171171
if cstr.is_null(){
172172
println!("failed to get pass timings");
173173
}else{
@@ -180,7 +180,7 @@ impl WriteBackendMethods for LlvmCodegenBackend {
180180
fnprint_statistics(&self){
181181
unsafe{
182182
letmut size = 0;
183-
let cstr = llvm::LLVMRustPrintStatistics(std::ptr::addr_of_mut!(size));
183+
let cstr = llvm::LLVMRustPrintStatistics(&rawmutsize);
184184
if cstr.is_null(){
185185
println!("failed to get pass stats");
186186
}else{

‎compiler/rustc_codegen_llvm/src/llvm_util.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ pub(crate) fn print(req: &PrintRequest, mut out: &mut String, sess: &Session) {
478478
&tm,
479479
cpu_cstring.as_ptr(),
480480
callback,
481-
std::ptr::addr_of_mut!(out)as*mutc_void,
481+
(&rawmutout)as*mutc_void,
482482
);
483483
}
484484
}

‎compiler/rustc_data_structures/src/sync.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ impl<T> RwLock<T> {
437437
#[inline(always)]
438438
pubfnleak(&self) -> &T{
439439
let guard = self.read();
440-
let ret = unsafe{&*std::ptr::addr_of!(*guard)};
440+
let ret = unsafe{&*(&rawconst*guard)};
441441
std::mem::forget(guard);
442442
ret
443443
}

‎compiler/rustc_middle/src/query/on_disk_cache.rs‎

Lines changed: 2 additions & 2 deletions
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 asu32);
236-
let file_ptr:*constSourceFile = std::ptr::addr_of!(**file);
236+
let file_ptr:*constSourceFile = &rawconst**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);
@@ -827,7 +827,7 @@ pub struct CacheEncoder<'a, 'tcx> {
827827
impl<'a,'tcx>CacheEncoder<'a,'tcx>{
828828
#[inline]
829829
fnsource_file_index(&mutself,source_file:Lrc<SourceFile>) -> SourceFileIndex{
830-
self.file_to_file_index[&std::ptr::addr_of!(*source_file)]
830+
self.file_to_file_index[&(&rawconst*source_file)]
831831
}
832832

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

‎compiler/rustc_middle/src/ty/list.rs‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,13 @@ impl<H, T> RawList<H, T> {
103103
let mem = arena.dropless.alloc_raw(layout)as*mutRawList<H,T>;
104104
unsafe{
105105
// Write the header
106-
ptr::addr_of_mut!((*mem).skel.header).write(header);
106+
(&rawmut(*mem).skel.header).write(header);
107107

108108
// Write the length
109-
ptr::addr_of_mut!((*mem).skel.len).write(slice.len());
109+
(&rawmut(*mem).skel.len).write(slice.len());
110110

111111
// Write the elements
112-
ptr::addr_of_mut!((*mem).skel.data)
112+
(&rawmut(*mem).skel.data)
113113
.cast::<T>()
114114
.copy_from_nonoverlapping(slice.as_ptr(), slice.len());
115115

@@ -160,7 +160,7 @@ macro_rules! impl_list_empty {
160160

161161
// SAFETY: `EMPTY` is sufficiently aligned to be an empty list for all
162162
// types with `align_of(T) <= align_of(MaxAlign)`, which we checked above.
163-
unsafe{&*(std::ptr::addr_of!(EMPTY)as*constRawList<$header_ty,T>)}
163+
unsafe{&*((&raw constEMPTY)as*constRawList<$header_ty,T>)}
164164
}
165165
}
166166
};
@@ -238,7 +238,7 @@ impl<H, T> Deref for RawList<H, T> {
238238
impl<H,T>AsRef<[T]>forRawList<H,T>{
239239
#[inline(always)]
240240
fnas_ref(&self) -> &[T]{
241-
let data_ptr = ptr::addr_of!(self.skel.data).cast::<T>();
241+
let data_ptr = (&rawconstself.skel.data).cast::<T>();
242242
// SAFETY: `data_ptr` has the same provenance as `self` and can therefore
243243
// access the `self.skel.len` elements stored at `self.skel.data`.
244244
// Note that we specifically don't reborrow `&self.skel.data`, because that

‎compiler/stable_mir/src/compiler_interface.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ where
255255
ifTLV.is_set(){
256256
Err(Error::from("StableMIR already running"))
257257
}else{
258-
let ptr:*const() = std::ptr::addr_of!(context)as_;
258+
let ptr:*const() = (&rawconstcontext)as_;
259259
TLV.set(&Cell::new(ptr), || Ok(f()))
260260
}
261261
}

0 commit comments

Comments
 (0)