Skip to content

Commit a85e949

Browse files
committed
Auto merge of #78106 - GuillaumeGomez:rollup-06vwk7p, r=GuillaumeGomez
Rollup of 4 pull requests Successful merges: - #77877 (Use `try{}` in `try_fold` to decouple iterators in the library from `Try` details) - #78089 (Fix issue with specifying generic arguments for primitive types) - #78099 (Add missing punctuation) - #78103 (Add link to rustdoc book in rustdoc help popup) Failed merges: r? `@ghost`
2 parents f90e617 + cbcf8d4 commit a85e949

File tree

18 files changed

+90
-47
lines changed

18 files changed

+90
-47
lines changed

compiler/rustc_typeck/src/collect/type_of.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,16 @@ pub(super) fn opt_const_param_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<
112112
tcx.sess.delay_span_bug(tcx.def_span(def_id), "anon const with Res::Err");
113113
return None;
114114
}
115-
_ => span_bug!(
116-
DUMMY_SP,
117-
"unexpected anon const res {:?} in path: {:?}",
118-
res,
119-
path,
120-
),
115+
_ => {
116+
// If the user tries to specify generics on a type that does not take them,
117+
// e.g. `usize<T>`, we may hit this branch, in which case we treat it as if
118+
// no arguments have been passed. An error should already have been emitted.
119+
tcx.sess.delay_span_bug(
120+
tcx.def_span(def_id),
121+
&format!("unexpected anon const res {:?} in path: {:?}", res, path),
122+
);
123+
return None;
124+
}
121125
};
122126

123127
generics

library/core/src/iter/adapters/chain.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ where
109109
acc = b.try_fold(acc, f)?;
110110
// we don't fuse the second iterator
111111
}
112-
Try::from_ok(acc)
112+
try { acc }
113113
}
114114

115115
fn fold<Acc, F>(self, mut acc: Acc, mut f: F) -> Acc
@@ -292,7 +292,7 @@ where
292292
acc = a.try_rfold(acc, f)?;
293293
// we don't fuse the second iterator
294294
}
295-
Try::from_ok(acc)
295+
try { acc }
296296
}
297297

298298
fn rfold<Acc, F>(self, mut acc: Acc, mut f: F) -> Acc

library/core/src/iter/adapters/flatten.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ where
317317
}
318318
self.backiter = None;
319319

320-
Try::from_ok(init)
320+
try { init }
321321
}
322322

323323
#[inline]
@@ -397,7 +397,7 @@ where
397397
}
398398
self.frontiter = None;
399399

400-
Try::from_ok(init)
400+
try { init }
401401
}
402402

403403
#[inline]

library/core/src/iter/adapters/fuse.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ where
303303
acc = iter.try_fold(acc, fold)?;
304304
self.iter = None;
305305
}
306-
Try::from_ok(acc)
306+
try { acc }
307307
}
308308

309309
#[inline]
@@ -353,7 +353,7 @@ where
353353
acc = iter.try_rfold(acc, fold)?;
354354
self.iter = None;
355355
}
356-
Try::from_ok(acc)
356+
try { acc }
357357
}
358358

359359
#[inline]

library/core/src/iter/adapters/mod.rs

+18-22
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ where
579579
})?;
580580

581581
if is_empty {
582-
return Try::from_ok(acc);
582+
return try { acc };
583583
}
584584

585585
loop {
@@ -715,7 +715,7 @@ where
715715
if self.first_take {
716716
self.first_take = false;
717717
match self.iter.next() {
718-
None => return Try::from_ok(acc),
718+
None => return try { acc },
719719
Some(x) => acc = f(acc, x)?,
720720
}
721721
}
@@ -792,7 +792,7 @@ where
792792
}
793793

