Skip to content

Commit 21ba1d5

Browse files
committed
auto merge of #19405 : jfager/rust/de-match-pyramid, r=bstrie
No semantic changes, no enabling `if let` where it wasn't already enabled.
2 parents de95ad4 + a779e3b commit 21ba1d5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+895
-1369
lines changed

src/librustc/lint/builtin.rs

+86-153
Large diffs are not rendered by default.

src/librustc/metadata/decoder.rs

+27-44
Original file line numberDiff line numberDiff line change
@@ -514,41 +514,27 @@ fn each_child_of_item_or_crate(intr: Rc<IdentInterner>,
514514
let inherent_impl_def_id = item_def_id(inherent_impl_def_id_doc,
515515
cdata);
516516
let items = reader::get_doc(rbml::Doc::new(cdata.data()), tag_items);
517-
match maybe_find_item(inherent_impl_def_id.node, items) {
518-
None => {}
519-
Some(inherent_impl_doc) => {
520-
let _ = reader::tagged_docs(inherent_impl_doc,
521-
tag_item_impl_item,
522-
|impl_item_def_id_doc| {
523-
let impl_item_def_id = item_def_id(impl_item_def_id_doc,
524-
cdata);
525-
match maybe_find_item(impl_item_def_id.node, items) {
526-
None => {}
527-
Some(impl_method_doc) => {
528-
match item_family(impl_method_doc) {
529-
StaticMethod => {
530-
// Hand off the static method
531-
// to the callback.
532-
let static_method_name =
533-
item_name(&*intr, impl_method_doc);
534-
let static_method_def_like =
535-
item_to_def_like(impl_method_doc,
536-
impl_item_def_id,
537-
cdata.cnum);
538-
callback(static_method_def_like,
539-
static_method_name,
540-
item_visibility(impl_method_doc));
541-
}
542-
_ => {}
543-
}
544-
}
517+
if let Some(inherent_impl_doc) = maybe_find_item(inherent_impl_def_id.node, items) {
518+
let _ = reader::tagged_docs(inherent_impl_doc,
519+
tag_item_impl_item,
520+
|impl_item_def_id_doc| {
521+
let impl_item_def_id = item_def_id(impl_item_def_id_doc,
522+
cdata);
523+
if let Some(impl_method_doc) = maybe_find_item(impl_item_def_id.node, items) {
524+
if let StaticMethod = item_family(impl_method_doc) {
525+
// Hand off the static method to the callback.
526+
let static_method_name = item_name(&*intr, impl_method_doc);
527+
let static_method_def_like = item_to_def_like(impl_method_doc,
528+
impl_item_def_id,
529+
cdata.cnum);
530+
callback(static_method_def_like,
531+
static_method_name,
532+
item_visibility(impl_method_doc));
545533
}
546-
547-
true
548-
});
549-
}
534+
}
535+
true
536+
});
550537
}
551-
552538
true
553539
});
554540

@@ -578,17 +564,14 @@ fn each_child_of_item_or_crate(intr: Rc<IdentInterner>,
578564
let other_crates_items = reader::get_doc(rbml::Doc::new(crate_data.data()), tag_items);
579565

580566
// Get the item.
581-
match maybe_find_item(child_def_id.node, other_crates_items) {
582-
None => {}
583-
Some(child_item_doc) => {
584-
// Hand off the item to the callback.
585-
let def_like = item_to_def_like(child_item_doc,
586-
child_def_id,
587-
child_def_id.krate);
588-
// These items have a public visibility because they're part of
589-
// a public re-export.
590-
callback(def_like, token::intern(name), ast::Public);
591-
}
567+
if let Some(child_item_doc) = maybe_find_item(child_def_id.node, other_crates_items) {
568+
// Hand off the item to the callback.
569+
let def_like = item_to_def_like(child_item_doc,
570+
child_def_id,
571+
child_def_id.krate);
572+
// These items have a public visibility because they're part of
573+
// a public re-export.
574+
callback(def_like, token::intern(name), ast::Public);
592575
}
593576

594577
true

src/librustc/metadata/encoder.rs

+63-86
Original file line numberDiff line numberDiff line change
@@ -433,17 +433,13 @@ fn encode_reexported_static_trait_methods(ecx: &EncodeContext,
433433
match ecx.tcx.trait_items_cache.borrow().get(&exp.def_id) {
434434
Some(trait_items) => {
435435
for trait_item in trait_items.iter() {
436-
match *trait_item {
437-
ty::MethodTraitItem(ref m) => {
438-
encode_reexported_static_method(rbml_w,
439-
exp,
440-
m.def_id,
441-
m.name);
442-
}
443-
_ => {}
436+
if let ty::MethodTraitItem(ref m) = *trait_item {
437+
encode_reexported_static_method(rbml_w,
438+
exp,
439+
m.def_id,
440+
m.name);
444441
}
445442
}
446-
447443
true
448444
}
449445
None => { false }
@@ -454,46 +450,42 @@ fn encode_reexported_static_methods(ecx: &EncodeContext,
454450
rbml_w: &mut Encoder,
455451
mod_path: PathElems,
456452
exp: &middle::resolve::Export2) {
457-
match ecx.tcx.map.find(exp.def_id.node) {
458-
Some(ast_map::NodeItem(item)) => {
459-
let original_name = token::get_ident(item.ident);
460-
461-
let path_differs = ecx.tcx.map.with_path(exp.def_id.node, |path| {
462-
let (mut a, mut b) = (path, mod_path.clone());
463-
loop {
464-
match (a.next(), b.next()) {
465-
(None, None) => return true,
466-
(None, _) | (_, None) => return false,
467-
(Some(x), Some(y)) => if x != y { return false },
468-
}
453+
if let Some(ast_map::NodeItem(item)) = ecx.tcx.map.find(exp.def_id.node) {
454+
let original_name = token::get_ident(item.ident);
455+
456+
let path_differs = ecx.tcx.map.with_path(exp.def_id.node, |path| {
457+
let (mut a, mut b) = (path, mod_path.clone());
458+
loop {
459+
match (a.next(), b.next()) {
460+
(None, None) => return true,
461+
(None, _) | (_, None) => return false,
462+
(Some(x), Some(y)) => if x != y { return false },
469463
}
470-
});
464+
}
465+
});
471466

472-
//
473-
// We don't need to reexport static methods on items
474-
// declared in the same module as our `pub use ...` since
475-
// that's done when we encode the item itself.
476-
//
477-
// The only exception is when the reexport *changes* the
478-
// name e.g. `pub use Foo = self::Bar` -- we have
479-
// encoded metadata for static methods relative to Bar,
480-
// but not yet for Foo.
481-
//
482-
if path_differs || original_name.get() != exp.name.as_slice() {
483-
if !encode_reexported_static_base_methods(ecx, rbml_w, exp) {
484-
if encode_reexported_static_trait_methods(ecx, rbml_w, exp) {
485-
debug!("(encode reexported static methods) {} \
486-
[trait]",
487-
original_name);
488-
}
489-
}
490-
else {
491-
debug!("(encode reexported static methods) {} [base]",
492-
original_name);
467+
//
468+
// We don't need to reexport static methods on items
469+
// declared in the same module as our `pub use ...` since
470+
// that's done when we encode the item itself.
471+
//
472+
// The only exception is when the reexport *changes* the
473+
// name e.g. `pub use Foo = self::Bar` -- we have
474+
// encoded metadata for static methods relative to Bar,
475+
// but not yet for Foo.
476+
//
477+
if path_differs || original_name.get() != exp.name.as_slice() {
478+
if !encode_reexported_static_base_methods(ecx, rbml_w, exp) {
479+
if encode_reexported_static_trait_methods(ecx, rbml_w, exp) {
480+
debug!("(encode reexported static methods) {} [trait]",
481+
original_name);
493482
}
494483
}
484+
else {
485+
debug!("(encode reexported static methods) {} [base]",
486+
original_name);
487+
}
495488
}
496-
_ => {}
497489
}
498490
}
499491

@@ -581,19 +573,15 @@ fn encode_info_for_mod(ecx: &EncodeContext,
581573
true
582574
});
583575

584-
match item.node {
585-
ast::ItemImpl(..) => {
586-
let (ident, did) = (item.ident, item.id);
587-
debug!("(encoding info for module) ... encoding impl {} \
588-
({}/{})",
589-
token::get_ident(ident),
590-
did, ecx.tcx.map.node_to_string(did));
576+
if let ast::ItemImpl(..) = item.node {
577+
let (ident, did) = (item.ident, item.id);
578+
debug!("(encoding info for module) ... encoding impl {} ({}/{})",
579+
token::get_ident(ident),
580+
did, ecx.tcx.map.node_to_string(did));
591581

592-
rbml_w.start_tag(tag_mod_impl);
593-
rbml_w.wr_str(def_to_string(local_def(did)).as_slice());
594-
rbml_w.end_tag();
595-
}
596-
_ => {}
582+
rbml_w.start_tag(tag_mod_impl);
583+
rbml_w.wr_str(def_to_string(local_def(did)).as_slice());
584+
rbml_w.end_tag();
597585
}
598586
}
599587

@@ -923,12 +911,9 @@ fn encode_method_argument_names(rbml_w: &mut Encoder,
923911
rbml_w.start_tag(tag_method_argument_names);
924912
for arg in decl.inputs.iter() {
925913
rbml_w.start_tag(tag_method_argument_name);
926-
match arg.pat.node {
927-
ast::PatIdent(_, ref path1, _) => {
928-
let name = token::get_ident(path1.node);
929-
rbml_w.writer.write(name.get().as_bytes());
930-
}
931-
_ => {}
914+
if let ast::PatIdent(_, ref path1, _) = arg.pat.node {
915+
let name = token::get_ident(path1.node);
916+
rbml_w.writer.write(name.get().as_bytes());
932917
}
933918
rbml_w.end_tag();
934919
}
@@ -1854,22 +1839,19 @@ struct ImplVisitor<'a, 'b:'a, 'c:'a, 'tcx:'b> {
18541839

18551840
impl<'a, 'b, 'c, 'tcx, 'v> Visitor<'v> for ImplVisitor<'a, 'b, 'c, 'tcx> {
18561841
fn visit_item(&mut self, item: &ast::Item) {
1857-
match item.node {
1858-
ast::ItemImpl(_, Some(ref trait_ref), _, _) => {
1859-
let def_map = &self.ecx.tcx.def_map;
1860-
let trait_def = def_map.borrow()[trait_ref.ref_id].clone();
1861-
let def_id = trait_def.def_id();
1862-
1863-
// Load eagerly if this is an implementation of the Drop trait
1864-
// or if the trait is not defined in this crate.
1865-
if Some(def_id) == self.ecx.tcx.lang_items.drop_trait() ||
1866-
def_id.krate != ast::LOCAL_CRATE {
1867-
self.rbml_w.start_tag(tag_impls_impl);
1868-
encode_def_id(self.rbml_w, local_def(item.id));
1869-
self.rbml_w.end_tag();
1870-
}
1842+
if let ast::ItemImpl(_, Some(ref trait_ref), _, _) = item.node {
1843+
let def_map = &self.ecx.tcx.def_map;
1844+
let trait_def = def_map.borrow()[trait_ref.ref_id].clone();
1845+
let def_id = trait_def.def_id();
1846+
1847+
// Load eagerly if this is an implementation of the Drop trait
1848+
// or if the trait is not defined in this crate.
1849+
if Some(def_id) == self.ecx.tcx.lang_items.drop_trait() ||
1850+
def_id.krate != ast::LOCAL_CRATE {
1851+
self.rbml_w.start_tag(tag_impls_impl);
1852+
encode_def_id(self.rbml_w, local_def(item.id));
1853+
self.rbml_w.end_tag();
18711854
}
1872-
_ => {}
18731855
}
18741856
visit::walk_item(self, item);
18751857
}
@@ -1931,17 +1913,12 @@ fn encode_reachable_extern_fns(ecx: &EncodeContext, rbml_w: &mut Encoder) {
19311913
rbml_w.start_tag(tag_reachable_extern_fns);
19321914

19331915
for id in ecx.reachable.iter() {
1934-
match ecx.tcx.map.find(*id) {
1935-
Some(ast_map::NodeItem(i)) => {
1936-
match i.node {
1937-
ast::ItemFn(_, _, abi, ref generics, _)
1938-
if abi != abi::Rust && !generics.is_type_parameterized() => {
1939-
rbml_w.wr_tagged_u32(tag_reachable_extern_fn_id, *id);
1940-
}
1941-
_ => {}
1916+
if let Some(ast_map::NodeItem(i)) = ecx.tcx.map.find(*id) {
1917+
if let ast::ItemFn(_, _, abi, ref generics, _) = i.node {
1918+
if abi != abi::Rust && !generics.is_type_parameterized() {
1919+
rbml_w.wr_tagged_u32(tag_reachable_extern_fn_id, *id);
19421920
}
19431921
}
1944-
_ => {}
19451922
}
19461923
}
19471924

src/librustc/middle/borrowck/check_loans.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -892,14 +892,9 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
892892
let guarantor = cmt.guarantor();
893893
debug!("check_for_aliasable_mutable_writes(cmt={}, guarantor={})",
894894
cmt.repr(this.tcx()), guarantor.repr(this.tcx()));
895-
match guarantor.cat {
896-
mc::cat_deref(ref b, _, mc::BorrowedPtr(ty::MutBorrow, _)) => {
897-
// Statically prohibit writes to `&mut` when aliasable
898-
899-
check_for_aliasability_violation(this, span, b.clone());
900-
}
901-
902-
_ => {}
895+
if let mc::cat_deref(ref b, _, mc::BorrowedPtr(ty::MutBorrow, _)) = guarantor.cat {
896+
// Statically prohibit writes to `&mut` when aliasable
897+
check_for_aliasability_violation(this, span, b.clone());
903898
}
904899

905900
return true; // no errors reported
@@ -962,4 +957,3 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
962957
self.bccx.loan_path_to_string(loan_path)).as_slice());
963958
}
964959
}
965-

src/librustc/middle/borrowck/gather_loans/mod.rs

+11-16
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,10 @@ impl<'a, 'tcx> euv::Delegate<'tcx> for GatherLoanCtxt<'a, 'tcx> {
9797
cmt.repr(self.tcx()),
9898
mode);
9999

100-
match cmt.cat {
101-
mc::cat_downcast(..) =>
102-
gather_moves::gather_match_variant(
103-
self.bccx, &self.move_data, &self.move_error_collector,
104-
matched_pat, cmt, mode),
105-
_ => {}
100+
if let mc::cat_downcast(..) = cmt.cat {
101+
gather_moves::gather_match_variant(
102+
self.bccx, &self.move_data, &self.move_error_collector,
103+
matched_pat, cmt, mode);
106104
}
107105
}
108106

@@ -489,17 +487,14 @@ struct StaticInitializerCtxt<'a, 'tcx: 'a> {
489487

490488
impl<'a, 'tcx, 'v> Visitor<'v> for StaticInitializerCtxt<'a, 'tcx> {
491489
fn visit_expr(&mut self, ex: &Expr) {
492-
match ex.node {
493-
ast::ExprAddrOf(mutbl, ref base) => {
494-
let base_cmt = self.bccx.cat_expr(&**base);
495-
let borrow_kind = ty::BorrowKind::from_mutbl(mutbl);
496-
// Check that we don't allow borrows of unsafe static items.
497-
if check_aliasability(self.bccx, ex.span, euv::AddrOf,
498-
base_cmt, borrow_kind).is_err() {
499-
return; // reported an error, no sense in reporting more.
500-
}
490+
if let ast::ExprAddrOf(mutbl, ref base) = ex.node {
491+
let base_cmt = self.bccx.cat_expr(&**base);
492+
let borrow_kind = ty::BorrowKind::from_mutbl(mutbl);
493+
// Check that we don't allow borrows of unsafe static items.
494+
if check_aliasability(self.bccx, ex.span, euv::AddrOf,
495+
base_cmt, borrow_kind).is_err() {
496+
return; // reported an error, no sense in reporting more.
501497
}
502-
_ => {}
503498
}
504499

505500
visit::walk_expr(self, ex);

src/librustc/middle/const_eval.rs

+5-9
Original file line numberDiff line numberDiff line change
@@ -278,11 +278,8 @@ impl<'a, 'tcx> ConstEvalVisitor<'a, 'tcx> {
278278

279279
impl<'a, 'tcx, 'v> Visitor<'v> for ConstEvalVisitor<'a, 'tcx> {
280280
fn visit_ty(&mut self, t: &ast::Ty) {
281-
match t.node {
282-
ast::TyFixedLengthVec(_, ref expr) => {
283-
check::check_const_in_type(self.tcx, &**expr, ty::mk_uint());
284-
}
285-
_ => {}
281+
if let ast::TyFixedLengthVec(_, ref expr) = t.node {
282+
check::check_const_in_type(self.tcx, &**expr, ty::mk_uint());
286283
}
287284

288285
visit::walk_ty(self, t);
@@ -321,10 +318,9 @@ pub fn const_expr_to_pat(tcx: &ty::ctxt, expr: &Expr) -> P<ast::Pat> {
321318

322319
ast::ExprCall(ref callee, ref args) => {
323320
let def = tcx.def_map.borrow()[callee.id].clone();
324-
match tcx.def_map.borrow_mut().entry(expr.id) {
325-
Vacant(entry) => { entry.set(def); }
326-
_ => {}
327-
};
321+
if let Vacant(entry) = tcx.def_map.borrow_mut().entry(expr.id) {
322+
entry.set(def);
323+
}
328324
let path = match def {
329325
def::DefStruct(def_id) => def_to_path(tcx, def_id),
330326
def::DefVariant(_, variant_did, _) => def_to_path(tcx, variant_did),

0 commit comments

Comments
 (0)