diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-06-23 01:39:13 +0200 |
|---|---|---|
| committer | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-06-23 01:39:13 +0200 |
| commit | 7abb2350df361effc0f2f4bad938c42547fbb8ed (patch) | |
| tree | f9e324d3e5656392dd281ccaa8645bf137a132a0 | |
| parent | 90b9e96cc343b81d8f3e4105b222c573e95ee71c (diff) | |
| download | rust-7abb2350df361effc0f2f4bad938c42547fbb8ed.tar.gz rust-7abb2350df361effc0f2f4bad938c42547fbb8ed.zip | |
let_chains: Revert 'fn with' in ast_validation.
| -rw-r--r-- | src/librustc_passes/ast_validation.rs | 29 |
1 files changed, 10 insertions, 19 deletions
diff --git a/src/librustc_passes/ast_validation.rs b/src/librustc_passes/ast_validation.rs index c6bc4f2f49e..2da9c5adf9b 100644 --- a/src/librustc_passes/ast_validation.rs +++ b/src/librustc_passes/ast_validation.rs @@ -76,29 +76,18 @@ struct AstValidator<'a> { warning_period_57979_impl_trait_in_proj: bool, } -/// With the `new` value in `store`, -/// runs and returns the `scoped` computation, -/// resetting the old value of `store` after, -/// and returning the result of `scoped`. -fn with<C, T, S>( - this: &mut C, - new: S, - store: impl Fn(&mut C) -> &mut S, - scoped: impl FnOnce(&mut C) -> T -) -> T { - let old = mem::replace(store(this), new); - let ret = scoped(this); - *store(this) = old; - ret -} - impl<'a> AstValidator<'a> { fn with_impl_trait_in_proj_warning<T>(&mut self, v: bool, f: impl FnOnce(&mut Self) -> T) -> T { - with(self, v, |this| &mut this.warning_period_57979_impl_trait_in_proj, f) + let old = mem::replace(&mut self.warning_period_57979_impl_trait_in_proj, v); + let ret = f(self); + self.warning_period_57979_impl_trait_in_proj = old; + ret } fn with_banned_impl_trait(&mut self, f: impl FnOnce(&mut Self)) { - with(self, true, |this| &mut this.is_impl_trait_banned, f) + let old = mem::replace(&mut self.is_impl_trait_banned, true); + f(self); + self.is_impl_trait_banned = old; } fn with_banned_assoc_ty_bound(&mut self, f: impl FnOnce(&mut Self)) { @@ -108,7 +97,9 @@ impl<'a> AstValidator<'a> { } fn with_impl_trait(&mut self, outer: Option<OuterImplTrait>, f: impl FnOnce(&mut Self)) { - with(self, outer, |this| &mut this.outer_impl_trait, f) + let old = mem::replace(&mut self.outer_impl_trait, outer); + f(self); + self.outer_impl_trait = old; } fn visit_assoc_ty_constraint_from_generic_args(&mut self, constraint: &'a AssocTyConstraint) { |
