Skip to content

Commit bfdc677

Browse files
committed
Fill in more stubs
1 parent 2704f5b commit bfdc677

File tree

19 files changed

+88
-67
lines changed

19 files changed

+88
-67
lines changed

src/librustc/infer/canonical/query_result.rs

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -502,29 +502,36 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
502502
Box::new(
503503
unsubstituted_region_constraints
504504
.iter()
505-
.map(move |constraint| {
505+
.filter_map(move |constraint| {
506506
let ty::OutlivesPredicate(k1, r2) = constraint.skip_binder(); // restored below
507507
let k1 = substitute_value(self.tcx, result_subst, k1);
508508
let r2 = substitute_value(self.tcx, result_subst, r2);
509509
match k1.unpack() {
510-
UnpackedKind::Lifetime(r1) => Obligation::new(
511-
cause.clone(),
512-
param_env,
513-
ty::Predicate::RegionOutlives(ty::Binder::dummy(
514-
ty::OutlivesPredicate(r1, r2),
515-
)),
516-
),
517-
518-
UnpackedKind::Type(t1) => Obligation::new(
519-
cause.clone(),
520-
param_env,
521-
ty::Predicate::TypeOutlives(ty::Binder::dummy(ty::OutlivesPredicate(
522-
t1, r2,
523-
))),
524-
),
525-
526-
// TODO(const_generics): does it even make sense to specify that a const outlives something?
527-
UnpackedKind::Const(_) => unimplemented!(),
510+
UnpackedKind::Lifetime(r1) => {
511+
Some(Obligation::new(
512+
cause.clone(),
513+
param_env,
514+
ty::Predicate::RegionOutlives(ty::Binder::dummy(
515+
ty::OutlivesPredicate(r1, r2),
516+
)),
517+
))
518+
}
519+
520+
UnpackedKind::Type(t1) => {
521+
Some(Obligation::new(
522+
cause.clone(),
523+
param_env,
524+
ty::Predicate::TypeOutlives(ty::Binder::dummy(ty::OutlivesPredicate(
525+
t1, r2,
526+
))),
527+
))
528+
}
529+
530+
UnpackedKind::Const(_) => {
531+
// Consts cannot outlive one another, so we don't have to do anything
532+
// in this case.
533+
None
534+
}
528535
}
529536
}),
530537
) as Box<dyn Iterator<Item = _>>

src/librustc/middle/resolve_lifetime.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,6 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
936936
}
937937
}
938938
GenericParamKind::Const { ref ty, .. } => {
939-
// TODO(const_generics): should we be walking the bounds?
940939
walk_list!(self, visit_param_bound, &param.bounds);
941940
self.visit_ty(&ty);
942941
}

