Rollup merge of #53636 - frewsxcv:frewsxcv-nth, r=rkruppe

Prefer `.nth(n)` over `.skip(n).next()`.

Found by clippy.
This commit is contained in:
kennytm 2018-08-24 16:44:50 +08:00
commit 9dfb95b11f
No known key found for this signature in database
GPG Key ID: FEF6C8051D0E013C
5 changed files with 5 additions and 5 deletions

View File

@ -1262,7 +1262,7 @@ impl<'a> Formatter<'a> {
// If our string is longer that the precision, then we must have // If our string is longer that the precision, then we must have
// truncation. However other flags like `fill`, `width` and `align` // truncation. However other flags like `fill`, `width` and `align`
// must act as always. // 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 // 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 // we know that it can't panic. Use `get` + `unwrap_or` to avoid
// `unsafe` and otherwise don't emit any panic-related code // `unsafe` and otherwise don't emit any panic-related code

View File

@ -1111,7 +1111,7 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
let trait_ref = tcx.impl_trait_ref(def_id); let trait_ref = tcx.impl_trait_ref(def_id);
let parent = if let Some(trait_ref) = trait_ref { let parent = if let Some(trait_ref) = trait_ref {
let trait_def = tcx.trait_def(trait_ref.def_id); 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 { match node {
specialization_graph::Node::Impl(parent) => Some(parent), specialization_graph::Node::Impl(parent) => Some(parent),
_ => None, _ => None,

View File

@ -1434,7 +1434,7 @@ fn check_specialization_validity<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
hir::ImplItemKind::Type(_) => ty::AssociatedKind::Type 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)); .map(|node_item| node_item.map(|parent| parent.defaultness));
if let Some(parent) = parent { if let Some(parent) = parent {

View File

@ -19,7 +19,7 @@ use proc_macro::*;
#[proc_macro_attribute] #[proc_macro_attribute]
pub fn attr_tru(_attr: TokenStream, item: TokenStream) -> TokenStream { 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 }) quote!(fn $name() -> bool { true })
} }

View File

@ -24,7 +24,7 @@ use std::sync::Arc;
use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::atomic::{AtomicUsize, Ordering};
fn main() { fn main() {
if let Some(arg) = env::args().skip(1).next() { if let Some(arg) = env::args().nth(1) {
match &arg[..] { match &arg[..] {
"test1" => println!("hello2"), "test1" => println!("hello2"),
"test2" => assert_eq!(env::var("FOO").unwrap(), "BAR"), "test2" => assert_eq!(env::var("FOO").unwrap(), "BAR"),