Skip to content

Commit 4a14677

Browse files
committedSep 23, 2022
Auto merge of #102192 - matthiaskrgr:rollup-0ctjzco, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - #102094 (Add missing documentation for `bool::from_str`) - #102115 (Add examples to `bool::then` and `bool::then_some`) - #102134 (Detect panic strategy using `rustc --print cfg`) - #102137 (Don't convert valtree to constvalue during normalization) - #102148 (add regression test for miri issue 2433) - #102158 (rustdoc: clean up CSS/DOM for deprecation warnings) - #102177 (Fix a typo in `std`'s root docs) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 9a963e3 + dfe045a commit 4a14677

File tree

69 files changed

+98
-166
lines changed

Some content is hidden

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

69 files changed

+98
-166
lines changed
 

‎compiler/rustc_trait_selection/src/traits/query/normalize.rs

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -351,25 +351,7 @@ impl<'cx, 'tcx> FallibleTypeFolder<'tcx> for QueryNormalizer<'cx, 'tcx> {
351351
&mut self,
352352
constant: mir::ConstantKind<'tcx>,
353353
) -> Result<mir::ConstantKind<'tcx>, Self::Error> {
354-
Ok(match constant {
355-
mir::ConstantKind::Ty(c) => {
356-
let const_folded = c.try_super_fold_with(self)?;
357-
match const_folded.kind() {
358-
ty::ConstKind::Value(valtree) => {
359-
let tcx = self.infcx.tcx;
360-
let ty = const_folded.ty();
361-
let const_val = tcx.valtree_to_const_val((ty, valtree));
362-
debug!(?ty, ?valtree, ?const_val);
363-
364-
mir::ConstantKind::Val(const_val, ty)
365-
}
366-
_ => mir::ConstantKind::Ty(const_folded),
367-
}
368-
}
369-
mir::ConstantKind::Val(_, _) | mir::ConstantKind::Unevaluated(..) => {
370-
constant.try_super_fold_with(self)?
371-
}
372-
})
354+
constant.try_super_fold_with(self)
373355
}
374356

375357
#[inline]

‎library/core/src/bool.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@ impl bool {
1818
/// assert_eq!(false.then_some(0), None);
1919
/// assert_eq!(true.then_some(0), Some(0));
2020
/// ```
21+
///
22+
/// ```
23+
/// let mut a = 0;
24+
/// let mut function_with_side_effects = || { a += 1; };
25+
///
26+
/// true.then_some(function_with_side_effects());
27+
/// false.then_some(function_with_side_effects());
28+
///
29+
/// // `a` is incremented twice because the value passed to `then_some` is
30+
/// // evaluated eagerly.
31+
/// assert_eq!(a, 2);
32+
/// ```
2133
#[stable(feature = "bool_to_option", since = "1.62.0")]
2234
#[rustc_const_unstable(feature = "const_bool_to_option", issue = "91917")]
2335
#[inline]
@@ -37,6 +49,17 @@ impl bool {
3749
/// assert_eq!(false.then(|| 0), None);
3850
/// assert_eq!(true.then(|| 0), Some(0));
3951
/// ```
52+
///
53+
/// ```
54+
/// let mut a = 0;
55+
///
56+
/// true.then(|| { a += 1; });
57+
/// false.then(|| { a += 1; });
58+
///
59+
/// // `a` is incremented once because the closure is evaluated lazily by
60+
/// // `then`.
61+
/// assert_eq!(a, 1);
62+
/// ```
4063
#[stable(feature = "lazy_bool_to_option", since = "1.50.0")]
4164
#[rustc_const_unstable(feature = "const_bool_to_option", issue = "91917")]
4265
#[inline]

0 commit comments

Comments
 (0)
Please sign in to comment.