diff options
| author | Maybe Waffle <waffle.lapkin@gmail.com> | 2023-02-15 11:43:41 +0000 | 
|---|---|---|
| committer | Maybe Waffle <waffle.lapkin@gmail.com> | 2023-02-16 15:26:00 +0000 | 
| commit | 8751fa1a9abda9fc7ced6b03315efbd82310830d (patch) | |
| tree | f15613d5ca2fa5aadfdde2df1d94907d1798a5bb /compiler/rustc_hir/src | |
| parent | af3c8b27266e290cf65704284f6862d0f90ee4fc (diff) | |
| download | rust-8751fa1a9abda9fc7ced6b03315efbd82310830d.tar.gz rust-8751fa1a9abda9fc7ced6b03315efbd82310830d.zip | |
`if $c:expr { Some($r:expr) } else { None }` =>> `$c.then(|| $r)`
Diffstat (limited to 'compiler/rustc_hir/src')
| -rw-r--r-- | compiler/rustc_hir/src/hir.rs | 11 | 
1 files changed, 4 insertions, 7 deletions
| 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<Span> { - if self.params.iter().any(|p| self.span.contains(p.span)) { + self.params.iter().any(|p| self.span.contains(p.span)).then(|| { // `fn foo<A>(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()) }, ) } | 
