Skip to content

Commit 35dbc5e

Browse files
authored
Rollup merge of rust-lang#60292 - varkor:ty-tuple-substs, r=nikomatsakis
Replace the `&'tcx List<Ty<'tcx>>` in `TyKind::Tuple` with `SubstsRef<'tcx>` Part of the suggested refactoring for rust-lang#42340. As expected, this is a little messy, because there are many places that the components of tuples are expected to be types, rather than arbitrary kinds. However, it should open up the way for a refactoring of `TyS` itself. r? @nikomatsakis
2 parents d4a32d5 + a3470c6 commit 35dbc5e

File tree

41 files changed

+146
-93
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+146
-93
lines changed

src/librustc/mir/tcx.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ impl<'a, 'gcx, 'tcx> PlaceTy<'tcx> {
4747
let field_def = &variant_def.fields[f.index()];
4848
field_def.ty(tcx, substs)
4949
}
50-
ty::Tuple(ref tys) => tys[f.index()],
50+
ty::Tuple(ref tys) => tys[f.index()].expect_ty(),
5151
_ => bug!("extracting field of non-tuple non-adt: {:?}", self),
5252
};
5353
debug!("field_ty self: {:?} f: {:?} yields: {:?}", self, f, answer);

src/librustc/traits/error_reporting.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -875,7 +875,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
875875
let expected_ty = expected_trait_ref.skip_binder().substs.type_at(1);
876876
let expected = match expected_ty.sty {
877877
ty::Tuple(ref tys) => tys.iter()
878-
.map(|t| ArgKind::from_expected_ty(t, Some(span))).collect(),
878+
.map(|t| ArgKind::from_expected_ty(t.expect_ty(), Some(span))).collect(),
879879
_ => vec![ArgKind::Arg("_".to_owned(), expected_ty.to_string())],
880880
};
881881

