diff --git a/src/libcore/fmt/mod.rs b/src/libcore/fmt/mod.rs index 4ac134c2b59c8..895a679fc3dcc 100644 --- a/src/libcore/fmt/mod.rs +++ b/src/libcore/fmt/mod.rs @@ -840,11 +840,8 @@ pub fn write(output: &mut Write, args: Arguments) -> Result { } // There can be only one trailing string piece left. - match pieces.next() { - Some(piece) => { - formatter.buf.write_str(*piece)?; - } - None => {} + if let Some(piece) = pieces.next() { + formatter.buf.write_str(*piece)?; } Ok(()) diff --git a/src/librand/rand_impls.rs b/src/librand/rand_impls.rs index 1185ad25485bd..41ad089ecd235 100644 --- a/src/librand/rand_impls.rs +++ b/src/librand/rand_impls.rs @@ -144,9 +144,8 @@ impl Rand for char { // Rejection sampling. About 0.2% of numbers with at most // 21-bits are invalid codepoints (surrogates), so this // will succeed first go almost every time. - match char::from_u32(rng.next_u32() & CHAR_MASK) { - Some(c) => return c, - None => {} + if let Some(c) = char::from_u32(rng.next_u32() & CHAR_MASK) { + return c; } } } diff --git a/src/librustc/hir/print.rs b/src/librustc/hir/print.rs index 598a2cfca1320..bf6188faa2fbd 100644 --- a/src/librustc/hir/print.rs +++ b/src/librustc/hir/print.rs @@ -1697,13 +1697,10 @@ impl<'a> State<'a> { self.commasep(Inconsistent, &data.inputs, |s, ty| s.print_type(&ty))?; word(&mut self.s, ")")?; - match data.output { - None => {} - Some(ref ty) => { - self.space_if_not_bol()?; - self.word_space("->")?; - self.print_type(&ty)?; - } + if let Some(ref ty) = data.output { + self.space_if_not_bol()?; + self.word_space("->")?; + self.print_type(&ty)?; } } } diff --git a/src/librustc/infer/region_inference/mod.rs b/src/librustc/infer/region_inference/mod.rs index ebfa942e5e415..d3b4afa2cee79 100644 --- a/src/librustc/infer/region_inference/mod.rs +++ b/src/librustc/infer/region_inference/mod.rs @@ -842,11 +842,8 @@ impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, 'tcx> { where F: FnMut(&RegionVarBindings<'a, 'gcx, 'tcx>, Region, Region) { let vars = TwoRegions { a: a, b: b }; - match self.combine_map(t).borrow().get(&vars) { - Some(&c) => { - return ReVar(c); - } - None => {} + if let Some(&c) = self.combine_map(t).borrow().get(&vars) { + return ReVar(c); } let c = self.new_region_var(MiscVariable(origin.span())); self.combine_map(t).borrow_mut().insert(vars, c); diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index 3e101e1934f29..01e14ad71b39c 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -1055,13 +1055,10 @@ impl<'a> ast_visit::Visitor for EarlyContext<'a> { // Output any lints that were previously added to the session. impl<'a, 'tcx> IdVisitingOperation for LateContext<'a, 'tcx> { fn visit_id(&mut self, id: ast::NodeId) { - match self.sess().lints.borrow_mut().remove(&id) { - None => {} - Some(lints) => { - debug!("LateContext::visit_id: id={:?} lints={:?}", id, lints); - for (lint_id, span, msg) in lints { - self.span_lint(lint_id.lint, span, &msg[..]) - } + if let Some(lints) = self.sess().lints.borrow_mut().remove(&id) { + debug!("LateContext::visit_id: id={:?} lints={:?}", id, lints); + for (lint_id, span, msg) in lints { + self.span_lint(lint_id.lint, span, &msg[..]) } } } diff --git a/src/librustc/middle/dataflow.rs b/src/librustc/middle/dataflow.rs index 4d01b59001c5d..fc1294c86c44f 100644 --- a/src/librustc/middle/dataflow.rs +++ b/src/librustc/middle/dataflow.rs @@ -168,9 +168,8 @@ fn build_nodeid_to_index(decl: Option<&hir::FnDecl>, // into cfg itself? i.e. introduce a fn-based flow-graph in // addition to the current block-based flow-graph, rather than // have to put traversals like this here? - match decl { - None => {} - Some(decl) => add_entries_from_fn_decl(&mut index, decl, cfg.entry) + if let Some(decl) = decl { + add_entries_from_fn_decl(&mut index, decl, cfg.entry); } cfg.graph.each_node(|node_idx, node| { diff --git a/src/librustc/middle/dependency_format.rs b/src/librustc/middle/dependency_format.rs index 0b398fd0d47c5..cf6905ecf439a 100644 --- a/src/librustc/middle/dependency_format.rs +++ b/src/librustc/middle/dependency_format.rs @@ -105,9 +105,8 @@ fn calculate_type(sess: &session::Session, // If the global prefer_dynamic switch is turned off, first attempt // static linkage (this can fail). config::CrateTypeExecutable if !sess.opts.cg.prefer_dynamic => { - match attempt_static(sess) { - Some(v) => return v, - None => {} + if let Some(v) = attempt_static(sess) { + return v; } } @@ -119,9 +118,8 @@ fn calculate_type(sess: &session::Session, // to be found, we generate some nice pretty errors. config::CrateTypeStaticlib | config::CrateTypeCdylib => { - match attempt_static(sess) { - Some(v) => return v, - None => {} + if let Some(v) = attempt_static(sess) { + return v; } for cnum in sess.cstore.crates() { let src = sess.cstore.used_crate_source(cnum); @@ -136,9 +134,8 @@ fn calculate_type(sess: &session::Session, // to try to eagerly statically link all dependencies. This is normally // done for end-product dylibs, not intermediate products. config::CrateTypeDylib if !sess.opts.cg.prefer_dynamic => { - match attempt_static(sess) { - Some(v) => return v, - None => {} + if let Some(v) = attempt_static(sess) { + return v; } } diff --git a/src/librustc/middle/expr_use_visitor.rs b/src/librustc/middle/expr_use_visitor.rs index 4e0b76365041c..c8b8c5dbdbbcb 100644 --- a/src/librustc/middle/expr_use_visitor.rs +++ b/src/librustc/middle/expr_use_visitor.rs @@ -735,26 +735,23 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> { for i in 0..autoderefs { let deref_id = ty::MethodCall::autoderef(expr.id, i as u32); - match self.mc.infcx.node_method_ty(deref_id) { - None => {} - Some(method_ty) => { - let cmt = return_if_err!(self.mc.cat_expr_autoderefd(expr, i)); - - // the method call infrastructure should have - // replaced all late-bound regions with variables: - let self_ty = method_ty.fn_sig().input(0); - let self_ty = self.tcx().no_late_bound_regions(&self_ty).unwrap(); - - let (m, r) = match self_ty.sty { - ty::TyRef(r, ref m) => (m.mutbl, r), - _ => span_bug!(expr.span, - "bad overloaded deref type {:?}", - method_ty) - }; - let bk = ty::BorrowKind::from_mutbl(m); - self.delegate.borrow(expr.id, expr.span, cmt, - *r, bk, AutoRef); - } + if let Some(method_ty) = self.mc.infcx.node_method_ty(deref_id) { + let cmt = return_if_err!(self.mc.cat_expr_autoderefd(expr, i)); + + // the method call infrastructure should have + // replaced all late-bound regions with variables: + let self_ty = method_ty.fn_sig().input(0); + let self_ty = self.tcx().no_late_bound_regions(&self_ty).unwrap(); + + let (m, r) = match self_ty.sty { + ty::TyRef(r, ref m) => (m.mutbl, r), + _ => span_bug!(expr.span, + "bad overloaded deref type {:?}", + method_ty) + }; + let bk = ty::BorrowKind::from_mutbl(m); + self.delegate.borrow(expr.id, expr.span, cmt, + *r, bk, AutoRef); } } } diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index cb2f68bb55397..ea3765c76f89b 100644 --- a/src/librustc/middle/liveness.rs +++ b/src/librustc/middle/liveness.rs @@ -598,11 +598,8 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { fn arm_pats_bindings(&mut self, pat: Option<&hir::Pat>, f: F) where F: FnMut(&mut Liveness<'a, 'tcx>, LiveNode, Variable, Span, NodeId), { - match pat { - Some(pat) => { - self.pat_bindings(pat, f); - } - None => {} + if let Some(pat) = pat { + self.pat_bindings(pat, f); } } diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index 2ba05b4ae3212..7f6614a959c89 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -284,9 +284,8 @@ impl<'a, 'tcx, 'v> Visitor<'v> for LifetimeContext<'a, 'tcx> { fn visit_generics(&mut self, generics: &hir::Generics) { for ty_param in generics.ty_params.iter() { walk_list!(self, visit_ty_param_bound, &ty_param.bounds); - match ty_param.default { - Some(ref ty) => self.visit_ty(&ty), - None => {} + if let Some(ref ty) = ty_param.default { + self.visit_ty(&ty); } } for predicate in &generics.where_clause.predicates { diff --git a/src/librustc/middle/weak_lang_items.rs b/src/librustc/middle/weak_lang_items.rs index 20c5320fd6464..6fb1b16705fe4 100644 --- a/src/librustc/middle/weak_lang_items.rs +++ b/src/librustc/middle/weak_lang_items.rs @@ -123,9 +123,8 @@ impl<'a> Context<'a> { impl<'a, 'v> Visitor<'v> for Context<'a> { fn visit_foreign_item(&mut self, i: &hir::ForeignItem) { - match lang_items::extract(&i.attrs) { - None => {} - Some(lang_item) => self.register(&lang_item, i.span), + if let Some(lang_item) = lang_items::extract(&i.attrs) { + self.register(&lang_item, i.span); } intravisit::walk_foreign_item(self, i) } diff --git a/src/librustc/session/mod.rs b/src/librustc/session/mod.rs index fdaf182c60542..57c4af6bed569 100644 --- a/src/librustc/session/mod.rs +++ b/src/librustc/session/mod.rs @@ -250,15 +250,12 @@ impl Session { msg: String) { let lint_id = lint::LintId::of(lint); let mut lints = self.lints.borrow_mut(); - match lints.get_mut(&id) { - Some(arr) => { - let tuple = (lint_id, sp, msg); - if !arr.contains(&tuple) { - arr.push(tuple); - } - return; + if let Some(arr) = lints.get_mut(&id) { + let tuple = (lint_id, sp, msg); + if !arr.contains(&tuple) { + arr.push(tuple); } - None => {} + return; } lints.insert(id, vec!((lint_id, sp, msg))); } diff --git a/src/librustc/ty/contents.rs b/src/librustc/ty/contents.rs index 33b33092b25c0..14b0a8070983c 100644 --- a/src/librustc/ty/contents.rs +++ b/src/librustc/ty/contents.rs @@ -168,13 +168,12 @@ impl<'a, 'tcx> ty::TyS<'tcx> { // which is incorrect. This value was computed based on the crutch // value for the type contents of list. The correct value is // TC::OwnsOwned. This manifested as issue #4821. - match cache.get(&ty) { - Some(tc) => { return *tc; } - None => {} + if let Some(tc) = cache.get(&ty) { + return *tc; } - match tcx.tc_cache.borrow().get(&ty) { // Must check both caches! - Some(tc) => { return *tc; } - None => {} + // Must check both caches! + if let Some(tc) = tcx.tc_cache.borrow().get(&ty) { + return *tc; } cache.insert(ty, TC::None); diff --git a/src/librustc/ty/fold.rs b/src/librustc/ty/fold.rs index 1a944e04effd7..b334964bf489b 100644 --- a/src/librustc/ty/fold.rs +++ b/src/librustc/ty/fold.rs @@ -521,9 +521,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { fn tcx<'b>(&'b self) -> TyCtxt<'b, 'gcx, 'tcx> { self.0 } fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> { - match self.tcx().normalized_cache.borrow().get(&ty).cloned() { - None => {} - Some(u) => return u + if let Some(u) = self.tcx().normalized_cache.borrow().get(&ty).cloned() { + return u; } // FIXME(eddyb) should local contexts have a cache too? @@ -714,4 +713,3 @@ impl<'tcx> TypeVisitor<'tcx> for LateBoundRegionsCollector { false } } - diff --git a/src/librustc/ty/util.rs b/src/librustc/ty/util.rs index ee7fb5fc94b77..21c14e6fe4c3b 100644 --- a/src/librustc/ty/util.rs +++ b/src/librustc/ty/util.rs @@ -712,16 +712,13 @@ impl<'a, 'tcx> ty::TyS<'tcx> { // struct Foo; // struct Bar { x: Bar } - match iter.next() { - Some(&seen_type) => { - if same_struct_or_enum(seen_type, def) { - debug!("SelfRecursive: {:?} contains {:?}", - seen_type, - ty); - return Representability::SelfRecursive; - } + if let Some(&seen_type) = iter.next() { + if same_struct_or_enum(seen_type, def) { + debug!("SelfRecursive: {:?} contains {:?}", + seen_type, + ty); + return Representability::SelfRecursive; } - None => {} } // We also need to know whether the first item contains other types diff --git a/src/librustc_borrowck/borrowck/move_data.rs b/src/librustc_borrowck/borrowck/move_data.rs index 4b8cbbffaa5ef..c9822a4fee749 100644 --- a/src/librustc_borrowck/borrowck/move_data.rs +++ b/src/librustc_borrowck/borrowck/move_data.rs @@ -274,11 +274,8 @@ impl<'a, 'tcx> MoveData<'tcx> { /// `lp` and any of its base paths that do not yet have an index. pub fn move_path(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, lp: Rc>) -> MovePathIndex { - match self.path_map.borrow().get(&lp) { - Some(&index) => { - return index; - } - None => {} + if let Some(&index) = self.path_map.borrow().get(&lp) { + return index; } let index = match lp.kind { diff --git a/src/librustc_const_eval/check_match.rs b/src/librustc_const_eval/check_match.rs index c878edcd4b2a8..a5a9dea61ad7c 100644 --- a/src/librustc_const_eval/check_match.rs +++ b/src/librustc_const_eval/check_match.rs @@ -176,9 +176,8 @@ fn check_expr(cx: &mut MatchCheckCtxt, ex: &hir::Expr) { // Second, if there is a guard on each arm, make sure it isn't // assigning or borrowing anything mutably. - match arm.guard { - Some(ref guard) => check_for_mutation_in_guard(cx, &guard), - None => {} + if let Some(ref guard) = arm.guard { + check_for_mutation_in_guard(cx, &guard); } } diff --git a/src/librustc_lint/unused.rs b/src/librustc_lint/unused.rs index b5b87718d2df7..4dc1a5e4f5e9f 100644 --- a/src/librustc_lint/unused.rs +++ b/src/librustc_lint/unused.rs @@ -150,12 +150,9 @@ impl LateLintPass for UnusedResults { if attr.check_name("must_use") { let mut msg = "unused result which must be used".to_string(); // check for #[must_use="..."] - match attr.value_str() { - None => {} - Some(s) => { - msg.push_str(": "); - msg.push_str(&s); - } + if let Some(s) = attr.value_str() { + msg.push_str(": "); + msg.push_str(&s); } cx.span_lint(UNUSED_MUST_USE, sp, &msg); return true; diff --git a/src/librustc_llvm/build.rs b/src/librustc_llvm/build.rs index 250aafd77a826..a2c808cbcb6b6 100644 --- a/src/librustc_llvm/build.rs +++ b/src/librustc_llvm/build.rs @@ -24,19 +24,17 @@ fn main() { let llvm_config = env::var_os("LLVM_CONFIG") .map(PathBuf::from) .unwrap_or_else(|| { - match env::var_os("CARGO_TARGET_DIR").map(PathBuf::from) { - Some(dir) => { - let to_test = dir.parent() - .unwrap() - .parent() - .unwrap() - .join(&target) - .join("llvm/bin/llvm-config"); - if Command::new(&to_test).output().is_ok() { - return to_test; - } + if let Some(dir) = env::var_os("CARGO_TARGET_DIR") + .map(PathBuf::from) { + let to_test = dir.parent() + .unwrap() + .parent() + .unwrap() + .join(&target) + .join("llvm/bin/llvm-config"); + if Command::new(&to_test).output().is_ok() { + return to_test; } - None => {} } PathBuf::from("llvm-config") }); diff --git a/src/librustc_metadata/decoder.rs b/src/librustc_metadata/decoder.rs index 0a59c152ca379..eada2a9cd7a63 100644 --- a/src/librustc_metadata/decoder.rs +++ b/src/librustc_metadata/decoder.rs @@ -682,15 +682,12 @@ fn each_child_of_item_or_crate(intr: Rc, }; // Get the item. - match crate_data.get_item(child_def_id.index) { - None => {} - Some(child_item_doc) => { - // Hand off the item to the callback. - let child_name = item_name(&intr, child_item_doc); - let def_like = item_to_def_like(crate_data, child_item_doc, child_def_id); - let visibility = item_visibility(child_item_doc); - callback(def_like, child_name, visibility); - } + if let Some(child_item_doc) = crate_data.get_item(child_def_id.index) { + // Hand off the item to the callback. + let child_name = item_name(&intr, child_item_doc); + let def_like = item_to_def_like(crate_data, child_item_doc, child_def_id); + let visibility = item_visibility(child_item_doc); + callback(def_like, child_name, visibility); } } diff --git a/src/librustc_metadata/loader.rs b/src/librustc_metadata/loader.rs index edfdbf2aeefa8..48c8bcff1ec56 100644 --- a/src/librustc_metadata/loader.rs +++ b/src/librustc_metadata/loader.rs @@ -503,19 +503,11 @@ impl<'a> Context<'a> { self.crate_name); err.note("candidates:"); for (_, lib) in libraries { - match lib.dylib { - Some((ref p, _)) => { - err.note(&format!("path: {}", - p.display())); - } - None => {} + if let Some((ref p, _)) = lib.dylib { + err.note(&format!("path: {}", p.display())); } - match lib.rlib { - Some((ref p, _)) => { - err.note(&format!("path: {}", - p.display())); - } - None => {} + if let Some((ref p, _)) = lib.rlib { + err.note(&format!("path: {}", p.display())); } let data = lib.metadata.as_slice(); let name = decoder::get_crate_name(data); diff --git a/src/librustc_metadata/tydecode.rs b/src/librustc_metadata/tydecode.rs index d96996a017986..119640af463aa 100644 --- a/src/librustc_metadata/tydecode.rs +++ b/src/librustc_metadata/tydecode.rs @@ -396,16 +396,13 @@ impl<'a,'tcx> TyDecoder<'a,'tcx> { let pos = self.parse_vuint(); let key = ty::CReaderCacheKey { cnum: self.krate, pos: pos }; - match tcx.rcache.borrow().get(&key).cloned() { - Some(tt) => { - // If there is a closure buried in the type some where, then we - // need to re-convert any def ids (see case 'k', below). That means - // we can't reuse the cached version. - if !tt.has_closure_types() { - return tt; - } + if let Some(tt) = tcx.rcache.borrow().get(&key).cloned() { + // If there is a closure buried in the type some where, then we + // need to re-convert any def ids (see case 'k', below). That means + // we can't reuse the cached version. + if !tt.has_closure_types() { + return tt; } - None => {} } let mut substate = TyDecoder::new(self.data, diff --git a/src/librustc_metadata/tyencode.rs b/src/librustc_metadata/tyencode.rs index 2b8ba107fefc6..1afeccdf8e3a9 100644 --- a/src/librustc_metadata/tyencode.rs +++ b/src/librustc_metadata/tyencode.rs @@ -64,9 +64,9 @@ pub struct ty_abbrev { pub type abbrev_map<'tcx> = RefCell, ty_abbrev>>; pub fn enc_ty<'a, 'tcx>(w: &mut Cursor>, cx: &ctxt<'a, 'tcx>, t: Ty<'tcx>) { - match cx.abbrevs.borrow_mut().get(&t) { - Some(a) => { w.write_all(&a.s); return; } - None => {} + if let Some(a) = cx.abbrevs.borrow_mut().get(&t) { + w.write_all(&a.s); + return; } let pos = w.position(); diff --git a/src/librustc_save_analysis/lib.rs b/src/librustc_save_analysis/lib.rs index 8eaf398778380..0580c51d9a17a 100644 --- a/src/librustc_save_analysis/lib.rs +++ b/src/librustc_save_analysis/lib.rs @@ -299,12 +299,10 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> { let mut result = String::from("<"); result.push_str(&rustc::hir::print::ty_to_string(&ty)); - match self.tcx.trait_of_item(self.tcx.map.local_def_id(id)) { - Some(def_id) => { - result.push_str(" as "); - result.push_str(&self.tcx.item_path_str(def_id)); - } - None => {} + if let Some(def_id) = self.tcx + .trait_of_item(self.tcx.map.local_def_id(id)) { + result.push_str(" as "); + result.push_str(&self.tcx.item_path_str(def_id)); } result.push_str(">"); result diff --git a/src/librustc_trans/_match.rs b/src/librustc_trans/_match.rs index 15beba0d9a6ee..3ef6e29a6f838 100644 --- a/src/librustc_trans/_match.rs +++ b/src/librustc_trans/_match.rs @@ -1706,17 +1706,13 @@ pub fn store_local<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, // // In such cases, the more general path is unsafe, because // it assumes it is matching against a valid value. - match simple_name(pat) { - Some(name) => { - let var_scope = cleanup::var_scope(tcx, local.id); - return mk_binding_alloca( - bcx, pat.id, name, var_scope, (), - "_match::store_local", - |(), bcx, Datum { val: v, .. }| expr::trans_into(bcx, &init_expr, - expr::SaveIn(v))); - } - - None => {} + if let Some(name) = simple_name(pat) { + let var_scope = cleanup::var_scope(tcx, local.id); + return mk_binding_alloca( + bcx, pat.id, name, var_scope, (), + "_match::store_local", + |(), bcx, Datum { val: v, .. }| expr::trans_into(bcx, &init_expr, + expr::SaveIn(v))); } // General path. diff --git a/src/librustc_trans/adt.rs b/src/librustc_trans/adt.rs index a4792ea328f08..23c4258caf7bd 100644 --- a/src/librustc_trans/adt.rs +++ b/src/librustc_trans/adt.rs @@ -191,9 +191,8 @@ pub fn represent_type<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, t: Ty<'tcx>) -> Rc> { debug!("Representing: {}", t); - match cx.adt_reprs().borrow().get(&t) { - Some(repr) => return repr.clone(), - None => {} + if let Some(repr) = cx.adt_reprs().borrow().get(&t) { + return repr.clone(); } let repr = Rc::new(represent_type_uncached(cx, t)); diff --git a/src/librustc_trans/base.rs b/src/librustc_trans/base.rs index 2998c834aca7a..7a572fdadc3d7 100644 --- a/src/librustc_trans/base.rs +++ b/src/librustc_trans/base.rs @@ -136,11 +136,8 @@ pub struct _InsnCtxt { impl Drop for _InsnCtxt { fn drop(&mut self) { TASK_LOCAL_INSN_KEY.with(|slot| { - match slot.borrow_mut().as_mut() { - Some(ctx) => { - ctx.pop(); - } - None => {} + if let Some(ctx) = slot.borrow_mut().as_mut() { + ctx.pop(); } }) } diff --git a/src/librustc_trans/consts.rs b/src/librustc_trans/consts.rs index 4e12d3d5d8231..5596ab0d819e0 100644 --- a/src/librustc_trans/consts.rs +++ b/src/librustc_trans/consts.rs @@ -138,18 +138,15 @@ pub fn addr_of(ccx: &CrateContext, align: machine::llalign, kind: &str) -> ValueRef { - match ccx.const_globals().borrow().get(&cv) { - Some(&gv) => { - unsafe { - // Upgrade the alignment in cases where the same constant is used with different - // alignment requirements - if align > llvm::LLVMGetAlignment(gv) { - llvm::LLVMSetAlignment(gv, align); - } + if let Some(&gv) = ccx.const_globals().borrow().get(&cv) { + unsafe { + // Upgrade the alignment in cases where the same constant is used with different + // alignment requirements + if align > llvm::LLVMGetAlignment(gv) { + llvm::LLVMSetAlignment(gv, align); } - return gv; } - None => {} + return gv; } let gv = addr_of_mut(ccx, cv, align, kind); unsafe { diff --git a/src/librustc_trans/mir/rvalue.rs b/src/librustc_trans/mir/rvalue.rs index 28bcd8a633c1c..c3f2c4f2c8bfe 100644 --- a/src/librustc_trans/mir/rvalue.rs +++ b/src/librustc_trans/mir/rvalue.rs @@ -572,11 +572,8 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> { // will only succeed if both operands are constant. // This is necessary to determine when an overflow Assert // will always panic at runtime, and produce a warning. - match const_scalar_checked_binop(bcx.tcx(), op, lhs, rhs, input_ty) { - Some((val, of)) => { - return OperandValue::Pair(val, C_bool(bcx.ccx(), of)); - } - None => {} + if let Some((val, of)) = const_scalar_checked_binop(bcx.tcx(), op, lhs, rhs, input_ty) { + return OperandValue::Pair(val, C_bool(bcx.ccx(), of)); } let (val, of) = match op { diff --git a/src/librustc_typeck/check/method/probe.rs b/src/librustc_typeck/check/method/probe.rs index 373fc83fa7444..6a1baf13b273d 100644 --- a/src/librustc_typeck/check/method/probe.rs +++ b/src/librustc_typeck/check/method/probe.rs @@ -864,9 +864,8 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> { // THE ACTUAL SEARCH fn pick(mut self) -> PickResult<'tcx> { - match self.pick_core() { - Some(r) => return r, - None => {} + if let Some(r) = self.pick_core() { + return r; } let static_candidates = mem::replace(&mut self.static_candidates, vec![]); @@ -929,9 +928,8 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> { return None; } - match self.pick_by_value_method(step) { - Some(result) => return Some(result), - None => {} + if let Some(result) = self.pick_by_value_method(step) { + return Some(result); } self.pick_autorefd_method(step) @@ -1003,12 +1001,10 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> { let mut possibly_unsatisfied_predicates = Vec::new(); debug!("searching inherent candidates"); - match self.consider_candidates(self_ty, &self.inherent_candidates, - &mut possibly_unsatisfied_predicates) { - None => {} - Some(pick) => { - return Some(pick); - } + if let Some(pick) = self.consider_candidates(self_ty, + &self.inherent_candidates, + &mut possibly_unsatisfied_predicates) { + return Some(pick); } debug!("searching extension candidates"); diff --git a/src/librustc_typeck/check/writeback.rs b/src/librustc_typeck/check/writeback.rs index 7f5f3ae120b7a..9786132dc537b 100644 --- a/src/librustc_typeck/check/writeback.rs +++ b/src/librustc_typeck/check/writeback.rs @@ -334,13 +334,8 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> { }; //NB(jroesch): We need to match twice to avoid a double borrow which would cause an ICE - match new_method { - Some(method) => { - self.tcx().tables.borrow_mut().method_map.insert( - method_call, - method); - } - None => {} + if let Some(method) = new_method { + self.tcx().tables.borrow_mut().method_map.insert(method_call, method); } } diff --git a/src/librustc_typeck/coherence/mod.rs b/src/librustc_typeck/coherence/mod.rs index ade7806e71d12..198e9afd5e12c 100644 --- a/src/librustc_typeck/coherence/mod.rs +++ b/src/librustc_typeck/coherence/mod.rs @@ -174,12 +174,9 @@ impl<'a, 'gcx, 'tcx> CoherenceChecker<'a, 'gcx, 'tcx> { } fn add_inherent_impl(&self, base_def_id: DefId, impl_def_id: DefId) { - match self.inherent_impls.borrow().get(&base_def_id) { - Some(implementation_list) => { - implementation_list.borrow_mut().push(impl_def_id); - return; - } - None => {} + if let Some(implementation_list) = self.inherent_impls.borrow().get(&base_def_id) { + implementation_list.borrow_mut().push(impl_def_id); + return; } self.inherent_impls.borrow_mut().insert( diff --git a/src/librustc_typeck/lib.rs b/src/librustc_typeck/lib.rs index 7ccff7ad3d87c..16e48767a6c60 100644 --- a/src/librustc_typeck/lib.rs +++ b/src/librustc_typeck/lib.rs @@ -313,14 +313,13 @@ fn check_start_fn_ty(ccx: &CrateCtxt, fn check_for_entry_fn(ccx: &CrateCtxt) { let tcx = ccx.tcx; let _task = tcx.dep_graph.in_task(DepNode::CheckEntryFn); - match *tcx.sess.entry_fn.borrow() { - Some((id, sp)) => match tcx.sess.entry_type.get() { + if let Some((id, sp)) = *tcx.sess.entry_fn.borrow() { + match tcx.sess.entry_type.get() { Some(config::EntryMain) => check_main_fn_ty(ccx, id, sp), Some(config::EntryStart) => check_start_fn_ty(ccx, id, sp), Some(config::EntryNone) => {} None => bug!("entry function without a type") - }, - None => {} + } } } diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index 760e84622cfe5..77c4a0f8174a3 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -131,9 +131,8 @@ impl fmt::Display for clean::Generics { write!(f, ": {}", TyParamBounds(&tp.bounds))?; } - match tp.default { - Some(ref ty) => { write!(f, " = {}", ty)?; }, - None => {} + if let Some(ref ty) = tp.default { + write!(f, " = {}", ty)?; }; } } @@ -401,15 +400,12 @@ fn primitive_link(f: &mut fmt::Formatter, } (_, render::Unknown) => None, }; - match loc { - Some(root) => { - write!(f, "", - root, - path.0.first().unwrap(), - prim.to_url_str())?; - needs_termination = true; - } - None => {} + if let Some(root) = loc { + write!(f, "", + root, + path.0.first().unwrap(), + prim.to_url_str())?; + needs_termination = true; } } None => {} diff --git a/src/librustdoc/html/highlight.rs b/src/librustdoc/html/highlight.rs index 2e2f99897733d..84e98a6739193 100644 --- a/src/librustdoc/html/highlight.rs +++ b/src/librustdoc/html/highlight.rs @@ -352,9 +352,8 @@ fn write_header(class: Option<&str>, out: &mut Write) -> io::Result<()> { write!(out, "
 write!(out, "id='{}' ", id)?,
