about summary refs log tree commit diff
diff options
context:
space:
mode:
authorvarkor <github@varkor.com>2019-02-15 22:22:54 +0000
committervarkor <github@varkor.com>2019-02-15 22:28:48 +0000
commit9a5f7b1eae10482d5d314c14db25f5abd6533bbe (patch)
treeb4b92079f6dd109c1f696d3586d663ef00b74b7c
parentd44030d8ec6245edabdbe23a69be21bffb51eb11 (diff)
downloadrust-9a5f7b1eae10482d5d314c14db25f5abd6533bbe.tar.gz
rust-9a5f7b1eae10482d5d314c14db25f5abd6533bbe.zip
Move const generic error from lowering to collect
Co-Authored-By: Gabriel Smith <yodaldevoid@users.noreply.github.com>
-rw-r--r--src/librustc/hir/lowering.rs25
-rw-r--r--src/librustc_typeck/collect.rs19
2 files changed, 28 insertions, 16 deletions
diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs
index 84487c40f87..52c3eb26d61 100644
--- a/src/librustc/hir/lowering.rs
+++ b/src/librustc/hir/lowering.rs
@@ -36,7 +36,7 @@ use crate::hir::HirVec;
 use crate::hir::map::{DefKey, DefPathData, Definitions};
 use crate::hir::def_id::{DefId, DefIndex, DefIndexAddressSpace, CRATE_DEF_INDEX};
 use crate::hir::def::{Def, PathResolution, PerNS};
-use crate::hir::GenericArg;
+use crate::hir::{GenericArg, ConstArg};
 use crate::lint::builtin::{self, PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES,
                     ELIDED_LIFETIMES_IN_PATHS};
 use crate::middle::cstore::CrateStore;
@@ -1172,13 +1172,10 @@ impl<'a> LoweringContext<'a> {
             ast::GenericArg::Lifetime(lt) => GenericArg::Lifetime(self.lower_lifetime(&lt)),
             ast::GenericArg::Type(ty) => GenericArg::Type(self.lower_ty_direct(&ty, itctx)),
             ast::GenericArg::Const(ct) => {
-                // FIXME(const_generics): const generics are not yet defined in the HIR.
-                self.sess.struct_span_err(
-                    ct.value.span,
-                    "const generics in any position are currently unsupported",
-                ).emit();
-                self.sess.abort_if_errors();
-                bug!();
+                GenericArg::Const(ConstArg {
+                    value: self.lower_anon_const(&ct),
+                    span: ct.value.span,
+                })
             }
         }
     }
@@ -2520,14 +2517,10 @@ impl<'a> LoweringContext<'a> {
 
                 (hir::ParamName::Plain(ident), kind)
             }
-            GenericParamKind::Const { .. } => {
-                // FIXME(const_generics): const generics are not yet defined in the HIR.
-                self.sess.struct_span_err(
-                    param.ident.span,
-                    "const generics in any position are currently unsupported",
-                ).emit();
-                self.sess.abort_if_errors();
-                bug!();
+            GenericParamKind::Const { ref ty } => {
+                (hir::ParamName::Plain(param.ident), hir::GenericParamKind::Const {
+                    ty: self.lower_ty(&ty, ImplTraitContext::disallowed()),
+                })
             }
         };
 
diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs
index 4a2d526263c..db508a57726 100644
--- a/src/librustc_typeck/collect.rs
+++ b/src/librustc_typeck/collect.rs
@@ -132,6 +132,10 @@ impl<'a, 'tcx> Visitor<'tcx> for CollectItemTypesVisitor<'a, 'tcx> {
                     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,
             }),
     );