]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc/middle/astconv_util.rs
Auto merge of #31077 - nagisa:mir-temp-promotion, r=dotdash
[rust.git] / src / librustc / middle / astconv_util.rs
index fb0131f258d437df00d5561bea74a9b3046f2520..8b1bdc31beb01bf916aed85ab623a9907edd9cc5 100644 (file)
  * Almost certainly this could (and should) be refactored out of existence.
  */
 
-use middle::def;
+use middle::def::Def;
 use middle::ty::{self, Ty};
-use syntax::ast;
 
-pub const NO_REGIONS: usize = 1;
-pub const NO_TPS: usize = 2;
+use syntax::codemap::Span;
+use rustc_front::hir as ast;
 
-pub fn check_path_args(tcx: &ty::ctxt, segments: &[ast::PathSegment], flags: usize) {
+pub fn prohibit_type_params(tcx: &ty::ctxt, segments: &[ast::PathSegment]) {
     for segment in segments {
-        if (flags & NO_TPS) != 0 {
-            for typ in segment.parameters.types() {
-                span_err!(tcx.sess, typ.span, E0109,
-                          "type parameters are not allowed on this type");
-                break;
-            }
+        for typ in segment.parameters.types() {
+            span_err!(tcx.sess, typ.span, E0109,
+                      "type parameters are not allowed on this type");
+            break;
         }
-
-        if (flags & NO_REGIONS) != 0 {
-            for lifetime in segment.parameters.lifetimes() {
-                span_err!(tcx.sess, lifetime.span, E0110,
-                          "lifetime parameters are not allowed on this type");
-                break;
-            }
+        for lifetime in segment.parameters.lifetimes() {
+            span_err!(tcx.sess, lifetime.span, E0110,
+                      "lifetime parameters are not allowed on this type");
+            break;
+        }
+        for binding in segment.parameters.bindings() {
+            prohibit_projection(tcx, binding.span);
+            break;
         }
     }
 }
 
+pub fn prohibit_projection(tcx: &ty::ctxt, span: Span)
+{
+    span_err!(tcx.sess, span, E0229,
+              "associated type bindings are not allowed here");
+}
+
 pub fn prim_ty_to_ty<'tcx>(tcx: &ty::ctxt<'tcx>,
                            segments: &[ast::PathSegment],
                            nty: ast::PrimTy)
                            -> Ty<'tcx> {
-    check_path_args(tcx, segments, NO_TPS | NO_REGIONS);
+    prohibit_type_params(tcx, segments);
     match nty {
         ast::TyBool => tcx.types.bool,
         ast::TyChar => tcx.types.char,
@@ -56,6 +60,8 @@ pub fn prim_ty_to_ty<'tcx>(tcx: &ty::ctxt<'tcx>,
     }
 }
 
+/// If a type in the AST is a primitive type, return the ty::Ty corresponding
+/// to it.
 pub fn ast_ty_to_prim_ty<'tcx>(tcx: &ty::ctxt<'tcx>, ast_ty: &ast::Ty)
                                -> Option<Ty<'tcx>> {
     if let ast::TyPath(None, ref path) = ast_ty.node {
@@ -66,7 +72,7 @@ pub fn ast_ty_to_prim_ty<'tcx>(tcx: &ty::ctxt<'tcx>, ast_ty: &ast::Ty)
             }
             Some(d) => d.full_def()
         };
-        if let def::DefPrimTy(nty) = def {
+        if let Def::PrimTy(nty) = def {
             Some(prim_ty_to_ty(tcx, &path.segments, nty))
         } else {
             None