Skip to content

Commit 08d0a98

Browse files
committed
Use consistent to/from naming convention in Fingerprint
1 parent 33fb63c commit 08d0a98

File tree

5 files changed

+17
-17
lines changed

5 files changed

+17
-17
lines changed

compiler/rustc_ast/src/crate_disambiguator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ impl CrateDisambiguator {
2020

2121
impl fmt::Display for CrateDisambiguator {
2222
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
23-
f.write_str(&base_n::encode(self.0.as_value_u128(), base_n::CASE_INSENSITIVE))
23+
f.write_str(&base_n::encode(self.0.to_value_u128(), base_n::CASE_INSENSITIVE))
2424
}
2525
}
2626

compiler/rustc_data_structures/src/fingerprint.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl Fingerprint {
4646
}
4747

4848
#[inline]
49-
pub fn as_value(&self) -> (u64, u64) {
49+
pub fn to_value(&self) -> (u64, u64) {
5050
(
5151
((self.0[0] as u64) << 0)
5252
| ((self.0[1] as u64) << 8)
@@ -73,8 +73,8 @@ impl Fingerprint {
7373
}
7474

7575
#[inline]
76-
pub fn as_value_u128(&self) -> u128 {
77-
let (v0, v1) = self.as_value();
76+
pub fn to_value_u128(&self) -> u128 {
77+
let (v0, v1) = self.to_value();
7878
v0 as u128 | ((v1 as u128) << 64)
7979
}
8080

@@ -85,27 +85,27 @@ impl Fingerprint {
8585

8686
#[inline]
8787
pub fn to_smaller_hash(&self) -> u64 {
88-
self.as_value().0
88+
self.to_value().0
8989
}
9090

9191
#[inline]
9292
pub fn combine(self, other: Fingerprint) -> Fingerprint {
9393
// See https://stackoverflow.com/a/27952689 on why this function is
9494
// implemented this way.
95-
let v = self.as_value_u128().wrapping_mul(3).wrapping_add(other.as_value_u128());
95+
let v = self.to_value_u128().wrapping_mul(3).wrapping_add(other.to_value_u128());
9696
Fingerprint::from_value_u128(v)
9797
}
9898

9999
// Combines two hashes in an order independent way. Make sure this is what
100100
// you want.
101101
#[inline]
102102
pub fn combine_commutative(self, other: Fingerprint) -> Fingerprint {
103-
let v = self.as_value_u128().wrapping_add(other.as_value_u128());
103+
let v = self.to_value_u128().wrapping_add(other.to_value_u128());
104104
Fingerprint::from_value_u128(v)
105105
}
106106

107107
pub fn to_hex(&self) -> String {
108-
let (self0, self1) = self.as_value();
108+
let (self0, self1) = self.to_value();
109109
format!("{:x}{:x}", self0, self1)
110110
}
111111

@@ -123,7 +123,7 @@ impl Fingerprint {
123123

124124
impl std::fmt::Display for Fingerprint {
125125
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
126-
let (self0, self1) = self.as_value();
126+
let (self0, self1) = self.to_value();
127127
write!(formatter, "{:x}-{:x}", self0, self1)
128128
}
129129
}
@@ -132,7 +132,7 @@ impl Ord for Fingerprint {
132132
#[inline]
133133
fn cmp(&self, other: &Fingerprint) -> Ordering {
134134
// This implementation is faster than the one generated by the `derive` attribute.
135-
self.as_value_u128().cmp(&other.as_value_u128())
135+
self.to_value_u128().cmp(&other.to_value_u128())
136136
}
137137
}
138138

@@ -148,7 +148,7 @@ impl PartialEq for Fingerprint {
148148
#[inline]
149149
fn eq(&self, other: &Fingerprint) -> bool {
150150
// This implementation is faster than the one generated by the `derive` attribute.
151-
self.as_value_u128() == other.as_value_u128()
151+
self.to_value_u128() == other.to_value_u128()
152152
}
153153
}
154154

@@ -167,7 +167,7 @@ impl<H: Hasher> FingerprintHasher for H {
167167
#[inline]
168168
default fn write_fingerprint(&mut self, fingerprint: &Fingerprint) {
169169
// It's faster to hash this as two `u64`s than as a `u128` or slice.
170-
let (fingerprint0, fingerprint1) = fingerprint.as_value();
170+
let (fingerprint0, fingerprint1) = fingerprint.to_value();
171171
self.write_u64(fingerprint0);
172172
self.write_u64(fingerprint1);
173173
}
@@ -177,7 +177,7 @@ impl FingerprintHasher for crate::unhash::Unhasher {
177177
#[inline]
178178
fn write_fingerprint(&mut self, fingerprint: &Fingerprint) {
179179
// `Unhasher` only wants a single `u64`
180-
let (fingerprint0, _) = fingerprint.as_value();
180+
let (fingerprint0, _) = fingerprint.to_value();
181181
self.write_u64(fingerprint0);
182182
}
183183
}

compiler/rustc_data_structures/src/fingerprint/tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ use super::*;
33
#[test]
44
fn test_value_roundtrip() {
55
let f0 = Fingerprint::from_value(0x00221133_44665577, 0x88AA99BB_CCEEDDFF);
6-
let v = f0.as_value();
6+
let v = f0.to_value();
77
let f1 = Fingerprint::from_value(v.0, v.1);
88
assert_eq!(f0, f1);
99
}
1010

1111
#[test]
1212
fn test_value_u128_roundtrip() {
1313
let f0 = Fingerprint::from_value_u128(0x00221133_44665577_88AA99BB_CCEEDDFF);
14-
let v = f0.as_value_u128();
14+
let v = f0.to_value_u128();
1515
let f1 = Fingerprint::from_value_u128(v);
1616
assert_eq!(f0, f1);
1717
}

compiler/rustc_save_analysis/src/dump_visitor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ impl<'tcx> DumpVisitor<'tcx> {
147147
.sess
148148
.local_crate_disambiguator()
149149
.to_fingerprint()
150-
.as_value(),
150+
.to_value(),
151151
},
152152
crate_root: crate_root.unwrap_or_else(|| "<no source>".to_owned()),
153153
external_crates: self.save_ctxt.get_external_crates(),

compiler/rustc_save_analysis/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ impl<'tcx> SaveContext<'tcx> {
128128
num: n.as_u32(),
129129
id: GlobalCrateId {
130130
name: self.tcx.crate_name(n).to_string(),
131-
disambiguator: self.tcx.crate_disambiguator(n).to_fingerprint().as_value(),
131+
disambiguator: self.tcx.crate_disambiguator(n).to_fingerprint().to_value(),
132132
},
133133
});
134134
}

0 commit comments

Comments
 (0)