794794
match self.next_back() {
795-
None => Try::from_ok(init),
795+
None => try { init },
796796
Some(x) => {
797797
let acc = f(init, x)?;
798798
from_fn(nth_back(&mut self.iter, self.step)).try_fold(acc, f)
@@ -1075,7 +1075,7 @@ fn filter_try_fold<'a, T, Acc, R: Try<Ok = Acc>>(
10751075
predicate: &'a mut impl FnMut(&T) -> bool,
10761076
mut fold: impl FnMut(Acc, T) -> R + 'a,
10771077
) -> impl FnMut(Acc, T) -> R + 'a {
1078-
move |acc, item| if predicate(&item) { fold(acc, item) } else { R::from_ok(acc) }
1078+
move |acc, item| if predicate(&item) { fold(acc, item) } else { try { acc } }
10791079
}
10801080

10811081
#[stable(feature = "rust1", since = "1.0.0")]
@@ -1229,7 +1229,7 @@ fn filter_map_try_fold<'a, T, B, Acc, R: Try<Ok = Acc>>(
12291229
) -> impl FnMut(Acc, T) -> R + 'a {
12301230
move |acc, item| match f(item) {
12311231
Some(x) => fold(acc, x),
1232-
None => R::from_ok(acc),
1232+
None => try { acc },
12331233
}
12341234
}
12351235

@@ -1660,7 +1660,7 @@ impl<I: Iterator> Iterator for Peekable<I> {
16601660
R: Try<Ok = B>,
16611661
{
16621662
let acc = match self.peeked.take() {
1663-
Some(None) => return Try::from_ok(init),
1663+
Some(None) => return try { init },
16641664
Some(Some(v)) => f(init, v)?,
16651665
None => init,
16661666
};
@@ -1703,7 +1703,7 @@ where
17031703
R: Try<Ok = B>,
17041704
{
17051705
match self.peeked.take() {
1706-
Some(None) => Try::from_ok(init),
1706+
Some(None) => try { init },
17071707
Some(Some(v)) => match self.iter.try_rfold(init, &mut f).into_result() {
17081708
Ok(acc) => f(acc, v),
17091709
Err(e) => {
@@ -1938,7 +1938,7 @@ where
19381938
if !self.flag {
19391939
match self.next() {
19401940
Some(v) => init = fold(init, v)?,
1941-
None => return Try::from_ok(init),
1941+
None => return try { init },
19421942
}
19431943
}
19441944
self.iter.try_fold(init, fold)
@@ -2065,13 +2065,13 @@ where
20652065
ControlFlow::from_try(fold(acc, x))
20662066
} else {
20672067
*flag = true;
2068-
ControlFlow::Break(Try::from_ok(acc))
2068+
ControlFlow::Break(try { acc })
20692069
}
20702070
}
20712071
}
20722072

20732073
if self.flag {
2074-
Try::from_ok(init)
2074+
try { init }
20752075
} else {
20762076
let flag = &mut self.flag;
20772077
let p = &mut self.predicate;
@@ -2180,7 +2180,7 @@ where
21802180
let Self { iter, predicate } = self;
21812181
iter.try_fold(init, |acc, x| match predicate(x) {
21822182
Some(item) => ControlFlow::from_try(fold(acc, item)),
2183-
None => ControlFlow::Break(Try::from_ok(acc)),
2183+
None => ControlFlow::Break(try { acc }),
21842184
})
21852185
.into_try()
21862186
}
@@ -2316,7 +2316,7 @@ where
23162316
if n > 0 {
23172317
// nth(n) skips n+1
23182318
if self.iter.nth(n - 1).is_none() {
2319-
return Try::from_ok(init);
2319+
return try { init };
23202320
}
23212321
}
23222322
self.iter.try_fold(init, fold)
@@ -2381,11 +2381,7 @@ where
23812381
}
23822382

23832383
let n = self.len();
2384-
if n == 0 {
2385-
Try::from_ok(init)
2386-
} else {
2387-
self.iter.try_rfold(init, check(n, fold)).into_try()
2388-
}
2384+
if n == 0 { try { init } } else { self.iter.try_rfold(init, check(n, fold)).into_try() }
23892385
}
23902386

23912387
fn rfold<Acc, Fold>(mut self, init: Acc, fold: Fold) -> Acc
@@ -2509,7 +2505,7 @@ where
25092505
}
25102506

