Skip to content

Commit 7948b18

Browse files
committed
Use ptr::eq where applicable
1 parent 1190f7c commit 7948b18

File tree

4 files changed

+12
-13
lines changed

4 files changed

+12
-13
lines changed

src/librustc/ty/context.rs

+7-10
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ use std::hash::{Hash, Hasher};
5959
use std::fmt;
6060
use std::mem;
6161
use std::ops::{Deref, Bound};
62+
use std::ptr;
6263
use std::iter;
6364
use std::sync::mpsc;
6465
use std::sync::Arc;
@@ -168,7 +169,7 @@ impl<'gcx: 'tcx, 'tcx> CtxtInterners<'tcx> {
168169

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

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

11331132
/// Create a type context and call the closure with a `TyCtxt` reference
@@ -1777,6 +1776,7 @@ pub mod tls {
17771776
use std::fmt;
17781777
use std::mem;
17791778
use std::marker::PhantomData;
1779+
use std::ptr;
17801780
use syntax_pos;
17811781
use ty::query;
17821782
use errors::{Diagnostic, TRACK_DIAGNOSTICS};
@@ -2011,8 +2011,7 @@ pub mod tls {
20112011
{
20122012
with_context(|context| {
20132013
unsafe {
2014-
let gcx = tcx.gcx as *const _ as usize;
2015-
assert!(context.tcx.gcx as *const _ as usize == gcx);
2014+
assert!(ptr::eq(context.tcx.gcx, tcx.gcx));
20162015
let context: &ImplicitCtxt<'_, '_, '_> = mem::transmute(context);
20172016
f(context)
20182017
}
@@ -2030,10 +2029,8 @@ pub mod tls {
20302029
{
20312030
with_context(|context| {
20322031
unsafe {
2033-
let gcx = tcx.gcx as *const _ as usize;
2034-
let interners = tcx.interners as *const _ as usize;
2035-
assert!(context.tcx.gcx as *const _ as usize == gcx);
2036-
assert!(context.tcx.interners as *const _ as usize == interners);
2032+
assert!(ptr::eq(context.tcx.gcx, tcx.gcx));
2033+
assert!(ptr::eq(context.tcx.interners, tcx.interners));
20372034
let context: &ImplicitCtxt<'_, '_, '_> = mem::transmute(context);
20382035
f(context)
20392036
}

src/librustc_codegen_llvm/debuginfo/metadata.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ use syntax_pos::{self, Span, FileName};
4747

4848
impl PartialEq for llvm::Metadata {
4949
fn eq(&self, other: &Self) -> bool {
50-
self as *const _ == other as *const _
50+
ptr::eq(self, other)
5151
}
5252
}
5353

src/librustc_codegen_llvm/type_.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@ use abi::{LlvmType, FnTypeExt};
2020

2121
use std::fmt;
2222
use std::cell::RefCell;
23+
use std::ptr;
2324

2425
use libc::c_uint;
2526

2627
impl PartialEq for Type {
2728
fn eq(&self, other: &Self) -> bool {
28-
self as *const _ == other as *const _
29+
ptr::eq(self, other)
2930
}
3031
}
3132

src/librustc_codegen_llvm/value.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ use llvm;
44

55
use std::fmt;
66
use std::hash::{Hash, Hasher};
7+
use std::ptr;
78

89
impl PartialEq for Value {
910
fn eq(&self, other: &Self) -> bool {
10-
self as *const _ == other as *const _
11+
ptr::eq(self, other)
1112
}
1213
}
1314

0 commit comments

Comments
 (0)