]> git.lizzy.rs Git - rust.git/commitdiff
Apply clippy suggestions
authorClemens Wasser <clemens.wasser@gmail.com>
Sat, 9 Oct 2021 18:44:22 +0000 (20:44 +0200)
committerClemens Wasser <clemens.wasser@gmail.com>
Sun, 10 Oct 2021 13:38:19 +0000 (15:38 +0200)
22 files changed:
compiler/rustc_apfloat/src/ieee.rs
compiler/rustc_data_structures/src/base_n.rs
compiler/rustc_data_structures/src/graph/implementation/mod.rs
compiler/rustc_data_structures/src/graph/iterate/mod.rs
compiler/rustc_data_structures/src/obligation_forest/mod.rs
compiler/rustc_data_structures/src/sorted_map.rs
compiler/rustc_data_structures/src/sorted_map/index_map.rs
compiler/rustc_data_structures/src/sso/map.rs
compiler/rustc_data_structures/src/sso/set.rs
compiler/rustc_data_structures/src/stable_hasher.rs
compiler/rustc_data_structures/src/stack.rs
compiler/rustc_data_structures/src/steal.rs
compiler/rustc_data_structures/src/tiny_list.rs
compiler/rustc_data_structures/src/vec_linked_list.rs
compiler/rustc_graphviz/src/lib.rs
compiler/rustc_index/src/bit_set.rs
compiler/rustc_index/src/vec.rs
compiler/rustc_lexer/src/unescape.rs
compiler/rustc_macros/src/hash_stable.rs
compiler/rustc_macros/src/session_diagnostic.rs
compiler/rustc_serialize/src/serialize.rs
library/core/src/num/fmt.rs

index 96277950cfe1a0fbf9489172436ddc6c49f18480..739c6fd0a435f3eea5a58e2339885ea0d32cd719 100644 (file)
@@ -389,6 +389,7 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         let _: Loss = sig::shift_right(&mut sig, &mut exp, trailing_zeros as usize);
 
         // Change the exponent from 2^e to 10^e.
