Skip to content

Commit 8ca3e59

Browse files
authored
Rollup merge of #69650 - matthiaskrgr:clnp, r=varkor
cleanup more iterator usages (and other things) * Improve weird formatting by moving comment inside else-code block. * Use .any(x) instead of .find(x).is_some() on iterators. * Use .nth(x) instead of .skip(x).next() on iterators. * Simplify conditions like x + 1 <= y to x < y * Use let instead of match to get value of enum with single variant.
2 parents 2cfab73 + 1018385 commit 8ca3e59

File tree

8 files changed

+16
-27
lines changed

8 files changed

+16
-27
lines changed

src/liballoc/collections/btree/node.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1191,7 +1191,7 @@ impl<'a, K, V> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Internal>, marker::
11911191
let right_len = right_node.len();
11921192

11931193
// necessary for correctness, but in a private module
1194-
assert!(left_len + right_len + 1 <= CAPACITY);
1194+
assert!(left_len + right_len < CAPACITY);
11951195

11961196
unsafe {
11971197
ptr::write(

src/librustc/mir/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ impl<'tcx> Body<'tcx> {
189189
) -> Self {
190190
// We need `arg_count` locals, and one for the return place.
191191
assert!(
192-
local_decls.len() >= arg_count + 1,
192+
local_decls.len() > arg_count,
193193
"expected at least {} locals, got {}",
194194
arg_count + 1,
195195
local_decls.len()

src/librustc_codegen_ssa/back/link.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ pub fn get_linker(sess: &Session, linker: &Path, flavor: LinkerFlavor) -> (PathB
186186
if flavor == LinkerFlavor::Msvc && t.target_vendor == "uwp" {
187187
if let Some(ref tool) = msvc_tool {
188188
let original_path = tool.path();
189-
if let Some(ref root_lib_path) = original_path.ancestors().skip(4).next() {
189+
if let Some(ref root_lib_path) = original_path.ancestors().nth(4) {
190190
let arch = match t.arch.as_str() {
191191
"x86_64" => Some("x64".to_string()),
192192
"x86" => Some("x86".to_string()),

src/librustc_expand/mbe/transcribe.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,9 @@ pub(super) fn transcribe(
119119
let tree = if let Some(tree) = stack.last_mut().unwrap().next() {
120120
// If it still has a TokenTree we have not looked at yet, use that tree.
121121
tree
122-
}
123-
// The else-case never produces a value for `tree` (it `continue`s or `return`s).
124-
else {
122+
} else {
123+
// This else-case never produces a value for `tree` (it `continue`s or `return`s).
124+
125125
// Otherwise, if we have just reached the end of a sequence and we can keep repeating,
126126
// go back to the beginning of the sequence.
127127
if let Frame::Sequence { idx, sep, .. } = stack.last_mut().unwrap() {

src/librustc_infer/traits/error_reporting/suggestions.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -401,9 +401,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
401401
if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(span) {
402402
let refs_number =
403403
snippet.chars().filter(|c| !c.is_whitespace()).take_while(|c| *c == '&').count();
404-
if let Some('\'') =
405-
snippet.chars().filter(|c| !c.is_whitespace()).skip(refs_number).next()
406-
{
404+
if let Some('\'') = snippet.chars().filter(|c| !c.is_whitespace()).nth(refs_number) {
407405
// Do not suggest removal of borrow from type arguments.
408406
return;
409407
}
@@ -464,9 +462,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
464462
if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(span) {
465463
let refs_number =
466464
snippet.chars().filter(|c| !c.is_whitespace()).take_while(|c| *c == '&').count();
467-
if let Some('\'') =
468-
snippet.chars().filter(|c| !c.is_whitespace()).skip(refs_number).next()
469-
{
465+
if let Some('\'') = snippet.chars().filter(|c| !c.is_whitespace()).nth(refs_number) {
470466
// Do not suggest removal of borrow from type arguments.
471467
return;
472468
}

src/librustc_mir/monomorphize/collector.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -824,11 +824,8 @@ fn find_vtable_types_for_unsizing<'tcx>(
824824
(&ty::Adt(source_adt_def, source_substs), &ty::Adt(target_adt_def, target_substs)) => {
825825
assert_eq!(source_adt_def, target_adt_def);
826826

827-
let kind = monomorphize::custom_coerce_unsize_info(tcx, source_ty, target_ty);
828-
829-
let coerce_index = match kind {
830-
CustomCoerceUnsized::Struct(i) => i,
831-
};
827+
let CustomCoerceUnsized::Struct(coerce_index) =
828+
monomorphize::custom_coerce_unsize_info(tcx, source_ty, target_ty);
832829

833830
let source_fields = &source_adt_def.non_enum_variant().fields;
834831
let target_fields = &target_adt_def.non_enum_variant().fields;

src/librustc_typeck/check/demand.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
236236
//
237237
// FIXME? Other potential candidate methods: `as_ref` and
238238
// `as_mut`?
239-
.find(|a| a.check_name(sym::rustc_conversion_suggestion))
240-
.is_some()
239+
.any(|a| a.check_name(sym::rustc_conversion_suggestion))
241240
});
242241

243242
methods

src/librustc_typeck/coherence/inherent_impls_overlap.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,11 @@ impl InherentOverlapChecker<'tcx> {
2323
let impl_items2 = self.tcx.associated_items(impl2);
2424

2525
for item1 in impl_items1.in_definition_order() {
26-
let collision = impl_items2
27-
.filter_by_name_unhygienic(item1.ident.name)
28-
.find(|item2| {
29-
// Symbols and namespace match, compare hygienically.
30-
item1.kind.namespace() == item2.kind.namespace()
31-
&& item1.ident.modern() == item2.ident.modern()
32-
})
33-
.is_some();
26+
let collision = impl_items2.filter_by_name_unhygienic(item1.ident.name).any(|item2| {
27+
// Symbols and namespace match, compare hygienically.
28+
item1.kind.namespace() == item2.kind.namespace()
29+
&& item1.ident.modern() == item2.ident.modern()
30+
});
3431

3532
if collision {
3633
return true;

0 commit comments

Comments
 (0)