diff options
| author | Zack M. Davis <code@zackmdavis.net> | 2016-07-03 14:38:37 -0700 |
|---|---|---|
| committer | Zack M. Davis <code@zackmdavis.net> | 2016-07-03 16:27:02 -0700 |
| commit | d37edef9dd088d953c5e272db37686a338c31778 (patch) | |
| tree | 294c125abc99a5d3e7d788c2cc0b056ecd35a26e /src/librustdoc | |
| parent | 5e858f34df6ac9ae9d2fbc40c84db9d4bcd29eff (diff) | |
| download | rust-d37edef9dd088d953c5e272db37686a338c31778.tar.gz rust-d37edef9dd088d953c5e272db37686a338c31778.zip | |
prefer `if let` to match with `None => {}` arm in some places
This is a spiritual succesor to #34268/8531d581, in which we replaced a number of matches of None to the unit value with `if let` conditionals where it was judged that this made for clearer/simpler code (as would be recommended by Manishearth/rust-clippy's `single_match` lint). The same rationale applies to matches of None to the empty block.
Diffstat (limited to 'src/librustdoc')
| -rw-r--r-- | src/librustdoc/html/format.rs | 20 | ||||
| -rw-r--r-- | src/librustdoc/html/highlight.rs | 5 | ||||
| -rw-r--r-- | src/librustdoc/html/render.rs | 36 |
3 files changed, 25 insertions, 36 deletions
diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index 760e84622cf..77c4a0f8174 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, "<a class='primitive' href='{}{}/primitive.{}.html'>", - root, - path.0.first().unwrap(), - prim.to_url_str())?; - needs_termination = true; - } - None => {} + if let Some(root) = loc { + write!(f, "<a class='primitive' href='{}{}/primitive.{}.html'>", + 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 2e2f9989773..84e98a67391 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, "<pre ")?; - match id { - Some(id) => 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 9f2b33c0282..acf867561a6 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, <h2 id='implementors'>Implementors</h2> <ul class='item-list' id='implementors-list'> ")?; - match cache.implementors.get(&it.def_id) { - Some(implementors) => { - for i in implementors { - write!(w, "<li><code>")?; - fmt_impl_for_trait_page(&i.impl_, w)?; - writeln!(w, "</code></li>")?; - } + if let Some(implementors) = cache.implementors.get(&it.def_id) { + for i in implementors { + write!(w, "<li><code>")?; + fmt_impl_for_trait_page(&i.impl_, w)?; + writeln!(w, "</code></li>")?; } - None => {} } write!(w, "</ul>")?; write!(w, r#"<script type="text/javascript" async |
