Skip to content

Commit cb3f343

Browse files
committed
Extend choose_generics_over_qpath to generic consts
1 parent 88fd414 commit cb3f343

File tree

10 files changed

+22
-15
lines changed

10 files changed

+22
-15
lines changed

src/librustc/hir/lowering.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2266,7 +2266,6 @@ impl<'a> LoweringContext<'a> {
22662266
mut itctx: ImplTraitContext)
22672267
-> hir::GenericParam {
22682268
let mut bounds = self.lower_param_bounds(&param.bounds, itctx.reborrow());
2269-
// TODO(const_generics): only create `hir::GenericParam` once.
22702269

22712270
let (name, kind) = match param.kind {
22722271
GenericParamKind::Lifetime => {

src/librustc/infer/const_variable.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ use syntax_pos::Span;
1616
pub enum ConstVariableOrigin {
1717
ConstInference(Span),
1818
ConstParameterDefinition(Span, InternedString),
19+
SubstitutionPlaceholder(Span),
1920
}

src/librustc/infer/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
589589
let mut type_variables = self.type_variables.borrow_mut();
590590
let mut int_unification_table = self.int_unification_table.borrow_mut();
591591
let mut float_unification_table = self.float_unification_table.borrow_mut();
592-
// TODO(const_generics)
592+
// TODO(const_generics): should there be an equivalent function for const variables?
593593

594594
type_variables
595595
.unsolved_variables()

src/librustc/ty/structural_impls.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,8 +1177,7 @@ impl<'tcx> TypeFoldable<'tcx> for ConstValue<'tcx> {
11771177
match *self {
11781178
ConstValue::Scalar(_) |
11791179
ConstValue::ScalarPair(_, _) |
1180-
ConstValue::Param(_) | // TODO(const_generics)
1181-
ConstValue::Infer(_) | // TODO(const_generics)
1180+
ConstValue::Param(_) | ConstValue::Infer(_) | // TODO(const_generics:param/infer)
11821181
ConstValue::ByRef(_, _) => false,
11831182
ConstValue::Unevaluated(_, substs) => substs.visit_with(visitor),
11841183
}

src/librustc/ty/walk.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ fn push_subtypes<'tcx>(stack: &mut TypeWalkerStack<'tcx>, parent_ty: Ty<'tcx>) {
140140
}
141141

142142
fn push_const<'tcx>(stack: &mut TypeWalkerStack<'tcx>, constant: &'tcx ty::Const<'tcx>) {
143-
// TODO(const_generics): `Param/Infer` case
143+
// TODO(const_generics:param/infer)
144144
if let ConstValue::Unevaluated(_, substs) = constant.val {
145145
stack.extend(substs.types().rev());
146146
}

src/librustc/ty/wf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ impl<'a, 'gcx, 'tcx> WfPredicates<'a, 'gcx, 'tcx> {
216216
/// into `self.out`.
217217
fn compute_const(&mut self, constant: &'tcx ty::Const<'tcx>) {
218218
self.require_sized(constant.ty, traits::ConstSized);
219-
// TODO(const_generics): `Param/Infer` case
219+
// TODO(const_generics:param/infer)
220220
if let ConstValue::Unevaluated(def_id, substs) = constant.val {
221221
let obligations = self.nominal_obligations(def_id, substs);
222222
self.out.extend(obligations);

src/librustc_codegen_llvm/mir/constant.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ impl FunctionCx<'a, 'll, 'tcx> {
157157
};
158158
tcx.const_eval(param_env.and(cid))
159159
},
160-
// TODO(const_generics): `Param/Infer` case
160+
// TODO(const_generics:param/infer)
161161
_ => Ok(constant),
162162
}
163163
}

src/librustc_typeck/astconv.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1531,7 +1531,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
15311531
hir::TyKind::Array(ref ty, ref length) => {
15321532
let length_def_id = tcx.hir.local_def_id(length.id);
15331533
let substs = Substs::identity_for_item(tcx, length_def_id);
1534-
// TODO(const_generics): `Param/Infer` case
1534+
// TODO(const_generics:param/infer)
15351535
let length = ty::Const::unevaluated(tcx, length_def_id, substs, tcx.types.usize);
15361536
let array_ty = tcx.mk_ty(ty::Array(self.ast_ty_to_ty(&ty), length));
15371537
self.normalize_ty(ast_ty.span, array_ty)

src/librustc_typeck/check/method/probe.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use rustc::traits::{self, ObligationCause};
2222
use rustc::ty::{self, Ty, ToPolyTraitRef, ToPredicate, TraitRef, TypeFoldable};
2323
use rustc::ty::GenericParamDefKind;
2424
use rustc::infer::type_variable::TypeVariableOrigin;
25+
use rustc::infer::const_variable::ConstVariableOrigin;
2526
use rustc::util::nodemap::FxHashSet;
2627
use rustc::infer::{self, InferOk};
2728
use rustc::middle::stability;
@@ -1420,10 +1421,14 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
14201421
match param.kind {
14211422
GenericParamDefKind::Lifetime => self.tcx.types.re_erased.into(),
14221423
GenericParamDefKind::Type { .. } => {
1423-
self.next_ty_var(TypeVariableOrigin::SubstitutionPlaceholder(
1424-
self.tcx.def_span(def_id))).into()
1424+
let span = self.tcx.def_span(def_id);
1425+
self.next_ty_var(TypeVariableOrigin::SubstitutionPlaceholder(span)).into()
1426+
}
1427+
GenericParamDefKind::Const => {
1428+
let span = self.tcx.def_span(def_id);
1429+
let origin = ConstVariableOrigin::SubstitutionPlaceholder(span);
1430+
self.next_const_var(self.tcx.type_of(param.def_id), origin).into()
14251431
}
1426-
GenericParamDefKind::Const => unimplemented!(), // TODO(const_generics)
14271432
}
14281433
})
14291434
}