25112507
if self.n == 0 {
2512-
Try::from_ok(init)
2508+
try { init }
25132509
} else {
25142510
let n = &mut self.n;
25152511
self.iter.try_fold(init, check(n, fold)).into_try()
@@ -2587,11 +2583,11 @@ where
25872583
R: Try<Ok = Acc>,
25882584
{
25892585
if self.n == 0 {
2590-
Try::from_ok(init)
2586+
try { init }
25912587
} else {
25922588
let len = self.iter.len();
25932589
if len > self.n && self.iter.nth_back(len - self.n - 1).is_none() {
2594-
Try::from_ok(init)
2590+
try { init }
25952591
} else {
25962592
self.iter.try_rfold(init, fold)
25972593
}
@@ -2687,7 +2683,7 @@ where
26872683
mut fold: impl FnMut(Acc, B) -> R + 'a,
26882684
) -> impl FnMut(Acc, T) -> ControlFlow<Acc, R> + 'a {
26892685
move |acc, x| match f(state, x) {
2690-
None => ControlFlow::Break(Try::from_ok(acc)),
2686+
None => ControlFlow::Break(try { acc }),
26912687
Some(x) => ControlFlow::from_try(fold(acc, x)),
26922688
}
26932689
}
@@ -2951,7 +2947,7 @@ where
29512947
Ok(x) => ControlFlow::from_try(f(acc, x)),
29522948
Err(e) => {
29532949
*error = Err(e);
2954-
ControlFlow::Break(Try::from_ok(acc))
2950+
ControlFlow::Break(try { acc })
29552951
}
29562952
})
29572953
.into_try()

