|
4 | 4 | //! We walk the set of items and, for each member, generate new constraints.
|
5 | 5 |
|
6 | 6 | use hir::def_id::DefId;
|
7 |
| -use rustc::ty::subst::{UnpackedKind, SubstsRef}; |
| 7 | +use rustc::mir::interpret::ConstValue; |
| 8 | +use rustc::ty::subst::{SubstsRef, UnpackedKind}; |
8 | 9 | use rustc::ty::{self, Ty, TyCtxt};
|
9 | 10 | use rustc::hir;
|
10 | 11 | use rustc::hir::itemlikevisit::ItemLikeVisitor;
|
@@ -229,12 +230,19 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
|
229 | 230 |
|
230 | 231 | // Trait are always invariant so we can take advantage of that.
|
231 | 232 | let variance_i = self.invariant(variance);
|
232 |
| - for ty in substs.types() { |
233 |
| - self.add_constraints_from_ty(current, ty, variance_i); |
234 |
| - } |
235 | 233 |
|
236 |
| - for region in substs.regions() { |
237 |
| - self.add_constraints_from_region(current, region, variance_i); |
| 234 | + for k in substs { |
| 235 | + match k.unpack() { |
| 236 | + UnpackedKind::Lifetime(lt) => { |
| 237 | + self.add_constraints_from_region(current, lt, variance_i) |
| 238 | + } |
| 239 | + UnpackedKind::Type(ty) => { |
| 240 | + self.add_constraints_from_ty(current, ty, variance_i) |
| 241 | + } |
| 242 | + UnpackedKind::Const(ct) => { |
| 243 | + self.add_constraints_from_const(current, ct, variance_i) |
| 244 | + } |
| 245 | + } |
238 | 246 | }
|
239 | 247 | }
|
240 | 248 |
|
@@ -267,7 +275,11 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
|
267 | 275 | self.add_constraints_from_mt(current, &ty::TypeAndMut { ty, mutbl }, variance);
|
268 | 276 | }
|
269 | 277 |
|
270 |
| - ty::Array(typ, _) | |
| 278 | + ty::Array(typ, len) => { |
| 279 | + self.add_constraints_from_ty(current, typ, variance); |
| 280 | + self.add_constraints_from_const(current, len, variance); |
| 281 | + } |
| 282 | + |
271 | 283 | ty::Slice(typ) => {
|
272 | 284 | self.add_constraints_from_ty(current, typ, variance);
|
273 | 285 | }
|
@@ -383,6 +395,9 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
|
383 | 395 | UnpackedKind::Type(ty) => {
|
384 | 396 | self.add_constraints_from_ty(current, ty, variance_i)
|
385 | 397 | }
|
| 398 | + UnpackedKind::Const(ct) => { |
| 399 | + self.add_constraints_from_const(current, ct, variance_i) |
| 400 | + } |
386 | 401 | }
|
387 | 402 | }
|
388 | 403 | }
|
@@ -434,6 +449,26 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
|
434 | 449 | }
|
435 | 450 | }
|
436 | 451 |
|
| 452 | + fn add_constraints_from_const( |
| 453 | + &mut self, |
| 454 | + current: &CurrentItem, |
| 455 | + ct: &ty::LazyConst<'tcx>, |
| 456 | + variance: VarianceTermPtr<'a> |
| 457 | + ) { |
| 458 | + debug!( |
| 459 | + "add_constraints_from_const(ct={:?}, variance={:?})", |
| 460 | + ct, |
| 461 | + variance |
| 462 | + ); |
| 463 | + |
| 464 | + if let ty::LazyConst::Evaluated(ct) = ct { |
| 465 | + self.add_constraints_from_ty(current, ct.ty, variance); |
| 466 | + if let ConstValue::Param(ref data) = ct.val { |
| 467 | + self.add_constraint(current, data.index, variance); |
| 468 | + } |
| 469 | + } |
| 470 | + } |
| 471 | + |
437 | 472 | /// Adds constraints appropriate for a mutability-type pair
|
438 | 473 | /// appearing in a context with ambient variance `variance`
|
439 | 474 | fn add_constraints_from_mt(&mut self,
|
|
0 commit comments