Skip to content

Commit cd8b56f

Browse files
committed
Auto merge of #89905 - matthiaskrgr:rev_89709_entirely, r=michaelwoerister
Revert "Auto merge of #89709 - clemenswasser:apply_clippy_suggestions… …_2, r=petrochenkov" The PR had some unforseen perf regressions that are not as easy to find. Revert the PR for now. This reverts commit 6ae8912, reversing changes made to 86d6d2b.
2 parents ec724ac + 4457014 commit cd8b56f

File tree

22 files changed

+72
-56
lines changed

22 files changed

+72
-56
lines changed

compiler/rustc_apfloat/src/ieee.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,6 @@ impl<S: Semantics> fmt::Display for IeeeFloat<S> {
389389
let _: Loss = sig::shift_right(&mut sig, &mut exp, trailing_zeros as usize);
390390

391391
// Change the exponent from 2^e to 10^e.
392-
#[allow(clippy::comparison_chain)]
393392
if exp == 0 {
394393
// Nothing to do.
395394
} else if exp > 0 {
@@ -2527,7 +2526,6 @@ mod sig {
25272526
if *a_sign ^ b_sign {
25282527
let (reverse, loss);
25292528

2530-
#[allow(clippy::comparison_chain)]
25312529
if bits == 0 {
25322530
reverse = cmp(a_sig, b_sig) == Ordering::Less;
25332531
loss = Loss::ExactlyZero;

compiler/rustc_data_structures/src/base_n.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const BASE_64: &[u8; MAX_BASE as usize] =
1414

1515
#[inline]
1616
pub fn push_str(mut n: u128, base: usize, output: &mut String) {
17-
debug_assert!((2..=MAX_BASE).contains(&base));
17+
debug_assert!(base >= 2 && base <= MAX_BASE);
1818
let mut s = [0u8; 128];
1919
let mut index = 0;
2020

compiler/rustc_data_structures/src/graph/implementation/mod.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,17 @@ impl<N: Debug, E: Debug> Graph<N, E> {
206206
AdjacentEdges { graph: self, direction, next: first_edge }
207207
}
208208

209-
pub fn successor_nodes(&self, source: NodeIndex) -> impl Iterator<Item = NodeIndex> + '_ {
209+
pub fn successor_nodes<'a>(
210+
&'a self,
211+
source: NodeIndex,
212+
) -> impl Iterator<Item = NodeIndex> + 'a {
210213
self.outgoing_edges(source).targets()
211214
}
212215

213-
pub fn predecessor_nodes(&self, target: NodeIndex) -> impl Iterator<Item = NodeIndex> + '_ {
216+
pub fn predecessor_nodes<'a>(
217+
&'a self,
218+
target: NodeIndex,
219+
) -> impl Iterator<Item = NodeIndex> + 'a {
214220
self.incoming_edges(target).sources()
215221
}
216222

compiler/rustc_data_structures/src/graph/iterate/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ fn post_order_walk<G: DirectedGraph + WithSuccessors + WithNumNodes>(
4848
let node = frame.node;
4949
visited[node] = true;
5050

51-
for successor in frame.iter.by_ref() {
51+
while let Some(successor) = frame.iter.next() {
5252
if !visited[successor] {
5353
stack.push(PostOrderFrame { node: successor, iter: graph.successors(successor) });
5454
continue 'recurse;
@@ -112,7 +112,7 @@ where
112112
/// This is equivalent to just invoke `next` repeatedly until
113113
/// you get a `None` result.
114114
pub fn complete_search(&mut self) {
115-
for _ in self {}
115+
while let Some(_) = self.next() {}
116116
}
117117

118118
/// Returns true if node has been visited thus far.

compiler/rustc_data_structures/src/obligation_forest/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ impl<O: ForestObligation> ObligationForest<O> {
390390
.map(|(index, _node)| Error { error: error.clone(), backtrace: self.error_at(index) })
391391
.collect();
392392

393-
self.compress(|_| unreachable!());
393+
self.compress(|_| assert!(false));
394394
errors
395395
}
396396

@@ -612,7 +612,7 @@ impl<O: ForestObligation> ObligationForest<O> {
612612
fn compress(&mut self, mut outcome_cb: impl FnMut(&O)) {
613613
let orig_nodes_len = self.nodes.len();
614614
let mut node_rewrites: Vec<_> = std::mem::take(&mut self.reused_node_vec);
615-
assert!(node_rewrites.is_empty());
615+
debug_assert!(node_rewrites.is_empty());
616616
node_rewrites.extend(0..orig_nodes_len);
617617
let mut dead_nodes = 0;
618618

@@ -623,13 +623,13 @@ impl<O: ForestObligation> ObligationForest<O> {
623623
// self.nodes[0..index - dead_nodes] are the first remaining nodes
624624
// self.nodes[index - dead_nodes..index] are all dead
625625
// self.nodes[index..] are unchanged
626-
for (index, node_rewrite) in node_rewrites.iter_mut().enumerate() {
626+
for index in 0..orig_nodes_len {
627627
let node = &self.nodes[index];
628628
match node.state.get() {
629629
NodeState::Pending | NodeState::Waiting => {
630630
if dead_nodes > 0 {
631631
self.nodes.swap(index, index - dead_nodes);
632-
*node_rewrite -= dead_nodes;
632+
node_rewrites[index] -= dead_nodes;
633633
}
634634
}
635635
NodeState::Done => {
@@ -646,7 +646,7 @@ impl<O: ForestObligation> ObligationForest<O> {
646646
}
647647
// Extract the success stories.
648648
outcome_cb(&node.obligation);
649-
*node_rewrite = orig_nodes_len;
649+
node_rewrites[index] = orig_nodes_len;
650650
dead_nodes += 1;
651651
}
652652
NodeState::Error => {
@@ -655,7 +655,7 @@ impl<O: ForestObligation> ObligationForest<O> {
655655
// check against.
656656
self.active_cache.remove(&node.obligation.as_cache_key());
657657
self.insert_into_error_cache(index);
658-
*node_rewrite = orig_nodes_len;
658+
node_rewrites[index] = orig_nodes_len;
659659
dead_nodes += 1;
660660
}
661661
NodeState::Success => unreachable!(),

compiler/rustc_data_structures/src/sorted_map.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,22 +205,22 @@ impl<K: Ord, V> SortedMap<K, V> {
205205
R: RangeBounds<K>,
206206
{
207207
let start = match range.start_bound() {
208-
Bound::Included(k) => match self.lookup_index_for(k) {
208+
Bound::Included(ref k) => match self.lookup_index_for(k) {
209209
Ok(index) | Err(index) => index,
210210
},
211-
Bound::Excluded(k) => match self.lookup_index_for(k) {
211+
Bound::Excluded(ref k) => match self.lookup_index_for(k) {
212212
Ok(index) => index + 1,
213213
Err(index) => index,
214214
},
215215
Bound::Unbounded => 0,
216216
};
217217

218218
let end = match range.end_bound() {
219-
Bound::Included(k) => match self.lookup_index_for(k) {
219+
Bound::Included(ref k) => match self.lookup_index_for(k) {
220220
Ok(index) => index + 1,
221221
Err(index) => index,
222222
},
223-
Bound::Excluded(k) => match self.lookup_index_for(k) {
223+
Bound::Excluded(ref k) => match self.lookup_index_for(k) {
224224
Ok(index) | Err(index) => index,
225225
},
226226
Bound::Unbounded => self.data.len(),

compiler/rustc_data_structures/src/sorted_map/index_map.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl<I: Idx, K: Ord, V> SortedIndexMultiMap<I, K, V> {
7575
///
7676
/// If there are multiple items that are equivalent to `key`, they will be yielded in
7777
/// insertion order.
78-
pub fn get_by_key(&self, key: K) -> impl Iterator<Item = &V> {
78+
pub fn get_by_key(&'a self, key: K) -> impl 'a + Iterator<Item = &'a V> {
7979
self.get_by_key_enumerated(key).map(|(_, v)| v)
8080
}
8181

@@ -84,7 +84,7 @@ impl<I: Idx, K: Ord, V> SortedIndexMultiMap<I, K, V> {
8484
///
8585
/// If there are multiple items that are equivalent to `key`, they will be yielded in
8686
/// insertion order.
87-
pub fn get_by_key_enumerated(&self, key: K) -> impl Iterator<Item = (I, &V)> {
87+
pub fn get_by_key_enumerated(&'a self, key: K) -> impl '_ + Iterator<Item = (I, &V)> {
8888
let lower_bound = self.idx_sorted_by_item_key.partition_point(|&i| self.items[i].0 < key);
8989
self.idx_sorted_by_item_key[lower_bound..].iter().map_while(move |&i| {
9090
let (k, v) = &self.items[i];

compiler/rustc_data_structures/src/sso/map.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,11 @@ impl<K: Eq + Hash, V> SsoHashMap<K, V> {
257257
pub fn remove(&mut self, key: &K) -> Option<V> {
258258
match self {
259259
SsoHashMap::Array(array) => {
260-
array.iter().position(|(k, _v)| k == key).map(|index| array.swap_remove(index).1)
260+
if let Some(index) = array.iter().position(|(k, _v)| k == key) {
261+
Some(array.swap_remove(index).1)
262+
} else {
263+
None
264+
}
261265
}
262266
SsoHashMap::Map(map) => map.remove(key),
263267
}
@@ -268,7 +272,11 @@ impl<K: Eq + Hash, V> SsoHashMap<K, V> {
268272
pub fn remove_entry(&mut self, key: &K) -> Option<(K, V)> {
269273
match self {
270274
SsoHashMap::Array(array) => {
271-
array.iter().position(|(k, _v)| k == key).map(|index| array.swap_remove(index))
275+
if let Some(index) = array.iter().position(|(k, _v)| k == key) {
276+
Some(array.swap_remove(index))
277+
} else {
278+
None
279+
}
272280
}
273281
SsoHashMap::Map(map) => map.remove_entry(key),
274282
}
@@ -415,14 +423,14 @@ impl<K, V> IntoIterator for SsoHashMap<K, V> {
415423

416424
/// adapts Item of array reference iterator to Item of hashmap reference iterator.
417425
#[inline(always)]
418-
fn adapt_array_ref_it<K, V>(pair: &(K, V)) -> (&K, &V) {
426+
fn adapt_array_ref_it<K, V>(pair: &'a (K, V)) -> (&'a K, &'a V) {
419427
let (a, b) = pair;
420428
(a, b)
421429
}
422430

423431
/// adapts Item of array mut reference iterator to Item of hashmap mut reference iterator.
424432
#[inline(always)]
425-
fn adapt_array_mut_it<K, V>(pair: &mut (K, V)) -> (&K, &mut V) {
433+
fn adapt_array_mut_it<K, V>(pair: &'a mut (K, V)) -> (&'a K, &'a mut V) {
426434
let (a, b) = pair;
427435
(a, b)
428436
}

compiler/rustc_data_structures/src/sso/set.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl<T> SsoHashSet<T> {
7575
/// An iterator visiting all elements in arbitrary order.
7676
/// The iterator element type is `&'a T`.
7777
#[inline]
78-
pub fn iter(&self) -> impl Iterator<Item = &T> {
78+
pub fn iter(&'a self) -> impl Iterator<Item = &'a T> {
7979
self.into_iter()
8080
}
8181

compiler/rustc_data_structures/src/stable_hasher.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,14 +229,14 @@ impl<CTX> HashStable<CTX> for ::std::num::NonZeroUsize {
229229

230230
impl<CTX> HashStable<CTX> for f32 {
231231
fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) {
232-
let val: u32 = self.to_bits();
232+
let val: u32 = unsafe { ::std::mem::transmute(*self) };
233233
val.hash_stable(ctx, hasher);
234234
}
235235
}
236236

237237
impl<CTX> HashStable<CTX> for f64 {
238238
fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) {
239-
let val: u64 = self.to_bits();
239+
let val: u64 = unsafe { ::std::mem::transmute(*self) };
240240
val.hash_stable(ctx, hasher);
241241
}
242242
}

0 commit comments

Comments
 (0)