Skip to content

Commit 9a5f7b1

Browse files
varkoryodaldevoid
andcommitted
Move const generic error from lowering to collect
Co-Authored-By: Gabriel Smith <[email protected]>
1 parent d44030d commit 9a5f7b1

File tree

2 files changed

+28
-16
lines changed

2 files changed

+28
-16
lines changed

src/librustc/hir/lowering.rs

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use crate::hir::HirVec;
3636
use crate::hir::map::{DefKey, DefPathData, Definitions};
3737
use crate::hir::def_id::{DefId, DefIndex, DefIndexAddressSpace, CRATE_DEF_INDEX};
3838
use crate::hir::def::{Def, PathResolution, PerNS};
39-
use crate::hir::GenericArg;
39+
use crate::hir::{GenericArg, ConstArg};
4040
use crate::lint::builtin::{self, PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES,
4141
ELIDED_LIFETIMES_IN_PATHS};
4242
use crate::middle::cstore::CrateStore;
@@ -1172,13 +1172,10 @@ impl<'a> LoweringContext<'a> {
11721172
ast::GenericArg::Lifetime(lt) => GenericArg::Lifetime(self.lower_lifetime(&lt)),
11731173
ast::GenericArg::Type(ty) => GenericArg::Type(self.lower_ty_direct(&ty, itctx)),
11741174
ast::GenericArg::Const(ct) => {
1175-
// FIXME(const_generics): const generics are not yet defined in the HIR.
1176-
self.sess.struct_span_err(
1177-
ct.value.span,
1178-
"const generics in any position are currently unsupported",
1179-
).emit();
1180-
self.sess.abort_if_errors();
1181-
bug!();
1175+
GenericArg::Const(ConstArg {
1176+
value: self.lower_anon_const(&ct),
1177+
span: ct.value.span,
1178+
})
11821179
}
11831180
}
11841181
}
@@ -2520,14 +2517,10 @@ impl<'a> LoweringContext<'a> {
25202517

25212518
(hir::ParamName::Plain(ident), kind)
25222519
}
2523-
GenericParamKind::Const { .. } => {
2524-
// FIXME(const_generics): const generics are not yet defined in the HIR.
2525-
self.sess.struct_span_err(
2526-
param.ident.span,
2527-
"const generics in any position are currently unsupported",
2528-
).emit();
2529-
self.sess.abort_if_errors();
2530-
bug!();
2520+
GenericParamKind::Const { ref ty } => {
2521+
(hir::ParamName::Plain(param.ident), hir::GenericParamKind::Const {
2522+
ty: self.lower_ty(&ty, ImplTraitContext::disallowed()),
2523+
})
25312524
}
25322525
};
25332526

src/librustc_typeck/collect.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ impl<'a, 'tcx> Visitor<'tcx> for CollectItemTypesVisitor<'a, 'tcx> {
132132
self.tcx.type_of(def_id);
133133
}
134134
hir::GenericParamKind::Type { .. } => {}
135+
hir::GenericParamKind::Const { .. } => {
136+
let def_id = self.tcx.hir().local_def_id(param.id);
137+
self.tcx.type_of(def_id);
138+
}
135139
}
136140
}
137141
intravisit::walk_generics(self, generics);
@@ -1041,6 +1045,21 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx ty
10411045
i += 1;
10421046
Some(ty_param)
10431047
}
1048+
GenericParamKind::Const { .. } => {
1049+
if param.name.ident().name == keywords::SelfUpper.name() {
1050+
span_bug!(
1051+
param.span,
1052+
"`Self` should not be the name of a regular parameter",
1053+
);
1054+
}
1055+
1056+
tcx.sess.struct_span_err(
1057+
param.span,
1058+
"const generics in any position are currently unsupported",
1059+
).emit();
1060+
tcx.sess.abort_if_errors();
1061+
bug!();
1062+
}
10441063
_ => None,
10451064
}),
10461065
);

0 commit comments

Comments
 (0)