src/librustc/ty/error.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,20 @@ impl<'tcx> fmt::Display for TypeError<'tcx> {
176176
OldStyleLUB(ref err) => {
177177
write!(f, "{}", err)
178178
}
179-
ConstError(..) => {
180-
unreachable!() // TODO(const_generics)
179+
ConstError(ref err) => {
180+
write!(f, "{}", err)
181+
}
182+
}
183+
}
184+
}
185+
186+
impl<'tcx> fmt::Display for ConstError<'tcx> {
187+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
188+
use self::ConstError::*;
189+
190+
match *self {
191+
Mismatch(ref values) => {
192+
write!(f, "expected `{:?}`, found `{:?}`", values.expected, values.found)
181193
}
182194
}
183195
}

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): double-check wrt `Param`
143+
// TODO(const_generics): `Param/Infer` case
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` case
219+
// TODO(const_generics): `Param/Infer` case
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/util/ppaux.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,13 +1244,9 @@ define_print! {
12441244
Array(ty, sz) => {
12451245
print!(f, cx, write("["), print(ty), write("; "))?;
12461246
match sz.val {
1247-
ConstValue::Unevaluated(_def_id, _substs) => {
1248-
write!(f, "_")?;
1249-
}
1250-
_ => ty::tls::with(|tcx| {
1251-
// TODO(const_generics): check wrt `Param`
1252-
write!(f, "{}", sz.unwrap_usize(tcx))
1253-
})?,
1247+
ConstValue::Unevaluated(..) | ConstValue::Infer(..) => write!(f, "_")?,
1248+
ConstValue::Param(ParamConst { name, .. }) => write!(f, "{}", name)?,
1249+
_ => ty::tls::with(|tcx| write!(f, "{}", sz.unwrap_usize(tcx)))?,
12541250
}
12551251
write!(f, "]")
12561252
}
@@ -1277,9 +1273,9 @@ define_print! {
12771273
('tcx) ConstValue<'tcx>, (self, f, cx) {
12781274
display {
12791275
match self {
1280-
ConstValue::Unevaluated(..) => write!(f, "_"),
1276+
ConstValue::Unevaluated(..) | ConstValue::Infer(..) => write!(f, "_"),
12811277
ConstValue::Param(ParamConst { name, .. }) => write!(f, "{}", name),
1282-
_ => write!(f, "{:?}", self), // TODO(const_generics)
1278+
_ => write!(f, "{:?}", self),
12831279
}
12841280
}
12851281
}

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): check wrt `Param`
160+
// TODO(const_generics): `Param/Infer` case
161161
_ => Ok(constant),
162162
}
163163
}

src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -490,9 +490,9 @@ impl<'tcx> RegionInferenceContext<'tcx> {
490490
}
491491

492492
/// We've found an enum/struct/union type with the substitutions
493-
/// `substs` and -- in the HIR -- a path with the generic
494-
/// arguments `args`. If `needle_fr` appears in the args, return
495-
/// the `hir::Lifetime` that corresponds to it. If not, push onto
493+
/// `substs` and, in the HIR, a path with the generic arguments
494+
/// `args`. If `needle_fr` appears in the args, return the
495+
/// `hir::Lifetime` that corresponds to it. If not, push on to
496496
/// `search_stack` the types+hir to search through.
497497
fn try_match_adt_and_generic_args<'hir>(
498498
&self,
@@ -514,7 +514,8 @@ impl<'tcx> RegionInferenceContext<'tcx> {
514514
}
515515

516516
(UnpackedKind::Const(_ct), hir::GenericArg::Const(_hir_ct)) => {
517-
unimplemented!() // TODO(const_generics)
517+
// Lifetimes cannot be found in consts, so we don't need
518+
// to search anything here.
518519
}
519520

520521
(UnpackedKind::Lifetime(_), _)

src/librustc_mir/borrow_check/nll/type_check/constraint_conversion.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ impl<'a, 'gcx, 'tcx> ConstraintConversion<'a, 'gcx, 'tcx> {
131131
}
132132

133133
UnpackedKind::Const(_c1) => {
134-
unimplemented!() // TODO(const_generics)
134+
// Consts cannot outlive one another, so we
135+
// don't need to handle any relations here.
135136
}
136137
}
137138
}

src/librustc_typeck/astconv.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1530,7 +1530,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
15301530
hir::TyKind::Array(ref ty, ref length) => {
15311531
let length_def_id = tcx.hir.local_def_id(length.id);
15321532
let substs = Substs::identity_for_item(tcx, length_def_id);
1533-
// TODO(const_generics): const param?
1533+
// TODO(const_generics): `Param/Infer` case
15341534
let length = ty::Const::unevaluated(tcx, length_def_id, substs, tcx.types.usize);
15351535
let array_ty = tcx.mk_ty(ty::Array(self.ast_ty_to_ty(&ty), length));
15361536
self.normalize_ty(ast_ty.span, array_ty)
@@ -1559,23 +1559,25 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
15591559
result_ty
15601560
}
15611561

1562-
pub fn ast_const_to_const(&self, ast_const: &hir::ConstArg, ty: Ty<'tcx>) -> &'tcx ty::Const<'tcx> {
1562+
pub fn ast_const_to_const(
1563+
&self,
1564+
ast_const: &hir::ConstArg,
1565+
ty: Ty<'tcx>
1566+
) -> &'tcx ty::Const<'tcx> {
15631567
debug!("ast_const_to_const(id={:?}, ast_ty={:?})", ast_const.value.id, ast_const);
15641568
let tcx = self.tcx();
15651569
let def_id = tcx.hir.local_def_id(ast_const.value.id);
15661570

15671571
let const_val = ConstValue::Unevaluated(def_id, Substs::identity_for_item(tcx, def_id));
15681572
// TODO(const_generics)
1569-
/*if let hir::Expr_::ExprPath(hir::QPath::Resolved(None, ref path)) = ast_const.node {
1573+
/*if let hir::ExprKind::Path(hir::QPath::Resolved(None, ref path)) = ast_const.value.node {
15701574
if let Def::ConstParam(def_id) = path.def {
1571-
self.prohibit_type_params(&path.segments);
1572-
15731575
let node_id = tcx.hir.as_local_node_id(def_id).unwrap();
15741576
let item_id = tcx.hir.get_parent_node(node_id);
15751577
let item_def_id = tcx.hir.local_def_id(item_id);
15761578
let generics = tcx.generics_of(item_def_id);
1577-
let index = generics.const_param_to_index[&tcx.hir.local_def_id(node_id)];
1578-
const_val = ConstValue::Param(ParamConst::new(index, tcx.hir.name(node_id)));
1579+
let index = generics.param_def_id_to_index[&tcx.hir.local_def_id(node_id)];
1580+
const_val = ConstValue::Param(ParamConst::new(index, tcx.hir.name(node_id).as_interned_str()));
15791581
}
15801582
}*/
15811583

0 commit comments

Comments
 (0)