diff options
| author | dileepb <dileepbapat@gmail.com> | 2016-02-23 21:18:07 +0530 |
|---|---|---|
| committer | dileepb <dileepbapat@gmail.com> | 2016-02-23 21:21:51 +0530 |
| commit | fbfe70e6ab26c0cccb5fbbf5b805eecb751cb576 (patch) | |
| tree | 3cbbaa4b464bf6288f1fa9555d2a8f6b4dbd3cc8 /src | |
| parent | 6ffd7cd1664b70fed34861df3957ddee87ec9ad1 (diff) | |
| download | rust-fbfe70e6ab26c0cccb5fbbf5b805eecb751cb576.tar.gz rust-fbfe70e6ab26c0cccb5fbbf5b805eecb751cb576.zip | |
#31820 - Utilize `if..let` instead of single `match` branch
Diffstat (limited to 'src')
| -rw-r--r-- | src/libgetopts/lib.rs | 5 | ||||
| -rw-r--r-- | src/librustc_trans/back/link.rs | 10 | ||||
| -rw-r--r-- | src/librustc_trans/trans/base.rs | 20 | ||||
| -rw-r--r-- | src/librustc_trans/trans/common.rs | 5 | ||||
| -rw-r--r-- | src/librustc_trans/trans/type_of.rs | 10 | ||||
| -rw-r--r-- | src/librustdoc/lib.rs | 5 | ||||
| -rw-r--r-- | src/libstd/net/addr.rs | 5 | ||||
| -rw-r--r-- | src/libstd/net/parser.rs | 5 | ||||
| -rw-r--r-- | src/libstd/sys/windows/thread_local.rs | 5 |
9 files changed, 28 insertions, 42 deletions
diff --git a/src/libgetopts/lib.rs b/src/libgetopts/lib.rs index 57ce53e73b0..fe059076926 100644 --- a/src/libgetopts/lib.rs +++ b/src/libgetopts/lib.rs @@ -331,9 +331,8 @@ impl Matches { /// Returns the string argument supplied to one of several matching options or `None`. pub fn opts_str(&self, names: &[String]) -> Option<String> { for nm in names { - match self.opt_val(&nm[..]) { - Some(Val(ref s)) => return Some(s.clone()), - _ => (), + if let Some(Val(ref s)) = self.opt_val(&nm[..]) { + return Some(s.clone()) } } None diff --git a/src/librustc_trans/back/link.rs b/src/librustc_trans/back/link.rs index 33734d615a6..76360dcc1b9 100644 --- a/src/librustc_trans/back/link.rs +++ b/src/librustc_trans/back/link.rs @@ -226,9 +226,8 @@ fn symbol_hash<'tcx>(tcx: &ty::ctxt<'tcx>, } fn get_symbol_hash<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, t: Ty<'tcx>) -> String { - match ccx.type_hashcodes().borrow().get(&t) { - Some(h) => return h.to_string(), - None => {} + if let Some(h) = ccx.type_hashcodes().borrow().get(&t) { + return h.to_string() } let mut symbol_hasher = ccx.symbol_hasher().borrow_mut(); @@ -315,9 +314,8 @@ pub fn mangle<PI: Iterator<Item=InternedString>>(path: PI, hash: Option<&str>) - push(&mut n, &data); } - match hash { - Some(s) => push(&mut n, s), - None => {} + if let Some(s) = hash { + push(&mut n, s) } n.push('E'); // End name-sequence. diff --git a/src/librustc_trans/trans/base.rs b/src/librustc_trans/trans/base.rs index e36905c6d90..161ab90c03a 100644 --- a/src/librustc_trans/trans/base.rs +++ b/src/librustc_trans/trans/base.rs @@ -150,9 +150,8 @@ impl Drop for _InsnCtxt { pub fn push_ctxt(s: &'static str) -> _InsnCtxt { debug!("new InsnCtxt: {}", s); TASK_LOCAL_INSN_KEY.with(|slot| { - match slot.borrow_mut().as_mut() { - Some(ctx) => ctx.push(s), - None => {} + if let Some(ctx) = slot.borrow_mut().as_mut() { + ctx.push(s) } }); _InsnCtxt { @@ -198,9 +197,8 @@ fn get_extern_rust_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, name: &str, did: DefId) -> ValueRef { - match ccx.externs().borrow().get(name) { - Some(n) => return *n, - None => (), + if let Some(n) = ccx.externs().borrow().get(name) { + return *n; } let f = declare::declare_rust_fn(ccx, name, fn_ty); @@ -238,9 +236,8 @@ pub fn get_extern_const<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, -> ValueRef { let name = ccx.sess().cstore.item_symbol(did); let ty = type_of(ccx, t); - match ccx.externs().borrow_mut().get(&name) { - Some(n) => return *n, - None => (), + if let Some(n) = ccx.externs().borrow_mut().get(&name) { + return *n; } // FIXME(nagisa): perhaps the map of externs could be offloaded to llvm somehow? // FIXME(nagisa): investigate whether it can be changed into define_global @@ -2755,9 +2752,8 @@ fn contains_null(s: &str) -> bool { pub fn get_item_val(ccx: &CrateContext, id: ast::NodeId) -> ValueRef { debug!("get_item_val(id=`{}`)", id); - match ccx.item_vals().borrow().get(&id).cloned() { - Some(v) => return v, - None => {} + if let Some(v) = ccx.item_vals().borrow().get(&id).cloned() { + return v; } let item = ccx.tcx().map.get(id); diff --git a/src/librustc_trans/trans/common.rs b/src/librustc_trans/trans/common.rs index bdc0f8539d6..7f7de0e872b 100644 --- a/src/librustc_trans/trans/common.rs +++ b/src/librustc_trans/trans/common.rs @@ -947,9 +947,8 @@ pub fn C_u8(ccx: &CrateContext, i: u8) -> ValueRef { // our boxed-and-length-annotated strings. pub fn C_cstr(cx: &CrateContext, s: InternedString, null_terminated: bool) -> ValueRef { unsafe { - match cx.const_cstr_cache().borrow().get(&s) { - Some(&llval) => return llval, - None => () + if let Some(&llval) = cx.const_cstr_cache().borrow().get(&s) { + return llval; } let sc = llvm::LLVMConstStringInContext(cx.llcx(), diff --git a/src/librustc_trans/trans/type_of.rs b/src/librustc_trans/trans/type_of.rs index 0f88269a2c9..24a7fd372f6 100644 --- a/src/librustc_trans/trans/type_of.rs +++ b/src/librustc_trans/trans/type_of.rs @@ -182,9 +182,8 @@ pub fn type_of_fn_from_ty<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, fty: Ty<'tcx>) // recursive types. For example, enum types rely on this behavior. pub fn sizing_type_of<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, t: Ty<'tcx>) -> Type { - match cx.llsizingtypes().borrow().get(&t).cloned() { - Some(t) => return t, - None => () + if let Some(t) = cx.llsizingtypes().borrow().get(&t).cloned() { + return t; } debug!("sizing_type_of {:?}", t); @@ -317,9 +316,8 @@ pub fn type_of<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, ty: Ty<'tcx>) -> Type { /// NB: If you update this, be sure to update `sizing_type_of()` as well. pub fn in_memory_type_of<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, t: Ty<'tcx>) -> Type { // Check the cache. - match cx.lltypes().borrow().get(&t) { - Some(&llty) => return llty, - None => () + if let Some(&llty) = cx.lltypes().borrow().get(&t) { + return llty; } debug!("type_of {:?}", t); diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 6cad0d7d940..ffb15d157b0 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -385,9 +385,8 @@ fn rust_input(cratefile: &str, externs: core::Externs, matches: &getopts::Matche *s.borrow_mut() = analysis.take(); }); - match matches.opt_str("crate-name") { - Some(name) => krate.name = name, - None => {} + if let Some(name) = matches.opt_str("crate-name") { + krate.name = name } // Process all of the crate attributes, extracting plugin metadata along diff --git a/src/libstd/net/addr.rs b/src/libstd/net/addr.rs index 89c51c70843..87d5dc20e9f 100644 --- a/src/libstd/net/addr.rs +++ b/src/libstd/net/addr.rs @@ -467,9 +467,8 @@ impl ToSocketAddrs for str { type Iter = vec::IntoIter<SocketAddr>; fn to_socket_addrs(&self) -> io::Result<vec::IntoIter<SocketAddr>> { // try to parse as a regular SocketAddr first - match self.parse().ok() { - Some(addr) => return Ok(vec![addr].into_iter()), - None => {} + if let Some(addr) = self.parse().ok() { + return Ok(vec![addr].into_iter()); } macro_rules! try_opt { diff --git a/src/libstd/net/parser.rs b/src/libstd/net/parser.rs index 46a0309dbb5..63eee6bcfde 100644 --- a/src/libstd/net/parser.rs +++ b/src/libstd/net/parser.rs @@ -66,9 +66,8 @@ impl<'a> Parser<'a> { fn read_or<T>(&mut self, parsers: &mut [Box<FnMut(&mut Parser) -> Option<T> + 'static>]) -> Option<T> { for pf in parsers { - match self.read_atomically(|p: &mut Parser| pf(p)) { - Some(r) => return Some(r), - None => {} + if let Some(r) = self.read_atomically(|p: &mut Parser| pf(p)) { + return Some(r); } } None diff --git a/src/libstd/sys/windows/thread_local.rs b/src/libstd/sys/windows/thread_local.rs index db2ad1d89c4..386d21a04c7 100644 --- a/src/libstd/sys/windows/thread_local.rs +++ b/src/libstd/sys/windows/thread_local.rs @@ -69,9 +69,8 @@ static mut DTORS: *mut Vec<(Key, Dtor)> = ptr::null_mut(); pub unsafe fn create(dtor: Option<Dtor>) -> Key { let key = c::TlsAlloc(); assert!(key != c::TLS_OUT_OF_INDEXES); - match dtor { - Some(f) => register_dtor(key, f), - None => {} + if let Some(f) = dtor { + register_dtor(key, f); } return key; } |
