]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_typeck/collect.rs
Check for Const param in collect
[rust.git] / src / librustc_typeck / collect.rs
index 4a2d526263c03cb5ae82952e588ca75e7cba2891..8f382243bb5a3f0f44da94d50b56b256c54b7654 100644 (file)
@@ -132,6 +132,10 @@ fn visit_generics(&mut self, generics: &'tcx hir::Generics) {
                     self.tcx.type_of(def_id);
                 }
                 hir::GenericParamKind::Type { .. } => {}
+                hir::GenericParamKind::Const { .. } => {
+                    let def_id = self.tcx.hir().local_def_id(param.id);
+                    self.tcx.type_of(def_id);
+                }
             }
         }
         intravisit::walk_generics(self, generics);
@@ -1041,6 +1045,21 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx ty
                     i += 1;
                     Some(ty_param)
                 }
+                GenericParamKind::Const { .. } => {
+                    if param.name.ident().name == keywords::SelfUpper.name() {
+                        span_bug!(
+                            param.span,
+                            "`Self` should not be the name of a regular parameter",
+                        );
+                    }
+
+                    tcx.sess.struct_span_err(
+                        param.span,
+                        "const generics in any position are currently unsupported",
+                    ).emit();
+                    tcx.sess.abort_if_errors();
+                    bug!();
+                }
                 _ => None,
             }),
     );
@@ -1301,10 +1320,10 @@ fn type_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Ty<'tcx> {
         },
 
         Node::GenericParam(param) => match &param.kind {
-            hir::GenericParamKind::Type {
-                default: Some(ref ty),
-                ..
-            } => icx.to_ty(ty),
+            hir::GenericParamKind::Type { default: Some(ref ty), .. } |
+            hir::GenericParamKind::Const { ref ty, .. } => {
+                icx.to_ty(ty)
+            }
             x => bug!("unexpected non-type Node::GenericParam: {:?}", x),
         },