Skip to content

Commit 0b36e9d

Browse files
committed
Auto merge of #64313 - Centril:rollup-7w8b67g, r=Centril
Rollup of 5 pull requests Successful merges: - #63468 (Resolve attributes in several places) - #64121 (Override `StepBy::{try_fold, try_rfold}`) - #64278 (check git in bootstrap.py) - #64306 (Fix typo in config.toml.example) - #64312 (Unify escape usage) Failed merges: r? @ghost
2 parents 45859b7 + f7ee130 commit 0b36e9d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1213
-509
lines changed

config.toml.example

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@
184184
# default.
185185
#extended = false
186186

187-
# Installs chosen set of extended tools if enables. By default builds all.
187+
# Installs chosen set of extended tools if enabled. By default builds all.
188188
# If chosen tool failed to build the installation fails.
189189
#tools = ["cargo", "rls", "clippy", "rustfmt", "analysis", "src"]
190190

src/bootstrap/bootstrap.py

+8
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,14 @@ def update_submodules(self):
708708
if (not os.path.exists(os.path.join(self.rust_root, ".git"))) or \
709709
self.get_toml('submodules') == "false":
710710
return
711+
712+
# check the existence of 'git' command
713+
try:
714+
subprocess.check_output(['git', '--version'])
715+
except (subprocess.CalledProcessError, OSError):
716+
print("error: `git` is not found, please make sure it's installed and in the path.")
717+
sys.exit(1)
718+
711719
slow_submodules = self.get_toml('fast-submodules') == "false"
712720
start_time = time()
713721
if slow_submodules:

src/libcore/iter/adapters/mod.rs

+43-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::usize;
55
use crate::intrinsics;
66

77
use super::{Iterator, DoubleEndedIterator, ExactSizeIterator, FusedIterator, TrustedLen};
8-
use super::LoopState;
8+
use super::{LoopState, from_fn};
99

1010
mod chain;
1111
mod flatten;
@@ -534,6 +534,26 @@ impl<I> Iterator for StepBy<I> where I: Iterator {
534534
self.iter.nth(nth - 1);
535535
}
536536
}
537+
538+
fn try_fold<Acc, F, R>(&mut self, mut acc: Acc, mut f: F) -> R
539+
where
540+
F: FnMut(Acc, Self::Item) -> R,
541+
R: Try<Ok = Acc>,
542+
{
543+
#[inline]
544+
fn nth<I: Iterator>(iter: &mut I, step: usize) -> impl FnMut() -> Option<I::Item> + '_ {
545+
move || iter.nth(step)
546+
}
547+
548+
if self.first_take {
549+
self.first_take = false;
550+
match self.iter.next() {
551+
None => return Try::from_ok(acc),
552+
Some(x) => acc = f(acc, x)?,
553+
}
554+
}
555+
from_fn(nth(&mut self.iter, self.step)).try_fold(acc, f)
556+
}
537557
}
538558

539559
impl<I> StepBy<I> where I: ExactSizeIterator {
@@ -567,6 +587,28 @@ impl<I> DoubleEndedIterator for StepBy<I> where I: DoubleEndedIterator + ExactSi
567587
.saturating_add(self.next_back_index());
568588
self.iter.nth_back(n)
569589
}
590+
591+
fn try_rfold<Acc, F, R>(&mut self, init: Acc, mut f: F) -> R
592+
where
593+
F: FnMut(Acc, Self::Item) -> R,
594+
R: Try<Ok = Acc>,
595+
{
596+
#[inline]
597+
fn nth_back<I: DoubleEndedIterator>(
598+
iter: &mut I,
599+
step: usize,
600+
) -> impl FnMut() -> Option<I::Item> + '_ {
601+
move || iter.nth_back(step)
602+
}
603+
604+
match self.next_back() {
605+
None => Try::from_ok(init),
606+
Some(x) => {
607+
let acc = f(init, x)?;
608+
from_fn(nth_back(&mut self.iter, self.step)).try_fold(acc, f)
609+
}
610+
}
611+
}
570612
}
571613

572614
// StepBy can only make the iterator shorter, so the len will still fit.

src/libcore/tests/iter.rs

+35
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,23 @@ fn test_iterator_step_by_nth_overflow() {
385385
assert_eq!(it.0, (usize::MAX as Bigger) * 1);
386386
}
387387