library/core/src/iter/range.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ impl<A: Step> Iterator for ops::RangeInclusive<A> {
713713
R: Try<Ok = B>,
714714
{
715715
if self.is_empty() {
716-
return Try::from_ok(init);
716+
return try { init };
717717
}
718718

719719
let mut accum = init;
@@ -731,7 +731,7 @@ impl<A: Step> Iterator for ops::RangeInclusive<A> {
731731
accum = f(accum, self.start.clone())?;
732732
}
733733

734-
Try::from_ok(accum)
734+
try { accum }
735735
}
736736

737737
#[inline]
@@ -818,7 +818,7 @@ impl<A: Step> DoubleEndedIterator for ops::RangeInclusive<A> {
818818
R: Try<Ok = B>,
819819
{
820820
if self.is_empty() {
821-
return Try::from_ok(init);
821+
return try { init };
822822
}
823823

824824
let mut accum = init;
@@ -836,7 +836,7 @@ impl<A: Step> DoubleEndedIterator for ops::RangeInclusive<A> {
836836
accum = f(accum, self.start.clone())?;
837837
}
838838

839-
Try::from_ok(accum)
839+
try { accum }
840840
}
841841

842842
#[inline]

library/core/src/iter/traits/double_ended.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ pub trait DoubleEndedIterator: Iterator {
224224
while let Some(x) = self.next_back() {
225225
accum = f(accum, x)?;
226226
}
227-
Try::from_ok(accum)
227+
try { accum }
228228
}
229229

230230
/// An iterator method that reduces the iterator's elements to a single,

library/core/src/iter/traits/iterator.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1887,7 +1887,7 @@ pub trait Iterator {
18871887
while let Some(x) = self.next() {
18881888
accum = f(accum, x)?;
18891889
}
1890-
Try::from_ok(accum)
1890+
try { accum }
18911891
}
18921892

18931893
/// An iterator method that applies a fallible function to each item in the

library/core/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@
129129
#![feature(str_split_as_str)]
130130
#![feature(str_split_inclusive_as_str)]
131131
#![feature(transparent_unions)]
132+
#![feature(try_blocks)]
132133
#![feature(unboxed_closures)]
133134
#![feature(unsized_locals)]
134135
#![cfg_attr(bootstrap, feature(untagged_unions))]

library/std/src/process.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1184,7 +1184,7 @@ impl Stdio {
11841184
}
11851185

11861186
/// This stream will be ignored. This is the equivalent of attaching the
1187-
/// stream to `/dev/null`
1187+
/// stream to `/dev/null`.
11881188
///
11891189
/// # Examples
11901190
///

src/librustdoc/html/static/main.js

+5
Original file line numberDiff line numberDiff line change
@@ -2792,6 +2792,10 @@ function defocusSearchBar() {
27922792
addClass(popup, "hidden");
27932793
popup.id = "help";
27942794

2795+
var book_info = document.createElement("span");
2796+
book_info.innerHTML = "You can find more information in \
2797+
<a href=\"https://doc.rust-lang.org/rustdoc/\">the rustdoc book</a>.";
2798+
27952799
var container = document.createElement("div");
27962800
var shortcuts = [
27972801
["?", "Show this help dialog"],
@@ -2825,6 +2829,7 @@ function defocusSearchBar() {
28252829
addClass(div_infos, "infos");
28262830
div_infos.innerHTML = "<h2>Search Tricks</h2>" + infos;
28272831

2832+
container.appendChild(book_info);
28282833
container.appendChild(div_shortcuts);
28292834
container.appendChild(div_infos);
28302835

src/librustdoc/html/static/rustdoc.css

+10-2
Original file line numberDiff line numberDiff line change
@@ -796,14 +796,22 @@ body.blur > :not(#help) {
796796
clear: left;
797797
display: block;
798798
}
799+
#help > div > span {
800+
text-align: center;
801+
display: block;
802+
margin: 10px 0;
803+
font-size: 18px;
804+
border-bottom: 1px solid #ccc;
805+
padding-bottom: 4px;
806+
margin-bottom: 6px;
807+
}
799808
#help dd { margin: 5px 35px; }
800809
#help .infos { padding-left: 0; }
801810
#help h1, #help h2 { margin-top: 0; }
802811
#help > div div {
803812
width: 50%;
804813
float: left;
805-
padding: 20px;
806-
padding-left: 17px;
814+
padding: 0 20px 20px 17px;;
807815
}
808816

809817
.stab {

src/librustdoc/html/static/themes/ayu.css

+6-1
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,8 @@ a {
219219
}
220220

221221
.docblock:not(.type-decl) a:not(.srclink):not(.test-arrow),
222-
.docblock-short a:not(.srclink):not(.test-arrow), .stability a {
222+
.docblock-short a:not(.srclink):not(.test-arrow), .stability a,
223+
#help a {
223224
color: #39AFD7;
224225
}
225226

@@ -275,6 +276,10 @@ a {
275276
border-radius: 4px;
276277
}
277278

279+
#help > div > span {
280+
border-bottom-color: #5c6773;
281+
}
282+
278283
.since {
279284
color: grey;
280285
}

src/librustdoc/html/static/themes/dark.css

+6-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,8 @@ a {
177177
}
178178

179179
.docblock:not(.type-decl) a:not(.srclink):not(.test-arrow),
180-
.docblock-short a:not(.srclink):not(.test-arrow), .stability a {
180+
.docblock-short a:not(.srclink):not(.test-arrow), .stability a,
181+
#help a {
181182
color: #D2991D;
182183
}
183184

@@ -231,6 +232,10 @@ a.test-arrow {
231232
border-color: #bfbfbf;
232233
}
233234

235+
#help > div > span {
236+
border-bottom-color: #bfbfbf;
237+
}
238+
234239
#help dt {
235240
border-color: #bfbfbf;
236241
background: rgba(0,0,0,0);

0 commit comments

Comments
 (0)