]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_typeck/lib.rs
A few cleanups and minor improvements to typeck
[rust.git] / src / librustc_typeck / lib.rs
index 1de79ddf4a49f8e53445e35d1398b987cf456ed5..a00a9f8613b64b75554a144fc50987ad75e5257b 100644 (file)
@@ -146,7 +146,7 @@ fn require_c_abi_if_variadic(tcx: TyCtxt,
                              span: Span) {
     if decl.variadic && !(abi == Abi::C || abi == Abi::Cdecl) {
         let mut err = struct_span_err!(tcx.sess, span, E0045,
-                  "variadic function must have C or cdecl calling convention");
+            "variadic function must have C or cdecl calling convention");
         err.span_label(span, "variadics require C or cdecl calling convention").emit();
     }
 }
@@ -186,35 +186,29 @@ fn check_main_fn_ty<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
     let main_t = tcx.type_of(main_def_id);
     match main_t.sty {
         ty::FnDef(..) => {
-            match tcx.hir.find(main_id) {
-                Some(Node::Item(it)) => {
-                    match it.node {
-                        hir::ItemKind::Fn(.., ref generics, _) => {
-                            let mut error = false;
-                            if !generics.params.is_empty() {
-                                let msg = "`main` function is not allowed to have generic \
-                                           parameters".to_string();
-                                let label = "`main` cannot have generic parameters".to_string();
-                                struct_span_err!(tcx.sess, generics.span, E0131, "{}", msg)
-                                    .span_label(generics.span, label)
-                                    .emit();
-                                error = true;
-                            }
-                            if let Some(sp) = generics.where_clause.span() {
-                                struct_span_err!(tcx.sess, sp, E0646,
-                                    "`main` function is not allowed to have a `where` clause")
-                                    .span_label(sp, "`main` cannot have a `where` clause")
-                                    .emit();
-                                error = true;
-                            }
-                            if error {
-                                return;
-                            }
-                        }
-                        _ => ()
+            if let Some(Node::Item(it)) = tcx.hir.find(main_id) {
+                if let hir::ItemKind::Fn(.., ref generics, _) = it.node {
+                    let mut error = false;
+                    if !generics.params.is_empty() {
+                        let msg = "`main` function is not allowed to have generic \
+                                   parameters".to_owned();
+                        let label = "`main` cannot have generic parameters".to_string();
+                        struct_span_err!(tcx.sess, generics.span, E0131, "{}", msg)
+                            .span_label(generics.span, label)
+                            .emit();
+                        error = true;
+                    }
+                    if let Some(sp) = generics.where_clause.span() {
+                        struct_span_err!(tcx.sess, sp, E0646,
+                            "`main` function is not allowed to have a `where` clause")
+                            .span_label(sp, "`main` cannot have a `where` clause")
+                            .emit();
+                        error = true;
+                    }
+                    if error {
+                        return;
                     }
                 }
-                _ => ()
             }
 
             let actual = tcx.fn_sig(main_def_id);
@@ -258,34 +252,28 @@ fn check_start_fn_ty<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
     let start_t = tcx.type_of(start_def_id);
     match start_t.sty {
         ty::FnDef(..) => {
-            match tcx.hir.find(start_id) {
-                Some(Node::Item(it)) => {
-                    match it.node {
-                        hir::ItemKind::Fn(.., ref generics, _) => {
-                            let mut error = false;
-                            if !generics.params.is_empty() {
-                                struct_span_err!(tcx.sess, generics.span, E0132,
-                                    "start function is not allowed to have type parameters")
-                                    .span_label(generics.span,
-                                                "start function cannot have type parameters")
-                                    .emit();
-                                error = true;
-                            }
-                            if let Some(sp) = generics.where_clause.span() {
-                                struct_span_err!(tcx.sess, sp, E0647,
-                                    "start function is not allowed to have a `where` clause")
-                                    .span_label(sp, "start function cannot have a `where` clause")
-                                    .emit();
-                                error = true;
-                            }
-                            if error {
-                                return;
-                            }
-                        }
-                        _ => ()
+            if let Some(Node::Item(it)) = tcx.hir.find(start_id) {
+                if let hir::ItemKind::Fn(.., ref generics, _) = it.node {
+                    let mut error = false;
+                    if !generics.params.is_empty() {
+                        struct_span_err!(tcx.sess, generics.span, E0132,
+                            "start function is not allowed to have type parameters")
+                            .span_label(generics.span,
+                                        "start function cannot have type parameters")
+                            .emit();
+                        error = true;
+                    }
+                    if let Some(sp) = generics.where_clause.span() {
+                        struct_span_err!(tcx.sess, sp, E0647,
+                            "start function is not allowed to have a `where` clause")
+                            .span_label(sp, "start function cannot have a `where` clause")
+                            .emit();
+                        error = true;
+                    }
+                    if error {
+                        return;
                     }
                 }
-                _ => ()
             }
 
             let se_ty = tcx.mk_fn_ptr(ty::Binder::bind(
@@ -388,6 +376,7 @@ pub fn hir_ty_to_ty<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, hir_ty: &hir::Ty) ->
     let env_node_id = tcx.hir.get_parent(hir_ty.id);
     let env_def_id = tcx.hir.local_def_id(env_node_id);
     let item_cx = self::collect::ItemCtxt::new(tcx, env_def_id);
+
     astconv::AstConv::ast_ty_to_ty(&item_cx, hir_ty)
 }
 
@@ -403,6 +392,7 @@ pub fn hir_trait_to_predicates<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, hir_trait:
     let principal = astconv::AstConv::instantiate_poly_trait_ref_inner(
         &item_cx, hir_trait, tcx.types.err, &mut projections, true
     );
+
     (principal, projections)
 }