]> git.lizzy.rs Git - rust.git/commitdiff
Rollup merge of #53636 - frewsxcv:frewsxcv-nth, r=rkruppe
authorkennytm <kennytm@gmail.com>
Fri, 24 Aug 2018 08:44:50 +0000 (16:44 +0800)
committerkennytm <kennytm@gmail.com>
Fri, 24 Aug 2018 11:24:44 +0000 (19:24 +0800)
Prefer `.nth(n)` over `.skip(n).next()`.

Found by clippy.

src/libcore/fmt/mod.rs
src/librustc_metadata/encoder.rs
src/librustc_typeck/check/mod.rs
src/test/run-pass-fulldeps/auxiliary/proc_macro_def.rs
src/test/run-pass/command-before-exec.rs

index 6493f5b39a7d736720256e5214194582c3b93e87..7d131b5c99dc09c66b9bf6af2c9adab0d6423f65 100644 (file)
@@ -1262,7 +1262,7 @@ pub fn pad(&mut self, s: &str) -> Result {
             // If our string is longer that the precision, then we must have
             // truncation. However other flags like `fill`, `width` and `align`
             // must act as always.
-            if let Some((i, _)) = s.char_indices().skip(max).next() {
+            if let Some((i, _)) = s.char_indices().nth(max) {
                 // LLVM here can't prove that `..i` won't panic `&s[..i]`, but
                 // we know that it can't panic. Use `get` + `unwrap_or` to avoid
                 // `unsafe` and otherwise don't emit any panic-related code
index 44d8d4a727769906b75d0430071a31d96fbcecf4..8219ec3df248aaebdbb096987fe6fae2cb5339d7 100644 (file)
@@ -1111,7 +1111,7 @@ fn encode_info_for_item(&mut self, (def_id, item): (DefId, &'tcx hir::Item)) ->
                 let trait_ref = tcx.impl_trait_ref(def_id);
                 let parent = if let Some(trait_ref) = trait_ref {
                     let trait_def = tcx.trait_def(trait_ref.def_id);
-                    trait_def.ancestors(tcx, def_id).skip(1).next().and_then(|node| {
+                    trait_def.ancestors(tcx, def_id).nth(1).and_then(|node| {
                         match node {
                             specialization_graph::Node::Impl(parent) => Some(parent),
                             _ => None,
index fd3cb1569689a1705572c8e46cd2e889afeaa29c..b2c324d260e64bcf7fe2dd8986650345de27b72e 100644 (file)
@@ -1434,7 +1434,7 @@ fn check_specialization_validity<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
         hir::ImplItemKind::Type(_) => ty::AssociatedKind::Type
     };
 
-    let parent = ancestors.defs(tcx, trait_item.ident, kind, trait_def.def_id).skip(1).next()
+    let parent = ancestors.defs(tcx, trait_item.ident, kind, trait_def.def_id).nth(1)
         .map(|node_item| node_item.map(|parent| parent.defaultness));
 
     if let Some(parent) = parent {
index 9faa7366ec5f19fba069c5db92945726f8487a1d..b9c565a9d3c23c590726725405e4f1bbf209aeff 100644 (file)
@@ -19,7 +19,7 @@
 
 #[proc_macro_attribute]
 pub fn attr_tru(_attr: TokenStream, item: TokenStream) -> TokenStream {
-    let name = item.into_iter().skip(1).next().unwrap();
+    let name = item.into_iter().nth(1).unwrap();
     quote!(fn $name() -> bool { true })
 }
 
index 9599f65da4eca31de48824d5b0bc58d469234ede..c4fc9ee53fd7fbde976b50d682d728cc48dbd5a5 100644 (file)
@@ -24,7 +24,7 @@
 use std::sync::atomic::{AtomicUsize, Ordering};
 
 fn main() {
-    if let Some(arg) = env::args().skip(1).next() {
+    if let Some(arg) = env::args().nth(1) {
         match &arg[..] {
             "test1" => println!("hello2"),
             "test2" => assert_eq!(env::var("FOO").unwrap(), "BAR"),