+        #[allow(clippy::comparison_chain)]
         if exp == 0 {
             // Nothing to do.
         } else if exp > 0 {
@@ -2526,6 +2527,7 @@ pub(super) fn add_or_sub(
         if *a_sign ^ b_sign {
             let (reverse, loss);
 
+            #[allow(clippy::comparison_chain)]
             if bits == 0 {
                 reverse = cmp(a_sig, b_sig) == Ordering::Less;
                 loss = Loss::ExactlyZero;
index 3c7bea27124096f35fd2cda702e5cb7ccc930b96..81e2501ecbeadeb8732d808e9940f10f8b336636 100644 (file)
@@ -14,7 +14,7 @@
 
 #[inline]
 pub fn push_str(mut n: u128, base: usize, output: &mut String) {
-    debug_assert!(base >= 2 && base <= MAX_BASE);
+    debug_assert!((2..=MAX_BASE).contains(&base));
     let mut s = [0u8; 128];
     let mut index = 0;
 
index 1aa7ac024d94e239d2acd5275dadd2515585e6e0..9ff401c3c7aad19d78a73c057b4001bce31d123e 100644 (file)
@@ -206,17 +206,11 @@ pub fn adjacent_edges(
         AdjacentEdges { graph: self, direction, next: first_edge }
     }
 
-    pub fn successor_nodes<'a>(
-        &'a self,
-        source: NodeIndex,
-    ) -> impl Iterator<Item = NodeIndex> + 'a {
+    pub fn successor_nodes(&self, source: NodeIndex) -> impl Iterator<Item = NodeIndex> + '_ {
         self.outgoing_edges(source).targets()
     }
 
-    pub fn predecessor_nodes<'a>(
-        &'a self,
-        target: NodeIndex,
-    ) -> impl Iterator<Item = NodeIndex> + 'a {
+    pub fn predecessor_nodes(&self, target: NodeIndex) -> impl Iterator<Item = NodeIndex> + '_ {
         self.incoming_edges(target).sources()
     }
 
index a9db3497b23908a50548e9a24ab74f189feed37d..1c6979dc489a6ad979d5deb9fca0bc4342ea6326 100644 (file)
@@ -48,7 +48,7 @@ struct PostOrderFrame<Node, Iter> {
         let node = frame.node;
         visited[node] = true;
 
-        while let Some(successor) = frame.iter.next() {
+        for successor in frame.iter.by_ref() {
             if !visited[successor] {
                 stack.push(PostOrderFrame { node: successor, iter: graph.successors(successor) });
                 continue 'recurse;
@@ -112,7 +112,7 @@ pub fn push_start_node(&mut self, start_node: G::Node) {
     /// This is equivalent to just invoke `next` repeatedly until
     /// you get a `None` result.
     pub fn complete_search(&mut self) {
-        while let Some(_) = self.next() {}
+        for _ in self {}
     }
 
     /// Returns true if node has been visited thus far.
index 25b7a84b3a06929fa5c0df1c8f1c3f92848727e0..c6b1fc53f5b91beb980ee8b7ab60e7762cbe0898 100644 (file)
@@ -390,7 +390,7 @@ pub fn to_errors<E: Clone>(&mut self, error: E) -> Vec<Error<O, E>> {
             .map(|(index, _node)| Error { error: error.clone(), backtrace: self.error_at(index) })
             .collect();
 
-        self.compress(|_| assert!(false));
+        self.compress(|_| unreachable!());
         errors
     }
 
@@ -623,13 +623,13 @@ fn compress(&mut self, mut outcome_cb: impl FnMut(&O)) {
         //     self.nodes[0..index - dead_nodes] are the first remaining nodes
         //     self.nodes[index - dead_nodes..index] are all dead
         //     self.nodes[index..] are unchanged
-        for index in 0..orig_nodes_len {
+        for (index, node_rewrite) in node_rewrites[..orig_nodes_len].iter_mut().enumerate() {
             let node = &self.nodes[index];
             match node.state.get() {
                 NodeState::Pending | NodeState::Waiting => {
                     if dead_nodes > 0 {
                         self.nodes.swap(index, index - dead_nodes);
-                        node_rewrites[index] -= dead_nodes;
+                        *node_rewrite -= dead_nodes;
                     }
                 }
                 NodeState::Done => {
@@ -646,7 +646,7 @@ fn compress(&mut self, mut outcome_cb: impl FnMut(&O)) {
                     }
                     // Extract the success stories.
                     outcome_cb(&node.obligation);
-                    node_rewrites[index] = orig_nodes_len;
+                    *node_rewrite = orig_nodes_len;
                     dead_nodes += 1;
                 }
                 NodeState::Error => {
@@ -655,7 +655,7 @@ fn compress(&mut self, mut outcome_cb: impl FnMut(&O)) {
                     // check against.
                     self.active_cache.remove(&node.obligation.as_cache_key());
                     self.insert_into_error_cache(index);
-                    node_rewrites[index] = orig_nodes_len;
+                    *node_rewrite = orig_nodes_len;
                     dead_nodes += 1;
                 }
                 NodeState::Success => unreachable!(),
index 20e2a3b9696e8560cb80d71d50cd9d8d6a0c281d..e80db0845a7be405a04b5c3c1ca4d543b8a731d0 100644 (file)
@@ -205,10 +205,10 @@ fn range_slice_indices<R>(&self, range: R) -> (usize, usize)
         R: RangeBounds<K>,
     {
         let start = match range.start_bound() {
-            Bound::Included(ref k) => match self.lookup_index_for(k) {
+            Bound::Included(k) => match self.lookup_index_for(k) {
                 Ok(index) | Err(index) => index,
             },
-            Bound::Excluded(ref k) => match self.lookup_index_for(k) {
+            Bound::Excluded(k) => match self.lookup_index_for(k) {
                 Ok(index) => index + 1,
                 Err(index) => index,
             },
@@ -216,11 +216,11 @@ fn range_slice_indices<R>(&self, range: R) -> (usize, usize)
         };
 
         let end = match range.end_bound() {
-            Bound::Included(ref k) => match self.lookup_index_for(k) {
+            Bound::Included(k) => match self.lookup_index_for(k) {
                 Ok(index) => index + 1,
                 Err(index) => index,
             },
-            Bound::Excluded(ref k) => match self.lookup_index_for(k) {
+            Bound::Excluded(k) => match self.lookup_index_for(k) {
                 Ok(index) | Err(index) => index,
             },
             Bound::Unbounded => self.data.len(),
index e92db9ea128057f4c82556a55ff27d3d728aafb0..1395bb16e875c62ef81f909792ed5e3745322ee2 100644 (file)
@@ -75,7 +75,7 @@ pub fn get(&self, idx: I) -> Option<&(K, V)> {
     ///
     /// If there are multiple items that are equivalent to `key`, they will be yielded in
     /// insertion order.
-    pub fn get_by_key(&'a self, key: K) -> impl 'a + Iterator<Item = &'a V> {
+    pub fn get_by_key(&self, key: K) -> impl Iterator<Item = &V> {
         self.get_by_key_enumerated(key).map(|(_, v)| v)
     }
 
@@ -84,7 +84,7 @@ pub fn get_by_key(&'a self, key: K) -> impl 'a + Iterator<Item = &'a V> {
     ///
     /// If there are multiple items that are equivalent to `key`, they will be yielded in
     /// insertion order.
-    pub fn get_by_key_enumerated(&'a self, key: K) -> impl '_ + Iterator<Item = (I, &V)> {
+    pub fn get_by_key_enumerated(&self, key: K) -> impl Iterator<Item = (I, &V)> {
         let lower_bound = self.idx_sorted_by_item_key.partition_point(|&i| self.items[i].0 < key);
         self.idx_sorted_by_item_key[lower_bound..].iter().map_while(move |&i| {
             let (k, v) = &self.items[i];
index 2de05cd4e56794180ae27b5fb476bed3f07e101c..d4274e99f1cffc071184bd34a12054dc7815d494 100644 (file)
@@ -257,11 +257,7 @@ pub fn insert(&mut self, key: K, value: V) -> Option<V> {
     pub fn remove(&mut self, key: &K) -> Option<V> {
         match self {
             SsoHashMap::Array(array) => {
-                if let Some(index) = array.iter().position(|(k, _v)| k == key) {
-                    Some(array.swap_remove(index).1)
-                } else {
-                    None
-                }
+                array.iter().position(|(k, _v)| k == key).map(|index| array.swap_remove(index).1)
             }
             SsoHashMap::Map(map) => map.remove(key),
         }
@@ -272,11 +268,7 @@ pub fn remove(&mut self, key: &K) -> Option<V> {
     pub fn remove_entry(&mut self, key: &K) -> Option<(K, V)> {
         match self {
             SsoHashMap::Array(array) => {
-                if let Some(index) = array.iter().position(|(k, _v)| k == key) {
-                    Some(array.swap_remove(index))
-                } else {
-                    None
-                }
+                array.iter().position(|(k, _v)| k == key).map(|index| array.swap_remove(index))
             }
             SsoHashMap::Map(map) => map.remove_entry(key),
         }
@@ -423,14 +415,14 @@ fn into_iter(self) -> Self::IntoIter {
 
 /// adapts Item of array reference iterator to Item of hashmap reference iterator.
 #[inline(always)]
-fn adapt_array_ref_it<K, V>(pair: &'a (K, V)) -> (&'a K, &'a V) {
+fn adapt_array_ref_it<K, V>(pair: &(K, V)) -> (&K, &V) {
     let (a, b) = pair;
     (a, b)
 }
 
 /// adapts Item of array mut reference iterator to Item of hashmap mut reference iterator.
 #[inline(always)]
-fn adapt_array_mut_it<K, V>(pair: &'a mut (K, V)) -> (&'a K, &'a mut V) {
+fn adapt_array_mut_it<K, V>(pair: &mut (K, V)) -> (&K, &mut V) {
     let (a, b) = pair;
     (a, b)
 }
index 29baf4e1ddb661c4a4a421e9c58e3b0a81e50afc..f71522d37148ad8b86217000570356f4b0540a2b 100644 (file)
@@ -75,7 +75,7 @@ pub fn is_empty(&self) -> bool {
     /// An iterator visiting all elements in arbitrary order.
     /// The iterator element type is `&'a T`.
     #[inline]
-    pub fn iter(&'a self) -> impl Iterator<Item = &'a T> {
+    pub fn iter(&self) -> impl Iterator<Item = &T> {
         self.into_iter()
     }
 
index 354f9dd93cc4d4e491f6a15feffcdbf491a837dd..2e992e762273c1c3b1fab6dd6a2ab2df273e7ee9 100644 (file)
@@ -229,14 +229,14 @@ fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) {
 
 impl<CTX> HashStable<CTX> for f32 {
     fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) {
-        let val: u32 = unsafe { ::std::mem::transmute(*self) };
+        let val: u32 = self.to_bits();
         val.hash_stable(ctx, hasher);
     }
 }
 
 impl<CTX> HashStable<CTX> for f64 {
     fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) {
-        let val: u64 = unsafe { ::std::mem::transmute(*self) };
+        let val: u64 = self.to_bits();
         val.hash_stable(ctx, hasher);
     }
 }
index a4964b7aa0cc8c95f72f9f90807beb89da952d98..ba22c7f9b979966627712c6cab0b2475e613f90f 100644 (file)
@@ -5,6 +5,7 @@
 
 // Only the first stack that is pushed, grows exponentially (2^n * STACK_PER_RECURSION) from then
 // on. This flag has performance relevant characteristics. Don't set it too high.
+#[allow(clippy::identity_op)]
 const STACK_PER_RECURSION: usize = 1 * 1024 * 1024; // 1MB
 
 /// Grows the stack on demand to prevent stack overflow. Call this in strategic locations
index a1ffbae8b15f6dd7d3c02264ade7a1c2faf2d24d..a3ece6550473cce4ce080bbdc5e28f15b69e1cc2 100644 (file)
@@ -34,7 +34,7 @@ pub fn new(value: T) -> Self {
     #[track_caller]
     pub fn borrow(&self) -> MappedReadGuard<'_, T> {
         let borrow = self.value.borrow();
-        if let None = &*borrow {
+        if borrow.is_none() {
             panic!("attempted to read from stolen value: {}", std::any::type_name::<T>());
         }
         ReadGuard::map(borrow, |opt| opt.as_ref().unwrap())
index 9b07f86846eb32089b26b5834dcdb72ab0b29e9e..9e605ea2d982c950b22d044a07d768718bc8b7b3 100644 (file)
@@ -48,7 +48,7 @@ pub fn remove(&mut self, data: &T) -> bool {
     #[inline]
     pub fn contains(&self, data: &T) -> bool {
         let mut elem = self.head.as_ref();
-        while let Some(ref e) = elem {
+        while let Some(e) = elem {
             if &e.data == data {
                 return true;
             }
index 1cf030d852e9fc8153388b6897a55da453bccf02..ce60d40b24b44e1087a5428c02d214c0379f8e89 100644 (file)
@@ -2,8 +2,8 @@
 
 pub fn iter<Ls>(
     first: Option<Ls::LinkIndex>,
-    links: &'a Ls,
-) -> impl Iterator<Item = Ls::LinkIndex> + 'a
+    links: &Ls,
+) -> impl Iterator<Item = Ls::LinkIndex> + '_
 where
     Ls: Links,
 {
index 27390fd2e4d9117b784b786a7c466bdffb1d79eb..e69289b71f97f9feee16f51ad18f61fe67a01477 100644 (file)
@@ -512,7 +512,7 @@ fn escape_str(s: &str) -> String {
     pub fn to_dot_string(&self) -> String {
         match *self {
             LabelStr(ref s) => format!("\"{}\"", s.escape_default()),
-            EscStr(ref s) => format!("\"{}\"", LabelText::escape_str(&s)),
+            EscStr(ref s) => format!("\"{}\"", LabelText::escape_str(s)),
             HtmlStr(ref s) => format!("<{}>", s),
         }
     }
index 5b1add4cfc6117c65baf25e3da754f4699c237a8..d3c7a390cd5b2de1afe9eedb16576190ce950cb3 100644 (file)
@@ -991,8 +991,8 @@ pub fn insert_all_into_row(&mut self, row: R) {
         assert!(row.index() < self.num_rows);
         let (start, end) = self.range(row);
         let words = &mut self.words[..];
-        for index in start..end {
-            words[index] = !0;
+        for word in words[start..end].iter_mut() {
+            *word = !0;
         }
         self.clear_excess_bits(row);
     }
@@ -1144,7 +1144,7 @@ pub fn rows(&self) -> impl Iterator<Item = R> {
 
     /// Iterates through all the columns set to true in a given row of
     /// the matrix.
-    pub fn iter<'a>(&'a self, row: R) -> impl Iterator<Item = C> + 'a {
+    pub fn iter(&self, row: R) -> impl Iterator<Item = C> + '_ {
         self.row(row).into_iter().flat_map(|r| r.iter())
     }
 
index 8831524683432352848f7fb692d97d86323fc585..e9efa2f255d1413dbde14cc5bf29ab2db87a9b12 100644 (file)
@@ -634,18 +634,15 @@ pub fn iter_enumerated_mut(
     }
 
     #[inline]
-    pub fn drain<'a, R: RangeBounds<usize>>(
-        &'a mut self,
-        range: R,
-    ) -> impl Iterator<Item = T> + 'a {
+    pub fn drain<R: RangeBounds<usize>>(&mut self, range: R) -> impl Iterator<Item = T> + '_ {
         self.raw.drain(range)
     }
 
     #[inline]
-    pub fn drain_enumerated<'a, R: RangeBounds<usize>>(
-        &'a mut self,
+    pub fn drain_enumerated<R: RangeBounds<usize>>(
+        &mut self,
         range: R,
-    ) -> impl Iterator<Item = (I, T)> + 'a {
+    ) -> impl Iterator<Item = (I, T)> + '_ {
         self.raw.drain(range).enumerate().map(|(n, t)| (I::new(n), t))
     }
 
index b970c9e4911fafb36ff0612c0e30fb417d46437f..804dc657f2d473b624610de24a648fe9c556e186 100644 (file)
@@ -68,11 +68,10 @@ pub enum EscapeError {
 impl EscapeError {
     /// Returns true for actual errors, as opposed to warnings.
     pub fn is_fatal(&self) -> bool {
-        match self {
-            EscapeError::UnskippedWhitespaceWarning => false,
-            EscapeError::MultipleSkippedLinesWarning => false,
-            _ => true,
-        }
+        !matches!(
+            self,
+            EscapeError::UnskippedWhitespaceWarning | EscapeError::MultipleSkippedLinesWarning
+        )
     }
 }
 
@@ -330,7 +329,7 @@ fn skip_ascii_whitespace<F>(chars: &mut Chars<'_>, start: usize, callback: &mut
             callback(start..end, Err(EscapeError::MultipleSkippedLinesWarning));
         }
         let tail = &tail[first_non_space..];
-        if let Some(c) = tail.chars().nth(0) {
+        if let Some(c) = tail.chars().next() {
             // For error reporting, we would like the span to contain the character that was not
             // skipped.  The +1 is necessary to account for the leading \ that started the escape.
             let end = start + first_non_space + c.len_utf8() + 1;
index dba885a27fe229f3c73176568cb4891135acf097..63bdcea87f8170a97df6b45df4f8bc8d8032e910 100644 (file)
@@ -24,11 +24,9 @@ fn parse_attributes(field: &syn::Field) -> Attributes {
                         }
                         if meta.path().is_ident("project") {
                             if let Meta::List(list) = meta {
-                                if let Some(nested) = list.nested.iter().next() {
-                                    if let NestedMeta::Meta(meta) = nested {
-                                        attrs.project = meta.path().get_ident().cloned();
-                                        any_attr = true;
-                                    }
+                                if let Some(NestedMeta::Meta(meta)) = list.nested.iter().next() {
+                                    attrs.project = meta.path().get_ident().cloned();
+                                    any_attr = true;
                                 }
                             }
                         }
index 80dcf99da6224b775936e1b1d746e89a640987c1..c8959dc86ad2d87b3fd0c67a81389d211cf758de 100644 (file)
@@ -349,14 +349,14 @@ fn generate_field_code(
     ) -> Result<proc_macro2::TokenStream, SessionDiagnosticDeriveError> {
         let field_binding = &info.binding.binding;
 
-        let option_ty = option_inner_ty(&info.ty);
+        let option_ty = option_inner_ty(info.ty);
 
         let generated_code = self.generate_non_option_field_code(
             attr,
             FieldInfo {
                 vis: info.vis,
                 binding: info.binding,
-                ty: option_ty.unwrap_or(&info.ty),
+                ty: option_ty.unwrap_or(info.ty),
                 span: info.span,
             },
         )?;
@@ -388,7 +388,7 @@ fn generate_non_option_field_code(
                 let formatted_str = self.build_format(&s.value(), attr.span());
                 match name {
                     "message" => {
-                        if type_matches_path(&info.ty, &["rustc_span", "Span"]) {
+                        if type_matches_path(info.ty, &["rustc_span", "Span"]) {
                             quote! {
                                 #diag.set_span(*#field_binding);
                                 #diag.set_primary_message(#formatted_str);
@@ -401,7 +401,7 @@ fn generate_non_option_field_code(
                         }
                     }
                     "label" => {
-                        if type_matches_path(&info.ty, &["rustc_span", "Span"]) {
+                        if type_matches_path(info.ty, &["rustc_span", "Span"]) {
                             quote! {
                                 #diag.span_label(*#field_binding, #formatted_str);
                             }
index e32e4493726dbb7d279c66e1451a10d99ccfc41b..6671c7c0fa60ca18d15472ef72157f6b54a86a9f 100644 (file)
@@ -500,8 +500,8 @@ fn encode(&self, s: &mut S) -> Result<(), S::Error> {
         d.read_seq(|d, len| {
             assert!(len == N);
             let mut v = [0u8; N];
-            for i in 0..len {
-                v[i] = d.read_seq_elt(|d| Decodable::decode(d))?;
+            for x in &mut v {
+                *x = d.read_seq_elt(|d| Decodable::decode(d))?;
             }
             Ok(v)
         })
index 578288bda259545d199e7586609855d232ff997d..8cff266642fef674f715e6f8f6cafd99df4dac92 100644 (file)
@@ -31,8 +31,10 @@ pub fn len(&self) -> usize {
                     } else {
                         3
                     }
+                } else if v < 10_000 {
+                    4
                 } else {
-                    if v < 10_000 { 4 } else { 5 }
+                    5
                 }
             }
             Part::Copy(buf) => buf.len(),