Skip to content

Commit 94c3856

Browse files
committed
A few cleanups for rustc_data_structures
1 parent 1601879 commit 94c3856

File tree

10 files changed

+27
-24
lines changed

10 files changed

+27
-24
lines changed

src/librustc_data_structures/base_n.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub const MAX_BASE: usize = 64;
1717
pub const ALPHANUMERIC_ONLY: usize = 62;
1818
pub const CASE_INSENSITIVE: usize = 36;
1919

20-
const BASE_64: &'static [u8; MAX_BASE as usize] =
20+
const BASE_64: &[u8; MAX_BASE as usize] =
2121
b"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@$";
2222

2323
#[inline]
@@ -37,7 +37,8 @@ pub fn push_str(mut n: u128, base: usize, output: &mut String) {
3737
break;
3838
}
3939
}
40-
&mut s[0..index].reverse();
40+
s[0..index].reverse();
41+
4142
output.push_str(str::from_utf8(&s[0..index]).unwrap());
4243
}
4344

src/librustc_data_structures/bitslice.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ fn bit_lookup(bit: usize) -> BitLookup {
7575
let word = bit / word_bits;
7676
let bit_in_word = bit % word_bits;
7777
let bit_mask = 1 << bit_in_word;
78-
BitLookup { word: word, bit_in_word: bit_in_word, bit_mask: bit_mask }
78+
BitLookup { word, bit_in_word, bit_mask }
7979
}
8080

8181
pub fn bits_to_string(words: &[Word], bits: usize) -> String {
@@ -105,7 +105,8 @@ pub fn bits_to_string(words: &[Word], bits: usize) -> String {
105105
sep = '|';
106106
}
107107
result.push(']');
108-
return result
108+
109+
result
109110
}
110111

111112
#[inline]

src/librustc_data_structures/bitvec.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,8 @@ impl<'a, C: Idx> Iterator for BitIter<'a, C> {
196196
self.current >>= offset;
197197
self.current >>= 1; // shift otherwise overflows for 0b1000_0000_…_0000
198198
self.idx += offset + 1;
199-
return Some(C::new(self.idx - 1));
199+
200+
Some(C::new(self.idx - 1))
200201
}
201202

202203
fn size_hint(&self) -> (usize, Option<usize>) {
@@ -299,7 +300,7 @@ impl<R: Idx, C: Idx> BitMatrix<R, C> {
299300
let v1 = vector[write_index];
300301
let v2 = v1 | vector[read_index];
301302
vector[write_index] = v2;
302-
changed = changed | (v1 != v2);
303+
changed |= v1 != v2;
303304
}
304305
changed
305306
}

src/librustc_data_structures/flock.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,8 @@ mod imp {
254254
type ULONG_PTR = usize;
255255

256256
type LPOVERLAPPED = *mut OVERLAPPED;
257-
const LOCKFILE_EXCLUSIVE_LOCK: DWORD = 0x00000002;
258-
const LOCKFILE_FAIL_IMMEDIATELY: DWORD = 0x00000001;
257+
const LOCKFILE_EXCLUSIVE_LOCK: DWORD = 0x0000_0002;
258+
const LOCKFILE_FAIL_IMMEDIATELY: DWORD = 0x0000_0001;
259259

260260
const FILE_SHARE_DELETE: DWORD = 0x4;
261261
const FILE_SHARE_READ: DWORD = 0x1;

src/librustc_data_structures/graph/dominators/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ fn intersect<Node: Idx>(
107107
node2 = immediate_dominators[node2].unwrap();
108108
}
109109
}
110-
return node1;
110+
111+
node1
111112
}
112113

113114
#[derive(Clone, Debug)]

src/librustc_data_structures/graph/implementation/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ pub const INCOMING: Direction = Direction { repr: 1 };
9090

