diff --git a/src/librustc_attr/builtin.rs b/src/librustc_attr/builtin.rs index ab5a844e58f..c2b2e7ce59f 100644 --- a/src/librustc_attr/builtin.rs +++ b/src/librustc_attr/builtin.rs @@ -98,7 +98,7 @@ pub fn find_unwind_attr(diagnostic: Option<&Handler>, attrs: &[Attribute]) -> Op } } - diagnostic.map(|d| { + if let Some(d) = diagnostic { struct_span_err!(d, attr.span, E0633, "malformed `unwind` attribute input") .span_label(attr.span, "invalid argument") .span_suggestions( @@ -110,7 +110,7 @@ pub fn find_unwind_attr(diagnostic: Option<&Handler>, attrs: &[Attribute]) -> Op Applicability::MachineApplicable, ) .emit(); - }); + }; } } } diff --git a/src/librustc_expand/expand.rs b/src/librustc_expand/expand.rs index 2618c758ca5..972e75d201b 100644 --- a/src/librustc_expand/expand.rs +++ b/src/librustc_expand/expand.rs @@ -1172,10 +1172,10 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> { // ignore derives so they remain unused let (attr, after_derive) = self.classify_nonitem(&mut expr); - if attr.is_some() { + if let Some(ref attr_value) = attr { // Collect the invoc regardless of whether or not attributes are permitted here // expansion will eat the attribute so it won't error later. - attr.as_ref().map(|a| self.cfg.maybe_emit_expr_attr_err(a)); + self.cfg.maybe_emit_expr_attr_err(attr_value); // AstFragmentKind::Expr requires the macro to emit an expression. return self @@ -1322,8 +1322,8 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> { // Ignore derives so they remain unused. let (attr, after_derive) = self.classify_nonitem(&mut expr); - if attr.is_some() { - attr.as_ref().map(|a| self.cfg.maybe_emit_expr_attr_err(a)); + if let Some(ref attr_value) = attr { + self.cfg.maybe_emit_expr_attr_err(attr_value); return self .collect_attr( diff --git a/src/librustc_hir/definitions.rs b/src/librustc_hir/definitions.rs index 033c2973af6..30cddac6aac 100644 --- a/src/librustc_hir/definitions.rs +++ b/src/librustc_hir/definitions.rs @@ -246,7 +246,7 @@ impl DefPath { let mut opt_delimiter = None; for component in &self.data { - opt_delimiter.map(|d| s.push(d)); + s.extend(opt_delimiter); opt_delimiter = Some('-'); if component.disambiguator == 0 { write!(s, "{}", component.data.as_symbol()).unwrap(); diff --git a/src/librustc_infer/infer/error_reporting/mod.rs b/src/librustc_infer/infer/error_reporting/mod.rs index dd1d08a75ae..8b530191065 100644 --- a/src/librustc_infer/infer/error_reporting/mod.rs +++ b/src/librustc_infer/infer/error_reporting/mod.rs @@ -755,7 +755,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { }, ObligationCauseCode::IfExpression(box IfExpressionCause { then, outer, semicolon }) => { err.span_label(then, "expected because of this"); - outer.map(|sp| err.span_label(sp, "`if` and `else` have incompatible types")); + if let Some(sp) = outer { + err.span_label(sp, "`if` and `else` have incompatible types"); + } if let Some(sp) = semicolon { err.span_suggestion_short( sp, diff --git a/src/librustc_metadata/creader.rs b/src/librustc_metadata/creader.rs index fe8fbd50627..e7a863c63cc 100644 --- a/src/librustc_metadata/creader.rs +++ b/src/librustc_metadata/creader.rs @@ -101,9 +101,15 @@ fn dump_crates(cstore: &CStore) { info!(" hash: {}", data.hash()); info!(" reqd: {:?}", data.dep_kind()); let CrateSource { dylib, rlib, rmeta } = data.source(); - dylib.as_ref().map(|dl| info!(" dylib: {}", dl.0.display())); - rlib.as_ref().map(|rl| info!(" rlib: {}", rl.0.display())); - rmeta.as_ref().map(|rl| info!(" rmeta: {}", rl.0.display())); + if let Some(dylib) = dylib { + info!(" dylib: {}", dylib.0.display()); + } + if let Some(rlib) = rlib { + info!(" rlib: {}", rlib.0.display()); + } + if let Some(rmeta) = rmeta { + info!(" rmeta: {}", rmeta.0.display()); + } }); } diff --git a/src/librustc_mir_build/build/matches/mod.rs b/src/librustc_mir_build/build/matches/mod.rs index 10ffc81f179..b9d61458a83 100644 --- a/src/librustc_mir_build/build/matches/mod.rs +++ b/src/librustc_mir_build/build/matches/mod.rs @@ -1388,7 +1388,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { } // Insert a Shallow borrow of any places that is switched on. - fake_borrows.as_mut().map(|fb| fb.insert(match_place)); + if let Some(fb) = fake_borrows { + fb.insert(match_place); + } // perform the test, branching to one of N blocks. For each of // those N possible outcomes, create a (initially empty) diff --git a/src/librustc_parse/parser/mod.rs b/src/librustc_parse/parser/mod.rs index b987813e38d..9264fc8a735 100644 --- a/src/librustc_parse/parser/mod.rs +++ b/src/librustc_parse/parser/mod.rs @@ -1206,8 +1206,8 @@ pub fn emit_unclosed_delims(unclosed_delims: &mut Vec, sess: &Pa *sess.reached_eof.borrow_mut() |= unclosed_delims.iter().any(|unmatched_delim| unmatched_delim.found_delim.is_none()); for unmatched in unclosed_delims.drain(..) { - make_unclosed_delims_error(unmatched, sess).map(|mut e| { + if let Some(mut e) = make_unclosed_delims_error(unmatched, sess) { e.emit(); - }); + } } } diff --git a/src/librustc_passes/loops.rs b/src/librustc_passes/loops.rs index 23a605bef0c..09b3d44020d 100644 --- a/src/librustc_passes/loops.rs +++ b/src/librustc_passes/loops.rs @@ -68,7 +68,9 @@ impl<'a, 'hir> Visitor<'hir> for CheckLoopVisitor<'a, 'hir> { self.with_context(LabeledBlock, |v| v.visit_block(&b)); } hir::ExprKind::Break(label, ref opt_expr) => { - opt_expr.as_ref().map(|e| self.visit_expr(e)); + if let Some(e) = opt_expr { + self.visit_expr(e); + } if self.require_label_in_labeled_block(e.span, &label, "break") { // If we emitted an error about an unlabeled break in a labeled diff --git a/src/librustc_query_system/query/job.rs b/src/librustc_query_system/query/job.rs index de6dc81d868..5150b278a77 100644 --- a/src/librustc_query_system/query/job.rs +++ b/src/librustc_query_system/query/job.rs @@ -133,7 +133,11 @@ impl QueryJob { /// as there are no concurrent jobs which could be waiting on us pub fn signal_complete(self) { #[cfg(parallel_compiler)] - self.latch.map(|latch| latch.set()); + { + if let Some(latch) = self.latch { + latch.set(); + } + } } } diff --git a/src/librustc_resolve/late.rs b/src/librustc_resolve/late.rs index 67713b56369..f369e827a40 100644 --- a/src/librustc_resolve/late.rs +++ b/src/librustc_resolve/late.rs @@ -1996,7 +1996,9 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> { this.visit_expr(cond); this.visit_block(then); }); - opt_else.as_ref().map(|expr| self.visit_expr(expr)); + if let Some(expr) = opt_else { + self.visit_expr(expr); + } } ExprKind::Loop(ref block, label) => self.resolve_labeled_block(label, expr.id, &block), diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index e94d7d6a85f..77aa7230aa8 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -499,7 +499,9 @@ impl<'a> ModuleData<'a> { F: FnMut(&mut R, Ident, Namespace, &'a NameBinding<'a>), { for (key, name_resolution) in resolver.as_mut().resolutions(self).borrow().iter() { - name_resolution.borrow().binding.map(|binding| f(resolver, key.ident, key.ns, binding)); + if let Some(binding) = name_resolution.borrow().binding { + f(resolver, key.ident, key.ns, binding); + } } } diff --git a/src/librustc_target/spec/mod.rs b/src/librustc_target/spec/mod.rs index 8f3097ad423..d9040463317 100644 --- a/src/librustc_target/spec/mod.rs +++ b/src/librustc_target/spec/mod.rs @@ -979,20 +979,21 @@ impl Target { macro_rules! key { ($key_name:ident) => ( { let name = (stringify!($key_name)).replace("_", "-"); - obj.find(&name[..]).map(|o| o.as_string() - .map(|s| base.options.$key_name = s.to_string())); + if let Some(s) = obj.find(&name).and_then(Json::as_string) { + base.options.$key_name = s.to_string(); + } } ); ($key_name:ident, bool) => ( { let name = (stringify!($key_name)).replace("_", "-"); - obj.find(&name[..]) - .map(|o| o.as_boolean() - .map(|s| base.options.$key_name = s)); + if let Some(s) = obj.find(&name).and_then(Json::as_boolean) { + base.options.$key_name = s; + } } ); ($key_name:ident, Option) => ( { let name = (stringify!($key_name)).replace("_", "-"); - obj.find(&name[..]) - .map(|o| o.as_u64() - .map(|s| base.options.$key_name = Some(s))); + if let Some(s) = obj.find(&name).and_then(Json::as_u64) { + base.options.$key_name = Some(s); + } } ); ($key_name:ident, MergeFunctions) => ( { let name = (stringify!($key_name)).replace("_", "-"); @@ -1034,19 +1035,19 @@ impl Target { } ); ($key_name:ident, list) => ( { let name = (stringify!($key_name)).replace("_", "-"); - obj.find(&name[..]).map(|o| o.as_array() - .map(|v| base.options.$key_name = v.iter() - .map(|a| a.as_string().unwrap().to_string()).collect() - ) - ); + if let Some(v) = obj.find(&name).and_then(Json::as_array) { + base.options.$key_name = v.iter() + .map(|a| a.as_string().unwrap().to_string()) + .collect(); + } } ); ($key_name:ident, opt_list) => ( { let name = (stringify!($key_name)).replace("_", "-"); - obj.find(&name[..]).map(|o| o.as_array() - .map(|v| base.options.$key_name = Some(v.iter() - .map(|a| a.as_string().unwrap().to_string()).collect()) - ) - ); + if let Some(v) = obj.find(&name).and_then(Json::as_array) { + base.options.$key_name = Some(v.iter() + .map(|a| a.as_string().unwrap().to_string()) + .collect()); + } } ); ($key_name:ident, optional) => ( { let name = (stringify!($key_name)).replace("_", "-"); diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 706dca999fa..c7d749815fe 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -213,7 +213,9 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { None, ); - assoc_bindings.first().map(|b| Self::prohibit_assoc_ty_binding(self.tcx(), b.span)); + if let Some(b) = assoc_bindings.first() { + Self::prohibit_assoc_ty_binding(self.tcx(), b.span); + } substs } @@ -1095,7 +1097,9 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { ) -> ty::TraitRef<'tcx> { let (substs, assoc_bindings, _) = self.create_substs_for_ast_trait_ref(span, trait_def_id, self_ty, trait_segment); - assoc_bindings.first().map(|b| AstConv::prohibit_assoc_ty_binding(self.tcx(), b.span)); + if let Some(b) = assoc_bindings.first() { + AstConv::prohibit_assoc_ty_binding(self.tcx(), b.span); + } ty::TraitRef::new(trait_def_id, substs) } diff --git a/src/librustc_typeck/check/demand.rs b/src/librustc_typeck/check/demand.rs index 7db376b20aa..c75283e419a 100644 --- a/src/librustc_typeck/check/demand.rs +++ b/src/librustc_typeck/check/demand.rs @@ -36,7 +36,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // Requires that the two types unify, and prints an error message if // they don't. pub fn demand_suptype(&self, sp: Span, expected: Ty<'tcx>, actual: Ty<'tcx>) { - self.demand_suptype_diag(sp, expected, actual).map(|mut e| e.emit()); + if let Some(mut e) = self.demand_suptype_diag(sp, expected, actual) { + e.emit(); + } } pub fn demand_suptype_diag( diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 51e3bc4cae4..b7e86c0791f 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -4492,15 +4492,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { _ => Err(ErrorReported), }; if item_name.name != kw::Invalid { - self.report_method_error( + if let Some(mut e) = self.report_method_error( span, ty, item_name, SelfSource::QPath(qself), error, None, - ) - .map(|mut e| e.emit()); + ) { + e.emit(); + } } result }); diff --git a/src/librustc_typeck/check/pat.rs b/src/librustc_typeck/check/pat.rs index b53ae6acdeb..8e109efbcb5 100644 --- a/src/librustc_typeck/check/pat.rs +++ b/src/librustc_typeck/check/pat.rs @@ -104,7 +104,9 @@ impl<'tcx> FnCtxt<'_, 'tcx> { actual: Ty<'tcx>, ti: TopInfo<'tcx>, ) { - self.demand_eqtype_pat_diag(cause_span, expected, actual, ti).map(|mut err| err.emit()); + if let Some(mut err) = self.demand_eqtype_pat_diag(cause_span, expected, actual, ti) { + err.emit(); + } } } @@ -449,12 +451,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // Subtyping doesn't matter here, as the value is some kind of scalar. let demand_eqtype = |x, y| { if let Some((_, x_ty, x_span)) = x { - self.demand_eqtype_pat_diag(x_span, expected, x_ty, ti).map(|mut err| { + if let Some(mut err) = self.demand_eqtype_pat_diag(x_span, expected, x_ty, ti) { if let Some((_, y_ty, y_span)) = y { self.endpoint_has_type(&mut err, y_span, y_ty); } err.emit(); - }); + }; } }; demand_eqtype(lhs, rhs); @@ -852,8 +854,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // Type-check the tuple struct pattern against the expected type. let diag = self.demand_eqtype_pat_diag(pat.span, expected, pat_ty, ti); - let had_err = diag.is_some(); - diag.map(|mut err| err.emit()); + let had_err = if let Some(mut err) = diag { + err.emit(); + true + } else { + false + }; // Type-check subpatterns. if subpats.len() == variant.fields.len() diff --git a/src/librustc_typeck/check/writeback.rs b/src/librustc_typeck/check/writeback.rs index 56714a4fa67..c5bf151bc1e 100644 --- a/src/librustc_typeck/check/writeback.rs +++ b/src/librustc_typeck/check/writeback.rs @@ -165,12 +165,18 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { hir::ExprKind::Binary(..) => { if !op.node.is_by_value() { let mut adjustments = tables.adjustments_mut(); - adjustments.get_mut(lhs.hir_id).map(|a| a.pop()); - adjustments.get_mut(rhs.hir_id).map(|a| a.pop()); + if let Some(a) = adjustments.get_mut(lhs.hir_id) { + a.pop(); + } + if let Some(a) = adjustments.get_mut(rhs.hir_id) { + a.pop(); + } } } hir::ExprKind::AssignOp(..) => { - tables.adjustments_mut().get_mut(lhs.hir_id).map(|a| a.pop()); + if let Some(a) = tables.adjustments_mut().get_mut(lhs.hir_id) { + a.pop(); + } } _ => {} } @@ -215,7 +221,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { tables.type_dependent_defs_mut().remove(e.hir_id); tables.node_substs_mut().remove(e.hir_id); - tables.adjustments_mut().get_mut(base.hir_id).map(|a| { + if let Some(a) = tables.adjustments_mut().get_mut(base.hir_id) { // Discard the need for a mutable borrow // Extra adjustment made when indexing causes a drop @@ -229,7 +235,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { // So the borrow discard actually happens here a.pop(); } - }); + } } } } diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 4d03bb21cb3..63ab0ef5f17 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1599,7 +1599,9 @@ impl<'tcx> Clean for Ty<'tcx> { inline::record_extern_fqn(cx, did, TypeKind::Trait); let mut param_names = vec![]; - reg.clean(cx).map(|b| param_names.push(GenericBound::Outlives(b))); + if let Some(b) = reg.clean(cx) { + param_names.push(GenericBound::Outlives(b)); + } for did in dids { let empty = cx.tcx.intern_substs(&[]); let path = @@ -1662,10 +1664,9 @@ impl<'tcx> Clean for Ty<'tcx> { tr } else if let ty::Predicate::TypeOutlives(pred) = *predicate { // these should turn up at the end - pred.skip_binder() - .1 - .clean(cx) - .map(|r| regions.push(GenericBound::Outlives(r))); + if let Some(r) = pred.skip_binder().1.clean(cx) { + regions.push(GenericBound::Outlives(r)); + } return None; } else { return None; diff --git a/src/librustdoc/html/toc.rs b/src/librustdoc/html/toc.rs index 034fb273000..37540295774 100644 --- a/src/librustdoc/html/toc.rs +++ b/src/librustdoc/html/toc.rs @@ -94,7 +94,7 @@ impl TocBuilder { loop { match self.chain.pop() { Some(mut next) => { - this.map(|e| next.children.entries.push(e)); + next.children.entries.extend(this); if next.level < level { // this is the parent we want, so return it to // its rightful place. @@ -105,7 +105,7 @@ impl TocBuilder { } } None => { - this.map(|e| self.top_level.entries.push(e)); + self.top_level.entries.extend(this); return; } } diff --git a/src/libstd/sync/mpsc/shared.rs b/src/libstd/sync/mpsc/shared.rs index c4e929624d7..fd9d61e99c2 100644 --- a/src/libstd/sync/mpsc/shared.rs +++ b/src/libstd/sync/mpsc/shared.rs @@ -91,7 +91,7 @@ impl Packet { // // This can only be called at channel-creation time pub fn inherit_blocker(&self, token: Option, guard: MutexGuard<'_, ()>) { - token.map(|token| { + if let Some(token) = token { assert_eq!(self.cnt.load(Ordering::SeqCst), 0); assert_eq!(self.to_wake.load(Ordering::SeqCst), 0); self.to_wake.store(unsafe { token.cast_to_usize() }, Ordering::SeqCst); @@ -118,7 +118,7 @@ impl Packet { unsafe { *self.steals.get() = -1; } - }); + } // When the shared packet is constructed, we grabbed this lock. The // purpose of this lock is to ensure that abort_selection() doesn't diff --git a/src/libstd/sync/mpsc/sync.rs b/src/libstd/sync/mpsc/sync.rs index 3e2050799cc..79123903e92 100644 --- a/src/libstd/sync/mpsc/sync.rs +++ b/src/libstd/sync/mpsc/sync.rs @@ -343,8 +343,12 @@ impl Packet { mem::drop(guard); // only outside of the lock do we wake up the pending threads - pending_sender1.map(|t| t.signal()); - pending_sender2.map(|t| t.signal()); + if let Some(token) = pending_sender1 { + token.signal(); + } + if let Some(token) = pending_sender2 { + token.signal(); + } } // Prepares this shared packet for a channel clone, essentially just bumping @@ -410,7 +414,9 @@ impl Packet { while let Some(token) = queue.dequeue() { token.signal(); } - waiter.map(|t| t.signal()); + if let Some(token) = waiter { + token.signal(); + } } }