@@ -1247,7 +1247,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
12471247
let inputs = trait_ref.substs.type_at(1);
12481248
let sig = if let ty::Tuple(inputs) = inputs.sty {
12491249
tcx.mk_fn_sig(
1250-
inputs.iter().cloned(),
1250+
inputs.iter().map(|k| k.expect_ty()),
12511251
tcx.mk_infer(ty::TyVar(ty::TyVid { index: 0 })),
12521252
false,
12531253
hir::Unsafety::Normal,

src/librustc/traits/query/dropck_outlives.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ pub fn trivial_dropck_outlives<'tcx>(tcx: TyCtxt<'_, '_, 'tcx>, ty: Ty<'tcx>) ->
217217

218218
// (T1..Tn) and closures have same properties as T1..Tn --
219219
// check if *any* of those are trivial.
220-
ty::Tuple(ref tys) => tys.iter().all(|t| trivial_dropck_outlives(tcx, t)),
220+
ty::Tuple(ref tys) => tys.iter().all(|t| trivial_dropck_outlives(tcx, t.expect_ty())),
221221
ty::Closure(def_id, ref substs) => substs
222222
.upvar_tys(def_id, tcx)
223223
.all(|t| trivial_dropck_outlives(tcx, t)),

src/librustc/traits/select.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2429,7 +2429,9 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
24292429

24302430
ty::Str | ty::Slice(_) | ty::Dynamic(..) | ty::Foreign(..) => None,
24312431

2432-
ty::Tuple(tys) => Where(ty::Binder::bind(tys.last().into_iter().cloned().collect())),
2432+
ty::Tuple(tys) => {
2433+
Where(ty::Binder::bind(tys.last().into_iter().map(|k| k.expect_ty()).collect()))
2434+
}
24332435

24342436
ty::Adt(def, substs) => {
24352437
let sized_crit = def.sized_constraint(self.tcx());
@@ -2503,7 +2505,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
25032505

25042506
ty::Tuple(tys) => {
25052507
// (*) binder moved here
2506-
Where(ty::Binder::bind(tys.to_vec()))
2508+
Where(ty::Binder::bind(tys.iter().map(|k| k.expect_ty()).collect()))
25072509
}
25082510

25092511
ty::Closure(def_id, substs) => {
@@ -2590,7 +2592,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
25902592

25912593
ty::Tuple(ref tys) => {
25922594
// (T1, ..., Tn) -- meets any bound that all of T1...Tn meet
2593-
tys.to_vec()
2595+
tys.iter().map(|k| k.expect_ty()).collect()
25942596
}
25952597

25962598
ty::Closure(def_id, ref substs) => substs.upvar_tys(def_id, self.tcx()).collect(),
@@ -3495,7 +3497,9 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
34953497

34963498
// Check that the source tuple with the target's
34973499
// last element is equal to the target.
3498-
let new_tuple = tcx.mk_tup(a_mid.iter().cloned().chain(iter::once(b_last)));
3500+
let new_tuple = tcx.mk_tup(
3501+
a_mid.iter().map(|k| k.expect_ty()).chain(iter::once(b_last.expect_ty())),
3502+
);
34993503
let InferOk { obligations, .. } = self.infcx
35003504
.at(&obligation.cause, obligation.param_env)
35013505
.eq(target, new_tuple)
@@ -3508,7 +3512,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
35083512
obligation.cause.clone(),
35093513
obligation.predicate.def_id(),
35103514
obligation.recursion_depth + 1,
3511-
a_last,
3515+
a_last.expect_ty(),
35123516
&[b_last.into()],
35133517
));
35143518
}

src/librustc/ty/context.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2431,7 +2431,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
24312431
let converted_sig = sig.map_bound(|s| {
24322432
let params_iter = match s.inputs()[0].sty {
24332433
ty::Tuple(params) => {
2434-
params.into_iter().cloned()
2434+
params.into_iter().map(|k| k.expect_ty())
24352435
}
24362436
_ => bug!(),
24372437
};
@@ -2573,11 +2573,15 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
25732573

25742574
#[inline]
25752575
pub fn intern_tup(self, ts: &[Ty<'tcx>]) -> Ty<'tcx> {
2576-
self.mk_ty(Tuple(self.intern_type_list(ts)))
2576+
let kinds: Vec<_> = ts.into_iter().map(|&t| Kind::from(t)).collect();
2577+
self.mk_ty(Tuple(self.intern_substs(&kinds)))
25772578
}
25782579

25792580
pub fn mk_tup<I: InternAs<[Ty<'tcx>], Ty<'tcx>>>(self, iter: I) -> I::Output {
2580-
iter.intern_with(|ts| self.mk_ty(Tuple(self.intern_type_list(ts))))
2581+
iter.intern_with(|ts| {
2582+
let kinds: Vec<_> = ts.into_iter().map(|&t| Kind::from(t)).collect();
2583+
self.mk_ty(Tuple(self.intern_substs(&kinds)))
2584+
})
25812585
}
25822586

25832587
#[inline]

src/librustc/ty/flags.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,8 @@ impl FlagComputation {
195195
self.add_ty(ty);
196196
}
197197

198-
&ty::Tuple(ref ts) => {
199-
self.add_tys(&ts[..]);
198+
&ty::Tuple(ref substs) => {
199+
self.add_substs(substs);
200200
}
201201

202202
&ty::FnDef(_, substs) => {

src/librustc/ty/inhabitedness/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> {
181181

182182
Tuple(ref tys) => {
183183
DefIdForest::union(tcx, tys.iter().map(|ty| {
184-
ty.uninhabited_from(tcx)
184+
ty.expect_ty().uninhabited_from(tcx)
185185
}))
186186
}
187187

src/librustc/ty/layout.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -626,8 +626,9 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
626626
StructKind::MaybeUnsized
627627
};
628628

629-
univariant(&tys.iter().map(|ty| self.layout_of(ty)).collect::<Result<Vec<_>, _>>()?,
630-
&ReprOptions::default(), kind)?
629+
univariant(&tys.iter().map(|k| {
630+
self.layout_of(k.expect_ty())
631+
}).collect::<Result<Vec<_>, _>>()?, &ReprOptions::default(), kind)?
631632
}
632633

633634
// SIMD vector types.
@@ -1723,7 +1724,7 @@ impl<'a, 'tcx, C> TyLayoutMethods<'tcx, C> for Ty<'tcx>
17231724
substs.field_tys(def_id, tcx).nth(i).unwrap()
17241725
}
17251726

1726-
ty::Tuple(tys) => tys[i],
1727+
ty::Tuple(tys) => tys[i].expect_ty(),
17271728

17281729
// SIMD vector types.
17291730
ty::Adt(def, ..) if def.repr.simd() => {

src/librustc/ty/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2501,7 +2501,7 @@ impl<'a, 'gcx, 'tcx> AdtDef {
25012501
Tuple(ref tys) => {
25022502
match tys.last() {
25032503
None => vec![],
2504-
Some(ty) => self.sized_constraint_for_ty(tcx, ty)
2504+
Some(ty) => self.sized_constraint_for_ty(tcx, ty.expect_ty()),
25052505
}
25062506
}
25072507

src/librustc/ty/print/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ pub fn characteristic_def_id_of_type(ty: Ty<'_>) -> Option<DefId> {
264264
ty::Ref(_, ty, _) => characteristic_def_id_of_type(ty),
265265

266266
ty::Tuple(ref tys) => tys.iter()
267-
.filter_map(|ty| characteristic_def_id_of_type(ty))
267+
.filter_map(|ty| characteristic_def_id_of_type(ty.expect_ty()))
268268
.next(),
269269

270270
ty::FnDef(def_id, _) |

0 commit comments

Comments
 (0)