From 8751fa1a9abda9fc7ced6b03315efbd82310830d Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Wed, 15 Feb 2023 11:43:41 +0000 Subject: `if $c:expr { Some($r:expr) } else { None }` =>> `$c.then(|| $r)` --- compiler/rustc_hir/src/hir.rs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'compiler/rustc_hir/src') diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index 7cb3b6e1525..80ec1caf521 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -574,14 +574,11 @@ impl<'hir> Generics<'hir> { /// If there are generic parameters, return where to introduce a new one. pub fn span_for_param_suggestion(&self) -> Option { - if self.params.iter().any(|p| self.span.contains(p.span)) { + self.params.iter().any(|p| self.span.contains(p.span)).then(|| { // `fn foo(t: impl Trait)` // ^ suggest `, T: Trait` here - let span = self.span.with_lo(self.span.hi() - BytePos(1)).shrink_to_lo(); - Some(span) - } else { - None - } + self.span.with_lo(self.span.hi() - BytePos(1)).shrink_to_lo() + }) } /// `Span` where further predicates would be suggested, accounting for trailing commas, like @@ -639,7 +636,7 @@ impl<'hir> Generics<'hir> { // We include bounds that come from a `#[derive(_)]` but point at the user's code, // as we use this method to get a span appropriate for suggestions. let bs = bound.span(); - if bs.can_be_used_for_suggestions() { Some(bs.shrink_to_hi()) } else { None } + bs.can_be_used_for_suggestions().then(|| bs.shrink_to_hi()) }, ) } -- cgit 1.4.1-3-g733a5