src/libsyntax/parse/parser.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5253,7 +5253,7 @@ impl<'a> Parser<'a> {
52535253
// We are considering adding generics to the `where` keyword as an alternative higher-rank
52545254
// parameter syntax (as in `where<'a>` or `where<T>`. To avoid that being a breaking
52555255
// change we parse those generics now, but report an error.
5256-
if self.choose_generics_over_qpath() {
5256+
if self.choose_generics_over_qpath(false) {
52575257
let generics = self.parse_generics()?;
52585258
self.span_err(generics.span,
52595259
"generic parameters on `where` clauses are reserved for future use");
@@ -5829,7 +5829,7 @@ impl<'a> Parser<'a> {
58295829

58305830
// TODO(const_generics): const generics introduces expressions to the list of
58315831
// things we can see after '<'.
5832-
fn choose_generics_over_qpath(&self) -> bool {
5832+
fn choose_generics_over_qpath(&self, param: bool) -> bool {
58335833
// There's an ambiguity between generic parameters and qualified paths in impls.
58345834
// If we see `<` it may start both, so we have to inspect some following tokens.
58355835
// The following combinations can only start generics,
@@ -5840,6 +5840,7 @@ impl<'a> Parser<'a> {
58405840
// `<` (LIFETIME|IDENT) `,` - first generic parameter in a list
58415841
// `<` (LIFETIME|IDENT) `:` - generic parameter with bounds
58425842
// `<` (LIFETIME|IDENT) `=` - generic parameter with a default
5843+
// `<` const IDENT - generic const parameter
58435844
// The only truly ambiguous case is
58445845
// `<` IDENT `>` `::` IDENT ...
58455846
// we disambiguate it in favor of generics (`impl<T> ::absolute::Path<T> { ... }`)
@@ -5849,7 +5850,9 @@ impl<'a> Parser<'a> {
58495850
(self.look_ahead(1, |t| t == &token::Pound || t == &token::Gt) ||
58505851
self.look_ahead(1, |t| t.is_lifetime() || t.is_ident()) &&
58515852
self.look_ahead(2, |t| t == &token::Gt || t == &token::Comma ||
5852-
t == &token::Colon || t == &token::Eq))
5853+
t == &token::Colon || t == &token::Eq) ||
5854+
param && self.look_ahead(1, |t| t.is_keyword(keywords::Const) &&
5855+
self.look_ahead(2, |t| t.is_ident())))
58535856
}
58545857

58555858
fn parse_impl_body(&mut self) -> PResult<'a, (Vec<ImplItem>, Vec<Attribute>)> {
@@ -5882,7 +5885,7 @@ impl<'a> Parser<'a> {
58825885
fn parse_item_impl(&mut self, unsafety: Unsafety, defaultness: Defaultness)
58835886
-> PResult<'a, ItemInfo> {
58845887
// First, parse generic parameters if necessary.
5885-
let mut generics = if self.choose_generics_over_qpath() {
5888+
let mut generics = if self.choose_generics_over_qpath(true) {
58865889
self.parse_generics()?
58875890
} else {
58885891
ast::Generics::default()

0 commit comments

Comments
 (0)