-        None => {}
+    if let Some(id) = id {
+        write!(out, "id='{}' ", id)?;
     }
     write!(out, "class='rust {}'>\n", class.unwrap_or(""))
 }
diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs
index 9f2b33c0282ed..acf867561a637 100644
--- a/src/librustdoc/html/render.rs
+++ b/src/librustdoc/html/render.rs
@@ -589,19 +589,16 @@ fn build_index(krate: &clean::Crate, cache: &mut Cache) -> String {
     // Attach all orphan methods to the type's definition if the type
     // has since been learned.
     for &(did, ref item) in orphan_methods {
-        match paths.get(&did) {
-            Some(&(ref fqp, _)) => {
-                search_index.push(IndexItem {
-                    ty: shortty(item),
-                    name: item.name.clone().unwrap(),
-                    path: fqp[..fqp.len() - 1].join("::"),
-                    desc: Escape(&shorter(item.doc_value())).to_string(),
-                    parent: Some(did),
-                    parent_idx: None,
-                    search_type: get_index_search_type(&item),
-                });
-            },
-            None => {}
+        if let Some(&(ref fqp, _)) = paths.get(&did) {
+            search_index.push(IndexItem {
+                ty: shortty(item),
+                name: item.name.clone().unwrap(),
+                path: fqp[..fqp.len() - 1].join("::"),
+                desc: Escape(&shorter(item.doc_value())).to_string(),
+                parent: Some(did),
+                parent_idx: None,
+                search_type: get_index_search_type(&item),
+            });
         }
     }
 
@@ -2093,15 +2090,12 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
         

Implementors

    ")?; - match cache.implementors.get(&it.def_id) { - Some(implementors) => { - for i in implementors { - write!(w, "
  • ")?; - fmt_impl_for_trait_page(&i.impl_, w)?; - writeln!(w, "
  • ")?; - } + if let Some(implementors) = cache.implementors.get(&it.def_id) { + for i in implementors { + write!(w, "
  • ")?; + fmt_impl_for_trait_page(&i.impl_, w)?; + writeln!(w, "
  • ")?; } - None => {} } write!(w, "
")?; write!(w, r#"