388+
#[test]
389+
fn test_iterator_step_by_nth_try_fold() {
390+
let mut it = (0..).step_by(10);
391+
assert_eq!(it.try_fold(0, i8::checked_add), None);
392+
assert_eq!(it.next(), Some(60));
393+
assert_eq!(it.try_fold(0, i8::checked_add), None);
394+
assert_eq!(it.next(), Some(90));
395+
396+
let mut it = (100..).step_by(10);
397+
assert_eq!(it.try_fold(50, i8::checked_add), None);
398+
assert_eq!(it.next(), Some(110));
399+
400+
let mut it = (100..=100).step_by(10);
401+
assert_eq!(it.next(), Some(100));
402+
assert_eq!(it.try_fold(0, i8::checked_add), Some(0));
403+
}
404+
388405
#[test]
389406
fn test_iterator_step_by_nth_back() {
390407
let mut it = (0..16).step_by(5);
@@ -410,6 +427,24 @@ fn test_iterator_step_by_nth_back() {
410427
assert_eq!(it().nth_back(42), None);
411428
}
412429

430+
#[test]
431+
fn test_iterator_step_by_nth_try_rfold() {
432+
let mut it = (0..100).step_by(10);
433+
assert_eq!(it.try_rfold(0, i8::checked_add), None);
434+
assert_eq!(it.next_back(), Some(70));
435+
assert_eq!(it.next(), Some(0));
436+
assert_eq!(it.try_rfold(0, i8::checked_add), None);
437+
assert_eq!(it.next_back(), Some(30));
438+
439+
let mut it = (0..100).step_by(10);
440+
assert_eq!(it.try_rfold(50, i8::checked_add), None);
441+
assert_eq!(it.next_back(), Some(80));
442+
443+
let mut it = (100..=100).step_by(10);
444+
assert_eq!(it.next_back(), Some(100));
445+
assert_eq!(it.try_fold(0, i8::checked_add), Some(0));
446+
}
447+
413448
#[test]
414449
#[should_panic]
415450
fn test_iterator_step_by_zero() {

src/librustc/hir/map/def_collector.rs

+57-1
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
155155
}
156156

157157
fn visit_variant(&mut self, v: &'a Variant) {
158+
if v.is_placeholder {
159+
return self.visit_macro_invoc(v.id);
160+
}
158161
let def = self.create_def(v.id,
159162
DefPathData::TypeNs(v.ident.as_interned_str()),
160163
v.span);
@@ -168,16 +171,24 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
168171

169172
fn visit_variant_data(&mut self, data: &'a VariantData) {
170173
for (index, field) in data.fields().iter().enumerate() {
174+
if field.is_placeholder {
175+
self.visit_macro_invoc(field.id);
176+
continue;
177+
}
171178
let name = field.ident.map(|ident| ident.name)
172179
.unwrap_or_else(|| sym::integer(index));
173180
let def = self.create_def(field.id,
174181
DefPathData::ValueNs(name.as_interned_str()),
175182
field.span);
176-
self.with_parent(def, |this| this.visit_struct_field(field));
183+
self.with_parent(def, |this| visit::walk_struct_field(this, field));
177184
}
178185
}
179186

180187
fn visit_generic_param(&mut self, param: &'a GenericParam) {
188+
if param.is_placeholder {
189+
self.visit_macro_invoc(param.id);
190+
return;
191+
}
181192
let name = param.ident.as_interned_str();
182193
let def_path_data = match param.kind {
183194
GenericParamKind::Lifetime { .. } => DefPathData::LifetimeNs(name),
@@ -294,4 +305,49 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
294305
}
295306
}
296307
}
308+
309+
fn visit_arm(&mut self, arm: &'a Arm) {
310+
if arm.is_placeholder {
311+
self.visit_macro_invoc(arm.id)
312+
} else {
313+
visit::walk_arm(self, arm)
314+
}
315+
}
316+
317+
fn visit_field(&mut self, f: &'a Field) {
318+
if f.is_placeholder {
319+
self.visit_macro_invoc(f.id)
320+
} else {
321+
visit::walk_field(self, f)
322+
}
323+
}
324+
325+
fn visit_field_pattern(&mut self, fp: &'a FieldPat) {
326+
if fp.is_placeholder {
327+
self.visit_macro_invoc(fp.id)
328+
} else {
329+
visit::walk_field_pattern(self, fp)
330+
}
331+
}
332+
333+
fn visit_param(&mut self, p: &'a Param) {
334+
if p.is_placeholder {
335+
self.visit_macro_invoc(p.id)
336+
} else {
337+
visit::walk_param(self, p)
338+
}
339+
}
340+
341+
fn visit_struct_field(&mut self, sf: &'a StructField) {
342+
if sf.is_placeholder {
343+
self.visit_macro_invoc(sf.id)
344+
} else {
345+
let name = sf.ident.map(|ident| ident.name)
346+
.unwrap_or_else(|| panic!("don't know the field number in this context"));
347+
let def = self.create_def(sf.id,
348+
DefPathData::ValueNs(name.as_interned_str()),
349+
sf.span);
350+
self.with_parent(def, |this| visit::walk_struct_field(this, sf));
351+
}
352+
}
297353
}

0 commit comments

Comments
 (0)