Skip to content

Commit cd8b56f

Browse files
committed
Auto merge of rust-lang#89905 - matthiaskrgr:rev_89709_entirely, r=michaelwoerister
Revert "Auto merge of rust-lang#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

-2
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

+1-1
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

+8-2
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

+2-2
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

+6-6
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

+4-4
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

+2-2
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

+12-4
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

+1-1
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

+2-2
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
}

compiler/rustc_data_structures/src/stack.rs

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ const RED_ZONE: usize = 100 * 1024; // 100k
55

66
// Only the first stack that is pushed, grows exponentially (2^n * STACK_PER_RECURSION) from then
77
// on. This flag has performance relevant characteristics. Don't set it too high.
8-
#[allow(clippy::identity_op)]
98
const STACK_PER_RECURSION: usize = 1 * 1024 * 1024; // 1MB
109

1110
/// Grows the stack on demand to prevent stack overflow. Call this in strategic locations

compiler/rustc_data_structures/src/steal.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl<T> Steal<T> {
3434
#[track_caller]
3535
pub fn borrow(&self) -> MappedReadGuard<'_, T> {
3636
let borrow = self.value.borrow();
37-
if borrow.is_none() {
37+
if let None = &*borrow {
3838
panic!("attempted to read from stolen value: {}", std::any::type_name::<T>());
3939
}
4040
ReadGuard::map(borrow, |opt| opt.as_ref().unwrap())

compiler/rustc_data_structures/src/tiny_list.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ impl<T: PartialEq> TinyList<T> {
4848
#[inline]
4949
pub fn contains(&self, data: &T) -> bool {
5050
let mut elem = self.head.as_ref();
51-
while let Some(e) = elem {
51+
while let Some(ref e) = elem {
5252
if &e.data == data {
5353
return true;
5454
}

compiler/rustc_data_structures/src/vec_linked_list.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ use rustc_index::vec::{Idx, IndexVec};
22

33
pub fn iter<Ls>(
44
first: Option<Ls::LinkIndex>,
5-
links: &Ls,
6-
) -> impl Iterator<Item = Ls::LinkIndex> + '_
5+
links: &'a Ls,
6+
) -> impl Iterator<Item = Ls::LinkIndex> + 'a
77
where
88
Ls: Links,
99
{

compiler/rustc_graphviz/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ impl<'a> LabelText<'a> {
512512
pub fn to_dot_string(&self) -> String {
513513
match *self {
514514
LabelStr(ref s) => format!("\"{}\"", s.escape_default()),
515-
EscStr(ref s) => format!("\"{}\"", LabelText::escape_str(s)),
515+
EscStr(ref s) => format!("\"{}\"", LabelText::escape_str(&s)),
516516
HtmlStr(ref s) => format!("<{}>", s),
517517
}
518518
}

compiler/rustc_index/src/bit_set.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -990,8 +990,9 @@ impl<R: Idx, C: Idx> BitMatrix<R, C> {
990990
pub fn insert_all_into_row(&mut self, row: R) {
991991
assert!(row.index() < self.num_rows);
992992
let (start, end) = self.range(row);
993-
for word in self.words[start..end].iter_mut() {
994-
*word = !0;
993+
let words = &mut self.words[..];
994+
for index in start..end {
995+
words[index] = !0;
995996
}
996997
self.clear_excess_bits(row);
997998
}
@@ -1143,7 +1144,7 @@ impl<R: Idx, C: Idx> SparseBitMatrix<R, C> {
11431144

11441145
/// Iterates through all the columns set to true in a given row of
11451146
/// the matrix.
1146-
pub fn iter(&self, row: R) -> impl Iterator<Item = C> + '_ {
1147+
pub fn iter<'a>(&'a self, row: R) -> impl Iterator<Item = C> + 'a {
11471148
self.row(row).into_iter().flat_map(|r| r.iter())
11481149
}
11491150

compiler/rustc_index/src/vec.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -634,15 +634,18 @@ impl<I: Idx, T> IndexVec<I, T> {
634634
}
635635

636636
#[inline]
637-
pub fn drain<R: RangeBounds<usize>>(&mut self, range: R) -> impl Iterator<Item = T> + '_ {
637+
pub fn drain<'a, R: RangeBounds<usize>>(
638+
&'a mut self,
639+
range: R,
640+
) -> impl Iterator<Item = T> + 'a {
638641
self.raw.drain(range)
639642
}
640643

641644
#[inline]
642-
pub fn drain_enumerated<R: RangeBounds<usize>>(
643-
&mut self,
645+
pub fn drain_enumerated<'a, R: RangeBounds<usize>>(
646+
&'a mut self,
644647
range: R,
645-
) -> impl Iterator<Item = (I, T)> + '_ {
648+
) -> impl Iterator<Item = (I, T)> + 'a {
646649
self.raw.drain(range).enumerate().map(|(n, t)| (I::new(n), t))
647650
}
648651

compiler/rustc_lexer/src/unescape.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,11 @@ pub enum EscapeError {
6868
impl EscapeError {
6969
/// Returns true for actual errors, as opposed to warnings.
7070
pub fn is_fatal(&self) -> bool {
71-
!matches!(
72-
self,
73-
EscapeError::UnskippedWhitespaceWarning | EscapeError::MultipleSkippedLinesWarning
74-
)
71+
match self {
72+
EscapeError::UnskippedWhitespaceWarning => false,
73+
EscapeError::MultipleSkippedLinesWarning => false,
74+
_ => true,
75+
}
7576
}
7677
}
7778

@@ -329,7 +330,7 @@ where
329330
callback(start..end, Err(EscapeError::MultipleSkippedLinesWarning));
330331
}
331332
let tail = &tail[first_non_space..];
332-
if let Some(c) = tail.chars().next() {
333+
if let Some(c) = tail.chars().nth(0) {
333334
// For error reporting, we would like the span to contain the character that was not
334335
// skipped. The +1 is necessary to account for the leading \ that started the escape.
335336
let end = start + first_non_space + c.len_utf8() + 1;

compiler/rustc_macros/src/hash_stable.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@ fn parse_attributes(field: &syn::Field) -> Attributes {
2424
}
2525
if meta.path().is_ident("project") {
2626
if let Meta::List(list) = meta {
27-
if let Some(NestedMeta::Meta(meta)) = list.nested.iter().next() {
28-
attrs.project = meta.path().get_ident().cloned();
29-
any_attr = true;
27+
if let Some(nested) = list.nested.iter().next() {
28+
if let NestedMeta::Meta(meta) = nested {
29+
attrs.project = meta.path().get_ident().cloned();
30+
any_attr = true;
31+
}
3032
}
3133
}
3234
}

compiler/rustc_macros/src/session_diagnostic.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -349,14 +349,14 @@ impl<'a> SessionDiagnosticDeriveBuilder<'a> {
349349
) -> Result<proc_macro2::TokenStream, SessionDiagnosticDeriveError> {
350350
let field_binding = &info.binding.binding;
351351

352-
let option_ty = option_inner_ty(info.ty);
352+
let option_ty = option_inner_ty(&info.ty);
353353

354354
let generated_code = self.generate_non_option_field_code(
355355
attr,
356356
FieldInfo {
357357
vis: info.vis,
358358
binding: info.binding,
359-
ty: option_ty.unwrap_or(info.ty),
359+
ty: option_ty.unwrap_or(&info.ty),
360360
span: info.span,
361361
},
362362
)?;
@@ -388,7 +388,7 @@ impl<'a> SessionDiagnosticDeriveBuilder<'a> {
388388
let formatted_str = self.build_format(&s.value(), attr.span());
389389
match name {
390390
"message" => {
391-
if type_matches_path(info.ty, &["rustc_span", "Span"]) {
391+
if type_matches_path(&info.ty, &["rustc_span", "Span"]) {
392392
quote! {
393393
#diag.set_span(*#field_binding);
394394
#diag.set_primary_message(#formatted_str);
@@ -401,7 +401,7 @@ impl<'a> SessionDiagnosticDeriveBuilder<'a> {
401401
}
402402
}
403403
"label" => {
404-
if type_matches_path(info.ty, &["rustc_span", "Span"]) {
404+
if type_matches_path(&info.ty, &["rustc_span", "Span"]) {
405405
quote! {
406406
#diag.span_label(*#field_binding, #formatted_str);
407407
}

0 commit comments

Comments
 (0)