1
Fork 0

Rollup merge of #121556 - GrigorenkoPV:addr_of, r=Nilstrieb

Use `addr_of!`

As per https://github.com/rust-lang/rust/pull/121303#discussion_r1500954662
This commit is contained in:
Matthias Krüger 2024-02-24 22:39:01 +01:00 committed by GitHub
commit 4c401531f5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
42 changed files with 92 additions and 83 deletions

View file

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

View file

@ -61,7 +61,7 @@ impl<T> List<T> {
// length) that is 64-byte aligned, thus featuring the necessary
// trailing padding for elements with up to 64-byte alignment.
static EMPTY_SLICE: InOrder<usize, MaxAlign> = InOrder(0, MaxAlign);
unsafe { &*(&EMPTY_SLICE as *const _ as *const List<T>) }
unsafe { &*(std::ptr::addr_of!(EMPTY_SLICE) as *const List<T>) }
}
pub fn len(&self) -> usize {