Skip to content

Commit

Permalink
Rollup merge of rust-lang#57547 - Xanewok:ptr-eq, r=petrochenkov
Browse files Browse the repository at this point in the history
Use `ptr::eq` where applicable

Stumbled upon a few of `A as *const _ as usize == B as *const as usize`, so I decided to follow the programming boy scout rule (:smile:) and replaced the pattern with more widely used `ptr::eq`.
  • Loading branch information
Centril committed Jan 13, 2019
2 parents 8f11da4 + 7948b18 commit 8c1813d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
17 changes: 7 additions & 10 deletions src/librustc/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ use std::hash::{Hash, Hasher};
use std::fmt;
use std::mem;
use std::ops::{Deref, Bound};
use std::ptr;
use std::iter;
use std::sync::mpsc;
use std::sync::Arc;
Expand Down Expand Up @@ -168,7 +169,7 @@ impl<'gcx: 'tcx, 'tcx> CtxtInterners<'tcx> {

// Make sure we don't end up with inference
// types/regions in the global interner
if local as *const _ as usize == global as *const _ as usize {
if ptr::eq(local, global) {
bug!("Attempted to intern `{:?}` which contains \
inference types/regions in the global type context",
&ty_struct);
Expand Down Expand Up @@ -1135,9 +1136,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {

/// Returns true if self is the same as self.global_tcx().
fn is_global(self) -> bool {
let local = self.interners as *const _;
let global = &self.global_interners as *const _;
local as usize == global as usize
ptr::eq(self.interners, &self.global_interners)
}

/// Create a type context and call the closure with a `TyCtxt` reference
Expand Down Expand Up @@ -1787,6 +1786,7 @@ pub mod tls {
use std::fmt;
use std::mem;
use std::marker::PhantomData;
use std::ptr;
use syntax_pos;
use ty::query;
use errors::{Diagnostic, TRACK_DIAGNOSTICS};
Expand Down Expand Up @@ -2021,8 +2021,7 @@ pub mod tls {
{
with_context(|context| {
unsafe {
let gcx = tcx.gcx as *const _ as usize;
assert!(context.tcx.gcx as *const _ as usize == gcx);
assert!(ptr::eq(context.tcx.gcx, tcx.gcx));
let context: &ImplicitCtxt<'_, '_, '_> = mem::transmute(context);
f(context)
}
Expand All @@ -2040,10 +2039,8 @@ pub mod tls {
{
with_context(|context| {
unsafe {
let gcx = tcx.gcx as *const _ as usize;
let interners = tcx.interners as *const _ as usize;
assert!(context.tcx.gcx as *const _ as usize == gcx);
assert!(context.tcx.interners as *const _ as usize == interners);
assert!(ptr::eq(context.tcx.gcx, tcx.gcx));
assert!(ptr::eq(context.tcx.interners, tcx.interners));
let context: &ImplicitCtxt<'_, '_, '_> = mem::transmute(context);
f(context)
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/debuginfo/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ use syntax_pos::{self, Span, FileName};

impl PartialEq for llvm::Metadata {
fn eq(&self, other: &Self) -> bool {
self as *const _ == other as *const _
ptr::eq(self, other)
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/librustc_codegen_llvm/type_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ use abi::{LlvmType, FnTypeExt};

use std::fmt;
use std::cell::RefCell;
use std::ptr;

use libc::c_uint;

impl PartialEq for Type {
fn eq(&self, other: &Self) -> bool {
self as *const _ == other as *const _
ptr::eq(self, other)
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/librustc_codegen_llvm/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ use llvm;

use std::fmt;
use std::hash::{Hash, Hasher};
use std::ptr;

impl PartialEq for Value {
fn eq(&self, other: &Self) -> bool {
self as *const _ == other as *const _
ptr::eq(self, other)
}
}

Expand Down

0 comments on commit 8c1813d

Please sign in to comment.