9191
impl NodeIndex {
9292
/// Returns unique id (unique with respect to the graph holding associated node).
93-
pub fn node_id(&self) -> usize {
93+
pub fn node_id(self) -> usize {
9494
self.0
9595
}
9696
}
@@ -187,7 +187,7 @@ impl<N: Debug, E: Debug> Graph<N, E> {
187187
self.nodes[source.0].first_edge[OUTGOING.repr] = idx;
188188
self.nodes[target.0].first_edge[INCOMING.repr] = idx;
189189

190-
return idx;
190+
idx
191191
}
192192

193193
pub fn edge(&self, idx: EdgeIndex) -> &Edge<E> {
@@ -261,8 +261,8 @@ impl<N: Debug, E: Debug> Graph<N, E> {
261261
DepthFirstTraversal::with_start_node(self, start, direction)
262262
}
263263

264-
pub fn nodes_in_postorder<'a>(
265-
&'a self,
264+
pub fn nodes_in_postorder(
265+
&self,
266266
direction: Direction,
267267
entry_node: NodeIndex,
268268
) -> Vec<NodeIndex> {

src/librustc_data_structures/indexed_set.rs

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ impl<T: Idx> rustc_serialize::Decodable for IdxSetBuf<T> {
6565
///
6666
/// In other words, `T` is the type used to index into the bitslice
6767
/// this type uses to represent the set of object it holds.
68+
#[repr(transparent)]
6869
pub struct IdxSet<T: Idx> {
6970
_pd: PhantomData<fn(&T)>,
7071
bits: [Word],

src/librustc_data_structures/obligation_forest/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ impl<O: ForestObligation> ObligationForest<O> {
573573
}
574574

575575
let mut kill_list = vec![];
576-
for (predicate, index) in self.waiting_cache.iter_mut() {
576+
for (predicate, index) in &mut self.waiting_cache {
577577
let new_index = node_rewrites[index.get()];
578578
if new_index >= nodes_len {
579579
kill_list.push(predicate.clone());

src/librustc_data_structures/tiny_list.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ impl<T: PartialEq> Element<T> {
107107
};
108108

109109
self.next = new_next;
110-
return true
110+
111+
true
111112
}
112113

113114
fn len(&self) -> usize {

src/librustc_data_structures/transitive_relation.rs

+6-9
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl<T: Clone + Debug + Eq + Hash> TransitiveRelation<T> {
7777
..
7878
} = self;
7979

80-
map.entry(a.clone())
80+
*map.entry(a.clone())
8181
.or_insert_with(|| {
8282
elements.push(a);
8383

@@ -86,7 +86,6 @@ impl<T: Clone + Debug + Eq + Hash> TransitiveRelation<T> {
8686

8787
Index(elements.len() - 1)
8888
})
89-
.clone()
9089
}
9190

9291
/// Applies the (partial) function to each edge and returns a new
@@ -98,14 +97,12 @@ impl<T: Clone + Debug + Eq + Hash> TransitiveRelation<T> {
9897
{
9998
let mut result = TransitiveRelation::new();
10099
for edge in &self.edges {
101-
let r = f(&self.elements[edge.source.0]).and_then(|source| {
100+
f(&self.elements[edge.source.0]).and_then(|source| {
102101
f(&self.elements[edge.target.0]).and_then(|target| {
103-
Some(result.add(source, target))
102+
result.add(source, target);
103+
Some(())
104104
})
105-
});
106-
if r.is_none() {
107-
return None;
108-
}
105+
})?;
109106
}
110107
Some(result)
111108
}
@@ -372,7 +369,7 @@ impl<T: Clone + Debug + Eq + Hash> TransitiveRelation<T> {
372369
let mut changed = true;
373370
while changed {
374371
changed = false;
375-
for edge in self.edges.iter() {
372+
for edge in &self.edges {
376373
// add an edge from S -> T
377374
changed |= matrix.add(edge.source.0, edge.target.0);
378375

0 commit comments

Comments
 (0)